zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r1757453 - in /zookeeper/branches/branch-3.5: ./ src/java/test/org/apache/zookeeper/server/ src/java/test/org/apache/zookeeper/server/quorum/ src/java/test/org/apache/zookeeper/test/
Date Tue, 23 Aug 2016 23:36:49 GMT
Author: phunt
Date: Tue Aug 23 23:36:49 2016
New Revision: 1757453

URL: http://svn.apache.org/viewvc?rev=1757453&view=rev
Log:
ZOOKEEPER-2508: Many ZooKeeper tests are flaky because they proceed with zk operation without connecting to ZooKeeper server. (Arshad Mohammad via phunt)

Modified:
    zookeeper/branches/branch-3.5/CHANGES.txt
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/CRCTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/PurgeTxnTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigBackupTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLCountTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/AsyncTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientBase.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/GetProposalFromTxnTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LeaderSessionTrackerTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/RestoreCommittedLogTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SSLTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SledgeHammer.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TestHammer.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java

Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Tue Aug 23 23:36:49 2016
@@ -25,6 +25,10 @@ BUGFIXES:
   ZOOKEEPER-2247: Zookeeper service becomes unavailable when leader
   fails to write transaction log (Rakesh via fpj)
   
+  ZOOKEEPER-2508: Many ZooKeeper tests are flaky because they proceed
+  with zk operation without connecting to ZooKeeper server.
+  (Arshad Mohammad via phunt)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-2505: Use shared library instead of static library in C

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/CRCTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/CRCTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/CRCTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/CRCTest.java Tue Aug 23 23:36:49 2016
@@ -29,36 +29,30 @@ import java.io.RandomAccessFile;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
 import java.util.zip.Adler32;
 import java.util.zip.CheckedInputStream;
 
 import org.apache.jute.BinaryInputArchive;
 import org.apache.jute.InputArchive;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.server.persistence.FileSnap;
 import org.apache.zookeeper.server.persistence.FileTxnLog;
 import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator;
 import org.apache.zookeeper.test.ClientBase;
 import org.junit.Assert;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-public class CRCTest extends ZKTestCase implements Watcher {
+public class CRCTest extends ZKTestCase{
     private static final Logger LOG = LoggerFactory.getLogger(CRCTest.class);
 
     private static final String HOSTPORT =
         "127.0.0.1:" + PortAssignment.unique();
-    private volatile CountDownLatch startSignal;
-
     /**
      * corrupt a file by writing m at 500 b
      * offset
@@ -121,7 +115,7 @@ public class CRCTest extends ZKTestCase
         LOG.info("starting up the zookeeper server .. waiting");
         Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
         try {
             for (int i =0; i < 2000; i++) {
                 zk.create("/crctest- " + i , ("/crctest- " + i).getBytes(),
@@ -178,13 +172,4 @@ public class CRCTest extends ZKTestCase
         }
         Assert.assertTrue(cfile);
    }
-
-    public void process(WatchedEvent event) {
-        LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath());
-        if (event.getState() == KeeperState.SyncConnected
-                && startSignal != null && startSignal.getCount() > 0)
-        {
-            startSignal.countDown();
-        }
-    }
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/PurgeTxnTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/PurgeTxnTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/PurgeTxnTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/PurgeTxnTest.java Tue Aug 23 23:36:49 2016
@@ -32,8 +32,6 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
@@ -49,7 +47,7 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class PurgeTxnTest extends ZKTestCase implements  Watcher {
+public class PurgeTxnTest extends ZKTestCase {
     private static final Logger LOG = LoggerFactory.getLogger(PurgeTxnTest.class);
     private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
     private static final int CONNECTION_TIMEOUT = 3000;
@@ -78,7 +76,7 @@ public class PurgeTxnTest extends ZKTest
         f.startup(zks);
         Assert.assertTrue("waiting for server being up ",
                 ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
         try {
             for (int i = 0; i< 2000; i++) {
                 zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
@@ -125,7 +123,7 @@ public class PurgeTxnTest extends ZKTest
         f.startup(zks);
         Assert.assertTrue("waiting for server being up ",
                 ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-        final ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        final ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
         final CountDownLatch doPurge = new CountDownLatch(1);
         final CountDownLatch purgeFinished = new CountDownLatch(1);
         final AtomicBoolean opFailed = new AtomicBoolean(false);
@@ -452,9 +450,4 @@ public class PurgeTxnTest extends ZKTest
         }
         return znodes;
     }
-
-    public void process(WatchedEvent event) {
-        // do nothing
-    }
-
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java Tue Aug 23 23:36:49 2016
@@ -210,9 +210,11 @@ public class ZooKeeperServerMainTest ext
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                         CONNECTION_TIMEOUT));
 
-
+        clientConnected = new CountDownLatch(1);
         ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
                 ClientBase.CONNECTION_TIMEOUT, this);
+        Assert.assertTrue("Failed to establish zkclient connection!",
+                clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS));
 
         zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
@@ -272,9 +274,11 @@ public class ZooKeeperServerMainTest ext
         Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                         CONNECTION_TIMEOUT));
-
+        clientConnected = new CountDownLatch(1);
         ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
                 ClientBase.CONNECTION_TIMEOUT, this);
+        Assert.assertTrue("Failed to establish zkclient connection!",
+                clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS));
 
         zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigBackupTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigBackupTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigBackupTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigBackupTest.java Tue Aug 23 23:36:49 2016
@@ -163,8 +163,7 @@ public class ReconfigBackupTest extends
             Assert.assertTrue("waiting for server " + i + " being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                             CONNECTION_TIMEOUT));
-            zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i],
-                    ClientBase.CONNECTION_TIMEOUT, this);
+            zk[i] = ClientBase.createZKClient("127.0.0.1:" + clientPorts[i]);
 
             Properties cfg = ReconfigLegacyTest.readPropertiesFromFile(mt[i].confFile);
             String filename = cfg.getProperty("dynamicConfigFile", "");
@@ -200,8 +199,7 @@ public class ReconfigBackupTest extends
             Assert.assertTrue("waiting for server " + i + " being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                             CONNECTION_TIMEOUT));
-            zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i],
-                    ClientBase.CONNECTION_TIMEOUT, this);
+            zk[i] = ClientBase.createZKClient("127.0.0.1:" + clientPorts[i]);
         }
 
         // test that all servers have:
@@ -312,9 +310,7 @@ public class ReconfigBackupTest extends
             Assert.assertTrue("waiting for server " + i + " being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                             CONNECTION_TIMEOUT));
-
-            ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[i],
-                    ClientBase.CONNECTION_TIMEOUT, this);
+            ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[i]);
 
             // we should see that now all servers have the same config of 5 servers
             // including the lag-off server.

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java Tue Aug 23 23:36:49 2016
@@ -32,7 +32,6 @@ import org.apache.zookeeper.PortAssignme
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.test.ClientBase;
-import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
 import org.apache.zookeeper.test.ReconfigTest;
 import org.junit.Assert;
 import org.junit.Before;
@@ -87,8 +86,7 @@ public class ReconfigLegacyTest extends
             Assert.assertTrue("waiting for server " + i + " being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                             CONNECTION_TIMEOUT));
-            zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i],
-                    ClientBase.CONNECTION_TIMEOUT, this);
+            zk[i] = ClientBase.createZKClient("127.0.0.1:" + clientPorts[i]);
             File[] dynamicFiles = mt[i].getDynamicFiles();
 
             Assert.assertTrue( dynamicFiles.length== 1 );
@@ -125,8 +123,7 @@ public class ReconfigLegacyTest extends
             Assert.assertTrue("waiting for server " + i + " being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                             CONNECTION_TIMEOUT));
-            zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i],
-                    ClientBase.CONNECTION_TIMEOUT, this);
+            zk[i] = ClientBase.createZKClient("127.0.0.1:" + clientPorts[i]);
             ReconfigTest.testServerHasConfig(zk[i], allServers, null);
         }
         ReconfigTest.testNormalOperation(zk[0], zk[1]);
@@ -190,8 +187,7 @@ public class ReconfigLegacyTest extends
             Assert.assertTrue("waiting for server " + i + " being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                             CONNECTION_TIMEOUT));
-            zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i],
-                    ClientBase.CONNECTION_TIMEOUT, this);
+            zk[i] = ClientBase.createZKClient("127.0.0.1:" + clientPorts[i]);
 
             ReconfigTest.testServerHasConfig(zk[i], allServers, null);
             Properties cfg = readPropertiesFromFile(mt[i].confFile);
@@ -272,10 +268,7 @@ public class ReconfigLegacyTest extends
                             CONNECTION_TIMEOUT));
         }
 
-        CountdownWatcher watch1 = new CountdownWatcher();        
-        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[0],
-                ClientBase.CONNECTION_TIMEOUT, watch1);
-        watch1.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
+        ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[0]);
 
         String zNodePath="/serverRestartTest";
         String data = "originalData";
@@ -296,10 +289,7 @@ public class ReconfigLegacyTest extends
                     ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
                             CONNECTION_TIMEOUT));
         }
-        CountdownWatcher watch2 = new CountdownWatcher();
-        zk = new ZooKeeper("127.0.0.1:" + clientPorts[0],
-                ClientBase.CONNECTION_TIMEOUT, watch2);
-        watch2.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
+        zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[0]);
 
         byte[] dataBytes = zk.getData(zNodePath, null, null);
         String receivedData = new String(dataBytes);

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java Tue Aug 23 23:36:49 2016
@@ -161,13 +161,12 @@ public class StandaloneDisabledTest exte
      */
     private void startServer(int id, String config) throws Exception {
         peers[id] = new MainThread(id, clientPorts[id], config);
-        zkHandles[id] = new ZooKeeper("127.0.0.1:" + clientPorts[id],
-                                                CONNECTION_TIMEOUT, this);
         peers[id].start();
         Assert.assertTrue("Server " + id + " is not up",
                           ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[id], CONNECTION_TIMEOUT));
         Assert.assertTrue("Error- Server started in Standalone Mode!",
-                          peers[id].isQuorumPeerRunning());
+                peers[id].isQuorumPeerRunning());
+        zkHandles[id] = ClientBase.createZKClient("127.0.0.1:" + clientPorts[id]);
     }
 
     /**

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLCountTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLCountTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLCountTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLCountTest.java Tue Aug 23 23:36:49 2016
@@ -22,18 +22,14 @@ import static org.apache.zookeeper.test.
 
 import java.io.File;
 import java.util.ArrayList;
-import java.util.concurrent.CountDownLatch;
 import java.util.List;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.ACL;
@@ -44,11 +40,10 @@ import org.apache.zookeeper.server.ZooKe
 import org.junit.Assert;
 import org.junit.Test;
 
-public class ACLCountTest extends ZKTestCase implements Watcher {
-    private static final Logger LOG = LoggerFactory.getLogger(ACLTest.class);
+public class ACLCountTest extends ZKTestCase{
+    private static final Logger LOG = LoggerFactory.getLogger(ACLCountTest.class);
     private static final String HOSTPORT =
         "127.0.0.1:" + PortAssignment.unique();
-    private volatile CountDownLatch startSignal;
 
     /**
      *
@@ -86,7 +81,7 @@ public class ACLCountTest extends ZKTest
             LOG.info("starting up the zookeeper server .. waiting");
             Assert.assertTrue("waiting for server being up",
                     ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-            zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+            zk = ClientBase.createZKClient(HOSTPORT);
 
             zk.addAuthInfo("digest", "pat:test".getBytes());
             zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
@@ -113,24 +108,4 @@ public class ACLCountTest extends ZKTest
         f.shutdown();
         zks.shutdown();
     }
-
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatcherEvent)
-     */
-    public void process(WatchedEvent event) {
-        LOG.info("Event:" + event.getState() + " " + event.getType() + " "
-                 + event.getPath());
-        if (event.getState() == KeeperState.SyncConnected) {
-            if (startSignal != null && startSignal.getCount() > 0) {
-                LOG.info("startsignal.countDown()");
-                startSignal.countDown();
-            } else {
-                LOG.warn("startsignal " + startSignal);
-            }
-        }
-    }
-
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ACLTest.java Tue Aug 23 23:36:49 2016
@@ -23,7 +23,6 @@ import static org.apache.zookeeper.test.
 import java.io.File;
 import java.util.ArrayList;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,9 +30,9 @@ import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.PortAssignment;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
