List of usage examples for org.apache.commons.pool2.impl GenericObjectPool close
@Override public void close()
From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java
@Test public void genericPoolUsingWrappingShouldPropagateExceptionsCorrectly() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig()); StatefulRedisConnection<String, String> connection = pool.borrowObject(); RedisCommands<String, String> sync = connection.sync(); sync.set(key, value);//from www.j ava 2 s . c o m try { sync.hgetall(key); fail("Missing RedisCommandExecutionException"); } catch (RedisCommandExecutionException e) { assertThat(e).hasMessageContaining("WRONGTYPE"); } connection.close(); pool.close(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void tryWithResourcesReturnsConnectionToPool() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig()); StatefulRedisConnection<String, String> usedConnection = null; try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) { RedisCommands<String, String> sync = connection.sync(); sync.ping();/*from w w w.j a v a 2 s .c om*/ usedConnection = connection; } try { usedConnection.isMulti(); fail("Missing RedisException"); } catch (RedisException e) { assertThat(e).hasMessageContaining("deallocated"); } pool.close(); }
From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java
@Test public void genericPoolShouldCloseConnectionsAboveMaxIdleSize() throws Exception { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxIdle(2);/* www. j av a 2 s . co m*/ GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), poolConfig); borrowAndReturn(pool); borrowAndClose(pool); borrowAndCloseTryWithResources(pool); StatefulRedisConnection<String, String> c1 = pool.borrowObject(); StatefulRedisConnection<String, String> c2 = pool.borrowObject(); StatefulRedisConnection<String, String> c3 = pool.borrowObject(); assertThat(channels).hasSize(3); pool.returnObject(c1); pool.returnObject(c2); pool.returnObject(c3); assertThat(channels).hasSize(2); pool.close(); Wait.untilTrue(channels::isEmpty).waitOrTimeout(); assertThat(channels).isEmpty(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void plainConnectionShouldNotUseWrappers() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig(), false); StatefulRedisConnection<String, String> connection = pool.borrowObject(); RedisCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class); assertThat(Proxy.isProxyClass(connection.getClass())).isFalse(); assertThat(sync).isInstanceOf(RedisCommands.class); assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class) .isInstanceOf(RedisAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class) .isInstanceOf(RedisReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class) .isInstanceOf(StatefulRedisConnectionImpl.class); pool.returnObject(connection);/* ww w.j a v a 2 s. c o m*/ pool.close(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void wrappedConnectionShouldUseWrappers() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig()); StatefulRedisConnection<String, String> connection = pool.borrowObject(); RedisCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class); assertThat(Proxy.isProxyClass(connection.getClass())).isTrue(); assertThat(sync).isInstanceOf(RedisCommands.class); assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class) .isNotInstanceOf(RedisAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class) .isNotInstanceOf(RedisReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class) .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection); sync.close();//from w ww. j ava2 s . c o m pool.close(); }
From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java
@Test public void wrappedConnectionShouldUseWrappers() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig()); StatefulRedisConnection<String, String> connection = pool.borrowObject(); RedisCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class); assertThat(Proxy.isProxyClass(connection.getClass())).isTrue(); assertThat(sync).isInstanceOf(RedisCommands.class); assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class) .isNotInstanceOf(RedisAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class) .isNotInstanceOf(RedisReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class) .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection); connection.close();/*from w w w.ja v a 2 s .c o m*/ pool.close(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void wrappedMasterSlaveConnectionShouldUseWrappers() throws Exception { GenericObjectPool<StatefulRedisMasterSlaveConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(/*from w ww.j a v a2 s . c o m*/ () -> MasterSlave.connect(client, new StringCodec(), RedisURI.create(host, port)), new GenericObjectPoolConfig()); StatefulRedisMasterSlaveConnection<String, String> connection = pool.borrowObject(); RedisCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisMasterSlaveConnection.class); assertThat(Proxy.isProxyClass(connection.getClass())).isTrue(); assertThat(sync).isInstanceOf(RedisCommands.class); assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class) .isNotInstanceOf(RedisAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class) .isNotInstanceOf(RedisReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class) .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection); sync.close(); pool.close(); }
From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java
@Test public void wrappedMasterSlaveConnectionShouldUseWrappers() throws Exception { GenericObjectPool<StatefulRedisMasterSlaveConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(//from www . j a v a 2 s .co m () -> MasterSlave.connect(client, new StringCodec(), RedisURI.create(host, port)), new GenericObjectPoolConfig()); StatefulRedisMasterSlaveConnection<String, String> connection = pool.borrowObject(); RedisCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisMasterSlaveConnection.class); assertThat(Proxy.isProxyClass(connection.getClass())).isTrue(); assertThat(sync).isInstanceOf(RedisCommands.class); assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class) .isNotInstanceOf(RedisAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class) .isNotInstanceOf(RedisReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class) .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection); connection.close(); pool.close(); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void wrappedClusterConnectionShouldUseWrappers() throws Exception { RedisClusterClient redisClusterClient = RedisClusterClient.create(TestClientResources.create(), RedisURI.create(TestSettings.host(), 7379)); GenericObjectPool<StatefulRedisClusterConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(redisClusterClient::connect, new GenericObjectPoolConfig()); StatefulRedisClusterConnection<String, String> connection = pool.borrowObject(); RedisAdvancedClusterCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisClusterConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class); assertThat(Proxy.isProxyClass(connection.getClass())).isTrue(); assertThat(sync).isInstanceOf(RedisAdvancedClusterCommands.class); assertThat(connection.async()).isInstanceOf(RedisAdvancedClusterAsyncCommands.class) .isNotInstanceOf(RedisAdvancedClusterAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisAdvancedClusterReactiveCommands.class) .isNotInstanceOf(RedisAdvancedClusterReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisClusterConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class).isSameAs(connection); sync.close();/* ww w. ja v a2 s. com*/ pool.close(); FastShutdown.shutdown(redisClusterClient); }
From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java
@Test public void wrappedClusterConnectionShouldUseWrappers() throws Exception { RedisClusterClient redisClusterClient = RedisClusterClient.create(TestClientResources.get(), RedisURI.create(TestSettings.host(), 7379)); GenericObjectPool<StatefulRedisClusterConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(redisClusterClient::connect, new GenericObjectPoolConfig()); StatefulRedisClusterConnection<String, String> connection = pool.borrowObject(); RedisAdvancedClusterCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisClusterConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class); assertThat(Proxy.isProxyClass(connection.getClass())).isTrue(); assertThat(sync).isInstanceOf(RedisAdvancedClusterCommands.class); assertThat(connection.async()).isInstanceOf(RedisAdvancedClusterAsyncCommands.class) .isNotInstanceOf(RedisAdvancedClusterAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisAdvancedClusterReactiveCommands.class) .isNotInstanceOf(RedisAdvancedClusterReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisClusterConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class).isSameAs(connection); connection.close();//from w ww.ja va2 s. co m pool.close(); FastShutdown.shutdown(redisClusterClient); }