Przeglądaj źródła

ZOOKEEPER-1891. StaticHostProviderTest.testUpdateLoadBalancing times out (Michi Mutsuzaki via rakeshr)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1593682 13f79535-47bb-0310-9956-ffa450edef68
Rakesh Radhakrishnan 11 lat temu
rodzic
commit
85aac3dd0b

+ 3 - 0
CHANGES.txt

@@ -639,6 +639,9 @@ BUGFIXES:
   ZOOKEEPER-1926. Unit tests should only use build/test/data for data (Enis
   Soztutar via michim)
 
+  ZOOKEEPER-1891. StaticHostProviderTest.testUpdateLoadBalancing times out
+  (Michi Mutsuzaki via rakeshr)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

+ 5 - 12
src/java/main/org/apache/zookeeper/client/StaticHostProvider.java

@@ -27,6 +27,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Random;
 
+import org.apache.zookeeper.common.HostNameUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -116,18 +117,10 @@ public final class StaticHostProvider implements HostProvider {
             InetAddress resolvedAddresses[] = InetAddress.getAllByName((ia!=null) ? ia.getHostAddress():
                     address.getHostName());
             for (InetAddress resolvedAddress : resolvedAddresses) {
-                // If hostName is null but the address is not, we can tell that
-                // the hostName is an literal IP address. Then we can set the host string as the hostname
-                // safely to avoid reverse DNS lookup.
-                // As far as i know, the only way to check if the hostName is null is use toString().
-                // Both the two implementations of InetAddress are final class, so we can trust the return value of
-                // the toString() method.
-                if (resolvedAddress.toString().startsWith("/") && resolvedAddress.getAddress() != null) {
-                    tmpList.add(new InetSocketAddress(InetAddress.getByAddress(address.getHostName(),
-                            resolvedAddress.getAddress()), address.getPort()));
-                } else {
-                    tmpList.add(new InetSocketAddress(resolvedAddress.getHostAddress(), address.getPort()));
-                }
+                tmpList.add(new InetSocketAddress(InetAddress.getByAddress(
+                                HostNameUtils.getHostString(address),
+                                resolvedAddress.getAddress()),
+                                address.getPort()));
             }
         }
         Collections.shuffle(tmpList, sourceOfRandomness);