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 d874aeb84f
commit 4a46d40504
2 changed files with 25 additions and 5 deletions

View File

@@ -1139,12 +1139,7 @@ public class LettuceConnectionFactory
if (!valid) {
if (connection != null) {
connectionProvider.release(connection);
}
log.warn("Validation of shared connection failed. Creating a new connection.");
resetConnection();
this.connection = getNativeConnection();
}

View File

@@ -687,6 +687,31 @@ 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.connect(ByteArrayCodec.INSTANCE)).thenReturn(connectionMock);
when(connectionMock.isOpen()).thenReturn(false);
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig,
LettuceClientConfiguration.defaultConfiguration()) {
@Override
protected AbstractRedisClient createClient() {
return clientMock;
}
};
connectionFactory.setValidateConnection(true);
connectionFactory.afterPropertiesSet();
connectionFactory.getConnection().close();
verify(connectionMock).close();
}
@Test // DATAREDIS-842
public void databaseShouldBeSetCorrectlyOnSentinelClient() {