Add "closeable" unit tests to JedisSentinelPool, ShardedJedisPoolTest

This commit is contained in:
Jungtaek Lim
2014-03-16 22:58:26 +09:00
parent 28fdd60f98
commit c0697cd6d7
2 changed files with 29 additions and 0 deletions

View File

@@ -34,6 +34,22 @@ public class JedisSentinelPoolTest extends JedisTestBase {
sentinelJedis1 = new Jedis(sentinel1.getHost(), sentinel1.getPort());
}
@Test
public void checkCloseableConnections() throws Exception {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
Closer closer = new Closer();
JedisSentinelPool pool = closer.register(new JedisSentinelPool(
MASTER_NAME, sentinels, config, 1000, "foobared", 2));
Jedis jedis = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
pool.returnResource(jedis);
closer.close();
assertTrue(pool.isClosed());
}
@Test
public void ensureSafeTwiceFailover() throws InterruptedException {

View File

@@ -54,6 +54,19 @@ public class ShardedJedisPoolTest extends Assert {
pool.destroy();
}
@Test
public void checkCloseableConnections() throws Exception {
Closer closer = new Closer();
ShardedJedisPool pool = closer.register(new ShardedJedisPool(
new GenericObjectPoolConfig(), shards));
ShardedJedis jedis = pool.getResource();
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
pool.returnResource(jedis);
closer.close();
assertTrue(pool.isClosed());
}
@Test
public void checkConnectionWithDefaultPort() {
ShardedJedisPool pool = new ShardedJedisPool(