Search in sources :

Example 1 with PoolException

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);
}
Also used : StatefulConnection(io.lettuce.core.api.StatefulConnection) PoolException(org.springframework.data.redis.connection.PoolException)

Example 2 with PoolException

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);
    }
}
Also used : StatefulConnection(io.lettuce.core.api.StatefulConnection) PoolException(org.springframework.data.redis.connection.PoolException) PoolException(org.springframework.data.redis.connection.PoolException)

Example 3 with PoolException

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);
    }
}
Also used : PoolException(org.springframework.data.redis.connection.PoolException) PoolException(org.springframework.data.redis.connection.PoolException)

Example 4 with PoolException

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();
    }
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) PoolException(org.springframework.data.redis.connection.PoolException) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 5 with PoolException

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);
}
Also used : RedisCodec(io.lettuce.core.codec.RedisCodec) AbstractRedisClient(io.lettuce.core.AbstractRedisClient) PoolException(org.springframework.data.redis.connection.PoolException) Test(org.junit.jupiter.api.Test)

Aggregations

PoolException (org.springframework.data.redis.connection.PoolException)5 StatefulConnection (io.lettuce.core.api.StatefulConnection)2 Test (org.junit.jupiter.api.Test)2 AbstractRedisClient (io.lettuce.core.AbstractRedisClient)1 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 RedisCodec (io.lettuce.core.codec.RedisCodec)1 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)1