DATAREDIS-953 - Release connection after failed validation only once.

We now release a connection after a failed validation only once. Previously, a connection was released twice which caused a failure if the connection was obtained from a pool.

Original Pull Request: #445
This commit is contained in:
Mark Paluch
2019-03-27 09:51:27 +01:00
committed by Christoph Strobl
parent 138198fd0f
commit 5cd8bb8e27
2 changed files with 27 additions and 5 deletions

View File

@@ -692,6 +692,33 @@ public class LettuceConnectionFactoryUnitTests {
verify(syncMock).ping();
}
@Test // DATAREDIS-953
public void shouldReleaseSharedConnectionOnlyOnce() {
RedisClusterClient clientMock = mock(RedisClusterClient.class);
StatefulRedisClusterConnection<byte[], byte[]> connectionMock = mock(StatefulRedisClusterConnection.class);
when(clientMock.connectAsync(ByteArrayCodec.INSTANCE))
.thenReturn(CompletableFuture.completedFuture(connectionMock));
when(connectionMock.isOpen()).thenReturn(false);
when(connectionMock.closeAsync()).thenReturn(CompletableFuture.completedFuture(null));
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig,
LettuceClientConfiguration.defaultConfiguration()) {
@Override
protected AbstractRedisClient createClient() {
return clientMock;
}
};
connectionFactory.setValidateConnection(true);
connectionFactory.afterPropertiesSet();
connectionFactory.getConnection().close();
verify(connectionMock).closeAsync();
}
@Test // DATAREDIS-721
@SuppressWarnings("unchecked")
public void shouldEagerlyInitializeSharedConnection() {