From 960594d2289e5ceb66f5379c1c4cca1a3ef22272 Mon Sep 17 00:00:00 2001 From: TaylorMapes Date: Tue, 2 Nov 2021 15:30:14 -0500 Subject: [PATCH 1/2] RedisClusterNode: Validate that the RedisURI are equal when comparing 2 nodes. --- .../models/partitions/RedisClusterNode.java | 5 +++++ .../partitions/RedisClusterNodeUnitTests.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java b/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java index 5fa64dbafb..04176fbcea 100644 --- a/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java +++ b/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.function.IntConsumer; @@ -423,6 +424,10 @@ public boolean equals(Object o) { return false; } + if (uri != null ? !uri.equals(that.uri) : that.uri != null) { + return false; + } + return true; } diff --git a/src/test/java/io/lettuce/core/cluster/models/partitions/RedisClusterNodeUnitTests.java b/src/test/java/io/lettuce/core/cluster/models/partitions/RedisClusterNodeUnitTests.java index ff1c15cbe1..bdf55646cf 100644 --- a/src/test/java/io/lettuce/core/cluster/models/partitions/RedisClusterNodeUnitTests.java +++ b/src/test/java/io/lettuce/core/cluster/models/partitions/RedisClusterNodeUnitTests.java @@ -56,6 +56,20 @@ void testEquality() { assertThat(node.hashCode()).isNotEqualTo(new RedisClusterNode()); } + @Test + void testEqualityWithSameNodeIdDifferentHost() { + + RedisClusterNode nodeOne = new RedisClusterNode(); + nodeOne.setNodeId("123"); + nodeOne.setUri(RedisURI.builder().withHost("127.0.0.1").build()); + + RedisClusterNode nodeTwo = new RedisClusterNode(); + nodeOne.setNodeId("123"); + nodeOne.setUri(RedisURI.builder().withHost("127.0.0.2").build()); + + assertThat(nodeOne).isNotEqualTo(nodeTwo); + } + @Test void testToString() { From 3fbf638204ebc3b39319246620a94e688bd628b2 Mon Sep 17 00:00:00 2001 From: TaylorMapes Date: Tue, 2 Nov 2021 15:38:21 -0500 Subject: [PATCH 2/2] RedisClusterNode: Remove unused import --- .../lettuce/core/cluster/models/partitions/RedisClusterNode.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java b/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java index 04176fbcea..e3aae7d028 100644 --- a/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java +++ b/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.EnumSet; import java.util.List; -import java.util.Objects; import java.util.Set; import java.util.function.IntConsumer;