Polish "Fix handling of Redis nodes with IPv6 addresses"

See gh-39819
This commit is contained in:
Andy Wilkinson
2024-04-22 11:49:44 +01:00
parent 9b326d59fe
commit 34f53d48b9
5 changed files with 27 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails.Node;
import static org.assertj.core.api.Assertions.assertThat;
/**
@@ -122,9 +124,8 @@ class PropertiesRedisConnectionDetailsTests {
cluster.setNodes(List.of("localhost:1111", "127.0.0.1:2222", "[::1]:3333"));
this.properties.setCluster(cluster);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getCluster().getNodes()).containsExactly(
new RedisConnectionDetails.Node("localhost", 1111), new RedisConnectionDetails.Node("127.0.0.1", 2222),
new RedisConnectionDetails.Node("[::1]", 3333));
assertThat(connectionDetails.getCluster().getNodes()).containsExactly(new Node("localhost", 1111),
new Node("127.0.0.1", 2222), new Node("[::1]", 3333));
}
@Test
@@ -133,9 +134,8 @@ class PropertiesRedisConnectionDetailsTests {
sentinel.setNodes(List.of("localhost:1111", "127.0.0.1:2222", "[::1]:3333"));
this.properties.setSentinel(sentinel);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getSentinel().getNodes()).containsExactly(
new RedisConnectionDetails.Node("localhost", 1111), new RedisConnectionDetails.Node("127.0.0.1", 2222),
new RedisConnectionDetails.Node("[::1]", 3333));
assertThat(connectionDetails.getSentinel().getNodes()).containsExactly(new Node("localhost", 1111),
new Node("127.0.0.1", 2222), new Node("[::1]", 3333));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -309,12 +309,11 @@ class RedisAutoConfigurationTests {
.withPropertyValues("spring.data.redis.sentinel.master:mymaster",
"spring.data.redis.sentinel.nodes:" + StringUtils.collectionToCommaDelimitedString(sentinels))
.run((context) -> {
assertThat(context.getBean(LettuceConnectionFactory.class).isRedisSentinelAware()).isTrue();
assertThat(context.getBean(LettuceConnectionFactory.class).getSentinelConfiguration()).isNotNull();
assertThat(context.getBean(LettuceConnectionFactory.class).getSentinelConfiguration().getSentinels())
.isNotNull()
.extracting(RedisNode::toString)
.containsExactlyInAnyOrder("[0:0:0:0:0:0:0:1]:26379", "[0:0:0:0:0:0:0:1]:26380");
LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
assertThat(connectionFactory.isRedisSentinelAware()).isTrue();
assertThat(connectionFactory.getSentinelConfiguration().getSentinels()).isNotNull()
.containsExactlyInAnyOrder(new RedisNode("[0:0:0:0:0:0:0:1]", 26379),
new RedisNode("[0:0:0:0:0:0:0:1]", 26380));
});
}
@@ -409,10 +408,10 @@ class RedisAutoConfigurationTests {
RedisClusterConfiguration clusterConfiguration = context.getBean(LettuceConnectionFactory.class)
.getClusterConfiguration();
assertThat(clusterConfiguration.getClusterNodes()).hasSize(3);
assertThat(clusterConfiguration.getClusterNodes()).extracting(RedisNode::asString)
.containsExactlyInAnyOrder("127.0.0.1:27379", "127.0.0.1:27380", "[::1]:27381");
assertThat(clusterConfiguration.getClusterNodes()).containsExactlyInAnyOrder(
new RedisNode("127.0.0.1", 27379), new RedisNode("127.0.0.1", 27380),
new RedisNode("[::1]", 27381));
});
}
@Test