zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r1748608 - in /zookeeper/trunk: CHANGES.txt src/java/test/org/apache/zookeeper/test/ReconfigTest.java
Date Wed, 15 Jun 2016 17:11:39 GMT
Author: phunt
Date: Wed Jun 15 17:11:39 2016
New Revision: 1748608

URL: http://svn.apache.org/viewvc?rev=1748608&view=rev
Log:
ZOOKEEPER-2137: Make testPortChange() less flaky (Michael Han via phunt)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ReconfigTest.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1748608&r1=1748607&r2=1748608&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Wed Jun 15 17:11:39 2016
@@ -311,6 +311,9 @@ BUGFIXES:
   ZOOKEEPER-2442: Socket leak in QuorumCnxManager connectOne
   (Michael Han via rgs)
 
+  ZOOKEEPER-2137: Make testPortChange() less flaky
+  (Michael Han via phunt)
+
 IMPROVEMENTS:
   ZOOKEEPER-2024 Major throughput improvement with mixed workloads (Kfir Lev-Ari via shralex)
 

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ReconfigTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ReconfigTest.java?rev=1748608&r1=1748607&r2=1748608&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ReconfigTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ReconfigTest.java Wed Jun 15 17:11:39
2016
@@ -98,10 +98,17 @@ public class ReconfigTest extends ZKTest
     public static String testServerHasConfig(ZooKeeper zk,
             List<String> joiningServers, List<String> leavingServers)
             throws KeeperException, InterruptedException {
+        boolean testNodeExists = false;
         byte[] config = null;
         for (int j = 0; j < 30; j++) {
             try {
-                zk.sync("/", null, null);
+                if (!testNodeExists) {
+                    createZNode(zk, "/dummy", "dummy");
+                    testNodeExists = true;
+                }
+                // Use setData instead of sync API to force a view update.
+                // Check ZOOKEEPER-2137 for details.
+                zk.setData("/dummy", "dummy".getBytes(), -1);
                 config = zk.getConfig(false, new Stat());
                 break;
             } catch (KeeperException.ConnectionLossException e) {
@@ -113,8 +120,8 @@ public class ReconfigTest extends ZKTest
                     Assert.fail("client could not connect to reestablished quorum: giving
up after 30+ seconds.");
                 }
             }
-
         }
+
         String configStr = new String(config);
         if (joiningServers != null) {
             for (String joiner : joiningServers) {
@@ -128,24 +135,29 @@ public class ReconfigTest extends ZKTest
 
         return configStr;
     }
-    
+
     public static void testNormalOperation(ZooKeeper writer, ZooKeeper reader)
             throws KeeperException, InterruptedException {
-        boolean testNodeExists = false;
-       
-       for (int j = 0; j < 30; j++) {
+        boolean testReaderNodeExists = false;
+        boolean testWriterNodeExists = false;
+
+        for (int j = 0; j < 30; j++) {
             try {
-               if (!testNodeExists) {
-                   try{ 
-                       writer.create("/test", "test".getBytes(),
-                           ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-                   } catch (KeeperException.NodeExistsException e) {                    
  
-                   }
-                   testNodeExists = true;
-               }
+                if (!testWriterNodeExists) {
+                    createZNode(writer, "/test", "test");
+                    testWriterNodeExists = true;
+                }
+
+                if (!testReaderNodeExists) {
+                    createZNode(reader, "/dummy", "dummy");
+                    testReaderNodeExists = true;
+                }
+
                 String data = "test" + j;
                 writer.setData("/test", data.getBytes(), -1);
-                reader.sync("/", null, null);
+                // Use setData instead of sync API to force a view update.
+                // Check ZOOKEEPER-2137 for details.
+                reader.setData("/dummy", "dummy".getBytes(), -1);
                 byte[] res = reader.getData("/test", null, new Stat());
                 Assert.assertEquals(data, new String(res));
                 break;
@@ -158,10 +170,17 @@ public class ReconfigTest extends ZKTest
                     Assert.fail("client could not connect to reestablished quorum: giving
up after 30+ seconds.");
                 }
             }
-
         }
+    }
 
-    }    
+    private static void createZNode(ZooKeeper zk, String path, String data)
+            throws KeeperException, InterruptedException {
+        try{
+            zk.create(path, data.getBytes(),
+                    ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+        } catch (KeeperException.NodeExistsException e) {
+        }
+    }
     
     private int getLeaderId(QuorumUtil qu) {
         int leaderId = 1;



Mime
View raw message