File tree Expand file tree Collapse 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 Expand file tree Collapse file tree 2 files changed +36
-10
lines changed Original file line number Diff line number Diff line change @@ -299,16 +299,8 @@ public void destroy() {
299
299
300
300
resetConnection ();
301
301
302
- if (connectionProvider instanceof DisposableBean ) {
303
- try {
304
- ((DisposableBean ) connectionProvider ).destroy ();
305
- } catch (Exception e ) {
306
-
307
- if (log .isWarnEnabled ()) {
308
- log .warn (connectionProvider + " did not shut down gracefully." , e );
309
- }
310
- }
311
- }
302
+ dispose (connectionProvider );
303
+ dispose (reactiveConnectionProvider );
312
304
313
305
try {
314
306
Duration quietPeriod = clientConfiguration .getShutdownQuietPeriod ();
@@ -332,6 +324,20 @@ public void destroy() {
332
324
}
333
325
}
334
326
327
+ private void dispose (LettuceConnectionProvider connectionProvider ) {
328
+
329
+ if (connectionProvider instanceof DisposableBean ) {
330
+ try {
331
+ ((DisposableBean ) connectionProvider ).destroy ();
332
+ } catch (Exception e ) {
333
+
334
+ if (log .isWarnEnabled ()) {
335
+ log .warn (connectionProvider + " did not shut down gracefully." , e );
336
+ }
337
+ }
338
+ }
339
+ }
340
+
335
341
/*
336
342
* (non-Javadoc)
337
343
* @see org.springframework.data.redis.connection.RedisConnectionFactory#getConnection()
Original file line number Diff line number Diff line change 48
48
import org .mockito .ArgumentMatchers ;
49
49
50
50
import org .springframework .beans .DirectFieldAccessor ;
51
+ import org .springframework .beans .factory .DisposableBean ;
51
52
import org .springframework .data .redis .ConnectionFactoryTracker ;
52
53
import org .springframework .data .redis .connection .RedisClusterConfiguration ;
53
54
import org .springframework .data .redis .connection .RedisClusterConnection ;
@@ -805,6 +806,25 @@ protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClie
805
806
verify (connectionProviderMock , times (2 )).getConnection (StatefulConnection .class );
806
807
}
807
808
809
+ @ Test // DATAREDIS-1027
810
+ public void shouldDisposeConnectionProviders () throws Exception {
811
+
812
+ LettuceConnectionProvider connectionProviderMock = mock (LettuceConnectionProvider .class ,
813
+ withSettings ().extraInterfaces (DisposableBean .class ));
814
+ LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory () {
815
+ @ Override
816
+ protected LettuceConnectionProvider doCreateConnectionProvider (AbstractRedisClient client ,
817
+ RedisCodec <?, ?> codec ) {
818
+ return connectionProviderMock ;
819
+ }
820
+ };
821
+
822
+ connectionFactory .afterPropertiesSet ();
823
+ connectionFactory .destroy ();
824
+
825
+ verify ((DisposableBean ) connectionProviderMock , times (2 )).destroy ();
826
+ }
827
+
808
828
@ Test // DATAREDIS-842
809
829
public void databaseShouldBeSetCorrectlyOnSentinelClient () {
810
830
You can’t perform that action at this time.
0 commit comments