@@ -538,6 +538,35 @@ public void testReturnConnectionOnRedirection() {
538538 jc .get ("e" );
539539 }
540540
541+ @ Test
542+ public void testLocalhostNodeNotAddedWhen127Present () {
543+ HostAndPort localhost = new HostAndPort ("localhost" , 7379 );
544+ Set <HostAndPort > jedisClusterNode = new HashSet <HostAndPort >();
545+ // cluster node is defined as 127.0.0.1; adding localhost should work,
546+ // but shouldn't show up.
547+ jedisClusterNode .add (localhost );
548+ JedisPoolConfig config = new JedisPoolConfig ();
549+ config .setMaxTotal (1 );
550+ JedisCluster jc = new JedisCluster (jedisClusterNode , 0 , 2 , config );
551+ Map <String , JedisPool > clusterNodes = jc .getClusterNodes ();
552+ assertEquals (3 , clusterNodes .size ());
553+ assertFalse (clusterNodes .containsKey (JedisClusterInfoCache .getNodeKey (localhost )));
554+ }
555+
556+ @ Test
557+ public void testInvalidStartNodeNotAdded () {
558+ HostAndPort invalidHost = new HostAndPort ("not-a-real-host" , 7379 );
559+ Set <HostAndPort > jedisClusterNode = new HashSet <HostAndPort >();
560+ jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 7379 ));
561+ jedisClusterNode .add (invalidHost );
562+ JedisPoolConfig config = new JedisPoolConfig ();
563+ config .setMaxTotal (1 );
564+ JedisCluster jc = new JedisCluster (jedisClusterNode , 0 , 2 , config );
565+ Map <String , JedisPool > clusterNodes = jc .getClusterNodes ();
566+ assertEquals (3 , clusterNodes .size ());
567+ assertFalse (clusterNodes .containsKey (JedisClusterInfoCache .getNodeKey (invalidHost )));
568+ }
569+
541570 private static String getNodeServingSlotRange (String infoOutput ) {
542571 // f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0
543572 // 1394372400827 0 connected 5461-10922
0 commit comments