File tree 2 files changed +36
-10
lines changed
main/java/org/springframework/data/redis/connection/lettuce
test/java/org/springframework/data/redis/connection/lettuce
2 files changed +36
-10
lines changed Original file line number Diff line number Diff line change @@ -291,16 +291,8 @@ public void destroy() {
291
291
292
292
resetConnection ();
293
293
294
- if (connectionProvider instanceof DisposableBean ) {
295
- try {
296
- ((DisposableBean ) connectionProvider ).destroy ();
297
- } catch (Exception e ) {
298
-
299
- if (log .isWarnEnabled ()) {
300
- log .warn (connectionProvider + " did not shut down gracefully." , e );
301
- }
302
- }
303
- }
294
+ dispose (connectionProvider );
295
+ dispose (reactiveConnectionProvider );
304
296
305
297
try {
306
298
Duration timeout = clientConfiguration .getShutdownTimeout ();
@@ -323,6 +315,20 @@ public void destroy() {
323
315
}
324
316
}
325
317
318
+ private void dispose (LettuceConnectionProvider connectionProvider ) {
319
+
320
+ if (connectionProvider instanceof DisposableBean ) {
321
+ try {
322
+ ((DisposableBean ) connectionProvider ).destroy ();
323
+ } catch (Exception e ) {
324
+
325
+ if (log .isWarnEnabled ()) {
326
+ log .warn (connectionProvider + " did not shut down gracefully." , e );
327
+ }
328
+ }
329
+ }
330
+ }
331
+
326
332
/*
327
333
* (non-Javadoc)
328
334
* @see org.springframework.data.redis.connection.RedisConnectionFactory#getConnection()
Original file line number Diff line number Diff line change 45
45
import org .junit .Test ;
46
46
import org .mockito .ArgumentMatchers ;
47
47
import org .springframework .beans .DirectFieldAccessor ;
48
+ import org .springframework .beans .factory .DisposableBean ;
48
49
import org .springframework .data .redis .ConnectionFactoryTracker ;
49
50
import org .springframework .data .redis .connection .RedisClusterConfiguration ;
50
51
import org .springframework .data .redis .connection .RedisClusterConnection ;
@@ -712,6 +713,25 @@ protected AbstractRedisClient createClient() {
712
713
verify (connectionMock ).close ();
713
714
}
714
715
716
+ @ Test // DATAREDIS-1027
717
+ public void shouldDisposeConnectionProviders () throws Exception {
718
+
719
+ LettuceConnectionProvider connectionProviderMock = mock (LettuceConnectionProvider .class ,
720
+ withSettings ().extraInterfaces (DisposableBean .class ));
721
+ LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory () {
722
+ @ Override
723
+ protected LettuceConnectionProvider doCreateConnectionProvider (AbstractRedisClient client ,
724
+ RedisCodec <?, ?> codec ) {
725
+ return connectionProviderMock ;
726
+ }
727
+ };
728
+
729
+ connectionFactory .afterPropertiesSet ();
730
+ connectionFactory .destroy ();
731
+
732
+ verify ((DisposableBean ) connectionProviderMock , times (2 )).destroy ();
733
+ }
734
+
715
735
@ Test // DATAREDIS-842
716
736
public void databaseShouldBeSetCorrectlyOnSentinelClient () {
717
737
You can’t perform that action at this time.
0 commit comments