@@ -73,7 +72,7 @@ public class ACLTest extends ZKTestCase
             LOG.info("starting up the zookeeper server .. waiting");
             Assert.assertTrue("waiting for server being up",
                     ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-            ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+            ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
             try {
                 zk.addAuthInfo("digest", "pat:test".getBytes());
                 zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
@@ -109,7 +108,7 @@ public class ACLTest extends ZKTestCase
             LOG.info("starting up the zookeeper server .. waiting");
             Assert.assertTrue("waiting for server being up",
                     ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-            zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+            zk = ClientBase.createZKClient(HOSTPORT);
             LOG.info("starting creating acls");
             for (int i = 0; i < 100; i++) {
                 path = "/" + i;
@@ -137,7 +136,6 @@ public class ACLTest extends ZKTestCase
             Assert.assertTrue("waiting for server down",
                     ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
         }
-        startSignal = new CountDownLatch(1);
 
         zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
         f = ServerCnxnFactory.createFactory(PORT, -1);
@@ -146,11 +144,7 @@ public class ACLTest extends ZKTestCase
         try {
             Assert.assertTrue("waiting for server up",
                        ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-    
-            startSignal.await(CONNECTION_TIMEOUT,
-                    TimeUnit.MILLISECONDS);
-            Assert.assertTrue("count == 0", startSignal.getCount() == 0);
-    
+            zk = ClientBase.createZKClient(HOSTPORT);
             Assert.assertTrue("acl map ", (101 == zks.getZKDatabase().getAclSize()));
             for (int j = 200; j < 205; j++) {
                 path = "/" + j;

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/AsyncTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/AsyncTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/AsyncTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/AsyncTest.java Tue Aug 23 23:36:49 2016
@@ -18,32 +18,25 @@
 
 package org.apache.zookeeper.test;
 
-import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
 
-import java.io.IOException;
 import java.util.LinkedList;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class AsyncTest extends ZKTestCase
     implements StringCallback, VoidCallback, DataCallback
@@ -63,37 +56,20 @@ public class AsyncTest extends ZKTestCas
         qb.tearDown();
     }
 
-    private static class CountdownWatcher implements Watcher {
-        volatile CountDownLatch clientConnected = new CountDownLatch(1);
-
-        public void process(WatchedEvent event) {
-            if (event.getState() == KeeperState.SyncConnected) {
-                clientConnected.countDown();
-            }
-        }
-    }
-
-    private ZooKeeper createClient() throws IOException,InterruptedException {
+    private ZooKeeper createClient() throws Exception,InterruptedException {
         return createClient(qb.hostPort);
     }
 
     private ZooKeeper createClient(String hp)
-        throws IOException, InterruptedException
+        throws Exception, InterruptedException
     {
-        CountdownWatcher watcher = new CountdownWatcher();
-        ZooKeeper zk = new ZooKeeper(hp, CONNECTION_TIMEOUT, watcher);
-        if(!watcher.clientConnected.await(CONNECTION_TIMEOUT,
-                TimeUnit.MILLISECONDS))
-        {
-            Assert.fail("Unable to connect to server");
-        }
+        ZooKeeper zk = ClientBase.createZKClient(hp);
         return zk;
     }
 
     LinkedList<Integer> results = new LinkedList<Integer>();
     @Test
-    public void testAsync()
-        throws IOException, InterruptedException, KeeperException
+    public void testAsync() throws Exception
     {
         ZooKeeper zk = null;
         zk = createClient();

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientBase.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientBase.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientBase.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientBase.java Tue Aug 23 23:36:49 2016
@@ -129,7 +129,7 @@ public abstract class ClientBase extends
                 left = expire - Time.currentElapsedTime();
             }
             if (!connected) {
-                throw new TimeoutException("Did not connect");
+                throw new TimeoutException("Failed to connect to ZooKeeper server.");
 
             }
         }
@@ -679,4 +679,29 @@ public abstract class ClientBase extends
         }
         return sb.toString();
     }
+
+    public static ZooKeeper createZKClient(String cxnString) throws Exception {
+        return createZKClient(cxnString, CONNECTION_TIMEOUT);
+    }
+
+    /**
+     * Returns ZooKeeper client after connecting to ZooKeeper Server. Session
+     * timeout is {@link #CONNECTION_TIMEOUT}
+     *
+     * @param cxnString
+     *            connection string in the form of host:port
+     * @param sessionTimeout
+     * @throws IOException
+     *             in cases of network failure
+     */
+    public static ZooKeeper createZKClient(String cxnString, int sessionTimeout) throws IOException {
+        CountdownWatcher watcher = new CountdownWatcher();
+        ZooKeeper zk = new ZooKeeper(cxnString, sessionTimeout, watcher);
+        try {
+            watcher.waitForConnected(CONNECTION_TIMEOUT);
+        } catch (InterruptedException | TimeoutException e) {
+            Assert.fail("ZooKeeper client can not connect to " + cxnString);
+        }
+        return zk;
+    }
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java Tue Aug 23 23:36:49 2016
@@ -25,28 +25,21 @@ import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.NetworkInterface;
 import java.util.Enumeration;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.junit.Assert;
 import org.junit.Test;
 
-public class ClientPortBindTest extends ZKTestCase implements Watcher {
+public class ClientPortBindTest extends ZKTestCase{
     protected static final Logger LOG = 
         LoggerFactory.getLogger(ClientPortBindTest.class);
 
-    private volatile CountDownLatch startSignal;
-
     /**
      * Verify that the server binds to the specified address
      */
@@ -93,13 +86,8 @@ public class ClientPortBindTest extends
         Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp(HOSTPORT,
                                    CONNECTION_TIMEOUT));
-
-        startSignal = new CountDownLatch(1);
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
         try {
-            startSignal.await(CONNECTION_TIMEOUT,
-                    TimeUnit.MILLISECONDS);
-            Assert.assertTrue("count == 0", startSignal.getCount() == 0);
             zk.close();
         } finally {
             f.shutdown();
@@ -110,13 +98,4 @@ public class ClientPortBindTest extends
                                                     CONNECTION_TIMEOUT));
         }
     }
-
-    public void process(WatchedEvent event) {
-        LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath());
-        if (event.getState() == KeeperState.SyncConnected
-                && startSignal != null && startSignal.getCount() > 0)
-        {
-            startSignal.countDown();
-        }
-    }
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/GetProposalFromTxnTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/GetProposalFromTxnTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/GetProposalFromTxnTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/GetProposalFromTxnTest.java Tue Aug 23 23:36:49 2016
@@ -24,11 +24,8 @@ import java.util.Arrays;
 import java.util.Iterator;
 
 import org.apache.jute.Record;
-import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.OpCode;
@@ -48,9 +45,7 @@ import org.junit.Test;
  * Test loading committed proposal from txnlog. Learner uses these proposals to
  * catch-up with leader
  */
-public class GetProposalFromTxnTest extends ZKTestCase implements Watcher {
-    private static final Logger LOG = Logger
-            .getLogger(GetProposalFromTxnTest.class);
+public class GetProposalFromTxnTest extends ZKTestCase{
     private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
     private static final int CONNECTION_TIMEOUT = 3000;
 
@@ -73,7 +68,7 @@ public class GetProposalFromTxnTest exte
         f.startup(zks);
         Assert.assertTrue("waiting for server being up ",
                 ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
 
         // Generate transaction so we will have some txnlog
         Long[] zxids = new Long[MSG_COUNT];
@@ -139,9 +134,4 @@ public class GetProposalFromTxnTest exte
         f.shutdown();
         zks.shutdown();
     }
-
-    public void process(WatchedEvent event) {
-        // do nothing
-    }
-
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java Tue Aug 23 23:36:49 2016
@@ -31,7 +31,6 @@ package org.apache.zookeeper.test;
  * a value that we have previously read or set. (Each time we set a value, the
  * value will be one more than the previous set.)
  */
-import java.io.IOException;
 import java.util.Date;
 import java.util.HashMap;
 
@@ -39,16 +38,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.data.Stat;
 
-public class IntegrityCheck implements Watcher, StatCallback, DataCallback {
+public class IntegrityCheck implements StatCallback, DataCallback {
     private static final Logger LOG = LoggerFactory.getLogger(IntegrityCheck.class);
 
     ZooKeeper zk;
@@ -81,8 +77,8 @@ public class IntegrityCheck implements W
     }
 
     IntegrityCheck(String hostPort, String path, int count) throws
-            IOException {
-        zk = new ZooKeeper(hostPort, 30000, this);
+            Exception {
+        zk = ClientBase.createZKClient(hostPort);
         this.path = path;
         this.count = count;
     }
@@ -147,15 +143,6 @@ public class IntegrityCheck implements W
         }
     }
 
-    // watcher callback
-    public void process(WatchedEvent event) {
-        if(event.getState()==KeeperState.SyncConnected){
-            synchronized(this){
-                notifyAll();
-            }
-        }
-    }
-
     synchronized void ensureConnected(){
         while(zk.getState()!=ZooKeeper.States.CONNECTED){
             try {

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java Tue Aug 23 23:36:49 2016
@@ -21,12 +21,8 @@ package org.apache.zookeeper.test;
 import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
 
 import java.io.File;
-import java.util.concurrent.CountDownLatch;
 
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.server.LogFormatter;
@@ -39,14 +35,13 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class InvalidSnapshotTest extends ZKTestCase implements Watcher {
+public class InvalidSnapshotTest extends ZKTestCase{
     private final static Logger LOG = LoggerFactory.getLogger(InvalidSnapshotTest.class);
     private static final String HOSTPORT =
             "127.0.0.1:" + PortAssignment.unique();
 
     private static final File testData = new File(
             System.getProperty("test.data.dir", "build/test/data"));
-    private CountDownLatch startSignal;
 
     /**
      * Verify the LogFormatter by running it on a known file.
@@ -96,7 +91,7 @@ public class InvalidSnapshotTest extends
         LOG.info("starting up the zookeeper server .. waiting");
         Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
         try {
             // we know this from the data files
             // this node is the last node in the snapshot
@@ -112,13 +107,4 @@ public class InvalidSnapshotTest extends
                            ClientBase.CONNECTION_TIMEOUT));
 
     }
-
-    public void process(WatchedEvent event) {
-        LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath());
-        if (event.getState() == KeeperState.SyncConnected
-                && startSignal != null && startSignal.getCount() > 0)
-        {
-            startSignal.countDown();
-        }
-    }
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LeaderSessionTrackerTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LeaderSessionTrackerTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LeaderSessionTrackerTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LeaderSessionTrackerTest.java Tue Aug 23 23:36:49 2016
@@ -18,7 +18,6 @@
 
 package org.apache.zookeeper.test;
 
-import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
 
 import java.io.ByteArrayOutputStream;
 import java.nio.ByteBuffer;
@@ -26,8 +25,6 @@ import java.util.ArrayList;
 
 import org.apache.jute.BinaryOutputArchive;
 import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.OpCode;
@@ -49,7 +46,7 @@ import org.slf4j.LoggerFactory;
  * expired session. We need to make sure that we never allow ephmeral node
  * to be created in those case, but we do allow normal node to be created.
  */
-public class LeaderSessionTrackerTest extends ZKTestCase implements Watcher {
+public class LeaderSessionTrackerTest extends ZKTestCase {
 
     protected static final Logger LOG = LoggerFactory
             .getLogger(LeaderSessionTrackerTest.class);
@@ -91,8 +88,7 @@ public class LeaderSessionTrackerTest ex
         qu.startAll();
         QuorumPeer leader = qu.getLeaderQuorumPeer();
 
-        ZooKeeper zk = new ZooKeeper(qu.getConnectString(leader),
-                CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(qu.getConnectString(leader));
 
         CreateRequest createRequest = new CreateRequest("/impossible",
                 new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag());
@@ -134,8 +130,7 @@ public class LeaderSessionTrackerTest ex
 
         QuorumPeer leader = qu.getLeaderQuorumPeer();
 
-        ZooKeeper zk = new ZooKeeper(qu.getConnectString(leader),
-                CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(qu.getConnectString(leader));
 
         CreateRequest createRequest = new CreateRequest("/success",
                 new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT.toFlag());
@@ -165,9 +160,4 @@ public class LeaderSessionTrackerTest ex
         Assert.assertTrue("Request from local sesson failed", stat != null);
 
     }
-
-    @Override
-    public void process(WatchedEvent event) {
-    }
-
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java Tue Aug 23 23:36:49 2016
@@ -33,8 +33,6 @@ import org.apache.jute.Record;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException.NoNodeException;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.OpCode;
@@ -61,7 +59,7 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class LoadFromLogTest extends ZKTestCase implements  Watcher {
+public class LoadFromLogTest extends ZKTestCase {
     private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
     private static final int CONNECTION_TIMEOUT = 3000;
     private static final int NUM_MESSAGES = 300;
@@ -70,7 +68,6 @@ public class LoadFromLogTest extends ZKT
     // setting up the quorum has a transaction overhead for creating and closing the session
     private static final int TRANSACTION_OVERHEAD = 2;
     private static final int TOTAL_TRANSACTIONS = NUM_MESSAGES + TRANSACTION_OVERHEAD;
-    private volatile boolean connected;
 
     /**
      * test that all transactions from the Log are loaded, and only once
@@ -88,7 +85,7 @@ public class LoadFromLogTest extends ZKT
         f.startup(zks);
         Assert.assertTrue("waiting for server being up ",
                 ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
 
         // generate some transactions that will get logged
         try {
@@ -149,7 +146,7 @@ public class LoadFromLogTest extends ZKT
         f.startup(zks);
         Assert.assertTrue("waiting for server being up ",
                 ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
 
         // generate some transactions that will get logged
         try {
@@ -205,25 +202,6 @@ public class LoadFromLogTest extends ZKT
 
     }
 
-    public void process(WatchedEvent event) {
-    	switch (event.getType()) {
-    	case None:
-    		switch (event.getState()) {
-    		case SyncConnected:
-    			connected = true;
-    			break;
-    		case Disconnected:
-    			connected = false;
-    			break;
-    		default:
-    			break;
-    		}
-        	break;
-    	default:
-    		break;
-    	}
-    }
-
     /**
      * For ZOOKEEPER-1046. Verify if cversion and pzxid if incremented
      * after create/delete failure during restore.
@@ -296,7 +274,7 @@ public class LoadFromLogTest extends ZKT
             txnHeader = new TxnHeader(0xabcd, 0x123, prevPzxid + 1,
                     Time.currentElapsedTime(), OpCode.create);
             txn = new CreateTxn(path, new byte[0], null, false, cversion);
-            ArrayList txnList = new ArrayList();
+            List<Txn> txnList = new ArrayList<Txn>();
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
             txn.serialize(boa, "request") ;
@@ -397,7 +375,6 @@ public class LoadFromLogTest extends ZKT
 		f.startup(zks);
 		Assert.assertTrue("waiting for server being up ", ClientBase
 				.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-		connected = false;
 		long fZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid();
 
 		// Verify lastProcessedZxid is set correctly
@@ -566,22 +543,8 @@ public class LoadFromLogTest extends ZKT
         f.shutdown();
     }
 
-    private ZooKeeper getConnectedZkClient() throws IOException {
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
-
-        long start = Time.currentElapsedTime();
-        while (!connected) {
-            long end = Time.currentElapsedTime();
-            if (end - start > 5000) {
-                Assert.assertTrue("Could not connect with server in 5 seconds",
-                        false);
-            }
-            try {
-                Thread.sleep(200);
-            } catch (Exception e) {
-                LOG.warn("Interrupted");
-            }
-        }
+    private ZooKeeper getConnectedZkClient() throws Exception {
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
         return zk;
     }
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/RestoreCommittedLogTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/RestoreCommittedLogTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/RestoreCommittedLogTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/RestoreCommittedLogTest.java Tue Aug 23 23:36:49 2016
@@ -23,8 +23,6 @@ import java.util.List;
 
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
@@ -40,7 +38,7 @@ import org.slf4j.LoggerFactory;
 /** After a replica starts, it should load commits in its committedLog list.
  *  This test checks if committedLog != 0 after replica restarted.
  */
-public class RestoreCommittedLogTest extends ZKTestCase implements  Watcher {
+public class RestoreCommittedLogTest extends ZKTestCase{
     private static final Logger LOG = LoggerFactory.getLogger(RestoreCommittedLogTest.class);
     private static final String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
     private static final int CONNECTION_TIMEOUT = 3000;
@@ -59,7 +57,7 @@ public class RestoreCommittedLogTest ext
         f.startup(zks);
         Assert.assertTrue("waiting for server being up ",
                 ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
         try {
             for (int i = 0; i< 2000; i++) {
                 zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
@@ -82,9 +80,4 @@ public class RestoreCommittedLogTest ext
         Assert.assertTrue("log size != 0", (logsize != 0));
         zks.shutdown();
     }
-
-    public void process(WatchedEvent event) {
-        // do nothing
-    }
-
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SSLTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SSLTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SSLTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SSLTest.java Tue Aug 23 23:36:49 2016
@@ -21,13 +21,9 @@
  */
 package org.apache.zookeeper.test;
 
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.client.ZKClientConfig;
@@ -100,20 +96,7 @@ public class SSLTest extends QuorumPeerT
             Assert.assertTrue("waiting for server " + i + " being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], TIMEOUT));
 
-            final CountDownLatch latch = new CountDownLatch(1);
-            ZooKeeper zk = new ZooKeeper("127.0.0.1:" + secureClientPorts[i], TIMEOUT,
-                    new Watcher() {
-                        @Override
-                        public void process(WatchedEvent event) {
-                            if (event.getState() != Event.KeeperState.SyncConnected) {
-                                Assert.fail("failed to connect to ZK server secure client port");
-                            }
-                            latch.countDown();
-                        }
-                    });
-            if (!latch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
-                Assert.fail("Timeout connecting to ZK server secure port");
-            }
+            ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + secureClientPorts[i], TIMEOUT);
             // Do a simple operation to make sure the connection is fine.
             zk.create("/test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             zk.delete("/test", -1);
@@ -138,20 +121,7 @@ public class SSLTest extends QuorumPeerT
         MainThread mt = new MainThread(MainThread.UNSET_MYID, "", secureClientPort, false);
         mt.start();
 
-        final CountDownLatch latch = new CountDownLatch(1);
-        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + secureClientPort, TIMEOUT,
-                new Watcher() {
-                    @Override
-                    public void process(WatchedEvent event) {
-                        if (event.getState() != Event.KeeperState.SyncConnected) {
-                            Assert.fail("failed to connect to ZK server secure client port");
-                        }
-                        latch.countDown();
-                    }
-                });
-        if (!latch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
-            Assert.fail("Timeout connecting to ZK server secure port");
-        }
+        ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + secureClientPort, TIMEOUT);
         zk.create("/test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         zk.delete("/test", -1);
         zk.close();

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SledgeHammer.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SledgeHammer.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SledgeHammer.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/SledgeHammer.java Tue Aug 23 23:36:49 2016
@@ -24,13 +24,11 @@ import java.util.List;
 
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 
-public class SledgeHammer extends Thread implements Watcher {
+public class SledgeHammer extends Thread{
     ZooKeeper zk;
 
     int count;
@@ -38,8 +36,8 @@ public class SledgeHammer extends Thread
     int readsPerWrite;
 
     public SledgeHammer(String hosts, int count, int readsPerWrite)
-            throws IOException {
-        zk = new ZooKeeper(hosts, 10000, this);
+            throws Exception {
+        zk = ClientBase.createZKClient(hosts, 10000);
         this.count = count;
         this.readsPerWrite = readsPerWrite;
     }
@@ -98,7 +96,7 @@ public class SledgeHammer extends Thread
      * @throws NumberFormatException
      */
     public static void main(String[] args) throws NumberFormatException,
-            IOException {
+            Exception {
         if (args.length != 3) {
             System.err
                     .println("USAGE: SledgeHammer zookeeper_server reps reads_per_rep");
@@ -109,11 +107,4 @@ public class SledgeHammer extends Thread
         h.start();
         System.exit(0);
     }
-
-    public void process(WatchedEvent event) {
-        synchronized (this) {
-            notifyAll();
-        }
-    }
-
 }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TestHammer.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TestHammer.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TestHammer.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TestHammer.java Tue Aug 23 23:36:49 2016
@@ -18,7 +18,6 @@
 
 package org.apache.zookeeper.test;
 
-import java.io.IOException;
 
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooKeeper;
@@ -36,9 +35,8 @@ public class TestHammer implements VoidC
             long startTime = Time.currentElapsedTime();
             ZooKeeper zk = null;
             try {
-                zk = new ZooKeeper(args[0], 10000, null);
-            } catch (IOException e1) {
-                // TODO Auto-generated catch block
+                zk = ClientBase.createZKClient(args[0], 10000);
+            } catch (Exception e1) {
                 e1.printStackTrace();
                 throw new RuntimeException(e1);
             }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java Tue Aug 23 23:36:49 2016
@@ -27,8 +27,6 @@ import org.apache.jute.Record;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
@@ -69,14 +67,6 @@ public class TruncateTest extends ZKTest
         ClientBase.recursiveDelete(dataDir3);
     }
     
-    volatile boolean connected;
-    Watcher nullWatcher = new Watcher() {
-        @Override
-        public void process(WatchedEvent event) {
-            connected = event.getState() == Watcher.Event.KeeperState.SyncConnected;
-        }
-    };
-
     @Test
     public void testTruncationStreamReset() throws Exception {
         File tmpdir = ClientBase.createTmpDir();
@@ -152,7 +142,7 @@ public class TruncateTest extends ZKTest
     }
 
     @Test
-    public void testTruncate() throws IOException, InterruptedException, KeeperException {
+    public void testTruncate() throws Exception {
         // Prime the server that is going to come in late with 50 txns
         String hostPort = "127.0.0.1:" + PortAssignment.unique();
         int maxCnxns = 100;
@@ -169,7 +159,7 @@ public class TruncateTest extends ZKTest
         factory = ClientBase.createNewServerInstance(null, hostPort, maxCnxns);
         ClientBase.startServerInstance(dataDir1, factory, hostPort);
 
-        ZooKeeper zk = new ZooKeeper(hostPort, 15000, nullWatcher);
+        ZooKeeper zk = ClientBase.createZKClient(hostPort, 15000);
         for(int i = 0; i < 50; i++) {
             zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         }
@@ -214,17 +204,13 @@ public class TruncateTest extends ZKTest
         s2.start();
         QuorumPeer s3 = new QuorumPeer(peers, dataDir3, dataDir3, port3, 0, 3, tickTime, initLimit, syncLimit);
         s3.start();
-        connected = false;
-        zk = new ZooKeeper("127.0.0.1:" + port2, 15000, nullWatcher);
-        while(!connected) {
-            Thread.sleep(1000);
-        }
+        zk = ClientBase.createZKClient("127.0.0.1:" + port2, 15000);
+
         for(int i = 0; i < 10; i++) {
             zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         }
         zk.close();
-        
-        final ZooKeeper zk2 = new ZooKeeper("127.0.0.1:" + port2, 15000, nullWatcher);
+        final ZooKeeper zk2 = ClientBase.createZKClient("127.0.0.1:" + port2, 15000);
         zk2.getData("/9", false, new Stat());
         try {
             zk2.getData("/10", false, new Stat());
@@ -234,12 +220,7 @@ public class TruncateTest extends ZKTest
         }
         QuorumPeer s1 = new QuorumPeer(peers, dataDir1, dataDir1, port1, 0, 1, tickTime, initLimit, syncLimit);
         s1.start();
-
-        connected = false;
-        ZooKeeper zk1 = new ZooKeeper("127.0.0.1:" + port1, 15000, nullWatcher);
-        while(!connected) {
-            Thread.sleep(1000);
-        }
+        ZooKeeper zk1 = ClientBase.createZKClient("127.0.0.1:" + port1, 15000);
         zk1.getData("/9", false, new Stat());
         try {
             // /10 wont work because the session expiration

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java?rev=1757453&r1=1757452&r2=1757453&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java Tue Aug 23 23:36:49 2016
@@ -25,8 +25,6 @@ import java.util.Arrays;
 
 import org.apache.zookeeper.AsyncCallback;
 import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
@@ -84,9 +82,7 @@ public class ZkDatabaseCorruptionTest ex
     public void testCorruption() throws Exception {
         ClientBase.waitForServerUp(qb.hostPort, 10000);
         ClientBase.waitForServerUp(qb.hostPort, 10000);
-        ZooKeeper zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() {
-            public void process(WatchedEvent event) {
-            }});
+        ZooKeeper zk = ClientBase.createZKClient(qb.hostPort, 10000);
         SyncRequestProcessor.setSnapCount(100);
         for (int i = 0; i < 2000; i++) {
             zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,



Mime
View raw message