Skip to content

Commit 6524141

Browse files
committed
Merge pull request #47401 from NeatGuyCoding
* pr/47401: Polish "Validate node configuration with static master replica" Validate node configuration with static master replica Closes gh-47401
2 parents 8a9528e + 1e4cc94 commit 6524141

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ protected final RedisStandaloneConfiguration getStandaloneConfig() {
154154
}
155155
if (this.connectionDetails.getMasterReplica() != null) {
156156
List<Node> nodes = this.connectionDetails.getMasterReplica().getNodes();
157+
Assert.state(!nodes.isEmpty(), "At least one node is required for master-replica configuration");
157158
RedisStaticMasterReplicaConfiguration config = new RedisStaticMasterReplicaConfiguration(
158159
nodes.get(0).host(), nodes.get(0).port());
159160
nodes.stream().skip(1).forEach((node) -> config.addNode(node.host(), node.port()));

module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/autoconfigure/DataRedisAutoConfigurationTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,15 @@ void testRedisConfigurationWithClusterAndAuthentication() {
500500
});
501501
}
502502

503+
@Test
504+
void testRedisConfigurationWithMasterReplicaAndNoNode() {
505+
this.contextRunner.withPropertyValues("spring.data.redis.masterreplica.nodes=")
506+
.run((context) -> assertThat(context).hasFailed()
507+
.getFailure()
508+
.rootCause()
509+
.hasMessage("At least one node is required for master-replica configuration"));
510+
}
511+
503512
@Test
504513
void testRedisConfigurationWithMasterReplica() {
505514
this.contextRunner

0 commit comments

Comments
 (0)