Search in sources :

Example 96 with GenericObjectPoolConfig

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);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) PooledObject(org.apache.commons.pool2.PooledObject) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) PooledObject(org.apache.commons.pool2.PooledObject) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool)

Example 97 with GenericObjectPoolConfig

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());
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) GetExParams(redis.clients.jedis.params.GetExParams) JedisPool(redis.clients.jedis.JedisPool)

Example 98 with GenericObjectPoolConfig

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);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Test(org.testng.annotations.Test)

Example 99 with GenericObjectPoolConfig

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);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Test(org.testng.annotations.Test)

Example 100 with GenericObjectPoolConfig

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());
}
Also used : DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) PooledObjectFactory(org.apache.commons.pool2.PooledObjectFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PooledObject(org.apache.commons.pool2.PooledObject) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) URISyntaxException(java.net.URISyntaxException) JedisException(redis.clients.jedis.exceptions.JedisException) InvalidURIException(redis.clients.jedis.exceptions.InvalidURIException) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Aggregations

GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)222 Test (org.junit.Test)82 Jedis (redis.clients.jedis.Jedis)44 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)43 ShardedJedis (redis.clients.jedis.ShardedJedis)41 JedisPool (redis.clients.jedis.JedisPool)37 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)32 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)21 Bean (org.springframework.context.annotation.Bean)20 ArrayList (java.util.ArrayList)17 JedisShardInfo (redis.clients.jedis.JedisShardInfo)17 Test (org.junit.jupiter.api.Test)15 URI (java.net.URI)12 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)12 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)12 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)11 IOException (java.io.IOException)10 Test (org.testng.annotations.Test)10 PooledObject (org.apache.commons.pool2.PooledObject)9 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)9