Search in sources :

Example 16 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project bboss by bbossgroups.

the class BasicDataSource method createConnectionPool.

/**
 * Creates a connection pool for this datasource.  This method only exists
 * so subclasses can replace the implementation class.
 *
 * This implementation configures all pool properties other than
 * timeBetweenEvictionRunsMillis.  Setting that property is deferred to
 * {@link #startPoolMaintenance()}, since setting timeBetweenEvictionRunsMillis
 * to a positive value causes {@link GenericObjectPool}'s eviction timer
 * to be started.
 */
protected void createConnectionPool(PoolableConnectionFactory factory) {
    // Create an object pool to contain our active connections
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    updateJmxName(config);
    // Disable JMX on the underlying pool if the DS is not registered.
    config.setJmxEnabled(registeredJmxName != null);
    GenericObjectPool<PoolableConnection> gop;
    if (abandonedConfig != null && (abandonedConfig.getRemoveAbandonedOnBorrow() || abandonedConfig.getRemoveAbandonedOnMaintenance() || abandonedConfig.getLogAbandoned())) {
        // 改造实现跟踪功能 biaoping.yin
        gop = new GenericObjectPool<PoolableConnection>(factory, config, abandonedConfig);
    } else {
        gop = new GenericObjectPool<PoolableConnection>(factory, config);
    }
    gop.setMaxTotal(maxTotal);
    gop.setMaxIdle(maxIdle);
    gop.setMinIdle(minIdle);
    gop.setMaxWaitMillis(maxWaitMillis);
    gop.setTestOnCreate(testOnCreate);
    gop.setTestOnBorrow(testOnBorrow);
    gop.setTestOnReturn(testOnReturn);
    gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    gop.setTestWhileIdle(testWhileIdle);
    gop.setLifo(lifo);
    gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log, logExpiredConnections));
    gop.setEvictionPolicyClassName(evictionPolicyClassName);
    factory.setPool(gop);
    connectionPool = gop;
}
Also used : GenericObjectPoolConfig(com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig)

Example 17 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project lettuce-core by lettuce-io.

the class AsyncConnectionPoolSupportIntegrationTests method asyncPoolShouldCloseConnectionsAboveMaxIdleSize.

@Test
void asyncPoolShouldCloseConnectionsAboveMaxIdleSize() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxIdle(2);
    BoundedAsyncPool<StatefulRedisConnection<String, String>> pool = AsyncConnectionPoolSupport.createBoundedObjectPool(() -> client.connectAsync(StringCodec.ASCII, uri), CommonsPool2ConfigConverter.bounded(poolConfig));
    borrowAndReturn(pool);
    borrowAndClose(pool);
    StatefulRedisConnection<String, String> c1 = TestFutures.getOrTimeout(pool.acquire());
    StatefulRedisConnection<String, String> c2 = TestFutures.getOrTimeout(pool.acquire());
    StatefulRedisConnection<String, String> c3 = TestFutures.getOrTimeout(pool.acquire());
    assertThat(channels).hasSize(3);
    CompletableFuture.allOf(pool.release(c1), pool.release(c2), pool.release(c3)).join();
    assertThat(channels).hasSize(2);
    pool.close();
    assertThat(channels).isEmpty();
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 18 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project lettuce-core by lettuce-io.

the class GenericConnectionPoolBenchmark method setup.

@Setup
public void setup() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMinIdle(0);
    config.setMaxIdle(20);
    config.setMaxTotal(20);
    pool = ConnectionPoolSupport.createGenericObjectPool(() -> new EmptyStatefulRedisConnection(EmptyRedisChannelWriter.INSTANCE), config);
}
Also used : EmptyStatefulRedisConnection(io.lettuce.core.EmptyStatefulRedisConnection) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig)

Example 19 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project spring-data-redis by spring-projects.

the class DefaultLettucePoolTests method testReturnResource.

@Test
void testReturnResource() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
    assertThat(client).isNotNull();
    pool.returnResource(client);
    assertThat(pool.getResource()).isNotNull();
    client.close();
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 20 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project spring-data-redis by spring-projects.

the class DefaultLettucePoolTests method testReturnBrokenResource.

@Test
void testReturnBrokenResource() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
    assertThat(client).isNotNull();
    pool.returnBrokenResource(client);
    StatefulRedisConnection<byte[], byte[]> client2 = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
    assertThat(client2).isNotSameAs(client);
    try {
        client.sync().ping();
        fail("Broken resouce connection should be closed");
    } catch (RedisException e) {
    } finally {
        client.close();
        client2.close();
    }
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) RedisException(io.lettuce.core.RedisException) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.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