use of org.springframework.data.redis.connection.PoolException in project spring-data-redis by spring-projects.
the class LettucePoolingConnectionProvider method releaseAsync.
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceConnectionProvider#releaseAsync(io.lettuce.core.api.StatefulConnection)
*/
@Override
public CompletableFuture<Void> releaseAsync(StatefulConnection<?, ?> connection) {
GenericObjectPool<StatefulConnection<?, ?>> blockingPool = poolRef.remove(connection);
if (blockingPool != null) {
log.warn("Releasing asynchronously a connection that was obtained from a non-blocking pool");
blockingPool.returnObject(connection);
return CompletableFuture.completedFuture(null);
}
AsyncPool<StatefulConnection<?, ?>> pool = asyncPoolRef.remove(connection);
if (pool == null) {
return LettuceFutureUtils.failed(new PoolException("Returned connection " + connection + " was either previously returned or does not belong to this connection provider"));
}
return pool.release(connection);
}
use of org.springframework.data.redis.connection.PoolException in project spring-data-redis by spring-projects.
the class LettucePoolingConnectionProvider method getConnection.
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceConnectionProvider#getConnection(java.lang.Class)
*/
@Override
public <T extends StatefulConnection<?, ?>> T getConnection(Class<T> connectionType) {
GenericObjectPool<StatefulConnection<?, ?>> pool = pools.computeIfAbsent(connectionType, poolType -> {
return ConnectionPoolSupport.createGenericObjectPool(() -> connectionProvider.getConnection(connectionType), poolConfig, false);
});
try {
StatefulConnection<?, ?> connection = pool.borrowObject();
poolRef.put(connection, pool);
return connectionType.cast(connection);
} catch (Exception e) {
throw new PoolException("Could not get a resource from the pool", e);
}
}
use of org.springframework.data.redis.connection.PoolException in project spring-data-redis by spring-projects.
the class DefaultLettucePool method destroy.
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.Pool#destroy()
*/
@Override
public void destroy() {
try {
client.shutdown();
internalPool.close();
} catch (Exception e) {
throw new PoolException("Could not destroy the pool", e);
}
}
use of org.springframework.data.redis.connection.PoolException in project spring-data-redis by spring-projects.
the class DefaultLettucePoolTests method testGetResourcePoolExhausted.
@Test
void testGetResourcePoolExhausted() {
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();
try {
pool.getResource();
fail("PoolException should be thrown when pool exhausted");
} catch (PoolException e) {
} finally {
client.close();
}
}
use of org.springframework.data.redis.connection.PoolException in project spring-data-redis by spring-projects.
the class LettuceConnectionFactoryUnitTests method shouldTranslateConnectionException.
// DATAREDIS-1189
@Test
void shouldTranslateConnectionException() {
LettuceConnectionProvider connectionProviderMock = mock(LettuceConnectionProvider.class);
when(connectionProviderMock.getConnection(any())).thenThrow(new PoolException("error!"));
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory() {
@Override
protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClient client, RedisCodec<?, ?> codec) {
return connectionProviderMock;
}
};
connectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
connectionFactory.afterPropertiesSet();
assertThatExceptionOfType(RedisConnectionFailureException.class).isThrownBy(() -> connectionFactory.getConnection().ping()).withCauseInstanceOf(PoolException.class);
}
Aggregations