use of redis.clients.jedis.JedisPool in project cachecloud by sohutv.
the class JedisPoolTest method testCloseConnectionOnMakeObject.
@Test
public void testCloseConnectionOnMakeObject() {
JedisPoolConfig config = new JedisPoolConfig();
config.setTestOnBorrow(true);
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "wrong pass");
Jedis jedis = new Jedis("redis://:foobared@localhost:6379/");
int currentClientCount = getClientCount(jedis.clientList());
try {
pool.getResource();
fail("Should throw exception as password is incorrect.");
} catch (Exception e) {
assertEquals(currentClientCount, getClientCount(jedis.clientList()));
}
}
use of redis.clients.jedis.JedisPool in project cachecloud by sohutv.
the class JedisPoolTest method allowUrlWithNoDBAndNoPassword.
@Test
public void allowUrlWithNoDBAndNoPassword() throws URISyntaxException {
new JedisPool("redis://localhost:6380");
new JedisPool(new URI("redis://localhost:6380"));
}
use of redis.clients.jedis.JedisPool in project cachecloud by sohutv.
the class JedisPoolTest method checkConnectionWithDefaultPort.
@Test
public void checkConnectionWithDefaultPort() {
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
Jedis jedis = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
jedis.close();
pool.destroy();
assertTrue(pool.isClosed());
}
use of redis.clients.jedis.JedisPool in project cachecloud by sohutv.
the class JedisPoolTest method returnResourceDestroysResourceOnException.
@Test
public void returnResourceDestroysResourceOnException() {
class CrashingJedis extends Jedis {
@Override
public void resetState() {
throw new RuntimeException();
}
}
final AtomicInteger destroyed = new AtomicInteger(0);
class CrashingJedisPooledObjectFactory implements PooledObjectFactory<Jedis> {
@Override
public PooledObject<Jedis> makeObject() throws Exception {
return new DefaultPooledObject<Jedis>(new CrashingJedis());
}
@Override
public void destroyObject(PooledObject<Jedis> p) throws Exception {
destroyed.incrementAndGet();
}
@Override
public boolean validateObject(PooledObject<Jedis> p) {
return true;
}
@Override
public void activateObject(PooledObject<Jedis> p) throws Exception {
}
@Override
public void passivateObject(PooledObject<Jedis> p) throws Exception {
}
}
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");
pool.initPool(config, new CrashingJedisPooledObjectFactory());
Jedis crashingJedis = pool.getResource();
try {
crashingJedis.close();
} catch (Exception ignored) {
}
assertEquals(destroyed.get(), 1);
}
use of redis.clients.jedis.JedisPool in project cachecloud by sohutv.
the class JedisPoolTest method checkPoolOverflow.
@Test(expected = JedisConnectionException.class)
public void checkPoolOverflow() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort());
Jedis jedis = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "0");
Jedis newJedis = pool.getResource();
newJedis.auth("foobared");
newJedis.incr("foo");
}
Aggregations