Merge branch 'master' of https://github.com/gcasanova/tutorials into gcasanova-master

This commit is contained in:
Zeger Hendrikse 2016-07-08 01:20:12 +02:00
commit 16a9492017
1 changed files with 23 additions and 23 deletions

View File

@ -31,13 +31,13 @@ public class JedisTest {
public JedisTest() { public JedisTest() {
jedis = new Jedis(); jedis = new Jedis();
} }
@BeforeClass @BeforeClass
public static void setUp() throws IOException { public static void setUp() throws IOException {
redisServer = new RedisServer(6379); redisServer = new RedisServer(6379);
redisServer.start(); redisServer.start();
} }
@AfterClass @AfterClass
public static void destroy() { public static void destroy() {
redisServer.stop(); redisServer.stop();
@ -186,15 +186,15 @@ public class JedisTest {
Assert.assertTrue(pipeExists.get()); Assert.assertTrue(pipeExists.get());
Assert.assertEquals(2, pipeRanking.get().size()); Assert.assertEquals(2, pipeRanking.get().size());
} }
@Test @Test
public void givenAPoolConfigurationThenCreateAJedisPool() { public void givenAPoolConfigurationThenCreateAJedisPool() {
final JedisPoolConfig poolConfig = buildPoolConfig(); final JedisPoolConfig poolConfig = buildPoolConfig();
try (JedisPool jedisPool = new JedisPool(poolConfig, "localhost"); try (JedisPool jedisPool = new JedisPool(poolConfig, "localhost"); Jedis jedis = jedisPool.getResource()) {
Jedis jedis = jedisPool.getResource()) {
// do simple operation to verify that the Jedis resource is working
// do simple operation to verify that the Jedis resource is working properly // properly
String key = "key"; String key = "key";
String value = "value"; String value = "value";
@ -202,24 +202,24 @@ public class JedisTest {
String value2 = jedis.get(key); String value2 = jedis.get(key);
Assert.assertEquals(value, value2); Assert.assertEquals(value, value2);
// flush Redis // flush Redis
jedis.flushAll(); jedis.flushAll();
} }
} }
private JedisPoolConfig buildPoolConfig() { private JedisPoolConfig buildPoolConfig() {
final JedisPoolConfig poolConfig = new JedisPoolConfig(); final JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(128); poolConfig.setMaxTotal(128);
poolConfig.setMaxIdle(128); poolConfig.setMaxIdle(128);
poolConfig.setMinIdle(16); poolConfig.setMinIdle(16);
poolConfig.setTestOnBorrow(true); poolConfig.setTestOnBorrow(true);
poolConfig.setTestOnReturn(true); poolConfig.setTestOnReturn(true);
poolConfig.setTestWhileIdle(true); poolConfig.setTestWhileIdle(true);
poolConfig.setMinEvictableIdleTimeMillis(Duration.ofSeconds(60).toMillis()); poolConfig.setMinEvictableIdleTimeMillis(Duration.ofSeconds(60).toMillis());
poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofSeconds(30).toMillis()); poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofSeconds(30).toMillis());
poolConfig.setNumTestsPerEvictionRun(3); poolConfig.setNumTestsPerEvictionRun(3);
poolConfig.setBlockWhenExhausted(true); poolConfig.setBlockWhenExhausted(true);
return poolConfig; return poolConfig;
} }
} }