Skip to content

Commit

Permalink
Merge pull request redis#1240 from roblg/no-seed-nodes-in-node-list
Browse files Browse the repository at this point in the history
Attempted fix for redis#1229 - multiple entries in node list for same host
  • Loading branch information
HeartSaVioR committed Mar 14, 2016
2 parents 833308c + 7366fc1 commit 21fded3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ private void initializeSlotsCache(Set<HostAndPort> startNodes, GenericObjectPool
}
}
}

for (HostAndPort node : startNodes) {
cache.setNodeIfNotExist(node);
}
}

public void renewSlotCache() {
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/redis/clients/jedis/tests/JedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,35 @@ public void testReturnConnectionOnRedirection() {
jc.get("e");
}

@Test
public void testLocalhostNodeNotAddedWhen127Present() {
HostAndPort localhost = new HostAndPort("localhost", 7379);
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
// cluster node is defined as 127.0.0.1; adding localhost should work,
// but shouldn't show up.
jedisClusterNode.add(localhost);
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(1);
JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, config);
Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
assertEquals(3, clusterNodes.size());
assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(localhost)));
}

@Test
public void testInvalidStartNodeNotAdded() {
HostAndPort invalidHost = new HostAndPort("not-a-real-host", 7379);
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
jedisClusterNode.add(invalidHost);
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(1);
JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, config);
Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
assertEquals(3, clusterNodes.size());
assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(invalidHost)));
}

private static String getNodeServingSlotRange(String infoOutput) {
// f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0
// 1394372400827 0 connected 5461-10922
Expand Down

0 comments on commit 21fded3

Please sign in to comment.