Properly parse IPv6 host and port into RedisNode.

Closes #2418
This commit is contained in:
Mark Paluch
2022-10-04 09:41:52 +02:00
parent 4371d3f2e0
commit c3ee0d8b3c
5 changed files with 126 additions and 22 deletions

View File

@@ -28,6 +28,8 @@ import org.springframework.mock.env.MockPropertySource;
import org.springframework.util.StringUtils;
/**
* Unit tests for {@link RedisClusterConfiguration}.
*
* @author Christoph Strobl
* @author Mark Paluch
*/
@@ -48,12 +50,22 @@ class RedisClusterConfigurationUnitTests {
assertThat(config.getMaxRedirects()).isNull();
}
@Test // GH-2418
void shouldCreateRedisClusterConfigurationForIPV6Correctly() {
RedisClusterConfiguration config = new RedisClusterConfiguration(Collections.singleton("[aaa:bbb:ccc::dd1]:123"));
assertThat(config.getClusterNodes().size()).isEqualTo(1);
assertThat(config.getClusterNodes()).contains(new RedisNode("aaa:bbb:ccc::dd1", 123));
assertThat(config.getClusterNodes()).first().hasToString("[aaa:bbb:ccc::dd1]:123");
assertThat(config.getMaxRedirects()).isNull();
}
@Test // DATAREDIS-315
void shouldCreateRedisClusterConfigurationCorrectlyGivenMultipleHostAndPortStrings() {
RedisClusterConfiguration config = new RedisClusterConfiguration(
new HashSet<>(Arrays.asList(HOST_AND_PORT_1,
HOST_AND_PORT_2, HOST_AND_PORT_3)));
new HashSet<>(Arrays.asList(HOST_AND_PORT_1, HOST_AND_PORT_2, HOST_AND_PORT_3)));
assertThat(config.getClusterNodes().size()).isEqualTo(3);
assertThat(config.getClusterNodes()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),

View File

@@ -30,6 +30,7 @@ import org.springframework.util.StringUtils;
* Unit tests for {@link RedisSentinelConfiguration}.
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Vikas Garg
*/
class RedisSentinelConfigurationUnitTests {
@@ -49,6 +50,16 @@ class RedisSentinelConfigurationUnitTests {
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123));
}
@Test // GH-2418
void shouldCreateRedisSentinelConfigurationCorrectlyGivenMasterAndSingleIPV6HostAndPortString() {
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster",
Collections.singleton("[ca:fee::1]:123"));
assertThat(config.getSentinels()).hasSize(1);
assertThat(config.getSentinels()).contains(new RedisNode("ca:fee::1", 123));
}
@Test // DATAREDIS-372
void shouldCreateRedisSentinelConfigurationCorrectlyGivenMasterAndMultipleHostAndPortStrings() {