DATAREDIS-1027 - Dispose reactive LettuceConnectionProvider on connection factory shutdown.
LettuceConnectionFactory.destroy() now disposes also the reactive LettuceConnectionProvider to free resources of a connection pool. Original Pull Request: #470
This commit is contained in:
committed by
Christoph Strobl
parent
104dc8c625
commit
a704358885
@@ -291,16 +291,8 @@ public class LettuceConnectionFactory
|
||||
|
||||
resetConnection();
|
||||
|
||||
if (connectionProvider instanceof DisposableBean) {
|
||||
try {
|
||||
((DisposableBean) connectionProvider).destroy();
|
||||
} catch (Exception e) {
|
||||
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(connectionProvider + " did not shut down gracefully.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
dispose(connectionProvider);
|
||||
dispose(reactiveConnectionProvider);
|
||||
|
||||
try {
|
||||
Duration timeout = clientConfiguration.getShutdownTimeout();
|
||||
@@ -323,6 +315,20 @@ public class LettuceConnectionFactory
|
||||
}
|
||||
}
|
||||
|
||||
private void dispose(LettuceConnectionProvider connectionProvider) {
|
||||
|
||||
if (connectionProvider instanceof DisposableBean) {
|
||||
try {
|
||||
((DisposableBean) connectionProvider).destroy();
|
||||
} catch (Exception e) {
|
||||
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(connectionProvider + " did not shut down gracefully.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisConnectionFactory#getConnection()
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisClusterConnection;
|
||||
@@ -712,6 +713,25 @@ public class LettuceConnectionFactoryUnitTests {
|
||||
verify(connectionMock).close();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1027
|
||||
public void shouldDisposeConnectionProviders() throws Exception {
|
||||
|
||||
LettuceConnectionProvider connectionProviderMock = mock(LettuceConnectionProvider.class,
|
||||
withSettings().extraInterfaces(DisposableBean.class));
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory() {
|
||||
@Override
|
||||
protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClient client,
|
||||
RedisCodec<?, ?> codec) {
|
||||
return connectionProviderMock;
|
||||
}
|
||||
};
|
||||
|
||||
connectionFactory.afterPropertiesSet();
|
||||
connectionFactory.destroy();
|
||||
|
||||
verify((DisposableBean) connectionProviderMock, times(2)).destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-842
|
||||
public void databaseShouldBeSetCorrectlyOnSentinelClient() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user