Skip to content

Commit 9a0f5ac

Browse files
committed
Add test case for Redis cluster configuration using IPv6 address.
See #2360.
1 parent 149037d commit 9a0f5ac

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/test/java/org/springframework/data/redis/connection/RedisClusterConfigurationUnitTests.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
*
3333
* @author Christoph Strobl
3434
* @author Mark Paluch
35+
* @author John Blum
3536
*/
3637
class RedisClusterConfigurationUnitTests {
3738

3839
private static final String HOST_AND_PORT_1 = "127.0.0.1:123";
3940
private static final String HOST_AND_PORT_2 = "localhost:456";
4041
private static final String HOST_AND_PORT_3 = "localhost:789";
42+
private static final String HOST_AND_PORT_4 = "[fe80::a00:27ff:fe4b:ee48]:6379";
43+
private static final String HOST_AND_PORT_5 = "[fe80:1234:1a2b:0:27ff:fe4b:0:ee48]:6380";
4144
private static final String HOST_AND_NO_PORT = "localhost";
4245

4346
@Test // DATAREDIS-315
@@ -81,13 +84,13 @@ void shouldThrowExecptionOnInvalidHostAndPortString() {
8184
@Test // DATAREDIS-315
8285
void shouldThrowExceptionWhenListOfHostAndPortIsNull() {
8386
assertThatIllegalArgumentException()
84-
.isThrownBy(() -> new RedisClusterConfiguration(Collections.<String> singleton(null)));
87+
.isThrownBy(() -> new RedisClusterConfiguration(Collections.singleton(null)));
8588
}
8689

8790
@Test // DATAREDIS-315
8891
void shouldNotFailWhenListOfHostAndPortIsEmpty() {
8992

90-
RedisClusterConfiguration config = new RedisClusterConfiguration(Collections.<String> emptySet());
93+
RedisClusterConfiguration config = new RedisClusterConfiguration(Collections.emptySet());
9194

9295
assertThat(config.getClusterNodes().size()).isEqualTo(0);
9396
}
@@ -120,7 +123,7 @@ void shouldBeCreatedCorrectlyGivenValidPropertySourceWithSingleHostPort() {
120123
}
121124

122125
@Test // DATAREDIS-315
123-
void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMultipleHostPort() {
126+
void shouldBeCreatedCorrectlyGivenValidPropertySourceWithMultipleHostPort() {
124127

125128
MockPropertySource propertySource = new MockPropertySource();
126129
propertySource.setProperty("spring.redis.cluster.nodes",
@@ -134,4 +137,19 @@ void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMultipleHostPort() {
134137
new RedisNode("localhost", 789));
135138
}
136139

140+
@Test // GH-2360
141+
public void shouldBeCreatedCorrectlyGivenValidPropertySourceWithMultipleIPv6AddressesAndPorts() {
142+
143+
MockPropertySource propertySource = new MockPropertySource();
144+
145+
propertySource.setProperty("spring.redis.cluster.nodes",
146+
StringUtils.collectionToCommaDelimitedString(Arrays.asList(HOST_AND_PORT_4, HOST_AND_PORT_5)));
147+
propertySource.setProperty("spring.redis.cluster.max-redirects", 2);
148+
149+
RedisClusterConfiguration configuration = new RedisClusterConfiguration(propertySource);
150+
151+
assertThat(configuration.getMaxRedirects()).isEqualTo(2);
152+
assertThat(configuration.getClusterNodes()).contains(new RedisNode("fe80::a00:27ff:fe4b:ee48", 6379),
153+
new RedisNode("fe80:1234:1a2b:0:27ff:fe4b:0:ee48", 6380));
154+
}
137155
}

0 commit comments

Comments
 (0)