use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project jetcache by alibaba.
the class MultiLevelCacheMixTest method testWithJedis.
@Test
public void testWithJedis() {
l1Cache = CaffeineCacheBuilder.createCaffeineCacheBuilder().limit(10).expireAfterWrite(1000, TimeUnit.MILLISECONDS).keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
GenericObjectPoolConfig pc = new GenericObjectPoolConfig();
pc.setMinIdle(1);
pc.setMaxIdle(1);
pc.setMaxTotal(2);
JedisPool pool = new JedisPool(pc, "localhost", 6379);
l2Cache = RedisCacheBuilder.createRedisCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).valueEncoder(JavaValueEncoder.INSTANCE).valueDecoder(JavaValueDecoder.INSTANCE).jedisPool(pool).keyPrefix(new Random().nextInt() + "").expireAfterWrite(1000, TimeUnit.MILLISECONDS).buildCache();
cache = MultiLevelCacheBuilder.createMultiLevelCacheBuilder().addCache(l1Cache, l2Cache).buildCache();
testImpl();
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project jstorm by alibaba.
the class RedisSinkBolt method prepare.
@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
this.collector = collector;
GenericObjectPoolConfig pconf = new GenericObjectPoolConfig();
pconf.setMaxWaitMillis(2000);
pconf.setMaxTotal(1000);
pconf.setTestOnBorrow(false);
pconf.setTestOnReturn(false);
pconf.setTestWhileIdle(true);
pconf.setMinEvictableIdleTimeMillis(120000);
pconf.setTimeBetweenEvictionRunsMillis(60000);
pconf.setNumTestsPerEvictionRun(-1);
pool = new JedisPool(pconf, redisHost, redisPort, timeout);
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project new-cloud by xie-summer.
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.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project new-cloud by xie-summer.
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.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project new-cloud by xie-summer.
the class ShardedJedisPoolTest method checkPoolOverflow.
@Test(expected = JedisConnectionException.class)
public void checkPoolOverflow() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
ShardedJedisPool pool = new ShardedJedisPool(config, shards);
ShardedJedis jedis = pool.getResource();
jedis.set("foo", "0");
ShardedJedis newJedis = pool.getResource();
newJedis.incr("foo");
}
Aggregations