zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1558951 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/test/org/apache/zookeeper/test/JMXEnv.java src/java/test/org/apache/zookeeper/test/QuorumUtil.java
Date Thu, 16 Jan 2014 22:59:54 GMT
Author: fpj
Date: Thu Jan 16 22:59:54 2014
New Revision: 1558951

URL: http://svn.apache.org/r1558951
Log:
ZOOKEEPER-1837. Fix JMXEnv checks (potential race conditions)
  (Germán Blanco via fpj)


Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/JMXEnv.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1558951&r1=1558950&r2=1558951&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Thu Jan 16 22:59:54 2014
@@ -224,6 +224,9 @@ BUGFIXES:
   ZOOKEEPER-1238. when the linger time was changed for NIO the patch missed
   Netty (Skye Wanderman-Milne via fpj)
 
+  ZOOKEEPER-1837. Fix JMXEnv checks (potential race conditions)
+  (Germán Blanco via fpj)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1564. Allow JUnit test build with IBM Java

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/JMXEnv.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/JMXEnv.java?rev=1558951&r1=1558950&r2=1558951&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/JMXEnv.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/JMXEnv.java Thu
Jan 16 22:59:54 2014
@@ -84,34 +84,43 @@ public class JMXEnv {
      * Note that these are components of the name, and in particular
      * order matters - you want the more specific name (leafs) specified
      * before their parent(s) (since names are hierarchical)
+     * It waits in a loop up to 60 seconds before failing if there is a
+     * mismatch.
      * @param expectedNames
      * @return
      * @throws IOException
      * @throws MalformedObjectNameException
      */
     public static Set<ObjectName> ensureAll(String... expectedNames)
-        throws IOException
+        throws IOException, InterruptedException
     {
         Set<ObjectName> beans;
-        try {
-            beans = conn().queryNames(
-                    new ObjectName(CommonNames.DOMAIN + ":*"), null);
-        } catch (MalformedObjectNameException e) {
-            throw new RuntimeException(e);
-        }
+        Set<ObjectName> found;
+        int nTry = 0;
+        do {
+            if (nTry++ > 0) {
+                Thread.sleep(100);
+            }
+            try {
+                beans = conn().queryNames(
+                        new ObjectName(CommonNames.DOMAIN + ":*"), null);
+            } catch (MalformedObjectNameException e) {
+                throw new RuntimeException(e);
+            }
         
-        Set<ObjectName> found = new HashSet<ObjectName>();
-        for (String name : expectedNames) {
-            LOG.info("expect:" + name);
-            for (ObjectName bean : beans) {
-                if (bean.toString().contains(name)) {
-                    LOG.info("found:" + name + " " + bean);
-                    found.add(bean);
-                    break;
+            found = new HashSet<ObjectName>();
+            for (String name : expectedNames) {
+                LOG.info("expect:" + name);
+                for (ObjectName bean : beans) {
+                    if (bean.toString().contains(name)) {
+                        LOG.info("found:" + name + " " + bean);
+                        found.add(bean);
+                        break;
+                    }
                 }
+                beans.removeAll(found);
             }
-            beans.removeAll(found);
-        }
+        } while ((expectedNames.length != found.size()) && (nTry < 600));
         TestCase.assertEquals("expected " + Arrays.toString(expectedNames),
                 expectedNames.length, found.size());
         return beans;
@@ -122,8 +131,6 @@ public class JMXEnv {
      * Note that these are components of the name, and in particular
      * order matters - you want the more specific name (leafs) specified
      * before their parent(s) (since names are hierarchical)
-     * It waits in a loop up to 5 seconds before failing if there is a
-     * mismatch.
      * @param expectedNames
      * @return
      * @throws IOException
@@ -134,10 +141,6 @@ public class JMXEnv {
     {
         LOG.info("ensureOnly:" + Arrays.toString(expectedNames));
         Set<ObjectName> beans = ensureAll(expectedNames);
-        for (int i = 0; (i < 50) && (beans.size() != 0); i++) {
-            Thread.sleep(100);
-            beans = ensureAll(expectedNames);
-        }
         for (ObjectName bean : beans) {
             LOG.info("unexpected:" + bean.toString());
         }
@@ -146,23 +149,44 @@ public class JMXEnv {
     }
     
     public static void ensureNone(String... expectedNames)
-        throws IOException
+        throws IOException, InterruptedException
     {
         Set<ObjectName> beans;
-        try {
-            beans = conn().queryNames(
-                    new ObjectName(CommonNames.DOMAIN + ":*"), null);
-        } catch (MalformedObjectNameException e) {
-            throw new RuntimeException(e);
-        }
-        
-        for (String name : expectedNames) {
-            for (ObjectName bean : beans) {
-                if (bean.toString().contains(name)) {
-                    LOG.info("didntexpect:" + name);
-                    TestCase.fail(name + " " + bean.toString());
+        int nTry = 0;
+        boolean foundUnexpected = false;
+        String unexpectedName = "";
+        do {
+            if (nTry++ > 0) {
+                Thread.sleep(100);
+            }
+            try {
+                beans = conn().queryNames(
+                        new ObjectName(CommonNames.DOMAIN + ":*"), null);
+            } catch (MalformedObjectNameException e) {
+                throw new RuntimeException(e);
+            }
+  
+            foundUnexpected = false; 
+            for (String name : expectedNames) {
+                for (ObjectName bean : beans) {
+                    if (bean.toString().contains(name)) {
+                        LOG.info("didntexpect:" + name);
+                        foundUnexpected = true;
+                        unexpectedName = name + " " + bean.toString();
+                        break;
+                    }
                 }
+                if (foundUnexpected) {
+                    break;
+                }
+            }
+        } while ((foundUnexpected) && (nTry < 600));
+        if (foundUnexpected) {
+            LOG.info("List of all beans follows:");
+            for (ObjectName bean : beans) {
+                LOG.info("bean:" + bean.toString());
             }
+            TestCase.fail(unexpectedName);
         }
     }
 

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java?rev=1558951&r1=1558950&r2=1558951&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
Thu Jan 16 22:59:54 2014
@@ -161,6 +161,8 @@ public class QuorumUtil {
             JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()]));
         } catch (IOException e) {
             LOG.warn("IOException during JMXEnv operation", e);
+        } catch (InterruptedException e) {
+            LOG.warn("InterruptedException during JMXEnv operation", e);
         }
     }
 



Mime
View raw message