use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project micrometer by micrometer-metrics.
the class CommonsObjectPool2MetricsTest method createGenericObjectPool.
private GenericObjectPool<Object> createGenericObjectPool() {
genericObjectPoolCount++;
GenericObjectPoolConfig<Object> config = new GenericObjectPoolConfig<>();
config.setMaxTotal(10);
return new GenericObjectPool<>(new BasePooledObjectFactory<Object>() {
@Override
public Object create() {
return new Object();
}
@Override
public PooledObject<Object> wrap(Object testObject) {
return new DefaultPooledObject<>(testObject);
}
}, config);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project service-proxy by membrane.
the class RedisConnector method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
GenericObjectPoolConfig jedisPoolConfig = new GenericObjectPoolConfig();
jedisPoolConfig.setMaxTotal(connectionNumber);
jedisPoolConfig.setMaxIdle(connectionNumber);
jedisPoolConfig.setMinIdle(minIdleConnection);
if (user == null && password != null) {
pool = new JedisPool(jedisPoolConfig, host, port, timeout, password, ssl);
} else if (user != null && password != null) {
pool = new JedisPool(jedisPoolConfig, host, port, timeout, user, password, ssl);
} else {
pool = new JedisPool(jedisPoolConfig, host, port, ssl);
}
params = new GetExParams().ex(getTimeout());
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project athenz by AthenZ.
the class DataSourceFactoryTest method testPoolConfigSpecifiedValues.
@Test
public void testPoolConfigSpecifiedValues() {
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL, "10");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE, "20");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE, "30");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT, "40");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, "50");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, "60");
GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig();
assertNotNull(config);
assertEquals(config.getMaxTotal(), 10);
assertEquals(config.getMaxIdle(), 20);
assertEquals(config.getMinIdle(), 30);
assertEquals(config.getMaxWaitMillis(), 40);
assertEquals(config.getMinEvictableIdleTimeMillis(), 50);
assertEquals(config.getTimeBetweenEvictionRunsMillis(), 60);
assertTrue(config.getTestWhileIdle());
assertTrue(config.getTestOnBorrow());
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project athenz by AthenZ.
the class DataSourceFactoryTest method testPoolConfigZeroValues.
@Test
public void testPoolConfigZeroValues() {
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL, "0");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE, "0");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE, "0");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT, "0");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, "0");
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, "0");
GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig();
assertNotNull(config);
// MaxTotal and MaxIdle are set to -1 if the value is 0
assertEquals(config.getMaxTotal(), -1);
assertEquals(config.getMaxIdle(), -1);
assertEquals(config.getMinIdle(), 0);
assertEquals(config.getMaxWaitMillis(), 0);
assertEquals(config.getMinEvictableIdleTimeMillis(), 0);
assertEquals(config.getTimeBetweenEvictionRunsMillis(), 0);
assertTrue(config.getTestWhileIdle());
assertTrue(config.getTestOnBorrow());
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project jedis by redis.
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<Jedis> config = new GenericObjectPoolConfig<>();
config.setMaxTotal(1);
JedisPool pool = new JedisPool(config, new CrashingJedisPooledObjectFactory());
Jedis crashingJedis = pool.getResource();
try {
crashingJedis.close();
} catch (Exception ignored) {
}
assertEquals(1, destroyed.get());
}
Aggregations