|
48 | 48 | import org.springframework.data.redis.connection.RedisStaticMasterReplicaConfiguration;
|
49 | 49 | import org.springframework.data.redis.connection.StringRedisConnection;
|
50 | 50 | import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
|
| 51 | +import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable; |
51 | 52 | import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
52 | 53 |
|
53 | 54 | /**
|
@@ -85,7 +86,6 @@ void tearDown() {
|
85 | 86 | factory.destroy();
|
86 | 87 | }
|
87 | 88 |
|
88 |
| - |
89 | 89 | @SuppressWarnings("rawtypes")
|
90 | 90 | @Test
|
91 | 91 | void testGetNewConnectionOnError() throws Exception {
|
@@ -462,9 +462,8 @@ void pubSubDoesNotSupportMasterReplicaConnections() {
|
462 | 462 |
|
463 | 463 | RedisConnection connection = factory.getConnection();
|
464 | 464 |
|
465 |
| - assertThatThrownBy(() -> connection.pSubscribe((message, pattern) -> { |
466 |
| - }, "foo".getBytes())).isInstanceOf(RedisConnectionFailureException.class) |
467 |
| - .hasCauseInstanceOf(UnsupportedOperationException.class); |
| 465 | + assertThatThrownBy(() -> connection.pSubscribe((message, pattern) -> {}, "foo".getBytes())) |
| 466 | + .isInstanceOf(RedisConnectionFailureException.class).hasCauseInstanceOf(UnsupportedOperationException.class); |
468 | 467 |
|
469 | 468 | connection.close();
|
470 | 469 | factory.destroy();
|
@@ -558,4 +557,44 @@ void getClientNameShouldEqualWithFactorySetting() {
|
558 | 557 |
|
559 | 558 | connection.close();
|
560 | 559 | }
|
| 560 | + |
| 561 | + @Test // GH-2186 |
| 562 | + void shouldInitializeMasterReplicaConnectionsEagerly() { |
| 563 | + |
| 564 | + LettuceClientConfiguration configuration = LettuceClientConfiguration.builder() |
| 565 | + .clientResources(LettuceTestClientResources.getSharedClientResources()).build(); |
| 566 | + |
| 567 | + RedisStaticMasterReplicaConfiguration elastiCache = new RedisStaticMasterReplicaConfiguration( |
| 568 | + SettingsUtils.getHost()).node(SettingsUtils.getHost(), SettingsUtils.getPort() + 1); |
| 569 | + |
| 570 | + LettuceConnectionFactory factory = new LettuceConnectionFactory(elastiCache, configuration); |
| 571 | + factory.setEagerInitialization(true); |
| 572 | + factory.afterPropertiesSet(); |
| 573 | + |
| 574 | + assertThat(factory.getSharedConnection()).isNotNull(); |
| 575 | + assertThat(factory.getSharedClusterConnection()).isNull(); |
| 576 | + |
| 577 | + factory.getConnection().close(); |
| 578 | + factory.destroy(); |
| 579 | + } |
| 580 | + |
| 581 | + @Test // GH-2186 |
| 582 | + @EnabledOnRedisClusterAvailable |
| 583 | + void shouldInitializeClusterConnectionsEagerly() { |
| 584 | + |
| 585 | + LettuceClientConfiguration configuration = LettuceClientConfiguration.builder() |
| 586 | + .clientResources(LettuceTestClientResources.getSharedClientResources()).build(); |
| 587 | + |
| 588 | + LettuceConnectionFactory factory = new LettuceConnectionFactory(SettingsUtils.clusterConfiguration(), |
| 589 | + configuration); |
| 590 | + factory.setEagerInitialization(true); |
| 591 | + factory.afterPropertiesSet(); |
| 592 | + |
| 593 | + assertThat(factory.getSharedConnection()).isNull(); |
| 594 | + assertThat(factory.getSharedClusterConnection()).isNotNull(); |
| 595 | + |
| 596 | + factory.getConnection().close(); |
| 597 | + factory.destroy(); |
| 598 | + } |
| 599 | + |
561 | 600 | }
|
0 commit comments