Polishing.

Deprecate RedisSentinelConfiguration and RedisClusterConfiguration constructors taking PropertySource in favor of a factory method.

Reformat code. Update documentation.

See #2860
Original pull request: #2861
This commit is contained in:
Mark Paluch
2024-03-01 14:10:18 +01:00
parent f9a763e55a
commit 761115ab37
5 changed files with 72 additions and 36 deletions

View File

@@ -83,8 +83,7 @@ class RedisClusterConfigurationUnitTests {
@Test // DATAREDIS-315
void shouldThrowExceptionWhenListOfHostAndPortIsNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new RedisClusterConfiguration(Collections.singleton(null)));
assertThatIllegalArgumentException().isThrownBy(() -> new RedisClusterConfiguration(Collections.singleton(null)));
}
@Test // DATAREDIS-315
@@ -97,13 +96,13 @@ class RedisClusterConfigurationUnitTests {
@Test // DATAREDIS-315
void shouldThrowExceptionGivenNullPropertySource() {
assertThatIllegalArgumentException().isThrownBy(() -> new RedisClusterConfiguration((PropertySource<?>) null));
assertThatIllegalArgumentException().isThrownBy(() -> RedisClusterConfiguration.of((PropertySource<?>) null));
}
@Test // DATAREDIS-315
void shouldNotFailWhenGivenPropertySourceNotContainingRelevantProperties() {
RedisClusterConfiguration config = new RedisClusterConfiguration(new MockPropertySource());
RedisClusterConfiguration config = RedisClusterConfiguration.of(new MockPropertySource());
assertThat(config.getMaxRedirects()).isNull();
assertThat(config.getClusterNodes().size()).isEqualTo(0);
@@ -116,7 +115,7 @@ class RedisClusterConfigurationUnitTests {
propertySource.setProperty("spring.redis.cluster.nodes", HOST_AND_PORT_1);
propertySource.setProperty("spring.redis.cluster.max-redirects", "5");
RedisClusterConfiguration config = new RedisClusterConfiguration(propertySource);
RedisClusterConfiguration config = RedisClusterConfiguration.of(propertySource);
assertThat(config.getMaxRedirects()).isEqualTo(5);
assertThat(config.getClusterNodes()).contains(new RedisNode("127.0.0.1", 123));
@@ -130,7 +129,7 @@ class RedisClusterConfigurationUnitTests {
StringUtils.collectionToCommaDelimitedString(Arrays.asList(HOST_AND_PORT_1, HOST_AND_PORT_2, HOST_AND_PORT_3)));
propertySource.setProperty("spring.redis.cluster.max-redirects", "5");
RedisClusterConfiguration config = new RedisClusterConfiguration(propertySource);
RedisClusterConfiguration config = RedisClusterConfiguration.of(propertySource);
assertThat(config.getMaxRedirects()).isEqualTo(5);
assertThat(config.getClusterNodes()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),
@@ -138,7 +137,7 @@ class RedisClusterConfigurationUnitTests {
}
@Test // GH-2360
public void shouldBeCreatedCorrectlyGivenValidPropertySourceWithMultipleIPv6AddressesAndPorts() {
void shouldBeCreatedCorrectlyGivenValidPropertySourceWithMultipleIPv6AddressesAndPorts() {
MockPropertySource propertySource = new MockPropertySource();
@@ -146,7 +145,7 @@ class RedisClusterConfigurationUnitTests {
StringUtils.collectionToCommaDelimitedString(Arrays.asList(HOST_AND_PORT_4, HOST_AND_PORT_5)));
propertySource.setProperty("spring.redis.cluster.max-redirects", 2);
RedisClusterConfiguration configuration = new RedisClusterConfiguration(propertySource);
RedisClusterConfiguration configuration = RedisClusterConfiguration.of(propertySource);
assertThat(configuration.getMaxRedirects()).isEqualTo(2);
assertThat(configuration.getClusterNodes()).contains(new RedisNode("fe80::a00:27ff:fe4b:ee48", 6379),

View File

@@ -96,13 +96,13 @@ class RedisSentinelConfigurationUnitTests {
@Test // DATAREDIS-372
void shouldThrowExceptionGivenNullPropertySource() {
assertThatIllegalArgumentException().isThrownBy(() -> new RedisSentinelConfiguration(null));
assertThatIllegalArgumentException().isThrownBy(() -> RedisSentinelConfiguration.of(null));
}
@Test // DATAREDIS-372
void shouldNotFailWhenGivenPropertySourceNotContainingRelevantProperties() {
RedisSentinelConfiguration config = new RedisSentinelConfiguration(new MockPropertySource());
RedisSentinelConfiguration config = RedisSentinelConfiguration.of(new MockPropertySource());
assertThat(config.getMaster()).isNull();
assertThat(config.getSentinels()).isEmpty();
@@ -115,7 +115,7 @@ class RedisSentinelConfigurationUnitTests {
propertySource.setProperty("spring.redis.sentinel.master", "myMaster");
propertySource.setProperty("spring.redis.sentinel.nodes", HOST_AND_PORT_1);
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
RedisSentinelConfiguration config = RedisSentinelConfiguration.of(propertySource);
assertThat(config.getMaster()).isNotNull();
assertThat(config.getMaster().getName()).isEqualTo("myMaster");
@@ -131,7 +131,7 @@ class RedisSentinelConfigurationUnitTests {
propertySource.setProperty("spring.redis.sentinel.nodes",
StringUtils.collectionToCommaDelimitedString(Arrays.asList(HOST_AND_PORT_1, HOST_AND_PORT_2, HOST_AND_PORT_3)));
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
RedisSentinelConfiguration config = RedisSentinelConfiguration.of(propertySource);
assertThat(config.getSentinels()).hasSize(3);
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),
@@ -151,6 +151,7 @@ class RedisSentinelConfigurationUnitTests {
@Test // GH-2218
void dataNodeUsernameDoesNotAffectSentinelUsername() {
RedisSentinelConfiguration configuration = new RedisSentinelConfiguration("myMaster",
Collections.singleton(HOST_AND_PORT_1));
configuration.setUsername("data-admin");
@@ -168,7 +169,7 @@ class RedisSentinelConfigurationUnitTests {
propertySource.setProperty("spring.redis.sentinel.nodes", HOST_AND_PORT_1);
propertySource.setProperty("spring.redis.sentinel.password", "computer-says-no");
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
RedisSentinelConfiguration config = RedisSentinelConfiguration.of(propertySource);
assertThat(config.getSentinelPassword()).isEqualTo(RedisPassword.of("computer-says-no"));
assertThat(config.getSentinels()).hasSize(1).contains(new RedisNode("127.0.0.1", 123));
@@ -183,7 +184,7 @@ class RedisSentinelConfigurationUnitTests {
propertySource.setProperty("spring.redis.sentinel.username", "sentinel-admin");
propertySource.setProperty("spring.redis.sentinel.password", "foo");
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
RedisSentinelConfiguration config = RedisSentinelConfiguration.of(propertySource);
assertThat(config.getSentinelUsername()).isEqualTo("sentinel-admin");
assertThat(config.getSentinelPassword()).isEqualTo(RedisPassword.of("foo"));
@@ -192,40 +193,44 @@ class RedisSentinelConfigurationUnitTests {
@Test // GH-2860
void readSentinelDataNodeUsernameFromConfigProperty() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.username", "datanode-user");
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
RedisSentinelConfiguration config = RedisSentinelConfiguration.of(propertySource);
assertThat(config.getDataNodeUsername()).isEqualTo("datanode-user");
}
@Test // GH-2860
void readSentinelDataNodePasswordFromConfigProperty() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.password", "datanode-password");
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
RedisSentinelConfiguration config = RedisSentinelConfiguration.of(propertySource);
assertThat(config.getDataNodePassword()).isEqualTo(RedisPassword.of("datanode-password"));
}
@Test // GH-2860
void readSentinelDataNodeDatabaseFromConfigProperty() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.database", "5");
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
RedisSentinelConfiguration config = RedisSentinelConfiguration.of(propertySource);
assertThat(config.getDatabase()).isEqualTo(5);
}
@Test // GH-2860
void shouldThrowErrorWhen() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.database", "thisIsNotAnInteger");
ThrowableAssert.ThrowingCallable call = () -> new RedisSentinelConfiguration(propertySource);
ThrowableAssert.ThrowingCallable call = () -> RedisSentinelConfiguration.of(propertySource);
assertThatThrownBy(call).isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid DB index '%s'; integer required", "thisIsNotAnInteger");
@@ -233,10 +238,11 @@ class RedisSentinelConfigurationUnitTests {
@Test // GH-2860
void shouldThrowErrorWhen2() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.database", "null");
ThrowableAssert.ThrowingCallable call = () -> new RedisSentinelConfiguration(propertySource);
ThrowableAssert.ThrowingCallable call = () -> RedisSentinelConfiguration.of(propertySource);
assertThatThrownBy(call).isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid DB index '%s'; integer required", "null");