use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class RedisClusterTest method getPoolConfig.
private GenericObjectPoolConfig getPoolConfig() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL * 20);
poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 20);
poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 10);
// JedisPool.borrowObject最大等待时间
poolConfig.setMaxWaitMillis(1000L);
poolConfig.setJmxNamePrefix("jedis-pool");
poolConfig.setJmxEnabled(true);
return poolConfig;
}
use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class RedisSentinelTest method testSentinelExample.
@Test
public void testSentinelExample() {
JedisSentinelPool sentinelPool = null;
// 使用默认配置
// sentinelPool = ClientBuilder.redisSentinel(appId).build();
/**
* 自定义配置
*/
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 3);
poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE * 2);
poolConfig.setJmxEnabled(true);
poolConfig.setMaxWaitMillis(3000);
sentinelPool = ClientBuilder.redisSentinel(appId).setPoolConfig(poolConfig).setConnectionTimeout(2000).setSoTimeout(1000).build();
Jedis jedis = sentinelPool.getResource();
jedis.set("key1", "1");
assertEquals("2", jedis.incr("key1"));
jedis.close();
}
use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class RedisStandaloneTest method testStandalone.
@Test
public void testStandalone() {
long appId = 10121;
JedisPool jedisPool = ClientBuilder.redisStandalone(appId).setPoolConfig(new GenericObjectPoolConfig()).setTimeout(2000).build();
Jedis jedis = jedisPool.getResource();
for (int i = 0; i < 10; i++) {
jedis.zadd("key-zset", i * 0.1, "value-" + i);
}
Set<String> result = jedis.zrevrangeByScore("key-zset", 2, 0);
for (String s : result) {
logger.info("{}->", s);
}
jedis.close();
jedisPool.destroy();
}
use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class ShardedJedisPoolTest method shouldReturnActiveShardsWhenOneGoesOffline.
@Test
public void shouldReturnActiveShardsWhenOneGoesOffline() {
GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
redisConfig.setTestOnBorrow(false);
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
ShardedJedis jedis = pool.getResource();
// fill the shards
for (int i = 0; i < 1000; i++) {
jedis.set("a-test-" + i, "0");
}
jedis.close();
// check quantity for each shard
Jedis j = new Jedis(shards.get(0));
j.connect();
Long c1 = j.dbSize();
j.disconnect();
j = new Jedis(shards.get(1));
j.connect();
Long c2 = j.dbSize();
j.disconnect();
// shutdown shard 2 and check thay the pool returns an instance with c1
// items on one shard
// alter shard 1 and recreate pool
pool.destroy();
shards.set(1, new JedisShardInfo("localhost", 1234));
pool = new ShardedJedisPool(redisConfig, shards);
jedis = pool.getResource();
Long actual = Long.valueOf(0);
Long fails = Long.valueOf(0);
for (int i = 0; i < 1000; i++) {
try {
jedis.get("a-test-" + i);
actual++;
} catch (RuntimeException e) {
fails++;
}
}
jedis.close();
pool.destroy();
assertEquals(actual, c1);
assertEquals(fails, c2);
}
use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class ShardedJedisPoolTest method checkPoolRepairedWhenJedisIsBroken.
@Test
public void checkPoolRepairedWhenJedisIsBroken() {
ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
ShardedJedis jedis = pool.getResource();
jedis.disconnect();
jedis.close();
jedis = pool.getResource();
jedis.incr("foo");
jedis.close();
pool.destroy();
}
Aggregations