use of redis.clients.jedis.JedisPoolConfig in project jedis by xetorthio.
the class JedisClusterTest method testLocalhostNodeNotAddedWhen127Present.
@Test
public void testLocalhostNodeNotAddedWhen127Present() {
HostAndPort localhost = new HostAndPort("localhost", 7379);
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
// cluster node is defined as 127.0.0.1; adding localhost should work,
// but shouldn't show up.
jedisClusterNode.add(localhost);
JedisPoolConfig config = DEFAULT_CONFIG;
config.setMaxTotal(1);
JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
assertEquals(3, clusterNodes.size());
assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(localhost)));
}
use of redis.clients.jedis.JedisPoolConfig in project jedis by xetorthio.
the class JedisPoolTest method nonDefaultDatabase.
@Test
public void nonDefaultDatabase() {
JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "foobared");
Jedis jedis0 = pool0.getResource();
jedis0.set("foo", "bar");
assertEquals("bar", jedis0.get("foo"));
jedis0.close();
pool0.destroy();
assertTrue(pool0.isClosed());
JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "foobared", 1);
Jedis jedis1 = pool1.getResource();
assertNull(jedis1.get("foo"));
jedis1.close();
pool1.destroy();
assertTrue(pool1.isClosed());
}
use of redis.clients.jedis.JedisPoolConfig in project jedis by xetorthio.
the class JedisPoolTest method checkPoolRepairedWhenJedisIsBroken.
@Test
public void checkPoolRepairedWhenJedisIsBroken() {
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
Jedis jedis = pool.getResource();
jedis.auth("foobared");
jedis.quit();
jedis.close();
jedis = pool.getResource();
jedis.auth("foobared");
jedis.incr("foo");
jedis.close();
pool.destroy();
assertTrue(pool.isClosed());
}
use of redis.clients.jedis.JedisPoolConfig in project jedis by xetorthio.
the class JedisPoolTest method getNumActiveReturnsTheCorrectNumber.
@Test
public void getNumActiveReturnsTheCorrectNumber() {
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
Jedis jedis = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
assertEquals(1, pool.getNumActive());
Jedis jedis2 = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals(2, pool.getNumActive());
jedis.close();
assertEquals(1, pool.getNumActive());
jedis2.close();
assertEquals(0, pool.getNumActive());
pool.destroy();
}
use of redis.clients.jedis.JedisPoolConfig in project jedis by xetorthio.
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()));
}
}
Aggregations