Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
DATAREDIS-1027 - Dispose reactive LettuceConnectionProvider on connec…
…tion factory shutdown. LettuceConnectionFactory.destroy() now disposes also the reactive LettuceConnectionProvider to free resources of a connection pool.
  • Loading branch information
mp911de committed Aug 15, 2019
commit a68016304cecc2d475774f4a8898f71cecd5daba
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,8 @@ public void destroy() {

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 quietPeriod = clientConfiguration.getShutdownQuietPeriod();
Expand All @@ -332,6 +324,20 @@ public void destroy() {
}
}

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
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;
Expand Down Expand Up @@ -805,6 +806,25 @@ protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClie
verify(connectionProviderMock, times(2)).getConnection(StatefulConnection.class);
}

@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() {

Expand Down