Guard non-initialized RedisConnectionFactory.getConnection() with IllegalStateException.
Obtaining a Connection from RedisConnectionFactory and its reactive variant is now guarded by IllegalStateException that is thrown if the connection factory was not yet initialized. Previously, connections could be obtained where configuration was partially applied. Closes #2057
This commit is contained in:
@@ -90,6 +90,7 @@ class JedisConnectionFactorySentinelIntegrationTests {
|
||||
.sentinel("127.0.0.1", 1).sentinel("127.0.0.1", 26379);
|
||||
|
||||
factory = new JedisConnectionFactory(oneDownSentinelConfig);
|
||||
factory.afterPropertiesSet();
|
||||
assertThat(factory.getSentinelConnection().isOpen()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,6 +346,16 @@ class JedisConnectionFactoryUnitTests {
|
||||
assertThatIllegalStateException().isThrownBy(() -> connectionFactory.setClientName("foo"));
|
||||
}
|
||||
|
||||
@Test // GH-2057
|
||||
void getConnectionShouldFailIfNotInitialized() {
|
||||
|
||||
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getConnection);
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getClusterConnection);
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getSentinelConnection);
|
||||
}
|
||||
|
||||
private JedisConnectionFactory initSpyedConnectionFactory(RedisSentinelConfiguration sentinelConfig,
|
||||
JedisPoolConfig poolConfig) {
|
||||
|
||||
|
||||
@@ -1011,7 +1011,19 @@ class LettuceConnectionFactoryUnitTests {
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getRequiredNativeClient)
|
||||
.withMessageContaining("Client not yet initialized");
|
||||
.withMessageContaining("was not initialized through");
|
||||
}
|
||||
|
||||
@Test // GH-2057
|
||||
void getConnectionShouldFailIfNotInitialized() {
|
||||
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getConnection);
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getClusterConnection);
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getSentinelConnection);
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getReactiveConnection);
|
||||
assertThatIllegalStateException().isThrownBy(connectionFactory::getReactiveClusterConnection);
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
Reference in New Issue
Block a user