Browse Source

ZOOKEEPER-1964. Fix Flaky Test in ReconfigTest.java (Hongchao Deng via fpj)


git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1610468 13f79535-47bb-0310-9956-ffa450edef68
Flavio Paiva Junqueira 11 years ago
parent
commit
524895a265
2 changed files with 35 additions and 9 deletions
  1. 2 0
      CHANGES.txt
  2. 33 9
      src/java/test/org/apache/zookeeper/test/ReconfigTest.java

+ 2 - 0
CHANGES.txt

@@ -689,6 +689,8 @@ BUGFIXES:
   ZOOKEEPER-1222. getACL should only call DataTree.copyStat when passed in
   ZOOKEEPER-1222. getACL should only call DataTree.copyStat when passed in
   stat is not null (Michi Mutsuzaki via rakeshr)
   stat is not null (Michi Mutsuzaki via rakeshr)
 
 
+  ZOOKEEPER-1964. Fix Flaky Test in ReconfigTest.java (Hongchao Deng via fpj)
+
 IMPROVEMENTS:
 IMPROVEMENTS:
 
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

+ 33 - 9
src/java/test/org/apache/zookeeper/test/ReconfigTest.java

@@ -19,6 +19,8 @@
 package org.apache.zookeeper.test;
 package org.apache.zookeeper.test;
 
 
 import java.io.IOException;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.List;
@@ -956,20 +958,42 @@ public class ReconfigTest extends ZKTestCase implements DataCallback{
                 beanName, "QuorumSystemInfo"));
                 beanName, "QuorumSystemInfo"));
     }
     }
 
 
+    String getAddrPortFromBean(String beanName, String attribute) throws Exception {
+        String name = (String) JMXEnv.ensureBeanAttribute(
+                beanName, attribute);
+
+        if ( ! name.contains(":") ) {
+            return name;
+        }
+
+        return getNumericalAddrPort(name);
+    }
+
+    String getNumericalAddrPort(String name) throws UnknownHostException {
+        String port = name.split(":")[1];
+        String addr = name.split(":")[0];
+        addr = InetAddress.getByName(addr).getHostAddress();
+        return addr + ":" + port;
+    }
+
     private void assertRemotePeerMXBeanAttributes(QuorumServer qs,
     private void assertRemotePeerMXBeanAttributes(QuorumServer qs,
             String beanName) throws Exception {
             String beanName) throws Exception {
         Assert.assertEquals("Mismatches LearnerType!", qs.type.name(),
         Assert.assertEquals("Mismatches LearnerType!", qs.type.name(),
                 JMXEnv.ensureBeanAttribute(beanName, "LearnerType"));
                 JMXEnv.ensureBeanAttribute(beanName, "LearnerType"));
         Assert.assertEquals("Mismatches ClientAddress!",
         Assert.assertEquals("Mismatches ClientAddress!",
-                HostNameUtils.getHostString(qs.clientAddr) + ":"
-                        + qs.clientAddr.getPort(),
-                JMXEnv.ensureBeanAttribute(beanName, "ClientAddress"));
+                getNumericalAddrPort(
+                        HostNameUtils.getHostString(qs.clientAddr) + ":"
+                        + qs.clientAddr.getPort() ),
+                getAddrPortFromBean(beanName, "ClientAddress") );
         Assert.assertEquals("Mismatches ElectionAddress!",
         Assert.assertEquals("Mismatches ElectionAddress!",
-                HostNameUtils.getHostString(qs.electionAddr) + ":"
-                        + qs.electionAddr.getPort(),
-                JMXEnv.ensureBeanAttribute(beanName, "ElectionAddress"));
-        Assert.assertEquals("Mismatches QuorumAddress!", qs.addr.getHostName()
-                + ":" + qs.addr.getPort(),
-                JMXEnv.ensureBeanAttribute(beanName, "QuorumAddress"));
+                getNumericalAddrPort(
+                        HostNameUtils.getHostString(qs.electionAddr) + ":"
+                        + qs.electionAddr.getPort() ),
+                getAddrPortFromBean(beanName, "ElectionAddress") );
+        Assert.assertEquals("Mismatches QuorumAddress!",
+                getNumericalAddrPort(
+                        qs.addr.getHostName() + ":"
+                        + qs.addr.getPort() ),
+                getAddrPortFromBean(beanName, "QuorumAddress") );
     }
     }
 }
 }