diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 8b13789..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/test/java/com.bwie.redis/JedisPoolApplicationTests.java b/src/test/java/com.bwie.redis/JedisPoolApplicationTests.java deleted file mode 100644 index 58046c7..0000000 --- a/src/test/java/com.bwie.redis/JedisPoolApplicationTests.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.bwie.redis; - - -import com.bwie.pool.service.impl.MyRedisPool; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import redis.clients.jedis.Jedis; - -import javax.annotation.Resource; -import java.util.concurrent.CountDownLatch; - -@RunWith (SpringRunner.class) -@SpringBootTest -class JedisPoolApplicationTests { - private final static int THREAD_NUM = 50; - private final CountDownLatch cdl = new CountDownLatch (THREAD_NUM); - - @Resource - private MyRedisPool redisPool; - - @Test - void contextLoads () throws Exception { - redisPool.init (45, 2000); - - for (int i = 0; i < THREAD_NUM; i++) { - new Thread (() -> { - try { - System.out.println ("开始收集栅栏里的个体数" + THREAD_NUM); - cdl.await (); // 等待所有线程创建完毕 - } - catch (Exception e) { - throw new RuntimeException (e); - } - - Jedis jedis = null; - - try { - jedis = redisPool.getResource (); - jedis.incr ("poolTest.inr"); - } - catch (Exception e) { - System.out.println ("在运行时出现" + e.getMessage () + "异常"); - } - finally { - redisPool.release (jedis); - } - }).start (); - - cdl.countDown (); // 计数器减一,所有线程同时开始执行 - } - - Thread.sleep (2000); // 主线程休眠2秒,等待所有线程完成操作 - } -} diff --git a/src/test/java/com/bwie/pol/JedisPoolApplicationTests.java b/src/test/java/com/bwie/pol/JedisPoolApplicationTests.java new file mode 100644 index 0000000..79121d2 --- /dev/null +++ b/src/test/java/com/bwie/pol/JedisPoolApplicationTests.java @@ -0,0 +1,52 @@ +package com.bwie.pol; + +import com.bwie.pool.service.impl.MyRedisPool; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import redis.clients.jedis.Jedis; + +import javax.annotation.Resource; +import java.util.concurrent.CountDownLatch; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = MyRedisPool.class) + public class JedisPoolApplicationTests { + private final static int THREAD_NUM=50; + + private final CountDownLatch cdl = new CountDownLatch(THREAD_NUM); + + @Resource + public MyRedisPool redisPool; + + @Test + public void contextLoads() throws Exception{ + redisPool.init(45,2000); + for (int i = 0; i < THREAD_NUM; i++) { + new Thread(() ->{ + try{ + System.out.println("开始收集栅栏里的个体数" + THREAD_NUM); + cdl.await(); // 等待所有线程创建完毕 + } catch (Exception e) { + throw new RuntimeException(e); + } + Jedis jedis = null; + + try{ + jedis = redisPool.getResource(); + jedis.incr("poolTest.inr"); + } catch (Exception e) { + System.out.println("在运行时出现" + e.getMessage() + "异常"); + }finally { + redisPool.release(jedis); + } + }).start(); + + // 计数器减一,所有线程同时开始执行 + cdl.countDown(); + } + // 主线程休眠2秒,等待所有线程完成操作 + Thread.sleep(2000); + } +}