use of redis.clients.jedis.JedisPoolConfig 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.JedisPoolConfig 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.JedisPoolConfig in project jedis by xetorthio.
the class ClusterBinaryJedisCommandsTest method setUp.
@Before
public void setUp() throws InterruptedException {
node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
node1.auth("cluster");
node1.flushAll();
node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort());
node2.auth("cluster");
node2.flushAll();
node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort());
node3.auth("cluster");
node3.flushAll();
// ---- configure cluster
// add nodes to cluster
node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
node1.clusterMeet("127.0.0.1", nodeInfo3.getPort());
// split available slots across the three nodes
int slotsPerNode = JedisCluster.HASHSLOTS / 3;
int[] node1Slots = new int[slotsPerNode];
int[] node2Slots = new int[slotsPerNode + 1];
int[] node3Slots = new int[slotsPerNode];
for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) {
if (i < slotsPerNode) {
node1Slots[slot1++] = i;
} else if (i > slotsPerNode * 2) {
node3Slots[slot3++] = i;
} else {
node2Slots[slot2++] = i;
}
}
node1.clusterAddSlots(node1Slots);
node2.clusterAddSlots(node2Slots);
node3.clusterAddSlots(node3Slots);
waitForClusterReady();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
jedisCluster = new JedisCluster(jedisClusterNode, 2000, 2000, 5, "cluster", new JedisPoolConfig());
}
use of redis.clients.jedis.JedisPoolConfig in project jedis by xetorthio.
the class JedisClusterTest method testReturnConnectionOnJedisConnectionException.
@Test(timeout = DEFAULT_TIMEOUT)
public void testReturnConnectionOnJedisConnectionException() throws InterruptedException {
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
JedisPoolConfig config = DEFAULT_CONFIG;
config.setMaxTotal(1);
JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", config);
Jedis j = jc.getClusterNodes().get("127.0.0.1:7380").getResource();
ClientKillerUtil.tagClient(j, "DEAD");
ClientKillerUtil.killClient(j, "DEAD");
j.close();
jc.get("test");
}
use of redis.clients.jedis.JedisPoolConfig in project jedis by xetorthio.
the class JedisClusterTest method testInvalidStartNodeNotAdded.
@Test
public void testInvalidStartNodeNotAdded() {
HostAndPort invalidHost = new HostAndPort("not-a-real-host", 7379);
Set<HostAndPort> jedisClusterNode = new LinkedHashSet<HostAndPort>();
jedisClusterNode.add(invalidHost);
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
JedisPoolConfig config = DEFAULT_CONFIG;
config.setMaxTotal(1);
JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, DEFAULT_REDIRECTIONS, "cluster", config);
Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
assertEquals(3, clusterNodes.size());
assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(invalidHost)));
}
Aggregations