Pārlūkot izejas kodu

ZOOKEEPER-724. Improve junit test integration - log harness information (phunt via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@929377 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 15 gadi atpakaļ
vecāks
revīzija
a1a877a468
69 mainītis faili ar 1044 papildinājumiem un 1249 dzēšanām
  1. 2 0
      CHANGES.txt
  2. 7 16
      src/java/test/org/apache/zookeeper/server/CRCTest.java
  3. 10 5
      src/java/test/org/apache/zookeeper/server/DataTreeUnitTest.java
  4. 4 4
      src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java
  5. 9 9
      src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
  6. 2 3
      src/java/test/org/apache/zookeeper/server/SerializationPerfTest.java
  7. 4 4
      src/java/test/org/apache/zookeeper/server/ToStringTest.java
  8. 6 7
      src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
  9. 17 17
      src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
  10. 19 21
      src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
  11. 2 3
      src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTestBase.java
  12. 5 28
      src/java/test/org/apache/zookeeper/test/ACLRootTest.java
  13. 17 23
      src/java/test/org/apache/zookeeper/test/ACLTest.java
  14. 15 19
      src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java
  15. 5 23
      src/java/test/org/apache/zookeeper/test/AsyncOps.java
  16. 4 12
      src/java/test/org/apache/zookeeper/test/AsyncOpsTest.java
  17. 14 18
      src/java/test/org/apache/zookeeper/test/AsyncTest.java
  18. 6 5
      src/java/test/org/apache/zookeeper/test/AuthTest.java
  19. 2 4
      src/java/test/org/apache/zookeeper/test/ChrootAsyncTest.java
  20. 2 4
      src/java/test/org/apache/zookeeper/test/ChrootClientTest.java
  21. 20 17
      src/java/test/org/apache/zookeeper/test/ChrootTest.java
  22. 28 29
      src/java/test/org/apache/zookeeper/test/ClientBase.java
  23. 9 13
      src/java/test/org/apache/zookeeper/test/ClientHammerTest.java
  24. 7 16
      src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java
  25. 16 12
      src/java/test/org/apache/zookeeper/test/ClientRetry.java
  26. 79 84
      src/java/test/org/apache/zookeeper/test/ClientTest.java
  27. 36 51
      src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
  28. 20 20
      src/java/test/org/apache/zookeeper/test/CreateModeTest.java
  29. 8 8
      src/java/test/org/apache/zookeeper/test/DataTreeTest.java
  30. 0 5
      src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java
  31. 5 5
      src/java/test/org/apache/zookeeper/test/EventTypeTest.java
  32. 11 32
      src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java
  33. 12 13
      src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java
  34. 10 11
      src/java/test/org/apache/zookeeper/test/FLERestartTest.java
  35. 12 13
      src/java/test/org/apache/zookeeper/test/FLETest.java
  36. 12 14
      src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java
  37. 3 3
      src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java
  38. 2 1
      src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
  39. 41 41
      src/java/test/org/apache/zookeeper/test/GetChildren2Test.java
  40. 10 23
      src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
  41. 6 15
      src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java
  42. 7 7
      src/java/test/org/apache/zookeeper/test/KeeperStateTest.java
  43. 12 21
      src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java
  44. 9 6
      src/java/test/org/apache/zookeeper/test/LETest.java
  45. 27 23
      src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java
  46. 6 3
      src/java/test/org/apache/zookeeper/test/NullDataTest.java
  47. 5 8
      src/java/test/org/apache/zookeeper/test/OOMTest.java
  48. 0 5
      src/java/test/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java
  49. 1 4
      src/java/test/org/apache/zookeeper/test/ObserverQuorumHammerTest.java
  50. 15 18
      src/java/test/org/apache/zookeeper/test/ObserverTest.java
  51. 8 10
      src/java/test/org/apache/zookeeper/test/PurgeTxnTest.java
  52. 17 20
      src/java/test/org/apache/zookeeper/test/QuorumBase.java
  53. 6 3
      src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java
  54. 7 22
      src/java/test/org/apache/zookeeper/test/QuorumQuotaTest.java
  55. 36 32
      src/java/test/org/apache/zookeeper/test/QuorumTest.java
  56. 16 22
      src/java/test/org/apache/zookeeper/test/QuorumZxidSyncTest.java
  57. 19 28
      src/java/test/org/apache/zookeeper/test/RecoveryTest.java
  58. 5 9
      src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java
  59. 32 33
      src/java/test/org/apache/zookeeper/test/SessionTest.java
  60. 80 80
      src/java/test/org/apache/zookeeper/test/StatTest.java
  61. 4 4
      src/java/test/org/apache/zookeeper/test/SyncCallTest.java
  62. 5 5
      src/java/test/org/apache/zookeeper/test/TruncateTest.java
  63. 9 16
      src/java/test/org/apache/zookeeper/test/UpgradeTest.java
  64. 13 13
      src/java/test/org/apache/zookeeper/test/WatchedEventTest.java
  65. 109 101
      src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java
  66. 31 30
      src/java/test/org/apache/zookeeper/test/WatcherTest.java
  67. 21 16
      src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java
  68. 7 21
      src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java
  69. 38 38
      src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java

+ 2 - 0
CHANGES.txt

@@ -9,6 +9,8 @@ Backward compatible changes:
 BUGFIXES: 
 
 IMPROVEMENTS:
+  ZOOKEEPER-724. Improve junit test integration - log harness information 
+  (phunt via mahadev)
 
 NEW FEATURES:
 

+ 7 - 16
src/java/test/org/apache/zookeeper/server/CRCTest.java

@@ -34,8 +34,6 @@ import java.util.concurrent.CountDownLatch;
 import java.util.zip.Adler32;
 import java.util.zip.CheckedInputStream;
 
-import junit.framework.TestCase;
-
 import org.apache.jute.BinaryInputArchive;
 import org.apache.jute.InputArchive;
 import org.apache.log4j.Logger;
@@ -43,6 +41,7 @@ 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;
@@ -50,24 +49,16 @@ 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;
 
-public class CRCTest extends TestCase implements Watcher{
+public class CRCTest extends ZKTestCase implements Watcher {
     private static final Logger LOG = Logger.getLogger(CRCTest.class);
 
     private static final String HOSTPORT =
         "127.0.0.1:" + PortAssignment.unique();
     private volatile CountDownLatch startSignal;
 
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
-    }
-    @Override
-    protected void tearDown() throws Exception {
-        LOG.info("FINISHED " + getName());
-    }
-
     /**
      * corrupt a file by writing m at 500 b
      * offset
@@ -129,7 +120,7 @@ public class CRCTest extends TestCase implements Watcher{
                 new InetSocketAddress(PORT));
         f.startup(zks);
         LOG.info("starting up the zookeeper server .. waiting");
-        assertTrue("waiting for server being up",
+        Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
         ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
         try {
@@ -141,7 +132,7 @@ public class CRCTest extends TestCase implements Watcher{
             zk.close();
         }
         f.shutdown();
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                    ClientBase.waitForServerDown(HOSTPORT,
                            ClientBase.CONNECTION_TIMEOUT));
 
@@ -164,7 +155,7 @@ public class CRCTest extends TestCase implements Watcher{
         try {
             while (itr.next()) {
             }
-            assertTrue(false);
+            Assert.assertTrue(false);
         } catch(IOException ie) {
             LOG.info("crc corruption", ie);
         }
@@ -185,7 +176,7 @@ public class CRCTest extends TestCase implements Watcher{
             corruptFile(snapFile);
             cfile = getCheckSum(snap, snapFile);
         }
-        assertTrue(cfile);
+        Assert.assertTrue(cfile);
    }
 
     public void process(WatchedEvent event) {

+ 10 - 5
src/java/test/org/apache/zookeeper/server/DataTreeUnitTest.java

@@ -18,24 +18,29 @@
 
 package org.apache.zookeeper.server;
 
-import junit.framework.TestCase;
-
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.data.Stat;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 
-public class DataTreeUnitTest extends TestCase {
+public class DataTreeUnitTest extends ZKTestCase {
     DataTree dt;
 
+    @Before
     public void setUp() throws Exception {
         dt=new DataTree();
     }
 
+    @After
     public void tearDown() throws Exception {
         dt=null;
     }
 
-
+    @Test
     public void testRootWatchTriggered() throws Exception {
         class MyWatcher implements Watcher{
             boolean fired=false;
@@ -49,7 +54,7 @@ public class DataTreeUnitTest extends TestCase {
         dt.getChildren("/", new Stat(), watcher);
         // add a new node, should trigger a watch
         dt.createNode("/xyz", new byte[0], null, 0, 1, 1);
-        assertFalse("Root node watch not triggered",!watcher.fired);
+        Assert.assertFalse("Root node watch not triggered",!watcher.fired);
     }
 
 }

+ 4 - 4
src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java

@@ -22,15 +22,15 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
-import junit.framework.TestCase;
-
 import org.apache.jute.BinaryInputArchive;
 import org.apache.jute.BinaryOutputArchive;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZKTestCase;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class DeserializationPerfTest extends TestCase {
+public class DeserializationPerfTest extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(DeserializationPerfTest.class);
 
     private static void deserializeTree(int depth, int width, int len)
@@ -60,7 +60,7 @@ public class DeserializationPerfTest extends TestCase {
         long durationms = (end - start) / 1000000L;
         long pernodeus = ((end - start) / 1000L) / count;
 
-        assertEquals(count, dserTree.getNodeCount());
+        Assert.assertEquals(count, dserTree.getNodeCount());
 
         LOG.info("Deserialized " + count + " nodes in " + durationms
                 + " ms (" + pernodeus + "us/node), depth=" + depth + " width="

+ 9 - 9
src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java

@@ -22,16 +22,16 @@ import java.io.File;
 import java.io.RandomAccessFile;
 import java.net.InetSocketAddress;
 
-import junit.framework.TestCase;
-
 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.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.test.ClientBase;
+import org.junit.Assert;
 import org.junit.Test;
 
 /**
@@ -40,7 +40,7 @@ import org.junit.Test;
  * by corruption or if the server crashes
  * while generating the snapshot.
  */
-public class InvalidSnapshotTest extends TestCase implements Watcher {
+public class InvalidSnapshotTest extends ZKTestCase implements Watcher {
     private static final Logger LOG =
         Logger.getLogger(InvalidSnapshotTest.class);
 
@@ -63,7 +63,7 @@ public class InvalidSnapshotTest extends TestCase implements Watcher {
        NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(
                new InetSocketAddress(PORT));
        f.startup(zks);
-       assertTrue("waiting for server being up ",
+       Assert.assertTrue("waiting for server being up ",
                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
        try {
@@ -75,7 +75,7 @@ public class InvalidSnapshotTest extends TestCase implements Watcher {
            zk.close();
        }
        f.shutdown();
-       assertTrue("waiting for server to shutdown",
+       Assert.assertTrue("waiting for server to shutdown",
                ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
        // now corrupt the snapshot
        File snapFile = zks.getTxnLogFactory().findMostRecentSnapshot();
@@ -87,22 +87,22 @@ public class InvalidSnapshotTest extends TestCase implements Watcher {
        SyncRequestProcessor.setSnapCount(100);
        f = new NIOServerCnxn.Factory(new InetSocketAddress(PORT));
        f.startup(zks);
-       assertTrue("waiting for server being up ",
+       Assert.assertTrue("waiting for server being up ",
                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
        // the server should come up
        zk = new ZooKeeper(HOSTPORT, 20000, this);
        try {
-           assertTrue("the node should exist",
+           Assert.assertTrue("the node should exist",
                    (zk.exists("/invalidsnap-1999", false) != null));
            f.shutdown();
-           assertTrue("waiting for server to shutdown",
+           Assert.assertTrue("waiting for server to shutdown",
                    ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
        } finally {
            zk.close();
        }
 
        f.shutdown();
-       assertTrue("waiting for server to shutdown",
+       Assert.assertTrue("waiting for server to shutdown",
                ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
     }
 

+ 2 - 3
src/java/test/org/apache/zookeeper/server/SerializationPerfTest.java

@@ -21,14 +21,13 @@ package org.apache.zookeeper.server;
 import java.io.IOException;
 import java.io.OutputStream;
 
-import junit.framework.TestCase;
-
 import org.apache.jute.BinaryOutputArchive;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZKTestCase;
 import org.junit.Test;
 
-public class SerializationPerfTest extends TestCase {
+public class SerializationPerfTest extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(SerializationPerfTest.class);
 
     private static class NullOutputStream extends OutputStream {

+ 4 - 4
src/java/test/org/apache/zookeeper/server/ToStringTest.java

@@ -18,21 +18,21 @@
 
 package org.apache.zookeeper.server;
 
-import junit.framework.TestCase;
-
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.proto.SetDataRequest;
+import org.junit.Assert;
 import org.junit.Test;
 
 /**
  * A misc place to verify toString methods - mainly to make sure they don't
  * fail.
  */
-public class ToStringTest extends TestCase {
+public class ToStringTest extends ZKTestCase {
     /** Verify jute - which we've had particular problems with in the past 
      * wrt null fields */
     @Test
     public void testJuteToString() {
         SetDataRequest req = new SetDataRequest(null, null, 0);
-        assertNotSame("ERROR", req.toString());
+        Assert.assertNotSame("ERROR", req.toString());
     }
 }

+ 6 - 7
src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java

@@ -24,22 +24,22 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
 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;
 import org.apache.zookeeper.test.ClientBase;
+import org.junit.Assert;
 import org.junit.Test;
 
 /**
  * Test stand-alone server.
  *
  */
-public class ZooKeeperServerMainTest extends TestCase implements Watcher {
+public class ZooKeeperServerMainTest extends ZKTestCase implements Watcher {
     protected static final Logger LOG =
         Logger.getLogger(ZooKeeperServerMainTest.class);
 
@@ -97,7 +97,6 @@ public class ZooKeeperServerMainTest extends TestCase implements Watcher {
      */
     @Test
     public void testStandalone() throws Exception {
-        LOG.info("STARTING " + getName());
         ClientBase.setupTestEnv();
 
         final int CLIENT_PORT = 3181;
@@ -105,7 +104,7 @@ public class ZooKeeperServerMainTest extends TestCase implements Watcher {
         MainThread main = new MainThread(CLIENT_PORT);
         main.start();
 
-        assertTrue("waiting for server being up",
+        Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                         CONNECTION_TIMEOUT));
 
@@ -115,12 +114,12 @@ public class ZooKeeperServerMainTest extends TestCase implements Watcher {
 
         zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
-        assertEquals(new String(zk.getData("/foo", null, null)), "foobar");
+        Assert.assertEquals(new String(zk.getData("/foo", null, null)), "foobar");
         zk.close();
 
         main.shutdown();
 
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                 ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
                         ClientBase.CONNECTION_TIMEOUT));
     }

+ 17 - 17
src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java

@@ -21,13 +21,13 @@ package org.apache.zookeeper.server;
 import java.io.File;
 import java.util.List;
 
-import junit.framework.TestCase;
-
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.persistence.FileTxnLog;
 import org.apache.zookeeper.server.persistence.Util;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class ZooKeeperServerTest extends TestCase {
+public class ZooKeeperServerTest extends ZKTestCase {
     @Test
     public void testSortDataDirAscending() {
         File[] files = new File[5];
@@ -42,11 +42,11 @@ public class ZooKeeperServerTest extends TestCase {
 
         List<File> filelist = Util.sortDataDir(files, "foo", true);
 
-        assertEquals(orig[2], filelist.get(0));
-        assertEquals(orig[3], filelist.get(1));
-        assertEquals(orig[0], filelist.get(2));
-        assertEquals(orig[1], filelist.get(3));
-        assertEquals(orig[4], filelist.get(4));
+        Assert.assertEquals(orig[2], filelist.get(0));
+        Assert.assertEquals(orig[3], filelist.get(1));
+        Assert.assertEquals(orig[0], filelist.get(2));
+        Assert.assertEquals(orig[1], filelist.get(3));
+        Assert.assertEquals(orig[4], filelist.get(4));
     }
 
     @Test
@@ -63,11 +63,11 @@ public class ZooKeeperServerTest extends TestCase {
 
         List<File> filelist = Util.sortDataDir(files, "foo", false);
 
-        assertEquals(orig[4], filelist.get(0));
-        assertEquals(orig[1], filelist.get(1));
-        assertEquals(orig[0], filelist.get(2));
-        assertEquals(orig[3], filelist.get(3));
-        assertEquals(orig[2], filelist.get(4));
+        Assert.assertEquals(orig[4], filelist.get(0));
+        Assert.assertEquals(orig[1], filelist.get(1));
+        Assert.assertEquals(orig[0], filelist.get(2));
+        Assert.assertEquals(orig[3], filelist.get(3));
+        Assert.assertEquals(orig[2], filelist.get(4));
     }
 
     @Test
@@ -86,10 +86,10 @@ public class ZooKeeperServerTest extends TestCase {
                 FileTxnLog.getLogFiles(files,
                 Long.parseLong("10027c6de", 16));
 
-        assertEquals(3, filelist.length);
-        assertEquals(orig[0], filelist[0]);
-        assertEquals(orig[1], filelist[1]);
-        assertEquals(orig[4], filelist[2]);
+        Assert.assertEquals(3, filelist.length);
+        Assert.assertEquals(orig[0], filelist[0]);
+        Assert.assertEquals(orig[1], filelist[1]);
+        Assert.assertEquals(orig[4], filelist[2]);
     }
 
 }

+ 19 - 21
src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java

@@ -37,6 +37,7 @@ import org.apache.zookeeper.PortAssignment;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.test.ClientBase;
+import org.junit.Assert;
 import org.junit.Test;
 
 
@@ -50,7 +51,6 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
      */
     @Test
     public void testQuorum() throws Exception {
-        LOG.info("STARTING " + getName());
         ClientBase.setupTestEnv();
 
         final int CLIENT_PORT_QP1 = PortAssignment.unique();
@@ -67,10 +67,10 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
         q1.start();
         q2.start();
 
-        assertTrue("waiting for server 1 being up",
+        Assert.assertTrue("waiting for server 1 being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                         CONNECTION_TIMEOUT));
-        assertTrue("waiting for server 2 being up",
+        Assert.assertTrue("waiting for server 2 being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
                         CONNECTION_TIMEOUT));
 
@@ -80,7 +80,7 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
 
         zk.create("/foo_q1", "foobar1".getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
-        assertEquals(new String(zk.getData("/foo_q1", null, null)), "foobar1");
+        Assert.assertEquals(new String(zk.getData("/foo_q1", null, null)), "foobar1");
         zk.close();
 
         zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_QP2,
@@ -88,16 +88,16 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
 
         zk.create("/foo_q2", "foobar2".getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
-        assertEquals(new String(zk.getData("/foo_q2", null, null)), "foobar2");
+        Assert.assertEquals(new String(zk.getData("/foo_q2", null, null)), "foobar2");
         zk.close();
 
         q1.shutdown();
         q2.shutdown();
 
-        assertTrue("waiting for server 1 down",
+        Assert.assertTrue("waiting for server 1 down",
                 ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                         ClientBase.CONNECTION_TIMEOUT));
-        assertTrue("waiting for server 2 down",
+        Assert.assertTrue("waiting for server 2 down",
                 ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2,
                         ClientBase.CONNECTION_TIMEOUT));
     }
@@ -107,7 +107,6 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
      */
     @Test
     public void testBadPeerAddressInQuorum() throws Exception {
-        LOG.info("STARTING " + getName());
         ClientBase.setupTestEnv();
 
         // setup the logger to capture all logs
@@ -136,11 +135,11 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                         5000);
 
-            assertFalse("Server never came up", isup);
+            Assert.assertFalse("Server never came up", isup);
 
             q1.shutdown();
 
-            assertTrue("waiting for server 1 down",
+            Assert.assertTrue("waiting for server 1 down",
                     ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                             ClientBase.CONNECTION_TIMEOUT));
 
@@ -159,7 +158,7 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
                 break;
             }
         }
-        assertTrue("complains about host", found);
+        Assert.assertTrue("complains about host", found);
     }
 
     /**
@@ -167,8 +166,8 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
      * at the quorum port
      * @throws Exception
      */
+    @Test
     public void testBadPackets() throws Exception {
-        LOG.info("STARTING " + getName());
         ClientBase.setupTestEnv();
         final int CLIENT_PORT_QP1 = PortAssignment.unique();
         final int CLIENT_PORT_QP2 = PortAssignment.unique();
@@ -185,10 +184,10 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
         q1.start();
         q2.start();
         
-        assertTrue("waiting for server 1 being up",
+        Assert.assertTrue("waiting for server 1 being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                         CONNECTION_TIMEOUT));
-        assertTrue("waiting for server 2 being up",
+        Assert.assertTrue("waiting for server 2 being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
                             CONNECTION_TIMEOUT));
             
@@ -210,7 +209,7 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
 
         zk.create("/foo_q1", "foobar1".getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
-        assertEquals(new String(zk.getData("/foo_q1", null, null)), "foobar1");
+        Assert.assertEquals(new String(zk.getData("/foo_q1", null, null)), "foobar1");
         zk.close();
         q1.shutdown();
         q2.shutdown();
@@ -223,7 +222,6 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
      */
     @Test
     public void testQuorumDefaults() throws Exception {
-        LOG.info("STARTING " + getName());
         ClientBase.setupTestEnv();
 
         // setup the logger to capture all logs
@@ -251,20 +249,20 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
             q1.start();
             q2.start();
 
-            assertTrue("waiting for server 1 being up",
+            Assert.assertTrue("waiting for server 1 being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                             CONNECTION_TIMEOUT));
-            assertTrue("waiting for server 2 being up",
+            Assert.assertTrue("waiting for server 2 being up",
                     ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
                             CONNECTION_TIMEOUT));
 
             q1.shutdown();
             q2.shutdown();
 
-            assertTrue("waiting for server 1 down",
+            Assert.assertTrue("waiting for server 1 down",
                     ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                             ClientBase.CONNECTION_TIMEOUT));
-            assertTrue("waiting for server 2 down",
+            Assert.assertTrue("waiting for server 2 down",
                     ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2,
                             ClientBase.CONNECTION_TIMEOUT));
 
@@ -283,7 +281,7 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
                 break;
             }
         }
-        assertTrue("fastleaderelection used", found);
+        Assert.assertTrue("fastleaderelection used", found);
     }
    
 }

+ 2 - 3
src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTestBase.java

@@ -25,11 +25,10 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.test.ClientBase;
 import org.apache.zookeeper.test.QuorumBase;
 
@@ -37,7 +36,7 @@ import org.apache.zookeeper.test.QuorumBase;
  * Has some common functionality for tests that work with QuorumPeers.
  * Override process(WatchedEvent) to implement the Watcher interface
  */
-public class QuorumPeerTestBase extends TestCase implements Watcher {
+public class QuorumPeerTestBase extends ZKTestCase implements Watcher {
     protected static final Logger LOG =
         Logger.getLogger(QuorumPeerTestBase.class);
     

+ 5 - 28
src/java/test/org/apache/zookeeper/test/ACLRootTest.java

@@ -23,35 +23,12 @@ import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Assert;
 import org.junit.Test;
 
-/**
- * Functional testing of asynchronous operations, both positive and negative
- * testing.
- * 
- * This just scratches the surface, but exercises the basic async functionality.
- */
 public class ACLRootTest extends ClientBase {
     private static final Logger LOG = Logger.getLogger(ACLRootTest.class);
 
-    @Before
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        
-        LOG.info("STARTING " + getName());
-    }
-
-    @After
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        
-        LOG.info("FINISHED " + getName());
-    }
-
     @Test
     public void testRootAcl() throws Exception {
         ZooKeeper zk = createClient();
@@ -65,14 +42,14 @@ public class ACLRootTest extends ClientBase {
             zk = createClient();
             try {
                 zk.getData("/", false, null);
-                fail("validate auth");
+                Assert.fail("validate auth");
             } catch (KeeperException.NoAuthException e) {
                 // expected
             }
             try {
                 zk.create("/apps", null, Ids.CREATOR_ALL_ACL,
                         CreateMode.PERSISTENT);
-                fail("validate auth");
+                Assert.fail("validate auth");
             } catch (KeeperException.InvalidACLException e) {
                 // expected
             }
@@ -80,7 +57,7 @@ public class ACLRootTest extends ClientBase {
             try {
                 zk.create("/apps", null, Ids.CREATOR_ALL_ACL,
                         CreateMode.PERSISTENT);
-                fail("validate auth");
+                Assert.fail("validate auth");
             } catch (KeeperException.NoAuthException e) {
                 // expected
             }
@@ -102,7 +79,7 @@ public class ACLRootTest extends ClientBase {
             try {
                 zk.create("/apps", null, Ids.CREATOR_ALL_ACL,
                         CreateMode.PERSISTENT);
-                fail("validate auth");
+                Assert.fail("validate auth");
             } catch (KeeperException.InvalidACLException e) {
                 // expected
             }

+ 17 - 23
src/java/test/org/apache/zookeeper/test/ACLTest.java

@@ -26,13 +26,12 @@ import java.util.ArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import junit.framework.TestCase;
-
 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.ZooKeeper;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
@@ -41,22 +40,16 @@ import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.SyncRequestProcessor;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.Assert;
+import org.junit.Test;
 
-public class ACLTest extends TestCase implements Watcher {
+public class ACLTest extends ZKTestCase implements Watcher {
     private static final Logger LOG = Logger.getLogger(ACLTest.class);
     private static final String HOSTPORT =
         "127.0.0.1:" + PortAssignment.unique();
     private volatile CountDownLatch startSignal;
 
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
-    }
-    @Override
-    protected void tearDown() throws Exception {
-        LOG.info("FINISHED " + getName());
-    }
-
+    @Test
     public void testDisconnectedAddAuth() throws Exception {
         File tmpDir = ClientBase.createTmpDir();
         ClientBase.setupTestEnv();
@@ -67,7 +60,7 @@ public class ACLTest extends TestCase implements Watcher {
                 new InetSocketAddress(PORT));
         f.startup(zks);
         LOG.info("starting up the zookeeper server .. waiting");
-        assertTrue("waiting for server being up",
+        Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
         ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
         try {
@@ -79,7 +72,7 @@ public class ACLTest extends TestCase implements Watcher {
 
         f.shutdown();
 
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                    ClientBase.waitForServerDown(HOSTPORT,
                            ClientBase.CONNECTION_TIMEOUT));
     }
@@ -89,6 +82,7 @@ public class ACLTest extends TestCase implements Watcher {
      * a few acls and there references in the data
      * node is actually working.
      */
+    @Test
     public void testAcls() throws Exception {
         File tmpDir = ClientBase.createTmpDir();
         ClientBase.setupTestEnv();
@@ -99,7 +93,7 @@ public class ACLTest extends TestCase implements Watcher {
                 new InetSocketAddress(PORT));
         f.startup(zks);
         LOG.info("starting up the zookeeper server .. waiting");
-        assertTrue("waiting for server being up",
+        Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
         ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
         String path;
@@ -109,7 +103,7 @@ public class ACLTest extends TestCase implements Watcher {
             zk.create(path, path.getBytes(), Ids.OPEN_ACL_UNSAFE,
                     CreateMode.PERSISTENT);
         }
-        assertTrue("size of the acl map ", (1 == zks.getZKDatabase().getAclSize()));
+        Assert.assertTrue("size of the acl map ", (1 == zks.getZKDatabase().getAclSize()));
         for (int j = 100; j < 200; j++) {
             path = "/" + j;
             ACL acl = new ACL();
@@ -122,10 +116,10 @@ public class ACLTest extends TestCase implements Watcher {
             list.add(acl);
             zk.create(path, path.getBytes(), list, CreateMode.PERSISTENT);
         }
-        assertTrue("size of the acl map ", (101 == zks.getZKDatabase().getAclSize()));
+        Assert.assertTrue("size of the acl map ", (101 == zks.getZKDatabase().getAclSize()));
         // now shutdown the server and restart it
         f.shutdown();
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                 ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
         startSignal = new CountDownLatch(1);
 
@@ -134,14 +128,14 @@ public class ACLTest extends TestCase implements Watcher {
 
         f.startup(zks);
 
-        assertTrue("waiting for server up",
+        Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
 
         startSignal.await(CONNECTION_TIMEOUT,
                 TimeUnit.MILLISECONDS);
-        assertTrue("count == 0", startSignal.getCount() == 0);
+        Assert.assertTrue("count == 0", startSignal.getCount() == 0);
 
-        assertTrue("acl map ", (101 == zks.getZKDatabase().getAclSize()));
+        Assert.assertTrue("acl map ", (101 == zks.getZKDatabase().getAclSize()));
         for (int j = 200; j < 205; j++) {
             path = "/" + j;
             ACL acl = new ACL();
@@ -154,13 +148,13 @@ public class ACLTest extends TestCase implements Watcher {
             list.add(acl);
             zk.create(path, path.getBytes(), list, CreateMode.PERSISTENT);
         }
-        assertTrue("acl map ", (106 == zks.getZKDatabase().getAclSize()));
+        Assert.assertTrue("acl map ", (106 == zks.getZKDatabase().getAclSize()));
 
         zk.close();
 
         f.shutdown();
 
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                    ClientBase.waitForServerDown(HOSTPORT,
                            ClientBase.CONNECTION_TIMEOUT));
 

+ 15 - 19
src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java

@@ -23,13 +23,12 @@ import static org.apache.zookeeper.test.ClientBase.verifyThreadTerminated;
 
 import java.util.LinkedList;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.TestableZooKeeper;
 import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
@@ -37,10 +36,11 @@ import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class AsyncHammerTest extends TestCase
+public class AsyncHammerTest extends ZKTestCase
     implements StringCallback, VoidCallback, DataCallback
 {
     private static final Logger LOG = Logger.getLogger(AsyncHammerTest.class);
@@ -50,14 +50,12 @@ public class AsyncHammerTest extends TestCase
     private volatile boolean bang;
 
     @Before
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
+    public void setUp() throws Exception {
         qb.setUp();
     }
 
     protected void restart() throws Exception {
-        LOG.info("RESTARTING " + getName());
+        LOG.info("RESTARTING " + getTestName());
         qb.tearDown();
 
         // don't call setup - we don't want to reassign ports/dirs, etc...
@@ -66,11 +64,9 @@ public class AsyncHammerTest extends TestCase
     }
 
     @After
-    @Override
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         LOG.info("Test clients shutting down");
         qb.tearDown();
-        LOG.info("FINISHED " + getName());
     }
 
     /**
@@ -101,11 +97,11 @@ public class AsyncHammerTest extends TestCase
                 }
             } catch (InterruptedException e) {
                 if (bang) {
-                    LOG.error("sanity check failed!!!"); // sanity check
+                    LOG.error("sanity check Assert.failed!!!"); // sanity check
                     return;
                 }
             } catch (Exception e) {
-                LOG.error("Client create operation failed", e);
+                LOG.error("Client create operation Assert.failed", e);
                 return;
             } finally {
                 if (zk != null) {
@@ -131,7 +127,7 @@ public class AsyncHammerTest extends TestCase
 
         private synchronized void decOutstanding() {
             outstanding--;
-            assertTrue("outstanding >= 0", outstanding >= 0);
+            Assert.assertTrue("outstanding >= 0", outstanding >= 0);
             notifyAll();
         }
 
@@ -143,7 +139,7 @@ public class AsyncHammerTest extends TestCase
             if (rc != KeeperException.Code.OK.intValue()) {
                 if (bang) {
                     failed = true;
-                    LOG.error("Create failed for 0x"
+                    LOG.error("Create Assert.failed for 0x"
                             + Long.toHexString(zk.getSessionId())
                             + "with rc:" + rc + " path:" + path);
                 }
@@ -156,7 +152,7 @@ public class AsyncHammerTest extends TestCase
             } catch (Exception e) {
                 if (bang) {
                     failed = true;
-                    LOG.error("Client delete failed", e);
+                    LOG.error("Client delete Assert.failed", e);
                 }
             }
         }
@@ -165,7 +161,7 @@ public class AsyncHammerTest extends TestCase
             if (rc != KeeperException.Code.OK.intValue()) {
                 if (bang) {
                     failed = true;
-                    LOG.error("Delete failed for 0x"
+                    LOG.error("Delete Assert.failed for 0x"
                             + Long.toHexString(zk.getSessionId())
                             + "with rc:" + rc + " path:" + path);
                 }
@@ -189,7 +185,7 @@ public class AsyncHammerTest extends TestCase
         for (int i = 0; i < hammers.length; i++) {
             hammers[i].interrupt();
             verifyThreadTerminated(hammers[i], 60000);
-            assertFalse(hammers[i].failed);
+            Assert.assertFalse(hammers[i].failed);
         }
 
         // before restart
@@ -202,7 +198,7 @@ public class AsyncHammerTest extends TestCase
         LOG.info("Verifying hammers 2");
         qb.verifyRootOfAllServersMatch(qb.hostPort);
     }
-    
+
     @Test
     public void testObserversHammer() throws Exception {
         qb.tearDown();
@@ -220,7 +216,7 @@ public class AsyncHammerTest extends TestCase
             verifyThreadTerminated(hammers[i], 60000);
         }
         // before restart
-        qb.verifyRootOfAllServersMatch(qb.hostPort);          
+        qb.verifyRootOfAllServersMatch(qb.hostPort);
     }
 
     @SuppressWarnings("unchecked")

+ 5 - 23
src/java/test/org/apache/zookeeper/test/AsyncOps.java

@@ -18,10 +18,6 @@
 
 package org.apache.zookeeper.test;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertSame;
-import static junit.framework.Assert.fail;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
@@ -31,8 +27,8 @@ import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.ACLCallback;
-import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
 import org.apache.zookeeper.AsyncCallback.Children2Callback;
+import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
@@ -41,22 +37,8 @@ import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
 
-/**
- * The intent of these classes is to support testing the functionality of
- * asynchronous client operations. Both positive as well as negative tests.
- * 
- * This code acts as a "contract checker" of sorts. We look at the 
- * actual output as well as the expected output - if the actual output 
- * changes over time this code should catch the regression and alert to a 
- * potentially unwanted (unexpected) change.
- * 
- * In addition these classes can be re-used by other tests that need to
- * perform these operations. In general the classes err on the side of
- * convention over a lot of setup - such that you can use start using them
- * w/o a lot of though (default path/data/acl/etc...). See AsyncOpsTest
- * for some good examples of use.
- */
 public class AsyncOps {
     /**
      * This is the base class for all of the async callback classes. It will
@@ -121,14 +103,14 @@ public class AsyncOps {
             try {
                 latch.await(defaultTimeoutMillis, TimeUnit.MILLISECONDS);
             } catch (InterruptedException e) {
-                fail("unexpected interrupt");
+                Assert.fail("unexpected interrupt");
             }
             // on the lookout for timeout
-            assertSame(0L, latch.getCount());
+            Assert.assertSame(0L, latch.getCount());
             
             String actual = toString();
             
-            assertEquals(expected, actual);
+            Assert.assertEquals(expected, actual);
         }
     }
     

+ 4 - 12
src/java/test/org/apache/zookeeper/test/AsyncOpsTest.java

@@ -23,8 +23,8 @@ import java.util.concurrent.CountDownLatch;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.test.AsyncOps.ACLCB;
-import org.apache.zookeeper.test.AsyncOps.ChildrenCB;
 import org.apache.zookeeper.test.AsyncOps.Children2CB;
+import org.apache.zookeeper.test.AsyncOps.ChildrenCB;
 import org.apache.zookeeper.test.AsyncOps.DataCB;
 import org.apache.zookeeper.test.AsyncOps.StatCB;
 import org.apache.zookeeper.test.AsyncOps.StringCB;
@@ -33,12 +33,6 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-/**
- * Functional testing of asynchronous operations, both positive and negative
- * testing.
- *
- * This just scratches the surface, but exercises the basic async functionality.
- */
 public class AsyncOpsTest extends ClientBase {
     private static final Logger LOG = Logger.getLogger(AsyncOpsTest.class);
 
@@ -46,10 +40,10 @@ public class AsyncOpsTest extends ClientBase {
 
     @Before
     @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         super.setUp();
 
-        LOG.info("STARTING " + getName());
+        LOG.info("Creating client " + getTestName());
 
         zk = createClient();
         zk.addAuthInfo("digest", "ben:passwd".getBytes());
@@ -57,14 +51,12 @@ public class AsyncOpsTest extends ClientBase {
 
     @After
     @Override
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         zk.close();
 
         super.tearDown();
 
         LOG.info("Test clients shutting down");
-
-        LOG.info("FINISHED " + getName());
     }
 
     @Test

+ 14 - 18
src/java/test/org/apache/zookeeper/test/AsyncTest.java

@@ -25,13 +25,12 @@ import java.util.LinkedList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 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;
@@ -41,10 +40,11 @@ import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class AsyncTest extends TestCase
+public class AsyncTest extends ZKTestCase
     implements StringCallback, VoidCallback, DataCallback
 {
     private static final Logger LOG = Logger.getLogger(AsyncTest.class);
@@ -52,23 +52,19 @@ public class AsyncTest extends TestCase
     private QuorumBase qb = new QuorumBase();
 
     @Before
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
+    public void setUp() throws Exception {
         qb.setUp();
     }
 
-    protected void restart() throws Exception {
+    public void restart() throws Exception {
         JMXEnv.setUp();
         qb.startServers();
     }
 
     @After
-    @Override
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         LOG.info("Test clients shutting down");
         qb.tearDown();
-        LOG.info("FINISHED " + getName());
     }
 
     private static class CountdownWatcher implements Watcher {
@@ -93,7 +89,7 @@ public class AsyncTest extends TestCase
         if(!watcher.clientConnected.await(CONNECTION_TIMEOUT,
                 TimeUnit.MILLISECONDS))
         {
-            fail("Unable to connect to server");
+            Assert.fail("Unable to connect to server");
         }
         return zk;
     }
@@ -117,11 +113,11 @@ public class AsyncTest extends TestCase
                     results.wait();
                 }
             }
-            assertEquals(0, (int) results.get(0));
-            assertEquals(Code.NOAUTH, Code.get(results.get(1)));
-            assertEquals(0, (int) results.get(2));
-            assertEquals(0, (int) results.get(3));
-            assertEquals(0, (int) results.get(4));
+            Assert.assertEquals(0, (int) results.get(0));
+            Assert.assertEquals(Code.NOAUTH, Code.get(results.get(1)));
+            Assert.assertEquals(0, (int) results.get(2));
+            Assert.assertEquals(0, (int) results.get(3));
+            Assert.assertEquals(0, (int) results.get(4));
         } finally {
             zk.close();
         }
@@ -131,9 +127,9 @@ public class AsyncTest extends TestCase
             zk.addAuthInfo("digest", "ben:passwd2".getBytes());
             try {
                 zk.getData("/ben2", false, new Stat());
-                fail("Should have received a permission error");
+                Assert.fail("Should have received a permission error");
             } catch (KeeperException e) {
-                assertEquals(Code.NOAUTH, e.code());
+                Assert.assertEquals(Code.NOAUTH, e.code());
             }
         } finally {
             zk.close();

+ 6 - 5
src/java/test/org/apache/zookeeper/test/AuthTest.java

@@ -22,6 +22,7 @@ import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class AuthTest extends ClientBase {
@@ -43,27 +44,27 @@ public class AuthTest extends ClientBase {
             zk = createClient();
             try {
                 zk.getData("/path1", false, null);
-                fail("auth verification");
+                Assert.fail("auth verification");
             } catch (KeeperException.NoAuthException e) {
                 // expected
             }
             zk.close();
-            // verify bad pass fails
+            // verify bad pass Assert.fails
             zk = createClient();
             zk.addAuthInfo("digest", "pat:pass2".getBytes());
             try {
                 zk.getData("/path1", false, null);
-                fail("auth verification");
+                Assert.fail("auth verification");
             } catch (KeeperException.NoAuthException e) {
                 // expected
             }
             zk.close();
-            // verify super with bad pass fails
+            // verify super with bad pass Assert.fails
             zk = createClient();
             zk.addAuthInfo("digest", "super:test2".getBytes());
             try {
                 zk.getData("/path1", false, null);
-                fail("auth verification");
+                Assert.fail("auth verification");
             } catch (KeeperException.NoAuthException e) {
                 // expected
             }

+ 2 - 4
src/java/test/org/apache/zookeeper/test/ChrootAsyncTest.java

@@ -22,20 +22,18 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
-import org.junit.Before;
 
 public class ChrootAsyncTest extends AsyncOpsTest {
     private static final Logger LOG = Logger.getLogger(ChrootAsyncTest.class);
 
-    @Before
     @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         String hp = hostPort;
         hostPort = hostPort + "/chrootasynctest";
 
         super.setUp();
 
-        LOG.info("STARTING " + getName());
+        LOG.info("Creating client " + getTestName());
 
         ZooKeeper zk = createClient(hp);
         try {

+ 2 - 4
src/java/test/org/apache/zookeeper/test/ChrootClientTest.java

@@ -22,22 +22,20 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
-import org.junit.Before;
 import org.junit.Test;
 
 public class ChrootClientTest extends ClientTest {
     private static final Logger LOG = Logger.getLogger(ChrootClientTest.class);
 
-    @Before
     @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         String hp = hostPort;
         hostPort = hostPort + "/chrootclienttest";
 
         System.out.println(hostPort);
         super.setUp();
 
-        LOG.info("STARTING " + getName());
+        LOG.info("STARTING " + getTestName());
 
         ZooKeeper zk = createClient(hp);
         try {

+ 20 - 17
src/java/test/org/apache/zookeeper/test/ChrootTest.java

@@ -29,6 +29,8 @@ import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.junit.Assert;
+import org.junit.Test;
 
 public class ChrootTest extends ClientBase {
     private class MyWatcher implements Watcher {
@@ -46,12 +48,13 @@ public class ChrootTest extends ClientBase {
         }
         public boolean matches() throws InterruptedException {
             if (!latch.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)) {
-                fail("No watch received within timeout period " + path);
+                Assert.fail("No watch received within timeout period " + path);
             }
             return path.equals(eventPath);
         }
     }
 
+    @Test
     public void testChrootSynchronous()
         throws IOException, InterruptedException, KeeperException
     {
@@ -65,7 +68,7 @@ public class ChrootTest extends ClientBase {
         }
         ZooKeeper zk2 = createClient(hostPort + "/ch1");
         try {
-            assertEquals("/ch2",
+            Assert.assertEquals("/ch2",
                     zk2.create("/ch2", null, Ids.OPEN_ACL_UNSAFE,
                             CreateMode.PERSISTENT));
         } finally {
@@ -78,12 +81,12 @@ public class ChrootTest extends ClientBase {
         try {
             // check get
             MyWatcher w1 = new MyWatcher("/ch1");
-            assertNotNull(zk1.exists("/ch1", w1));
+            Assert.assertNotNull(zk1.exists("/ch1", w1));
             MyWatcher w2 = new MyWatcher("/ch1/ch2");
-            assertNotNull(zk1.exists("/ch1/ch2", w2));
+            Assert.assertNotNull(zk1.exists("/ch1/ch2", w2));
 
             MyWatcher w3 = new MyWatcher("/ch2");
-            assertNotNull(zk2.exists("/ch2", w3));
+            Assert.assertNotNull(zk2.exists("/ch2", w3));
             
             // set watches on child
             MyWatcher w4 = new MyWatcher("/ch1");
@@ -96,33 +99,33 @@ public class ChrootTest extends ClientBase {
             zk2.setData("/ch2", "2".getBytes(), -1);
 
             // check watches
-            assertTrue(w1.matches());
-            assertTrue(w2.matches());
-            assertTrue(w3.matches());
+            Assert.assertTrue(w1.matches());
+            Assert.assertTrue(w2.matches());
+            Assert.assertTrue(w3.matches());
 
             // check exceptions
             try {
                 zk2.setData("/ch3", "3".getBytes(), -1);
             } catch (KeeperException.NoNodeException e) {
-                assertEquals("/ch3", e.getPath());
+                Assert.assertEquals("/ch3", e.getPath());
             }
 
-            assertTrue(Arrays.equals("1".getBytes(),
+            Assert.assertTrue(Arrays.equals("1".getBytes(),
                     zk1.getData("/ch1", false, null)));
-            assertTrue(Arrays.equals("2".getBytes(),
+            Assert.assertTrue(Arrays.equals("2".getBytes(),
                     zk1.getData("/ch1/ch2", false, null)));
-            assertTrue(Arrays.equals("2".getBytes(),
+            Assert.assertTrue(Arrays.equals("2".getBytes(),
                     zk2.getData("/ch2", false, null)));
 
             // check delete
             zk2.delete("/ch2", -1);
-            assertTrue(w4.matches());
-            assertTrue(w5.matches());
+            Assert.assertTrue(w4.matches());
+            Assert.assertTrue(w5.matches());
             
             zk1.delete("/ch1", -1);
-            assertNull(zk1.exists("/ch1", false));
-            assertNull(zk1.exists("/ch1/ch2", false));
-            assertNull(zk2.exists("/ch2", false));
+            Assert.assertNull(zk1.exists("/ch1", false));
+            Assert.assertNull(zk1.exists("/ch1/ch2", false));
+            Assert.assertNull(zk2.exists("/ch2", false));
         } finally {
             if(zk1 != null)
                 zk1.close();

+ 28 - 29
src/java/test/org/apache/zookeeper/test/ClientBase.java

@@ -39,24 +39,26 @@ import java.util.concurrent.TimeoutException;
 
 import javax.management.MBeanServerConnection;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.PortAssignment;
 import org.apache.zookeeper.TestableZooKeeper;
 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.NIOServerCnxn;
 import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.persistence.FileTxnLog;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
 
 import com.sun.management.UnixOperatingSystemMXBean;
 
-public abstract class ClientBase extends TestCase {
+public abstract class ClientBase extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(ClientBase.class);
 
     public static int CONNECTION_TIMEOUT = 30000;
@@ -162,12 +164,12 @@ public abstract class ClientBase extends TestCase {
         TestableZooKeeper zk = new TestableZooKeeper(hp, timeout, watcher);
         if (!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS))
         {
-            fail("Unable to connect to server");
+            Assert.fail("Unable to connect to server");
         }
         synchronized(this) {
             if (!allClientsSetup) {
                 LOG.error("allClients never setup");
-                fail("allClients never setup");
+                Assert.fail("allClients never setup");
             }
             if (allClients != null) {
                 allClients.add(zk);
@@ -297,7 +299,7 @@ public abstract class ClientBase extends TestCase {
         if (thread.isAlive()) {
             LOG.error("Thread " + thread.getName() + " : "
                     + Arrays.toString(thread.getStackTrace()));
-            assertFalse("thread " + thread.getName()
+            Assert.assertFalse("thread " + thread.getName()
                     + " still alive after join", true);
         }
     }
@@ -311,8 +313,8 @@ public abstract class ClientBase extends TestCase {
         // don't delete tmpFile - this ensures we don't attempt to create
         // a tmpDir with a duplicate name
         File tmpDir = new File(tmpFile + ".dir");
-        assertFalse(tmpDir.exists()); // never true if tmpfile does it's job
-        assertTrue(tmpDir.mkdirs());
+        Assert.assertFalse(tmpDir.exists()); // never true if tmpfile does it's job
+        Assert.assertTrue(tmpDir.mkdirs());
 
         return tmpDir;
     }
@@ -336,7 +338,7 @@ public abstract class ClientBase extends TestCase {
             factory = new NIOServerCnxn.Factory(new InetSocketAddress(PORT),maxCnxns);
         }
         factory.startup(zks);
-        assertTrue("waiting for server up",
+        Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                                               CONNECTION_TIMEOUT));
 
@@ -345,18 +347,18 @@ public abstract class ClientBase extends TestCase {
 
     static void shutdownServerInstance(NIOServerCnxn.Factory factory,
             String hostPort)
-    {    	
-    	if (factory != null) {
-    	    ZKDatabase zkDb = factory.getZooKeeperServer().getZKDatabase();
+    {
+        if (factory != null) {
+            ZKDatabase zkDb = factory.getZooKeeperServer().getZKDatabase();
             factory.shutdown();
             try {
                 zkDb.close();
             } catch (IOException ie) {
                 LOG.warn("Error closing logs ", ie);
-       	 	}
+            }
             final int PORT = getPort(hostPort);
 
-            assertTrue("waiting for server down",
+            Assert.assertTrue("waiting for server down",
                        ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                     CONNECTION_TIMEOUT));
         }
@@ -368,7 +370,7 @@ public abstract class ClientBase extends TestCase {
     public static void setupTestEnv() {
         // during the tests we run with 100K prealloc in the logs.
         // on windows systems prealloc of 64M was seen to take ~15seconds
-        // resulting in test failure (client timeout on first session).
+        // resulting in test Assert.failure (client timeout on first session).
         // set env and directly in order to handle static init/gc issues
         System.setProperty("zookeeper.preAllocSize", "100");
         FileTxnLog.setPreallocSize(100 * 1024);
@@ -379,9 +381,8 @@ public abstract class ClientBase extends TestCase {
         allClientsSetup = true;
     }
 
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
+    @Before
+    public void setUp() throws Exception {
         setupTestEnv();
 
         JMXEnv.setUp();
@@ -438,8 +439,8 @@ public abstract class ClientBase extends TestCase {
         }
     }
 
-    @Override
-    protected void tearDown() throws Exception {
+    @After
+    public void tearDown() throws Exception {
         LOG.info("tearDown starting");
 
         /* some useful information - log the number of fds used before
@@ -461,15 +462,13 @@ public abstract class ClientBase extends TestCase {
         stopServer();
 
         if (tmpDir != null) {
-            assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir));
+            Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir));
         }
 
         // This has to be set to null when the same instance of this class is reused between test cases
         serverFactory = null;
 
         JMXEnv.tearDown();
-
-        LOG.info("FINISHED " + getName());
     }
 
     public static MBeanServerConnection jmxConn() throws IOException {
@@ -480,7 +479,7 @@ public abstract class ClientBase extends TestCase {
         if (d.isDirectory()) {
             File children[] = d.listFiles();
             for (File f : children) {
-                assertTrue("delete " + f.toString(), recursiveDelete(f));
+                Assert.assertTrue("delete " + f.toString(), recursiveDelete(f));
             }
         }
         return d.delete();
@@ -519,7 +518,7 @@ public abstract class ClientBase extends TestCase {
             for (String hp : parts) {
                 try {
                     ZooKeeper zk = createClient(hp);
-                   
+
                     try {
                         newcounts[i++] = zk.getChildren("/", false).size();
                     } finally {
@@ -527,7 +526,7 @@ public abstract class ClientBase extends TestCase {
                     }
                 } catch (Throwable t) {
                     failed++;
-                    // if session creation fails dump the thread stack
+                    // if session creation Assert.fails dump the thread stack
                     // and try the next server
                     logAllStackTraces();
                 }
@@ -542,8 +541,8 @@ public abstract class ClientBase extends TestCase {
                 counts = newcounts;
                 Thread.sleep(10000);
             }
-            
-            // don't keep this up too long, will assert false below
+
+            // don't keep this up too long, will Assert.assert false below
             if (failed > 10) {
                 break;
             }
@@ -551,7 +550,7 @@ public abstract class ClientBase extends TestCase {
 
         // verify all the servers reporting same number of nodes
         for (int i = 1; i < parts.length; i++) {
-            assertEquals("node count not consistent", counts[i-1], counts[i]);
+            Assert.assertEquals("node count not consistent", counts[i-1], counts[i]);
         }
     }
 }

+ 9 - 13
src/java/test/org/apache/zookeeper/test/ClientHammerTest.java

@@ -27,16 +27,12 @@ import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class ClientHammerTest extends ClientBase {
     protected static final Logger LOG = Logger.getLogger(ClientHammerTest.class);
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        LOG.info("FINISHED " + getName());
-    }
     private static final long HAMMERTHREAD_LATENCY = 5;
 
     private static abstract class HammerThread extends Thread {
@@ -68,7 +64,7 @@ public class ClientHammerTest extends ClientBase {
                     zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                 }
             } catch (Throwable t) {
-                LOG.error("Client create operation failed", t);
+                LOG.error("Client create operation Assert.failed", t);
             } finally {
                 try {
                     zk.close();
@@ -107,7 +103,7 @@ public class ClientHammerTest extends ClientBase {
                     }
                 }
             } catch (Throwable t) {
-                LOG.error("Client create operation failed", t);
+                LOG.error("Client create operation Assert.failed", t);
             }
         }
     }
@@ -143,7 +139,7 @@ public class ClientHammerTest extends ClientBase {
 
             verifyHammer(start, threads, childCount);
         } catch (Throwable t) {
-            LOG.error("test failed", t);
+            LOG.error("test Assert.failed", t);
             throw t;
         }
     }
@@ -182,7 +178,7 @@ public class ClientHammerTest extends ClientBase {
 
             verifyHammer(start, threads, childCount);
         } catch (Throwable t) {
-            LOG.error("test failed", t);
+            LOG.error("test Assert.failed", t);
             throw t;
         }
     }
@@ -230,16 +226,16 @@ public class ClientHammerTest extends ClientBase {
                 LOG.info("Doing thread: " + i + " " + new Date());
                 List<String> children =
                     zk.getChildren("/test-" + i, false);
-                assertEquals(childCount, children.size());
+                Assert.assertEquals(childCount, children.size());
                 children = zk.getChildren("/test-" + i, false, null);
-                assertEquals(childCount, children.size());
+                Assert.assertEquals(childCount, children.size());
             }
             for (int i = 0; i < threads.length; i++) {
                 List<String> children =
                     zk.getChildren("/test-" + i, false);
-                assertEquals(childCount, children.size());
+                Assert.assertEquals(childCount, children.size());
                 children = zk.getChildren("/test-" + i, false, null);
-                assertEquals(childCount, children.size());
+                Assert.assertEquals(childCount, children.size());
             }
         } finally {
             zk.close();

+ 7 - 16
src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java

@@ -28,37 +28,28 @@ import java.util.Enumeration;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 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.NIOServerCnxn;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class ClientPortBindTest extends TestCase implements Watcher {
+public class ClientPortBindTest extends ZKTestCase implements Watcher {
     protected static final Logger LOG = 
         Logger.getLogger(ClientPortBindTest.class);
 
     private volatile CountDownLatch startSignal;
 
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
-    }
-    @Override
-    protected void tearDown() throws Exception {
-        LOG.info("FINISHED " + getName());
-    }
-
-    @Test
     /**
      * Verify that the server binds to the specified address
      */
+    @Test
     public void testBindByAddress() throws Exception {
         String bindAddress = null;
         Enumeration<NetworkInterface> intfs =
@@ -96,7 +87,7 @@ public class ClientPortBindTest extends TestCase implements Watcher {
         f.startup(zks);
         LOG.info("starting up the the server, waiting");
 
-        assertTrue("waiting for server up",
+        Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp(HOSTPORT,
                                    CONNECTION_TIMEOUT));
 
@@ -105,12 +96,12 @@ public class ClientPortBindTest extends TestCase implements Watcher {
         try {
             startSignal.await(CONNECTION_TIMEOUT,
                     TimeUnit.MILLISECONDS);
-            assertTrue("count == 0", startSignal.getCount() == 0);
+            Assert.assertTrue("count == 0", startSignal.getCount() == 0);
             zk.close();
         } finally {
             f.shutdown();
 
-            assertTrue("waiting for server down",
+            Assert.assertTrue("waiting for server down",
                        ClientBase.waitForServerDown(HOSTPORT,
                                                     CONNECTION_TIMEOUT));
         }

+ 16 - 12
src/java/test/org/apache/zookeeper/test/ClientRetry.java

@@ -22,25 +22,29 @@ import java.util.concurrent.TimeoutException;
 
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper.States;
+import org.junit.Assert;
+import org.junit.Test;
 
 public class ClientRetry extends ClientBase {
 
+    @Override
     public void setUp() throws Exception {
         maxCnxns = 1;
-        super.setUp();     
+        super.setUp();
     }
     /*
-     * This is a simple test - try to connect two clients to a server 
-     * accepting a maximum of one connection from each address. Check that 
+     * This is a simple test - try to connect two clients to a server
+     * accepting a maximum of one connection from each address. Check that
      * only one is accepted. Close that connection, and check that the other
-     * eventually connects. 
-     * 
-     * There is a possibility of a false positive here, as when zk2 is tested 
+     * eventually connects.
+     *
+     * There is a possibility of a false positive here, as when zk2 is tested
      * for having connected it might not have been given enough time, and finish
      * connecting after the test is done. Since the
-     * server doesn't tell the client why it hasn't connected, there's no 
-     * obvious way to detect the difference. 
+     * server doesn't tell the client why it hasn't connected, there's no
+     * obvious way to detect the difference.
      */
+    @Test
     public void testClientRetry() throws IOException, InterruptedException, TimeoutException{
         CountdownWatcher cdw1 = new CountdownWatcher();
         CountdownWatcher cdw2 = new CountdownWatcher();
@@ -51,12 +55,12 @@ public class ClientRetry extends ClientBase {
             try {
                 States s1 = zk.getState();
                 States s2 = zk2.getState();
-                assertSame(s1,States.CONNECTED);
-                assertSame(s2,States.CONNECTING);
+                Assert.assertSame(s1,States.CONNECTED);
+                Assert.assertSame(s2,States.CONNECTING);
                 cdw1.reset();
                 cdw1.waitForDisconnected(CONNECTION_TIMEOUT);
                 cdw2.waitForConnected(CONNECTION_TIMEOUT);
-                assertSame(zk2.getState(),States.CONNECTED);
+                Assert.assertSame(zk2.getState(),States.CONNECTED);
             } finally {
                 zk2.close();
             }
@@ -65,4 +69,4 @@ public class ClientRetry extends ClientBase {
         }
     }
 }
-           
+

+ 79 - 84
src/java/test/org/apache/zookeeper/test/ClientTest.java

@@ -43,6 +43,7 @@ import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.PrepRequestProcessor;
+import org.junit.Assert;
 import org.junit.Test;
 
 import com.sun.management.UnixOperatingSystemMXBean;
@@ -50,12 +51,6 @@ import com.sun.management.UnixOperatingSystemMXBean;
 public class ClientTest extends ClientBase {
     protected static final Logger LOG = Logger.getLogger(ClientTest.class);
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        LOG.info("FINISHED " + getName());
-    }
-
     /** Verify that pings are sent, keeping the "idle" client alive */
     @Test
     public void testPing() throws Exception {
@@ -128,7 +123,7 @@ public class ClientTest extends ClientBase {
             zk = createClient();
             try {
                 zk.create("/acltest", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
-                fail("Should have received an invalid acl error");
+                Assert.fail("Should have received an invalid acl error");
             } catch(InvalidACLException e) {
                 LOG.info("Test successful, invalid acl received : "
                         + e.getMessage());
@@ -138,7 +133,7 @@ public class ClientTest extends ClientBase {
                 testACL.add(new ACL(Perms.ALL | Perms.ADMIN, Ids.AUTH_IDS));
                 testACL.add(new ACL(Perms.ALL | Perms.ADMIN, new Id("ip", "127.0.0.1/8")));
                 zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT);
-                fail("Should have received an invalid acl error");
+                Assert.fail("Should have received an invalid acl error");
             } catch(InvalidACLException e) {
                 LOG.info("Test successful, invalid acl received : "
                         + e.getMessage());
@@ -150,9 +145,9 @@ public class ClientTest extends ClientBase {
             zk.addAuthInfo("digest", "ben:passwd2".getBytes());
             try {
                 zk.getData("/acltest", false, new Stat());
-                fail("Should have received a permission error");
+                Assert.fail("Should have received a permission error");
             } catch (KeeperException e) {
-                assertEquals(Code.NOAUTH, e.code());
+                Assert.assertEquals(Code.NOAUTH, e.code());
             }
             zk.addAuthInfo("digest", "ben:passwd".getBytes());
             zk.getData("/acltest", false, new Stat());
@@ -161,8 +156,8 @@ public class ClientTest extends ClientBase {
             zk = createClient();
             zk.getData("/acltest", false, new Stat());
             List<ACL> acls = zk.getACL("/acltest", new Stat());
-            assertEquals(1, acls.size());
-            assertEquals(Ids.OPEN_ACL_UNSAFE, acls);
+            Assert.assertEquals(1, acls.size());
+            Assert.assertEquals(Ids.OPEN_ACL_UNSAFE, acls);
             zk.close();
         } finally {
             if (zk != null) {
@@ -212,10 +207,10 @@ public class ClientTest extends ClientBase {
             //   get all, then exists all
             //
             for (int i = 0; i < watchers.length; i++) {
-                assertNotNull(zk.getData("/foo-" + i, watchers[i], stat));
+                Assert.assertNotNull(zk.getData("/foo-" + i, watchers[i], stat));
             }
             for (int i = 0; i < watchers.length; i++) {
-                assertNotNull(zk.exists("/foo-" + i, watchers[i]));
+                Assert.assertNotNull(zk.exists("/foo-" + i, watchers[i]));
             }
             // trigger the watches
             for (int i = 0; i < watchers.length; i++) {
@@ -225,14 +220,14 @@ public class ClientTest extends ClientBase {
             for (int i = 0; i < watchers.length; i++) {
                 WatchedEvent event =
                     watchers[i].events.poll(10, TimeUnit.SECONDS);
-                assertEquals("/foo-" + i, event.getPath());
-                assertEquals(EventType.NodeDataChanged, event.getType());
-                assertEquals(KeeperState.SyncConnected, event.getState());
+                Assert.assertEquals("/foo-" + i, event.getPath());
+                Assert.assertEquals(EventType.NodeDataChanged, event.getType());
+                Assert.assertEquals(KeeperState.SyncConnected, event.getState());
 
                 // small chance that an unexpected message was delivered
                 //  after this check, but we would catch that next time
                 //  we check events
-                assertEquals(0, watchers[i].events.size());
+                Assert.assertEquals(0, watchers[i].events.size());
             }
 
             //
@@ -240,8 +235,8 @@ public class ClientTest extends ClientBase {
             //  get/exists together
             //
             for (int i = 0; i < watchers.length; i++) {
-                assertNotNull(zk.getData("/foo-" + i, watchers[i], stat));
-                assertNotNull(zk.exists("/foo-" + i, watchers[i]));
+                Assert.assertNotNull(zk.getData("/foo-" + i, watchers[i], stat));
+                Assert.assertNotNull(zk.exists("/foo-" + i, watchers[i]));
             }
             // trigger the watches
             for (int i = 0; i < watchers.length; i++) {
@@ -251,22 +246,22 @@ public class ClientTest extends ClientBase {
             for (int i = 0; i < watchers.length; i++) {
                 WatchedEvent event =
                     watchers[i].events.poll(10, TimeUnit.SECONDS);
-                assertEquals("/foo-" + i, event.getPath());
-                assertEquals(EventType.NodeDataChanged, event.getType());
-                assertEquals(KeeperState.SyncConnected, event.getState());
+                Assert.assertEquals("/foo-" + i, event.getPath());
+                Assert.assertEquals(EventType.NodeDataChanged, event.getType());
+                Assert.assertEquals(KeeperState.SyncConnected, event.getState());
 
                 // small chance that an unexpected message was delivered
                 //  after this check, but we would catch that next time
                 //  we check events
-                assertEquals(0, watchers[i].events.size());
+                Assert.assertEquals(0, watchers[i].events.size());
             }
 
             //
             // test get/exists with two sets of watchers
             //
             for (int i = 0; i < watchers.length; i++) {
-                assertNotNull(zk.getData("/foo-" + i, watchers[i], stat));
-                assertNotNull(zk.exists("/foo-" + i, watchers2[i]));
+                Assert.assertNotNull(zk.getData("/foo-" + i, watchers[i], stat));
+                Assert.assertNotNull(zk.exists("/foo-" + i, watchers2[i]));
             }
             // trigger the watches
             for (int i = 0; i < watchers.length; i++) {
@@ -276,26 +271,26 @@ public class ClientTest extends ClientBase {
             for (int i = 0; i < watchers.length; i++) {
                 WatchedEvent event =
                     watchers[i].events.poll(10, TimeUnit.SECONDS);
-                assertEquals("/foo-" + i, event.getPath());
-                assertEquals(EventType.NodeDataChanged, event.getType());
-                assertEquals(KeeperState.SyncConnected, event.getState());
+                Assert.assertEquals("/foo-" + i, event.getPath());
+                Assert.assertEquals(EventType.NodeDataChanged, event.getType());
+                Assert.assertEquals(KeeperState.SyncConnected, event.getState());
 
                 // small chance that an unexpected message was delivered
                 //  after this check, but we would catch that next time
                 //  we check events
-                assertEquals(0, watchers[i].events.size());
+                Assert.assertEquals(0, watchers[i].events.size());
 
                 // watchers2
                 WatchedEvent event2 =
                     watchers2[i].events.poll(10, TimeUnit.SECONDS);
-                assertEquals("/foo-" + i, event2.getPath());
-                assertEquals(EventType.NodeDataChanged, event2.getType());
-                assertEquals(KeeperState.SyncConnected, event2.getState());
+                Assert.assertEquals("/foo-" + i, event2.getPath());
+                Assert.assertEquals(EventType.NodeDataChanged, event2.getType());
+                Assert.assertEquals(KeeperState.SyncConnected, event2.getState());
 
                 // small chance that an unexpected message was delivered
                 //  after this check, but we would catch that next time
                 //  we check events
-                assertEquals(0, watchers2[i].events.size());
+                Assert.assertEquals(0, watchers2[i].events.size());
             }
 
         } finally {
@@ -318,11 +313,11 @@ public class ClientTest extends ClientBase {
             LOG.info("After create /benwashere");
             try {
                 zk.setData("/benwashere", "hi".getBytes(), 57);
-                fail("Should have gotten BadVersion exception");
+                Assert.fail("Should have gotten BadVersion exception");
             } catch(KeeperException.BadVersionException e) {
                 // expected that
             } catch (KeeperException e) {
-                fail("Should have gotten BadVersion exception");
+                Assert.fail("Should have gotten BadVersion exception");
             }
             LOG.info("Before delete /benwashere");
             zk.delete("/benwashere", 0);
@@ -337,7 +332,7 @@ public class ClientTest extends ClientBase {
 
             try {
                 zk.delete("/", -1);
-                fail("deleted root!");
+                Assert.fail("deleted root!");
             } catch(KeeperException.BadArgumentsException e) {
                 // good, expected that
             }
@@ -350,19 +345,19 @@ public class ClientTest extends ClientBase {
                     Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             LOG.info("Before getChildren /pat");
             List<String> children = zk.getChildren("/pat", false);
-            assertEquals(1, children.size());
-            assertEquals("ben", children.get(0));
+            Assert.assertEquals(1, children.size());
+            Assert.assertEquals("ben", children.get(0));
             List<String> children2 = zk.getChildren("/pat", false, null);
-            assertEquals(children, children2);
+            Assert.assertEquals(children, children2);
             String value = new String(zk.getData("/pat/ben", false, stat));
-            assertEquals("Ben was here", value);
+            Assert.assertEquals("Ben was here", value);
             // Test stat and watch of non existent node
 
             try {
                 if (withWatcherObj) {
-                    assertEquals(null, zk.exists("/frog", watcher));
+                    Assert.assertEquals(null, zk.exists("/frog", watcher));
                 } else {
-                    assertEquals(null, zk.exists("/frog", true));
+                    Assert.assertEquals(null, zk.exists("/frog", true));
                 }
                 LOG.info("Comment: asseting passed for frog setting /");
             } catch (KeeperException.NoNodeException e) {
@@ -374,9 +369,9 @@ public class ClientTest extends ClientBase {
             LOG.info("Comment: checking for events length "
                      + watcher.events.size());
             WatchedEvent event = watcher.events.poll(10, TimeUnit.SECONDS);
-            assertEquals("/frog", event.getPath());
-            assertEquals(EventType.NodeCreated, event.getType());
-            assertEquals(KeeperState.SyncConnected, event.getState());
+            Assert.assertEquals("/frog", event.getPath());
+            Assert.assertEquals(EventType.NodeCreated, event.getType());
+            Assert.assertEquals(KeeperState.SyncConnected, event.getState());
             // Test child watch and create with sequence
             zk.getChildren("/pat/ben", true);
             for (int i = 0; i < 10; i++) {
@@ -385,17 +380,17 @@ public class ClientTest extends ClientBase {
             }
             children = zk.getChildren("/pat/ben", false);
             Collections.sort(children);
-            assertEquals(10, children.size());
+            Assert.assertEquals(10, children.size());
             for (int i = 0; i < 10; i++) {
                 final String name = children.get(i);
-                assertTrue("starts with -", name.startsWith(i + "-"));
+                Assert.assertTrue("starts with -", name.startsWith(i + "-"));
                 byte b[];
                 if (withWatcherObj) {
                     b = zk.getData("/pat/ben/" + name, watcher, stat);
                 } else {
                     b = zk.getData("/pat/ben/" + name, true, stat);
                 }
-                assertEquals(Integer.toString(i), new String(b));
+                Assert.assertEquals(Integer.toString(i), new String(b));
                 zk.setData("/pat/ben/" + name, "new".getBytes(),
                         stat.getVersion());
                 if (withWatcherObj) {
@@ -406,19 +401,19 @@ public class ClientTest extends ClientBase {
                 zk.delete("/pat/ben/" + name, stat.getVersion());
             }
             event = watcher.events.poll(10, TimeUnit.SECONDS);
-            assertEquals("/pat/ben", event.getPath());
-            assertEquals(EventType.NodeChildrenChanged, event.getType());
-            assertEquals(KeeperState.SyncConnected, event.getState());
+            Assert.assertEquals("/pat/ben", event.getPath());
+            Assert.assertEquals(EventType.NodeChildrenChanged, event.getType());
+            Assert.assertEquals(KeeperState.SyncConnected, event.getState());
             for (int i = 0; i < 10; i++) {
                 event = watcher.events.poll(10, TimeUnit.SECONDS);
                 final String name = children.get(i);
-                assertEquals("/pat/ben/" + name, event.getPath());
-                assertEquals(EventType.NodeDataChanged, event.getType());
-                assertEquals(KeeperState.SyncConnected, event.getState());
+                Assert.assertEquals("/pat/ben/" + name, event.getPath());
+                Assert.assertEquals(EventType.NodeDataChanged, event.getType());
+                Assert.assertEquals(KeeperState.SyncConnected, event.getState());
                 event = watcher.events.poll(10, TimeUnit.SECONDS);
-                assertEquals("/pat/ben/" + name, event.getPath());
-                assertEquals(EventType.NodeDeleted, event.getType());
-                assertEquals(KeeperState.SyncConnected, event.getState());
+                Assert.assertEquals("/pat/ben/" + name, event.getPath());
+                Assert.assertEquals(EventType.NodeDeleted, event.getType());
+                Assert.assertEquals(KeeperState.SyncConnected, event.getState());
             }
             zk.create("/good\u0040path", "".getBytes(), Ids.OPEN_ACL_UNSAFE,
                     CreateMode.PERSISTENT);
@@ -428,7 +423,7 @@ public class ClientTest extends ClientBase {
             try {
                 zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE,
                         CreateMode.PERSISTENT);
-                fail("duplicate create allowed");
+                Assert.fail("duplicate create allowed");
             } catch(KeeperException.NodeExistsException e) {
                 // OK, expected that
             }
@@ -455,18 +450,18 @@ public class ClientTest extends ClientBase {
             zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             List<String> children = zk.getChildren(path, false);
-            assertEquals(1, children.size());
-            assertEquals(file + "0000000000", children.get(0));
+            Assert.assertEquals(1, children.size());
+            Assert.assertEquals(file + "0000000000", children.get(0));
 
             zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             children = zk.getChildren(path, false);
-            assertEquals(2, children.size());
-            assertTrue("contains child 1",  children.contains(file + "0000000001"));
+            Assert.assertEquals(2, children.size());
+            Assert.assertTrue("contains child 1",  children.contains(file + "0000000001"));
 
             zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             children = zk.getChildren(path, false);
-            assertEquals(3, children.size());
-            assertTrue("contains child 2",
+            Assert.assertEquals(3, children.size());
+            Assert.assertTrue("contains child 2",
                        children.contains(file + "0000000002"));
 
             // The pattern is holding so far.  Let's run the counter a bit
@@ -475,7 +470,7 @@ public class ClientTest extends ClientBase {
                zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
 
             children = zk.getChildren(path, false);
-            assertTrue("contains child 104",
+            Assert.assertTrue("contains child 104",
                        children.contains(file + "0000000104"));
 
         }
@@ -501,11 +496,11 @@ public class ClientTest extends ClientBase {
             zk.create(queue_handle + "/element", "1".getBytes(),
                     Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             List<String> children = zk.getChildren(queue_handle, true);
-            assertEquals(children.size(), 2);
+            Assert.assertEquals(children.size(), 2);
             String child1 = children.get(0);
             String child2 = children.get(1);
             int compareResult = child1.compareTo(child2);
-            assertNotSame(compareResult, 0);
+            Assert.assertNotSame(compareResult, 0);
             if (compareResult < 0) {
             } else {
                 String temp = child1;
@@ -516,8 +511,8 @@ public class ClientTest extends ClientBase {
                     + "/" + child1, false, null));
             String child2data = new String(zk.getData(queue_handle
                     + "/" + child2, false, null));
-            assertEquals(child1data, "0");
-            assertEquals(child2data, "1");
+            Assert.assertEquals(child1data, "0");
+            Assert.assertEquals(child2data, "1");
         } finally {
             if (zk != null) {
                 zk.close();
@@ -534,7 +529,7 @@ public class ClientTest extends ClientBase {
             // this is good
             return;
         }
-        fail("bad path \"" + path + "\" not caught");
+        Assert.fail("bad path \"" + path + "\" not caught");
     }
 
     // Test that the path string is validated
@@ -568,11 +563,11 @@ public class ClientTest extends ClientBase {
         zk.create("/createseqpar", null, Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
         // next two steps - related to sequential processing
-        // 1) verify that empty child name fails if not sequential
+        // 1) verify that empty child name Assert.fails if not sequential
         try {
             zk.create("/createseqpar/", null, Ids.OPEN_ACL_UNSAFE,
                     CreateMode.PERSISTENT);
-            assertTrue(false);
+            Assert.assertTrue(false);
         } catch(IllegalArgumentException be) {
             // catch this.
         }
@@ -587,21 +582,21 @@ public class ClientTest extends ClientBase {
         try {
             zk.create("/createseqpar//", null, Ids.OPEN_ACL_UNSAFE,
                     CreateMode.PERSISTENT_SEQUENTIAL);
-            assertTrue(false);
+            Assert.assertTrue(false);
         } catch(IllegalArgumentException be) {
             // catch this.
         }
         try {
             zk.create("/createseqpar/./", null, Ids.OPEN_ACL_UNSAFE,
                     CreateMode.PERSISTENT_SEQUENTIAL);
-            assertTrue(false);
+            Assert.assertTrue(false);
         } catch(IllegalArgumentException be) {
             // catch this.
         }
         try {
             zk.create("/createseqpar/../", null, Ids.OPEN_ACL_UNSAFE,
                     CreateMode.PERSISTENT_SEQUENTIAL);
-            assertTrue(false);
+            Assert.assertTrue(false);
         } catch(IllegalArgumentException be) {
             // catch this.
         }
@@ -611,7 +606,7 @@ public class ClientTest extends ClientBase {
         PrepRequestProcessor.setFailCreate(true);
         try {
             zk.create("/m", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-            assertTrue(false);
+            Assert.assertTrue(false);
         } catch(KeeperException.BadArgumentsException be) {
             // catch this.
         }
@@ -653,9 +648,9 @@ public class ClientTest extends ClientBase {
         zk.create("/parent/child", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         try {
             zk.delete("/parent", -1);
-            fail("Should have received a not equals message");
+            Assert.fail("Should have received a not equals message");
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NOTEMPTY, e.code());
+            Assert.assertEquals(KeeperException.Code.NOTEMPTY, e.code());
         }
         zk.delete("/parent/child", -1);
         zk.delete("/parent", -1);
@@ -678,11 +673,11 @@ public class ClientTest extends ClientBase {
                     zk.close();
                     // we've asked to close, wait for it to finish closing
                     // all the sub-threads otw the selector may not be
-                    // closed when we check (false positive on test failure
+                    // closed when we check (false positive on test Assert.failure
                     zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
                 }
             } catch (Throwable t) {
-                LOG.error("test failed", t);
+                LOG.error("test Assert.failed", t);
             }
         }
     }
@@ -726,12 +721,12 @@ public class ClientTest extends ClientBase {
 
         for (int i = 0; i < threads.length; i++) {
             threads[i].join(CONNECTION_TIMEOUT);
-            assertTrue(threads[i].current == threads[i].count);
+            Assert.assertTrue(threads[i].current == threads[i].count);
         }
 
-        // if this fails it means we are not cleaning up after the closed
+        // if this Assert.fails it means we are not cleaning up after the closed
         // sessions.
-        assertTrue("open fds after test are not significantly higher than before",
+        Assert.assertTrue("open fds after test are not significantly higher than before",
                 unixos.getOpenFileDescriptorCount() <= initialFdCount + 10);
     }
 }

+ 36 - 51
src/java/test/org/apache/zookeeper/test/CnxManagerTest.java

@@ -24,45 +24,35 @@ import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.concurrent.TimeUnit;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.quorum.QuorumCnxManager;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-
-/**
- * This test uses two mock servers, each running an instance of QuorumCnxManager.
- * It simulates the situation in which a peer P sends a message to another peer Q 
- * while Q is trying to open a connection to P. In this test, Q iniates a connection
- * to P as soon as it receives a message from P, and verifies that it receives a 
- * copy of the message.
- * 
- * This simple tests verifies that the new mechanism that duplicates the last message
- * sent upon a re-connection works. 
- *
- */
-public class CnxManagerTest extends TestCase {
+public class CnxManagerTest extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(FLENewEpochTest.class);
     protected static final int THRESHOLD = 4;
-    
+
     int count;
     HashMap<Long,QuorumServer> peers;
     File tmpdir[];
     int port[];
-    
+
+    @Before
     public void setUp() throws Exception {
-        
+
         this.count = 3;
-        this.peers = new HashMap<Long,QuorumServer>(count); 
+        this.peers = new HashMap<Long,QuorumServer>(count);
         tmpdir = new File[count];
         port = new int[count];
-        
+
         for(int i = 0; i < count; i++) {
             int clientport = PortAssignment.unique();
             peers.put(Long.valueOf(i),
@@ -73,36 +63,31 @@ public class CnxManagerTest extends TestCase {
             port[i] = clientport;
         }
     }
-    
-    public void tearDown() {
-        
-    }
-    
-    
+
     ByteBuffer createMsg(int state, long leader, long zxid, long epoch){
         byte requestBytes[] = new byte[28];
-        ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes);  
-        
+        ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes);
+
         /*
          * Building notification packet to send
          */
-                
+
         requestBuffer.clear();
         requestBuffer.putInt(state);
         requestBuffer.putLong(leader);
         requestBuffer.putLong(zxid);
         requestBuffer.putLong(epoch);
-        
+
         return requestBuffer;
     }
-    
+
     class CnxManagerThread extends Thread {
-        
+
         boolean failed;
         CnxManagerThread(){
             failed = false;
         }
-        
+
         public void run(){
             try {
                 QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 2, 2, 2);
@@ -113,24 +98,24 @@ public class CnxManagerTest extends TestCase {
                 } else {
                     LOG.error("Null listener when initializing cnx manager");
                 }
-                
+
                 long sid = 1;
                 cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));
-                
+
                 Message m = null;
                 int numRetries = 1;
                 while((m == null) && (numRetries++ <= THRESHOLD)){
                     m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
                     if(m == null) cnxManager.connectAll();
                 }
-                
+
                 if(numRetries > THRESHOLD){
                     failed = true;
                     return;
                 }
-                
+
                 cnxManager.testInitiateConnection(sid);
-            
+
                 m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
                 if(m == null){
                     failed = true;
@@ -138,17 +123,17 @@ public class CnxManagerTest extends TestCase {
                 }
             } catch (Exception e) {
                 LOG.error("Exception while running mock thread", e);
-                fail("Unexpected exception");
+                Assert.fail("Unexpected exception");
             }
         }
     }
-    
+
     @Test
     public void testCnxManager() throws Exception {
         CnxManagerThread thread = new CnxManagerThread();
-        
+
         thread.start();
-        
+
         QuorumPeer peer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 2, 2, 2);
         QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
         QuorumCnxManager.Listener listener = cnxManager.listener;
@@ -157,27 +142,27 @@ public class CnxManagerTest extends TestCase {
         } else {
             LOG.error("Null listener when initializing cnx manager");
         }
-            
+
         cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
-        
+
         Message m = null;
         int numRetries = 1;
         while((m == null) && (numRetries++ <= THRESHOLD)){
             m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
             if(m == null) cnxManager.connectAll();
         }
-        
-        assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
+
+        Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
 
         thread.join(5000);
         if (thread.isAlive()) {
-            fail("Thread didn't join");
+            Assert.fail("Thread didn't join");
         } else {
             if(thread.failed)
-                fail("Did not receive expected message");
+                Assert.fail("Did not receive expected message");
         }
     }
-    
-    
-    
+
+
+
 }

+ 20 - 20
src/java/test/org/apache/zookeeper/test/CreateModeTest.java

@@ -20,36 +20,36 @@ package org.apache.zookeeper.test;
 
 import java.util.EnumSet;
 
-import junit.framework.TestCase;
-
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.KeeperException.Code;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class CreateModeTest extends TestCase {
+public class CreateModeTest extends ZKTestCase {
     
     @Test
     public void testBasicCreateMode() {
         CreateMode cm = CreateMode.PERSISTENT;
-        assertEquals(cm.toFlag(), 0);
-        assertFalse(cm.isEphemeral());
-        assertFalse(cm.isSequential());
+        Assert.assertEquals(cm.toFlag(), 0);
+        Assert.assertFalse(cm.isEphemeral());
+        Assert.assertFalse(cm.isSequential());
         
         cm = CreateMode.EPHEMERAL;
-        assertEquals(cm.toFlag(), 1);
-        assertTrue(cm.isEphemeral());
-        assertFalse(cm.isSequential());
+        Assert.assertEquals(cm.toFlag(), 1);
+        Assert.assertTrue(cm.isEphemeral());
+        Assert.assertFalse(cm.isSequential());
         
         cm = CreateMode.PERSISTENT_SEQUENTIAL;
-        assertEquals(cm.toFlag(), 2);
-        assertFalse(cm.isEphemeral());
-        assertTrue(cm.isSequential());
+        Assert.assertEquals(cm.toFlag(), 2);
+        Assert.assertFalse(cm.isEphemeral());
+        Assert.assertTrue(cm.isSequential());
         
         cm = CreateMode.EPHEMERAL_SEQUENTIAL;
-        assertEquals(cm.toFlag(), 3);
-        assertTrue(cm.isEphemeral());
-        assertTrue(cm.isSequential());
+        Assert.assertEquals(cm.toFlag(), 3);
+        Assert.assertTrue(cm.isEphemeral());
+        Assert.assertTrue(cm.isSequential());
     }
     
     @Test
@@ -58,7 +58,7 @@ public class CreateModeTest extends TestCase {
         EnumSet<CreateMode> allModes = EnumSet.allOf(CreateMode.class);
 
         for(CreateMode cm : allModes) {
-            assertEquals(cm, CreateMode.fromFlag( cm.toFlag() ) );
+            Assert.assertEquals(cm, CreateMode.fromFlag( cm.toFlag() ) );
         }
     }
 
@@ -66,16 +66,16 @@ public class CreateModeTest extends TestCase {
     public void testInvalidFlagConversion() throws KeeperException {
         try {
             CreateMode cm = CreateMode.fromFlag(99);
-            fail("Shouldn't be able to convert 99 to a CreateMode.");
+            Assert.fail("Shouldn't be able to convert 99 to a CreateMode.");
         } catch(KeeperException ke) {
-            assertEquals(Code.BADARGUMENTS, ke.code());
+            Assert.assertEquals(Code.BADARGUMENTS, ke.code());
         }
 
         try {
             CreateMode cm = CreateMode.fromFlag(-1);
-            fail("Shouldn't be able to convert -1 to a CreateMode.");
+            Assert.fail("Shouldn't be able to convert -1 to a CreateMode.");
         } catch(KeeperException ke) {
-            assertEquals(Code.BADARGUMENTS, ke.code());
+            Assert.assertEquals(Code.BADARGUMENTS, ke.code());
         }
     }
 }

+ 8 - 8
src/java/test/org/apache/zookeeper/test/DataTreeTest.java

@@ -18,30 +18,30 @@
 
 package org.apache.zookeeper.test;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.DataTree;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-public class DataTreeTest extends TestCase {
+public class DataTreeTest extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(DataTreeTest.class);
 
     private DataTree dt;
 
-    @Override
+    @Before
     public void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
         dt=new DataTree();
     }
 
-    @Override
+    @After
     public void tearDown() throws Exception {
         dt=null;
-        LOG.info("FINISHED " + getName());
     }
 
     @Test
@@ -58,7 +58,7 @@ public class DataTreeTest extends TestCase {
         dt.getChildren("/", new Stat(), watcher);
         // add a new node, should trigger a watch
         dt.createNode("/xyz", new byte[0], null, 0, 1, 1);
-        assertFalse("Root node watch not triggered",!watcher.fired);
+        Assert.assertFalse("Root node watch not triggered",!watcher.fired);
     }
 
 }

+ 0 - 5
src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java

@@ -23,11 +23,6 @@ import java.io.IOException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 
-/**
- * Specialized form of ZooKeeper specific for testing. Typically provides
- * the ability to do unsafe or incorrect operations that allow negative
- * testing.
- */
 public class DisconnectableZooKeeper extends ZooKeeper {
     public DisconnectableZooKeeper(String host, int sessionTimeout, Watcher watcher)
         throws IOException

+ 5 - 5
src/java/test/org/apache/zookeeper/test/EventTypeTest.java

@@ -20,12 +20,12 @@ package org.apache.zookeeper.test;
 
 import java.util.EnumSet;
 
-import junit.framework.TestCase;
-
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.Watcher.Event.EventType;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class EventTypeTest extends TestCase {
+public class EventTypeTest extends ZKTestCase {
     
     @Test
     public void testIntConversion() {
@@ -33,7 +33,7 @@ public class EventTypeTest extends TestCase {
         EnumSet<EventType> allTypes = EnumSet.allOf(EventType.class);
 
         for(EventType et : allTypes) {
-            assertEquals(et, EventType.fromInt( et.getIntValue() ) );
+            Assert.assertEquals(et, EventType.fromInt( et.getIntValue() ) );
         }
     }
 
@@ -41,7 +41,7 @@ public class EventTypeTest extends TestCase {
     public void testInvalidIntConversion() {
         try {
             EventType et = EventType.fromInt(324242);
-            fail("Was able to create an invalid EventType via an integer");
+            Assert.fail("Was able to create an invalid EventType via an integer");
         } catch(RuntimeException re) {
             // we're good.
         }

+ 11 - 32
src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java

@@ -24,39 +24,21 @@ import java.net.InetSocketAddress;
 import java.nio.ByteBuffer;
 import java.util.HashMap;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.quorum.FastLeaderElection;
 import org.apache.zookeeper.server.quorum.QuorumCnxManager;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.Vote;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-
-/**
- * This test uses a mock server to interact with a ZooKeeper peer and 
- * reproduces a specific sequence of messages that can cause FLE to fail.
- * In particular, it reproduces the following scenario:
- * 
- * 1- We have an ensemble of 3 servers, but only two start;
- * 2- Process 0 elects 1, but 1 fails to receive the message from 0
- * stating that it changed its vote to 1;
- * 3- The next from 0 that 1 receives is a notification that 0 is 
- * following 1. However, because 1 does not receive a notification 
- * from 0 while 0 is following, it may end up not becoming leader
- * with old code.
- * 
- * This test checks that this sequence of messages does not lead to a 
- * deadlock. In practice, even if this situation occurs in a run, it would
- * have to occur continuously to prevent a leader from being elected 
- * forever. This happens with low probability. 
- *
- */
-public class FLELostMessageTest extends TestCase {
+public class FLELostMessageTest extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(FLELostMessageTest.class);
 
     
@@ -67,21 +49,18 @@ public class FLELostMessageTest extends TestCase {
     
     QuorumCnxManager cnxManager;
    
-    @Override
+    @Before
     public void setUp() throws Exception {
         count = 3;
 
         peers = new HashMap<Long,QuorumServer>(count);
         tmpdir = new File[count];
         port = new int[count];
-        
-        LOG.info("SetUp " + getName());
     }
 
-    @Override
+    @After
     public void tearDown() throws Exception {
         cnxManager.halt();
-        LOG.info("FINISHED " + getName());
     }
 
 
@@ -105,7 +84,7 @@ public class FLELostMessageTest extends TestCase {
                 v = peer.getElectionAlg().lookForLeader();
 
                 if (v == null){
-                    fail("Thread " + i + " got a null vote");
+                    Assert.fail("Thread " + i + " got a null vote");
                 }
 
                 /*
@@ -116,7 +95,7 @@ public class FLELostMessageTest extends TestCase {
 
                 LOG.info("Finished election: " + i + ", " + v.id);
                     
-                assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
+                Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -127,7 +106,7 @@ public class FLELostMessageTest extends TestCase {
     public void testLostMessage() throws Exception {
         FastLeaderElection le[] = new FastLeaderElection[count];
         
-        LOG.info("TestLE: " + getName()+ ", " + count);
+        LOG.info("TestLE: " + getTestName()+ ", " + count);
         for(int i = 0; i < count; i++) {
             int clientport = PortAssignment.unique();
             peers.put(Long.valueOf(i),
@@ -153,7 +132,7 @@ public class FLELostMessageTest extends TestCase {
         mockServer();
         thread.join(5000);
         if (thread.isAlive()) {
-            fail("Threads didn't join");
+            Assert.fail("Threads didn't join");
         }
     }
         

+ 12 - 13
src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java

@@ -24,18 +24,20 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.concurrent.Semaphore;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.quorum.FastLeaderElection;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.Vote;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-public class FLENewEpochTest extends TestCase {
+public class FLENewEpochTest extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(FLENewEpochTest.class);
 
     int count;
@@ -48,7 +50,7 @@ public class FLENewEpochTest extends TestCase {
     Semaphore start0;
     Semaphore finish3, finish0;
 
-    @Override
+    @Before
     public void setUp() throws Exception {
         count = 3;
 
@@ -65,16 +67,13 @@ public class FLENewEpochTest extends TestCase {
         start0 = new Semaphore(0);
         finish0 = new Semaphore(0);
         finish3 = new Semaphore(0);
-
-        LOG.info("SetUp " + getName());
     }
 
-    @Override
+    @After
     public void tearDown() throws Exception {
         for(int i = 0; i < threads.size(); i++) {
             ((FastLeaderElection) threads.get(i).peer.getElectionAlg()).shutdown();
         }
-        LOG.info("FINISHED " + getName());
     }
 
 
@@ -99,7 +98,7 @@ public class FLENewEpochTest extends TestCase {
                     v = peer.getElectionAlg().lookForLeader();
 
                     if (v == null){
-                        fail("Thread " + i + " got a null vote");
+                        Assert.fail("Thread " + i + " got a null vote");
                     }
 
                     /*
@@ -154,7 +153,7 @@ public class FLENewEpochTest extends TestCase {
 
           FastLeaderElection le[] = new FastLeaderElection[count];
 
-          LOG.info("TestLE: " + getName()+ ", " + count);
+          LOG.info("TestLE: " + getTestName()+ ", " + count);
           for(int i = 0; i < count; i++) {
               peers.put(Long.valueOf(i),
                       new QuorumServer(i,
@@ -172,7 +171,7 @@ public class FLENewEpochTest extends TestCase {
               threads.add(thread);
           }
           if(!start0.tryAcquire(4000, java.util.concurrent.TimeUnit.MILLISECONDS))
-              fail("First leader election failed");
+              Assert.fail("First leader election failed");
 
           QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 2, 2, 2);
           peer.startLeaderElection();
@@ -180,12 +179,12 @@ public class FLENewEpochTest extends TestCase {
           thread.start();
           threads.add(thread);
 
-          LOG.info("Started threads " + getName());
+          LOG.info("Started threads " + getTestName());
 
           for(int i = 0; i < threads.size(); i++) {
               threads.get(i).join(10000);
               if (threads.get(i).isAlive()) {
-                  fail("Threads didn't join");
+                  Assert.fail("Threads didn't join");
               }
 
           }

+ 10 - 11
src/java/test/org/apache/zookeeper/test/FLERestartTest.java

@@ -26,18 +26,20 @@ import java.util.HashSet;
 import java.util.Random;
 import java.util.concurrent.Semaphore;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.quorum.FastLeaderElection;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.Vote;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-public class FLERestartTest extends TestCase {
+public class FLERestartTest extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(FLETest.class);
 
     static class TestVote {
@@ -74,7 +76,7 @@ public class FLERestartTest extends TestCase {
     //volatile int round = 1;
     Random rand = new Random();
 
-    @Override
+    @Before
     public void setUp() throws Exception {
         count = 3;
 
@@ -86,16 +88,13 @@ public class FLERestartTest extends TestCase {
         port = new int[count];
         successCount = 0;
         finish = new Semaphore(0);
-
-        LOG.info("SetUp " + getName());
     }
 
-    @Override
+    @After
     public void tearDown() throws Exception {
         for(int i = 0; i < restartThreads.size(); i++) {
             ((FastLeaderElection) restartThreads.get(i).peer.getElectionAlg()).shutdown();
         }
-        LOG.info("FINISHED " + getName());
     }
 
     class FLERestartThread extends Thread {
@@ -175,7 +174,7 @@ public class FLERestartTest extends TestCase {
         leaderDies = true;
         boolean allowOneBadLeader = leaderDies;
 
-        LOG.info("TestLE: " + getName()+ ", " + count);
+        LOG.info("TestLE: " + getTestName()+ ", " + count);
         for(int i = 0; i < count; i++) {
             peers.put(Long.valueOf(i),
                     new QuorumServer(i,
@@ -192,11 +191,11 @@ public class FLERestartTest extends TestCase {
             thread.start();
             restartThreads.add(thread);
         }
-        LOG.info("Started threads " + getName());
+        LOG.info("Started threads " + getTestName());
         for(int i = 0; i < restartThreads.size(); i++) {
             restartThreads.get(i).join(10000);
             if (restartThreads.get(i).isAlive()) {
-                fail("Threads didn't join");
+                Assert.fail("Threads didn't join");
             }
 
         }

+ 12 - 13
src/java/test/org/apache/zookeeper/test/FLETest.java

@@ -25,18 +25,20 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Random;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.quorum.FastLeaderElection;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.Vote;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-public class FLETest extends TestCase {
+public class FLETest extends ZKTestCase {
     protected static final Logger LOG = Logger.getLogger(FLETest.class);
     private FLETest.LEThread leThread;
 
@@ -72,7 +74,7 @@ public class FLETest extends TestCase {
     //volatile int round = 1;
     Random rand = new Random();
 
-    @Override
+    @Before
     public void setUp() throws Exception {
         count = 7;
 
@@ -84,17 +86,14 @@ public class FLETest extends TestCase {
         port = new int[count];
         successCount = 0;
         finalObj = new Object();
-
-        LOG.info("SetUp " + getName());
     }
 
-    @Override
+    @After
     public void tearDown() throws Exception {
         for (int i = 0; i < threads.size(); i++) {
             leThread = threads.get(i);
             QuorumBase.shutdown(leThread.peer);
         }
-        LOG.info("FINISHED " + getName());
     }
 
     class LEThread extends Thread {
@@ -136,7 +135,7 @@ public class FLETest extends TestCase {
                     if (v.id == ((long) i)) {
                         /*
                          * A leader executes this part of the code. If it is the first leader to be
-                         * elected, then it fails right after. Otherwise, it waits until it has enough
+                         * elected, then it Assert.fails right after. Otherwise, it waits until it has enough
                          * followers supporting it.
                          */
                         LOG.info("I'm the leader: " + i);
@@ -261,7 +260,7 @@ public class FLETest extends TestCase {
         leaderDies = true;
         boolean allowOneBadLeader = leaderDies;
 
-        LOG.info("TestLE: " + getName()+ ", " + count);
+        LOG.info("TestLE: " + getTestName()+ ", " + count);
         for(int i = 0; i < count; i++) {
             peers.put(Long.valueOf(i),
                     new QuorumServer(i,
@@ -279,7 +278,7 @@ public class FLETest extends TestCase {
             thread.start();
             threads.add(thread);
         }
-        LOG.info("Started threads " + getName());
+        LOG.info("Started threads " + getTestName());
 
 
         int waitCounter = 0;
@@ -306,11 +305,11 @@ public class FLETest extends TestCase {
         * If we have a majority, then we are good to go.
         */
        if(successCount <= count/2){
-           fail("Fewer than a a majority has joined");
+           Assert.fail("Fewer than a a majority has joined");
        }
 
        if(threads.get((int) leader).isAlive()){
-           fail("Leader hasn't joined: " + leader);
+           Assert.fail("Leader hasn't joined: " + leader);
        }
     }
 }

+ 12 - 14
src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java

@@ -25,20 +25,21 @@ import java.util.HashMap;
 import java.util.Properties;
 import java.util.Random;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.quorum.FastLeaderElection;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.Vote;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
 import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical;
+import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class FLEZeroWeightTest extends TestCase {
+public class FLEZeroWeightTest extends ZKTestCase {
     private static final Logger LOG = Logger.getLogger(HierarchicalQuorumTest.class);
 
     Properties qp;
@@ -57,8 +58,7 @@ public class FLEZeroWeightTest extends TestCase {
 
 
     @Before
-    @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         count = 9;
 
         peers = new HashMap<Long,QuorumServer>(count);
@@ -84,11 +84,10 @@ public class FLEZeroWeightTest extends TestCase {
         ByteArrayInputStream is = new ByteArrayInputStream(config.getBytes());
         this.qp = new Properties();
         qp.load(is);
-
-        LOG.info("SetUp " + getName());
     }
 
-    protected void tearDown() throws Exception {
+    @After
+    public void tearDown() throws Exception {
         for(int i = 0; i < threads.size(); i++) {
             LEThread leThread = threads.get(i);
             // shutdown() has to be explicitly called for every thread to
@@ -96,7 +95,6 @@ public class FLEZeroWeightTest extends TestCase {
             // are available for other test cases
             QuorumBase.shutdown(leThread.peer);
         }
-        LOG.info("FINISHED " + getName());
     }
 
     class LEThread extends Thread {
@@ -136,7 +134,7 @@ public class FLEZeroWeightTest extends TestCase {
 
                     if((peer.getPeerState() == ServerState.LEADING) &&
                             (peer.getId() > 2)) fail = true;
-                    
+
                     if((peer.getPeerState() == ServerState.FOLLOWING) ||
                             (peer.getPeerState() == ServerState.LEADING)) break;
                 }
@@ -151,7 +149,7 @@ public class FLEZeroWeightTest extends TestCase {
     public void testZeroWeightQuorum() throws Exception {
         FastLeaderElection le[] = new FastLeaderElection[count];
 
-        LOG.info("TestZeroWeightQuorum: " + getName()+ ", " + count);
+        LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
         for(int i = 0; i < count; i++) {
             peers.put(Long.valueOf(i),
                     new QuorumServer(i,
@@ -169,15 +167,15 @@ public class FLEZeroWeightTest extends TestCase {
             thread.start();
             threads.add(thread);
         }
-        LOG.info("Started threads " + getName());
+        LOG.info("Started threads " + getTestName());
 
         for(int i = 0; i < threads.size(); i++) {
             threads.get(i).join(15000);
             if (threads.get(i).isAlive()) {
-                fail("Threads didn't join");
+                Assert.fail("Threads didn't join");
             } else {
                 if(threads.get(i).fail)
-                    fail("Elected zero-weight server");
+                    Assert.fail("Elected zero-weight server");
             }
         }
     }

+ 3 - 3
src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java

@@ -22,7 +22,7 @@ import java.io.IOException;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.TestableZooKeeper;
-import org.apache.zookeeper.test.ClientBase.HostPort;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class FourLetterWordsQuorumTest extends QuorumBase {
@@ -99,10 +99,10 @@ public class FourLetterWordsQuorumTest extends QuorumBase {
             String resp = send4LetterWord(hpobj.host, hpobj.port, cmd);
             LOG.info("cmd " + cmd + " expected " + expected + " got " + resp);
             if (cmd.equals("dump")) {
-                assertTrue(resp.contains(expected)
+                Assert.assertTrue(resp.contains(expected)
                         || resp.contains("Sessions with Ephemerals"));
             } else {
-                assertTrue(resp.contains(expected));
+                Assert.assertTrue(resp.contains(expected));
             }
         }
     }

+ 2 - 1
src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java

@@ -22,6 +22,7 @@ import java.io.IOException;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.TestableZooKeeper;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class FourLetterWordsTest extends ClientBase {
@@ -92,6 +93,6 @@ public class FourLetterWordsTest extends ClientBase {
         HostPort hpobj = parseHostPortList(hostPort).get(0);
         String resp = send4LetterWord(hpobj.host, hpobj.port, cmd);
         LOG.info("cmd " + cmd + " expected " + expected + " got " + resp);
-        assertTrue(resp.contains(expected));
+        Assert.assertTrue(resp.contains(expected));
     }
 }

+ 41 - 41
src/java/test/org/apache/zookeeper/test/GetChildren2Test.java

@@ -28,26 +28,26 @@ import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
 import org.junit.Test;
 
-/**
- *
- */
 public class GetChildren2Test extends ClientBase {
     private ZooKeeper zk;
-    
-    protected void setUp() throws Exception {
+
+    @Override
+    public void setUp() throws Exception {
         super.setUp();
-        
+
         zk = createClient();
     }
 
-    protected void tearDown() throws Exception {
+    @Override
+    public void tearDown() throws Exception {
         super.tearDown();
-        
+
         zk.close();
     }
-    
+
     @Test
     public void testChild()
         throws IOException, KeeperException, InterruptedException
@@ -63,29 +63,29 @@ public class GetChildren2Test extends ClientBase {
         Stat stat = new Stat();
         List<String> s = zk.getChildren(name, false, stat);
 
-        assertEquals(stat.getCzxid(), stat.getMzxid());
-        assertEquals(stat.getCzxid() + 1, stat.getPzxid());
-        assertEquals(stat.getCtime(), stat.getMtime());
-        assertEquals(1, stat.getCversion());
-        assertEquals(0, stat.getVersion());
-        assertEquals(0, stat.getAversion());
-        assertEquals(0, stat.getEphemeralOwner());
-        assertEquals(name.length(), stat.getDataLength());
-        assertEquals(1, stat.getNumChildren());
-        assertEquals(s.size(), stat.getNumChildren());
+        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
+        Assert.assertEquals(stat.getCzxid() + 1, stat.getPzxid());
+        Assert.assertEquals(stat.getCtime(), stat.getMtime());
+        Assert.assertEquals(1, stat.getCversion());
+        Assert.assertEquals(0, stat.getVersion());
+        Assert.assertEquals(0, stat.getAversion());
+        Assert.assertEquals(0, stat.getEphemeralOwner());
+        Assert.assertEquals(name.length(), stat.getDataLength());
+        Assert.assertEquals(1, stat.getNumChildren());
+        Assert.assertEquals(s.size(), stat.getNumChildren());
 
         s = zk.getChildren(childname, false, stat);
 
-        assertEquals(stat.getCzxid(), stat.getMzxid());
-        assertEquals(stat.getCzxid(), stat.getPzxid());
-        assertEquals(stat.getCtime(), stat.getMtime());
-        assertEquals(0, stat.getCversion());
-        assertEquals(0, stat.getVersion());
-        assertEquals(0, stat.getAversion());
-        assertEquals(zk.getSessionId(), stat.getEphemeralOwner());
-        assertEquals(childname.length(), stat.getDataLength());
-        assertEquals(0, stat.getNumChildren());
-        assertEquals(s.size(), stat.getNumChildren());
+        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
+        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
+        Assert.assertEquals(stat.getCtime(), stat.getMtime());
+        Assert.assertEquals(0, stat.getCversion());
+        Assert.assertEquals(0, stat.getVersion());
+        Assert.assertEquals(0, stat.getAversion());
+        Assert.assertEquals(zk.getSessionId(), stat.getEphemeralOwner());
+        Assert.assertEquals(childname.length(), stat.getDataLength());
+        Assert.assertEquals(0, stat.getNumChildren());
+        Assert.assertEquals(s.size(), stat.getNumChildren());
     }
 
     @Test
@@ -114,23 +114,23 @@ public class GetChildren2Test extends ClientBase {
             Stat stat = new Stat();
             List<String> s = zk.getChildren(name, false, stat);
 
-            assertEquals(stat.getCzxid(), stat.getMzxid());
-            assertEquals(stat.getCzxid() + i + 1, stat.getPzxid());
-            assertEquals(stat.getCtime(), stat.getMtime());
-            assertEquals(i + 1, stat.getCversion());
-            assertEquals(0, stat.getVersion());
-            assertEquals(0, stat.getAversion());
-            assertEquals(0, stat.getEphemeralOwner());
-            assertEquals(name.length(), stat.getDataLength());
-            assertEquals(i + 1, stat.getNumChildren());
-            assertEquals(s.size(), stat.getNumChildren());
+            Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
+            Assert.assertEquals(stat.getCzxid() + i + 1, stat.getPzxid());
+            Assert.assertEquals(stat.getCtime(), stat.getMtime());
+            Assert.assertEquals(i + 1, stat.getCversion());
+            Assert.assertEquals(0, stat.getVersion());
+            Assert.assertEquals(0, stat.getAversion());
+            Assert.assertEquals(0, stat.getEphemeralOwner());
+            Assert.assertEquals(name.length(), stat.getDataLength());
+            Assert.assertEquals(i + 1, stat.getNumChildren());
+            Assert.assertEquals(s.size(), stat.getNumChildren());
         }
         List<String> p = zk.getChildren(name, false, null);
         List<String> c_a = children_s;
         List<String> c_b = p;
         Collections.sort(c_a);
         Collections.sort(c_b);
-        assertEquals(c_a.size(), 10);
-        assertEquals(c_a, c_b);
+        Assert.assertEquals(c_a.size(), 10);
+        Assert.assertEquals(c_a, c_b);
     }
 }

+ 10 - 23
src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java

@@ -32,18 +32,9 @@ import org.apache.zookeeper.TestableZooKeeper;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical;
-import org.junit.After;
+import org.junit.Assert;
 import org.junit.Test;
 
-/**
- * Comprehensive test of hierarchical quorums, assuming servers with zero weight.
- * This test uses ClientTest to verify that the ensemble works after a leader is 
- * elected.
- * 
- * This implementation is based on QuorumBase, the main difference being that it 
- * uses hierarchical quorums and FLE.
- */
-
 public class HierarchicalQuorumTest extends ClientBase {
     private static final Logger LOG = Logger.getLogger(QuorumBase.class);
 
@@ -65,8 +56,7 @@ public class HierarchicalQuorumTest extends ClientBase {
     protected final ClientHammerTest cht = new ClientHammerTest();
     
     @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
+    public void setUp() throws Exception {
         setupTestEnv();
 
         JMXEnv.setUp();
@@ -160,17 +150,17 @@ public class HierarchicalQuorumTest extends ClientBase {
         LOG.info("creating QuorumPeer 1 port " + port1);
         QuorumHierarchical hq1 = new QuorumHierarchical(qp); 
         s1 = new QuorumPeer(peers, s1dir, s1dir, port1, 3, 1, tickTime, initLimit, syncLimit, hq1);
-        assertEquals(port1, s1.getClientPort());
+        Assert.assertEquals(port1, s1.getClientPort());
         
         LOG.info("creating QuorumPeer 2 port " + port2);
         QuorumHierarchical hq2 = new QuorumHierarchical(qp); 
         s2 = new QuorumPeer(peers, s2dir, s2dir, port2, 3, 2, tickTime, initLimit, syncLimit, hq2);
-        assertEquals(port2, s2.getClientPort());
+        Assert.assertEquals(port2, s2.getClientPort());
         
         LOG.info("creating QuorumPeer 3 port " + port3);
         QuorumHierarchical hq3 = new QuorumHierarchical(qp); 
         s3 = new QuorumPeer(peers, s3dir, s3dir, port3, 3, 3, tickTime, initLimit, syncLimit, hq3);
-        assertEquals(port3, s3.getClientPort());
+        Assert.assertEquals(port3, s3.getClientPort());
         
         LOG.info("creating QuorumPeer 4 port " + port4);
         QuorumHierarchical hq4 = new QuorumHierarchical(qp); 
@@ -178,7 +168,7 @@ public class HierarchicalQuorumTest extends ClientBase {
         if (withObservers) {
             s4.setPeerType(QuorumPeer.LearnerType.OBSERVER);
         }
-        assertEquals(port4, s4.getClientPort());
+        Assert.assertEquals(port4, s4.getClientPort());
                        
         LOG.info("creating QuorumPeer 5 port " + port5);
         QuorumHierarchical hq5 = new QuorumHierarchical(qp); 
@@ -186,7 +176,7 @@ public class HierarchicalQuorumTest extends ClientBase {
         if (withObservers) {
             s5.setPeerType(QuorumPeer.LearnerType.OBSERVER);
         }
-        assertEquals(port5, s5.getClientPort());
+        Assert.assertEquals(port5, s5.getClientPort());
         
         // Observers are currently only compatible with LeaderElection
         if (withObservers) {
@@ -211,7 +201,7 @@ public class HierarchicalQuorumTest extends ClientBase {
 
         LOG.info ("Closing ports " + hostPort);
         for (String hp : hostPort.split(",")) {
-            assertTrue("waiting for server up",
+            Assert.assertTrue("waiting for server up",
                        ClientBase.waitForServerUp(hp,
                                     CONNECTION_TIMEOUT));
             LOG.info(hp + " is accepting client connections");
@@ -240,9 +230,8 @@ public class HierarchicalQuorumTest extends ClientBase {
         JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()]));
     }
 
-    @After
     @Override
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         LOG.info("TearDown started");
         cht.tearDownAll();
 
@@ -258,15 +247,13 @@ public class HierarchicalQuorumTest extends ClientBase {
         shutdown(s5);
         
         for (String hp : hostPort.split(",")) {
-            assertTrue("waiting for server down",
+            Assert.assertTrue("waiting for server down",
                        ClientBase.waitForServerDown(hp,
                                            ClientBase.CONNECTION_TIMEOUT));
             LOG.info(hp + " is no longer accepting client connections");
         }
 
         JMXEnv.tearDown();
-
-        LOG.info("FINISHED " + getName());
     }
 
     protected void shutdown(QuorumPeer qp) {

+ 6 - 15
src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java

@@ -24,21 +24,21 @@ import java.io.File;
 import java.net.InetSocketAddress;
 import java.util.concurrent.CountDownLatch;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 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.LogFormatter;
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.SyncRequestProcessor;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class InvalidSnapshotTest extends TestCase implements Watcher {
+public class InvalidSnapshotTest extends ZKTestCase implements Watcher {
     private final static Logger LOG = Logger.getLogger(UpgradeTest.class);
     private static final String HOSTPORT =
             "127.0.0.1:" + PortAssignment.unique();
@@ -47,15 +47,6 @@ public class InvalidSnapshotTest extends TestCase implements Watcher {
             System.getProperty("test.data.dir", "build/test/data"));
     private CountDownLatch startSignal;
 
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
-    }
-    @Override
-    protected void tearDown() throws Exception {
-        LOG.info("FINISHED " + getName());
-    }
-
     /**
      * Verify the LogFormatter by running it on a known file.
      */
@@ -81,19 +72,19 @@ public class InvalidSnapshotTest extends TestCase implements Watcher {
                 new InetSocketAddress(PORT));
         f.startup(zks);
         LOG.info("starting up the zookeeper server .. waiting");
-        assertTrue("waiting for server being up",
+        Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
         ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
         try {
             // we know this from the data files
             // this node is the last node in the snapshot
 
-            assertTrue(zk.exists("/9/9/8", false) != null);
+            Assert.assertTrue(zk.exists("/9/9/8", false) != null);
         } finally {
             zk.close();
         }
         f.shutdown();
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                    ClientBase.waitForServerDown(HOSTPORT,
                            ClientBase.CONNECTION_TIMEOUT));
 

+ 7 - 7
src/java/test/org/apache/zookeeper/test/KeeperStateTest.java

@@ -20,13 +20,13 @@ package org.apache.zookeeper.test;
 
 import java.util.EnumSet;
 
-import junit.framework.TestCase;
-
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class KeeperStateTest extends TestCase {
+public class KeeperStateTest extends ZKTestCase {
     
     @Test
     public void testIntConversion() {
@@ -34,7 +34,7 @@ public class KeeperStateTest extends TestCase {
         EnumSet<KeeperState> allStates = EnumSet.allOf(KeeperState.class);
 
         for(KeeperState as : allStates) {
-            assertEquals(as, KeeperState.fromInt( as.getIntValue() ) );
+            Assert.assertEquals(as, KeeperState.fromInt( as.getIntValue() ) );
         }
     }
 
@@ -42,7 +42,7 @@ public class KeeperStateTest extends TestCase {
     public void testInvalidIntConversion() {
         try {
             KeeperState ks = KeeperState.fromInt(324142);
-            fail("Was able to create an invalid KeeperState via an integer");
+            Assert.fail("Was able to create an invalid KeeperState via an integer");
         } catch(RuntimeException re) {
             // we're good.
         }
@@ -58,7 +58,7 @@ public class KeeperStateTest extends TestCase {
         int test = 1;
         switch (test) {
         case Code.Ok:
-            assertTrue(true);
+            Assert.assertTrue(true);
             break;
         }
     }
@@ -69,7 +69,7 @@ public class KeeperStateTest extends TestCase {
         Code test = Code.OK;
         switch (test) {
         case OK:
-            assertTrue(true);
+            Assert.assertTrue(true);
             break;
         }
     }

+ 12 - 21
src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java

@@ -31,10 +31,9 @@ import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.quorum.Election;
 import org.apache.zookeeper.server.quorum.LeaderElection;
@@ -44,12 +43,11 @@ import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
 import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-/**
- * Tests that a particular run of LeaderElection terminates correctly.
- */
-public class LENonTerminateTest extends TestCase {
+public class LENonTerminateTest extends ZKTestCase {
     public class MockLeaderElection extends LeaderElection {
         public MockLeaderElection(QuorumPeer self) {
             super(self);            
@@ -153,7 +151,7 @@ public class LENonTerminateTest extends TestCase {
                  */
                 LOG.info("Waiting for first round of voting to complete");
                 latch.countDown();
-                assertTrue("Thread timed out waiting for latch",
+                Assert.assertTrue("Thread timed out waiting for latch",
                         latch.await(10000, TimeUnit.MILLISECONDS));
                 
                 // ZOOKEEPER-569:
@@ -233,22 +231,15 @@ public class LENonTerminateTest extends TestCase {
     File tmpdir[];
     int port[];   
    
-    @Override
+    @Before
     public void setUp() throws Exception {
         count = 3;
 
         peers = new HashMap<Long,QuorumServer>(count);
         tmpdir = new File[count];
         port = new int[count];
-        
-        LOG.info("SetUp " + getName());
     }
 
-    @Override
-    public void tearDown() throws Exception {
-        LOG.info("FINISHED " + getName());
-    }
-    
     static final CountDownLatch latch = new CountDownLatch(2);
     static final CountDownLatch mockLatch = new CountDownLatch(1);
 
@@ -272,7 +263,7 @@ public class LENonTerminateTest extends TestCase {
                 v = peer.getElectionAlg().lookForLeader();
 
                 if (v == null){
-                    fail("Thread " + i + " got a null vote");
+                    Assert.fail("Thread " + i + " got a null vote");
                 }                                
 
                 /*
@@ -300,7 +291,7 @@ public class LENonTerminateTest extends TestCase {
      */
     @Test
     public void testNonTermination() throws Exception {                
-        LOG.info("TestNonTermination: " + getName()+ ", " + count);
+        LOG.info("TestNonTermination: " + getTestName()+ ", " + count);
         for(int i = 0; i < count; i++) {
             int clientport = PortAssignment.unique();
             peers.put(Long.valueOf(i),
@@ -331,13 +322,13 @@ public class LENonTerminateTest extends TestCase {
                     mockServer();
                 } catch (Exception e) {
                     LOG.error(e);
-                    fail("Exception when running mocked server " + e);
+                    Assert.fail("Exception when running mocked server " + e);
                 }
             }
         };        
         
         thread3.start();
-        assertTrue("mockServer did not start in 5s",
+        Assert.assertTrue("mockServer did not start in 5s",
                 mockLatch.await(5000, TimeUnit.MILLISECONDS));
         thread1.start();
         thread2.start();
@@ -348,13 +339,13 @@ public class LENonTerminateTest extends TestCase {
         thread2.join(15000);
         thread3.join(15000);
         if (thread1.isAlive() || thread2.isAlive() || thread3.isAlive()) {
-            fail("Threads didn't join");
+            Assert.fail("Threads didn't join");
         }
     }
      
     /**
      * MockServer plays the role of peer C. Respond to two requests for votes
-     * with vote for self and then fail. 
+     * with vote for self and then Assert.fail. 
      */
     void mockServer() throws InterruptedException, IOException {          
         byte b[] = new byte[36];

+ 9 - 6
src/java/test/org/apache/zookeeper/test/LETest.java

@@ -24,16 +24,17 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Random;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.quorum.LeaderElection;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.Vote;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
+import org.junit.Assert;
+import org.junit.Test;
 
-public class LETest extends TestCase {
+public class LETest extends ZKTestCase {
     private static final Logger LOG = Logger.getLogger(LETest.class);
     volatile Vote votes[];
     volatile boolean leaderDies;
@@ -85,6 +86,8 @@ public class LETest extends TestCase {
             }
         }
     }
+
+    @Test
     public void testLE() throws Exception {
         int count = 30;
         HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
@@ -115,19 +118,19 @@ public class LETest extends TestCase {
         for(int i = 0; i < threads.size(); i++) {
             threads.get(i).join(15000);
             if (threads.get(i).isAlive()) {
-                fail("Threads didn't join");
+                Assert.fail("Threads didn't join");
             }
         }
         long id = votes[0].id;
         for(int i = 1; i < votes.length; i++) {
             if (votes[i] == null) {
-                fail("Thread " + i + " had a null vote");
+                Assert.fail("Thread " + i + " had a null vote");
             }
             if (votes[i].id != id) {
                 if (allowOneBadLeader && votes[i].id == i) {
                     allowOneBadLeader = false;
                 } else {
-                    fail("Thread " + i + " got " + votes[i].id + " expected " + id);
+                    Assert.fail("Thread " + i + " got " + votes[i].id + " expected " + id);
                 }
             }
         }

+ 27 - 23
src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java

@@ -27,18 +27,21 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.jute.BinaryOutputArchive;
 import org.apache.zookeeper.proto.ConnectRequest;
+import org.junit.Assert;
+import org.junit.Test;
 
 public class MaxCnxnsTest extends ClientBase {
     final private int numCnxns = 30;
-    AtomicInteger numConnected = new AtomicInteger(0); 
+    AtomicInteger numConnected = new AtomicInteger(0);
     String host;
     int port;
-    
-    protected void setUp() throws Exception {
+
+    @Override
+    public void setUp() throws Exception {
         maxCnxns = numCnxns;
         super.setUp();
     }
-    
+
     class CnxnThread extends Thread {
         int i;
         SocketChannel socket;
@@ -46,17 +49,17 @@ public class MaxCnxnsTest extends ClientBase {
             super("CnxnThread-"+i);
             this.i = i;
         }
-        
+
         public void run() {
             try {
                 /*
-                 * For future unwary socket programmers: although connect 'blocks' it 
+                 * For future unwary socket programmers: although connect 'blocks' it
                  * does not require an accept on the server side to return. Therefore
                  * you can not assume that all the sockets are connected at the end of
                  * this for loop.
-                 */                
+                 */
                 SocketChannel sChannel = SocketChannel.open();
-                sChannel.connect(new InetSocketAddress(host,port));                          
+                sChannel.connect(new InetSocketAddress(host,port));
                 // Construct a connection request
                 ConnectRequest conReq = new ConnectRequest(0, 0,
                         10000, 0, "password".getBytes());
@@ -66,60 +69,61 @@ public class MaxCnxnsTest extends ClientBase {
                 conReq.serialize(boa, "connect");
                 baos.close();
                 ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
-                bb.putInt(bb.capacity() - 4);                
+                bb.putInt(bb.capacity() - 4);
                 bb.rewind();
-                
+
                 /* Send a connect request. Any socket that has been closed (or at least
                  * not added to the cnxn list on the server) will not have any bytes to
                  * read and get an eof.
-                 * 
+                 *
                  *  The trick here was finding a call that caused the server to put
                  *  bytes in the input stream without closing the cnxn. None of
                  *  the four letter commands do that, so we actually try to create
                  *  a session which should send us something back, while maintaining
                  *  the connection.
                  */
-                
+
                 int eof = sChannel.write(bb);
-                // If the socket times out, we count that as failed - 
+                // If the socket times out, we count that as Assert.failed -
                 // the server should respond within 10s
-                sChannel.socket().setSoTimeout(10000);                
+                sChannel.socket().setSoTimeout(10000);
                 if (!sChannel.socket().isClosed()){
-                    eof = sChannel.socket().getInputStream().read(); 
+                    eof = sChannel.socket().getInputStream().read();
                     if (eof != -1) {
                         numConnected.incrementAndGet();
                     }
-                }                   
+                }
             }
             catch (IOException io) {
                 // "Connection reset by peer"
             }
         }
     }
-    
+
     /**
-     * Verify the ability to limit the number of concurrent connections. 
+     * Verify the ability to limit the number of concurrent connections.
      * @throws IOException
      * @throws InterruptedException
      */
-    public void testMaxCnxns() throws IOException, InterruptedException{        
+    @Test
+    public void testMaxCnxns() throws IOException, InterruptedException{
         String split[] = hostPort.split(":");
         host = split[0];
         port = Integer.parseInt(split[1]);
         int numThreads = numCnxns + 5;
         CnxnThread[] threads = new CnxnThread[numThreads];
 
-        for (int i=0;i<numCnxns;++i) {            
+        for (int i=0;i<numCnxns;++i) {
           threads[i] = new CnxnThread(i);
         }
-        
+
         for (int i=0;i<numCnxns;++i) {
             threads[i].start();
         }
-                        
+
         for (int i=0;i<numCnxns;++i) {
             threads[i].join();
         }
-        assertSame(numCnxns,numConnected.get());
+        Assert.assertSame(numCnxns,numConnected.get());
     }
 }

+ 6 - 3
src/java/test/org/apache/zookeeper/test/NullDataTest.java

@@ -28,13 +28,15 @@ import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
+import org.junit.Test;
 
 public class NullDataTest extends ClientBase implements StatCallback {
     String snapCount;
     CountDownLatch cn = new CountDownLatch(1);
     
     @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         // Change the snapcount to happen more often
         snapCount = System.getProperty("zookeeper.snapCount", "1024");
         System.setProperty("zookeeper.snapCount", "10");
@@ -42,11 +44,12 @@ public class NullDataTest extends ClientBase implements StatCallback {
     }
     
     @Override
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         System.setProperty("zookeeper.snapCount", snapCount);
         super.tearDown();
     }
     
+    @Test
     public void testNullData() throws IOException, 
         InterruptedException, KeeperException {
         String path = "/SIZE";
@@ -58,7 +61,7 @@ public class NullDataTest extends ClientBase implements StatCallback {
             zk.exists(path, false);
             zk.exists(path, false, this , null);
             cn.await(10, TimeUnit.SECONDS);
-            assertSame(0L, cn.getCount());
+            Assert.assertSame(0L, cn.getCount());
         } finally {
             if(zk != null)
                 zk.close();

+ 5 - 8
src/java/test/org/apache/zookeeper/test/OOMTest.java

@@ -25,24 +25,21 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 
-import junit.framework.TestCase;
-
 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.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.Assert;
 import org.junit.Test;
 
-/**
- *
- */
-public class OOMTest extends TestCase implements Watcher {
+public class OOMTest extends ZKTestCase implements Watcher {
     @Test
     public void testOOM() throws IOException, InterruptedException, KeeperException {
         // This test takes too long to run!
@@ -67,7 +64,7 @@ public class OOMTest extends TestCase implements Watcher {
         NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(
                 new InetSocketAddress(PORT));
         f.startup(zks);
-        assertTrue("waiting for server up",
+        Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                                               CONNECTION_TIMEOUT));
 
@@ -103,7 +100,7 @@ public class OOMTest extends TestCase implements Watcher {
         hog.get(0)[0] = (byte) 1;
 
         f.shutdown();
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                    ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                 CONNECTION_TIMEOUT));
     }

+ 0 - 5
src/java/test/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java

@@ -21,11 +21,6 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.junit.Test;
 
-/**
- * Mimics QuorumHierarchical test, but on an ensemble that includes 2 
- * observers.
- */
-
 public class ObserverHierarchicalQuorumTest extends HierarchicalQuorumTest {
     private static final Logger LOG = Logger.getLogger(QuorumBase.class);
        

+ 1 - 4
src/java/test/org/apache/zookeeper/test/ObserverQuorumHammerTest.java

@@ -20,16 +20,13 @@ package org.apache.zookeeper.test;
 import org.junit.Before;
 import org.junit.Test;
 
-/**
- * Mimics QuorumHammerTest, but with 2 observers in the 5 Learner ensemble.
- */
 public class ObserverQuorumHammerTest extends QuorumHammerTest {
     public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT;
 
     
     @Before
     @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         qb.setUp(true);
         cht.hostPort = qb.hostPort;
         cht.setUpAll();

+ 15 - 18
src/java/test/org/apache/zookeeper/test/ObserverTest.java

@@ -34,12 +34,9 @@ import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper.States;
 import org.apache.zookeeper.server.quorum.QuorumPeerTestBase;
+import org.junit.Assert;
 import org.junit.Test;
 
-/**
- * Test Observer behaviour and specific code paths.
- *
- */
 public class ObserverTest extends QuorumPeerTestBase implements Watcher{
     protected static final Logger LOG =
         Logger.getLogger(ObserverTest.class);    
@@ -89,13 +86,13 @@ public class ObserverTest extends QuorumPeerTestBase implements Watcher{
         q1.start();
         q2.start();
         q3.start();
-        assertTrue("waiting for server 1 being up",
+        Assert.assertTrue("waiting for server 1 being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                         CONNECTION_TIMEOUT));
-        assertTrue("waiting for server 2 being up",
+        Assert.assertTrue("waiting for server 2 being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
                         CONNECTION_TIMEOUT));
-        assertTrue("waiting for server 3 being up",
+        Assert.assertTrue("waiting for server 3 being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_OBS,
                         CONNECTION_TIMEOUT));        
         
@@ -105,29 +102,29 @@ public class ObserverTest extends QuorumPeerTestBase implements Watcher{
                 CreateMode.PERSISTENT);
         
         // Assert that commands are getting forwarded correctly
-        assertEquals(new String(zk.getData("/obstest", null, null)), "test");
+        Assert.assertEquals(new String(zk.getData("/obstest", null, null)), "test");
         
         // Now check that other commands don't blow everything up
         zk.sync("/", null, null);
         zk.setData("/obstest", "test2".getBytes(), -1);
         zk.getChildren("/", false);
         
-        assertEquals(zk.getState(), States.CONNECTED);
+        Assert.assertEquals(zk.getState(), States.CONNECTED);
         
         // Now kill one of the other real servers        
         q2.shutdown();
                 
-        assertTrue("Waiting for server 2 to shut down",
+        Assert.assertTrue("Waiting for server 2 to shut down",
                     ClientBase.waitForServerDown("127.0.0.1:"+CLIENT_PORT_QP2, 
                                     ClientBase.CONNECTION_TIMEOUT));
         
         // Now the resulting ensemble shouldn't be quorate         
         latch.await();        
-        assertNotSame("Client is still connected to non-quorate cluster", 
+        Assert.assertNotSame("Client is still connected to non-quorate cluster", 
                 KeeperState.SyncConnected,lastEvent.getState());
 
         try {
-            assertFalse("Shouldn't get a response when cluster not quorate!",
+            Assert.assertFalse("Shouldn't get a response when cluster not quorate!",
                     new String(zk.getData("/obstest", null, null)).equals("test"));
         }
         catch (ConnectionLossException c) {
@@ -140,14 +137,14 @@ public class ObserverTest extends QuorumPeerTestBase implements Watcher{
         q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
         q2.start();
         LOG.info("Waiting for server 2 to come up");
-        assertTrue("waiting for server 2 being up",
+        Assert.assertTrue("waiting for server 2 being up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
                         CONNECTION_TIMEOUT));
         
         latch.await();
         // It's possible our session expired - but this is ok, shows we 
         // were able to talk to the ensemble
-        assertTrue("Client didn't reconnect to quorate ensemble (state was" +
+        Assert.assertTrue("Client didn't reconnect to quorate ensemble (state was" +
                 lastEvent.getState() + ")",
                 (KeeperState.SyncConnected==lastEvent.getState() ||
                 KeeperState.Expired==lastEvent.getState())); 
@@ -157,13 +154,13 @@ public class ObserverTest extends QuorumPeerTestBase implements Watcher{
         q3.shutdown();
         
         zk.close();        
-        assertTrue("Waiting for server 1 to shut down",
+        Assert.assertTrue("Waiting for server 1 to shut down",
                 ClientBase.waitForServerDown("127.0.0.1:"+CLIENT_PORT_QP1, 
                                 ClientBase.CONNECTION_TIMEOUT));
-        assertTrue("Waiting for server 2 to shut down",
+        Assert.assertTrue("Waiting for server 2 to shut down",
                 ClientBase.waitForServerDown("127.0.0.1:"+CLIENT_PORT_QP2, 
                                 ClientBase.CONNECTION_TIMEOUT));
-        assertTrue("Waiting for server 3 to shut down",
+        Assert.assertTrue("Waiting for server 3 to shut down",
                 ClientBase.waitForServerDown("127.0.0.1:"+CLIENT_PORT_OBS, 
                                 ClientBase.CONNECTION_TIMEOUT));
     
@@ -195,7 +192,7 @@ public class ObserverTest extends QuorumPeerTestBase implements Watcher{
                     
         MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
         q1.start();
-        assertFalse("Observer shouldn't come up",
+        Assert.assertFalse("Observer shouldn't come up",
                 ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                                             CONNECTION_TIMEOUT));
         

+ 8 - 10
src/java/test/org/apache/zookeeper/test/PurgeTxnTest.java

@@ -22,12 +22,11 @@ import java.io.File;
 import java.net.InetSocketAddress;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 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;
 import org.apache.zookeeper.server.NIOServerCnxn;
@@ -35,12 +34,10 @@ import org.apache.zookeeper.server.PurgeTxnLog;
 import org.apache.zookeeper.server.SyncRequestProcessor;
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
+import org.junit.Assert;
+import org.junit.Test;
 
-/**
- * test the purging of the logs
- * and purging of the snapshots.
- */
-public class PurgeTxnTest extends TestCase implements  Watcher {
+public class PurgeTxnTest extends ZKTestCase implements  Watcher {
     //private static final Logger LOG = Logger.getLogger(PurgeTxnTest.class);
     private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
     private static final int CONNECTION_TIMEOUT = 3000;
@@ -48,6 +45,7 @@ public class PurgeTxnTest extends TestCase implements  Watcher {
      * test the purge
      * @throws Exception an exception might be thrown here
      */
+    @Test
     public void testPurge() throws Exception {
         File tmpDir = ClientBase.createTmpDir();
         ClientBase.setupTestEnv();
@@ -57,7 +55,7 @@ public class PurgeTxnTest extends TestCase implements  Watcher {
         NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(
                 new InetSocketAddress(PORT));
         f.startup(zks);
-        assertTrue("waiting for server being up ",
+        Assert.assertTrue("waiting for server being up ",
                 ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
         ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
         try {
@@ -69,7 +67,7 @@ public class PurgeTxnTest extends TestCase implements  Watcher {
             zk.close();
         }
         f.shutdown();
-        assertTrue("waiting for server to shutdown",
+        Assert.assertTrue("waiting for server to shutdown",
                 ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
         // now corrupt the snapshot
         PurgeTxnLog.purge(tmpDir, tmpDir, 3);
@@ -81,7 +79,7 @@ public class PurgeTxnTest extends TestCase implements  Watcher {
                 numSnaps++;
             }
         }
-        assertTrue("exactly 3 snapshots ", (numSnaps == 3));
+        Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
     }
 
     public void process(WatchedEvent event) {

+ 17 - 20
src/java/test/org/apache/zookeeper/test/QuorumBase.java

@@ -34,7 +34,7 @@ import org.apache.zookeeper.server.quorum.Election;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
-import org.junit.After;
+import org.junit.Assert;
 
 import com.sun.management.UnixOperatingSystemMXBean;
 
@@ -56,12 +56,12 @@ public class QuorumBase extends ClientBase {
     private int portLE5;
 
     @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         setUp(false);
     }
         
     protected void setUp(boolean withObservers) throws Exception {
-        LOG.info("STARTING " + getName());
+        LOG.info("QuorumBase.setup " + getTestName());
         setupTestEnv();
 
         JMXEnv.setUp();
@@ -144,19 +144,19 @@ public class QuorumBase extends ClientBase {
 
         LOG.info("creating QuorumPeer 1 port " + port1);
         s1 = new QuorumPeer(peers, s1dir, s1dir, port1, 3, 1, tickTime, initLimit, syncLimit);
-        assertEquals(port1, s1.getClientPort());
+        Assert.assertEquals(port1, s1.getClientPort());
         LOG.info("creating QuorumPeer 2 port " + port2);
         s2 = new QuorumPeer(peers, s2dir, s2dir, port2, 3, 2, tickTime, initLimit, syncLimit);
-        assertEquals(port2, s2.getClientPort());
+        Assert.assertEquals(port2, s2.getClientPort());
         LOG.info("creating QuorumPeer 3 port " + port3);
         s3 = new QuorumPeer(peers, s3dir, s3dir, port3, 3, 3, tickTime, initLimit, syncLimit);
-        assertEquals(port3, s3.getClientPort());
+        Assert.assertEquals(port3, s3.getClientPort());
         LOG.info("creating QuorumPeer 4 port " + port4);
         s4 = new QuorumPeer(peers, s4dir, s4dir, port4, 3, 4, tickTime, initLimit, syncLimit);
-        assertEquals(port4, s4.getClientPort());
+        Assert.assertEquals(port4, s4.getClientPort());
         LOG.info("creating QuorumPeer 5 port " + port5);
         s5 = new QuorumPeer(peers, s5dir, s5dir, port5, 3, 5, tickTime, initLimit, syncLimit);
-        assertEquals(port5, s5.getClientPort());
+        Assert.assertEquals(port5, s5.getClientPort());
         
         if (withObservers) {
             s4.setPeerType(LearnerType.OBSERVER);
@@ -177,7 +177,7 @@ public class QuorumBase extends ClientBase {
 
         LOG.info ("Checking ports " + hostPort);
         for (String hp : hostPort.split(",")) {
-            assertTrue("waiting for server up",
+            Assert.assertTrue("waiting for server up",
                        ClientBase.waitForServerUp(hp,
                                     CONNECTION_TIMEOUT));
             LOG.info(hp + " is accepting client connections");
@@ -234,24 +234,23 @@ public class QuorumBase extends ClientBase {
         
         LOG.info("creating QuorumPeer 1 port " + port1);
         s1 = new QuorumPeer(peers, s1dir, s1dir, port1, 3, 1, tickTime, initLimit, syncLimit);
-        assertEquals(port1, s1.getClientPort());
+        Assert.assertEquals(port1, s1.getClientPort());
         LOG.info("creating QuorumPeer 2 port " + port2);
         s2 = new QuorumPeer(peers, s2dir, s2dir, port2, 3, 2, tickTime, initLimit, syncLimit);
-        assertEquals(port2, s2.getClientPort());
+        Assert.assertEquals(port2, s2.getClientPort());
         LOG.info("creating QuorumPeer 3 port " + port3);
         s3 = new QuorumPeer(peers, s3dir, s3dir, port3, 3, 3, tickTime, initLimit, syncLimit);
-        assertEquals(port3, s3.getClientPort());
+        Assert.assertEquals(port3, s3.getClientPort());
         LOG.info("creating QuorumPeer 4 port " + port4);
         s4 = new QuorumPeer(peers, s4dir, s4dir, port4, 3, 4, tickTime, initLimit, syncLimit);
-        assertEquals(port4, s4.getClientPort());
+        Assert.assertEquals(port4, s4.getClientPort());
         LOG.info("creating QuorumPeer 5 port " + port5);
         s5 = new QuorumPeer(peers, s5dir, s5dir, port5, 3, 5, tickTime, initLimit, syncLimit);
-        assertEquals(port5, s5.getClientPort());
+        Assert.assertEquals(port5, s5.getClientPort());
     }
 
-    @After
     @Override
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         LOG.info("TearDown started");
         
         OperatingSystemMXBean osMbean =
@@ -266,15 +265,13 @@ public class QuorumBase extends ClientBase {
         shutdownServers();
 
         for (String hp : hostPort.split(",")) {
-            assertTrue("waiting for server down",
+            Assert.assertTrue("waiting for server down",
                        ClientBase.waitForServerDown(hp,
                                            ClientBase.CONNECTION_TIMEOUT));
             LOG.info(hp + " is no longer accepting client connections");
         }
 
         JMXEnv.tearDown();
-
-        LOG.info("FINISHED " + getName());
     }
     public void shutdownServers() {
         shutdown(s1);
@@ -298,7 +295,7 @@ public class QuorumBase extends ClientBase {
             LOG.info("Waiting for " + qp.getName() + " to exit thread");
             qp.join(30000);
             if (qp.isAlive()) {
-                fail("QP failed to shutdown in 30 seconds: " + qp.getName());
+                Assert.fail("QP failed to shutdown in 30 seconds: " + qp.getName());
             }
         } catch (InterruptedException e) {
             LOG.debug("QP interrupted: " + qp.getName(), e);

+ 6 - 3
src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java

@@ -18,6 +18,7 @@
 
 package org.apache.zookeeper.test;
 import org.apache.log4j.Logger;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -30,17 +31,19 @@ public class QuorumHammerTest extends QuorumBase {
 
     @Before
     @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         qb.setUp();
         cht.hostPort = qb.hostPort;
         cht.setUpAll();
     }
 
-    protected void tearDown() throws Exception {
+    @After
+    @Override
+    public void tearDown() throws Exception {
         cht.tearDownAll();
         qb.tearDown();
     }
-    
+
     @Test
     public void testHammerBasic() throws Throwable {
         cht.testHammerBasic();

+ 7 - 22
src/java/test/org/apache/zookeeper/test/QuorumQuotaTest.java

@@ -26,29 +26,14 @@ import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeperMain;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
-
-/**
- * this class tests quota on a quorum
- * zookeeper server.
- *
- */
+import org.junit.Assert;
+import org.junit.Test;
 
 public class QuorumQuotaTest extends QuorumBase {
     private static final Logger LOG =
         Logger.getLogger(QuorumQuotaTest.class);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        LOG.info("STARTING " + getClass().getName());
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        LOG.info("STOPPING " + getClass().getName());
-    }
-
+    @Test
     public void testQuotaWithQuorum() throws Exception {
         ZooKeeper zk = createClient();
         zk.setData("/", "some".getBytes(), -1);
@@ -63,15 +48,15 @@ public class QuorumQuotaTest extends QuorumBase {
         String statPath = Quotas.quotaZookeeper + "/a"+ "/" + Quotas.statNode;
         byte[] data = zk.getData(statPath, false, new Stat());
         StatsTrack st = new StatsTrack(new String(data));
-        assertTrue("bytes are set", st.getBytes() == 1204L);
-        assertTrue("num count is set", st.getCount() == 301);
+        Assert.assertTrue("bytes are set", st.getBytes() == 1204L);
+        Assert.assertTrue("num count is set", st.getCount() == 301);
         for (i=300; i < 600; i++) {
             zk.create("/a/" + i, "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
                     CreateMode.PERSISTENT);
         }
         data = zk.getData(statPath, false, new Stat());
         st = new StatsTrack(new String(data));
-        assertTrue("bytes are set", st.getBytes() == 2404L);
-        assertTrue("num count is set", st.getCount() == 601);
+        Assert.assertTrue("bytes are set", st.getBytes() == 2404L);
+        Assert.assertTrue("num count is set", st.getCount() == 601);
     }
 }

+ 36 - 32
src/java/test/org/apache/zookeeper/test/QuorumTest.java

@@ -33,6 +33,8 @@ import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.quorum.Leader;
 import org.apache.zookeeper.server.quorum.LearnerHandler;
+import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -45,17 +47,19 @@ public class QuorumTest extends QuorumBase {
 
     @Before
     @Override
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
         qb.setUp();
         ct.hostPort = qb.hostPort;
         ct.setUpAll();
     }
 
-    protected void tearDown() throws Exception {
+    @After
+    @Override
+    public void tearDown() throws Exception {
         ct.tearDownAll();
         qb.tearDown();
     }
-    
+
     @Test
     public void testDeleteWithChildren() throws Exception {
         ct.testDeleteWithChildren();
@@ -91,28 +95,28 @@ public class QuorumTest extends QuorumBase {
     {
         ct.testClientWithWatcherObj();
     }
-    
+
     @Test
-    public void testGetView() {                
-        ct.assertEquals(5,qb.s1.getView().size());        
-        ct.assertEquals(5,qb.s2.getView().size());        
-        ct.assertEquals(5,qb.s3.getView().size());        
-        ct.assertEquals(5,qb.s4.getView().size());
-        ct.assertEquals(5,qb.s5.getView().size());
+    public void testGetView() {
+        Assert.assertEquals(5,qb.s1.getView().size());
+        Assert.assertEquals(5,qb.s2.getView().size());
+        Assert.assertEquals(5,qb.s3.getView().size());
+        Assert.assertEquals(5,qb.s4.getView().size());
+        Assert.assertEquals(5,qb.s5.getView().size());
     }
-    
+
     @Test
     public void testViewContains() {
         // Test view contains self
-        ct.assertTrue(qb.s1.viewContains(qb.s1.getId()));
-        
+        Assert.assertTrue(qb.s1.viewContains(qb.s1.getId()));
+
         // Test view contains other servers
-        ct.assertTrue(qb.s1.viewContains(qb.s2.getId()));
-        
+        Assert.assertTrue(qb.s1.viewContains(qb.s2.getId()));
+
         // Test view does not contain non-existant servers
-        ct.assertFalse(qb.s1.viewContains(-1L));
+        Assert.assertFalse(qb.s1.viewContains(-1L));
     }
-    
+
     volatile int counter = 0;
     volatile int errors = 0;
     @Test
@@ -127,7 +131,7 @@ public class QuorumTest extends QuorumBase {
         if (leader == null) leader = qb.s3.leader;
         if (leader == null) leader = qb.s4.leader;
         if (leader == null) leader = qb.s5.leader;
-        assertNotNull(leader);
+        Assert.assertNotNull(leader);
         for(int i = 0; i < 5000; i++) {
             zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() {
                 public void processResult(int rc, String path, Object ctx,
@@ -155,23 +159,23 @@ public class QuorumTest extends QuorumBase {
             }, null);
         }
         // check if all the followers are alive
-        assertTrue(qb.s1.isAlive());
-        assertTrue(qb.s2.isAlive());
-        assertTrue(qb.s3.isAlive());
-        assertTrue(qb.s4.isAlive());
-        assertTrue(qb.s5.isAlive());
+        Assert.assertTrue(qb.s1.isAlive());
+        Assert.assertTrue(qb.s2.isAlive());
+        Assert.assertTrue(qb.s3.isAlive());
+        Assert.assertTrue(qb.s4.isAlive());
+        Assert.assertTrue(qb.s5.isAlive());
         zk.close();
     }
-    
+
     @Test
     public void testMultipleWatcherObjs() throws IOException,
             InterruptedException, KeeperException
     {
         ct.testMutipleWatcherObjs();
     }
-	
+
     /**
-     * Make sure that we can change sessions 
+     * Make sure that we can change sessions
      *  from follower to leader.
      *
      * @throws IOException
@@ -188,7 +192,7 @@ public class QuorumTest extends QuorumBase {
         // we want to loop through the list twice
         for(int i = 0; i < hostPorts.length*2; i++) {
             // This should stomp the zk handle
-            DisconnectableZooKeeper zknew = new DisconnectableZooKeeper(hostPorts[(i+1)%hostPorts.length], ClientBase.CONNECTION_TIMEOUT, 
+            DisconnectableZooKeeper zknew = new DisconnectableZooKeeper(hostPorts[(i+1)%hostPorts.length], ClientBase.CONNECTION_TIMEOUT,
                     new Watcher() {public void process(WatchedEvent event) {
                     }},
                     zk.getSessionId(),
@@ -196,7 +200,7 @@ public class QuorumTest extends QuorumBase {
             zknew.setData("/", new byte[1], -1);
             try {
                 zk.setData("/", new byte[1], -1);
-                fail("Should have lost the connection");
+                Assert.fail("Should have lost the connection");
             } catch(KeeperException.ConnectionLossException e) {
             }
             zk.disconnect(); // close w/o closing session
@@ -214,11 +218,11 @@ public class QuorumTest extends QuorumBase {
         }
     }
 
-    @Test
     /**
      * Connect to two different servers with two different handles using the same session and
      * make sure we cannot do any changes.
      */
+    @Test
     public void testSessionMove() throws IOException, InterruptedException, KeeperException {
         String hps[] = qb.hostPort.split(",");
         DiscoWatcher oldWatcher = new DiscoWatcher();
@@ -233,7 +237,7 @@ public class QuorumTest extends QuorumBase {
         zknew.create("/t2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
         try {
             zk.create("/t3", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
-            fail("Should have lost the connection");
+            Assert.fail("Should have lost the connection");
         } catch(KeeperException.ConnectionLossException e) {
             // wait up to 30 seconds for the disco to be delivered
             for (int i = 0; i < 30; i++) {
@@ -242,7 +246,7 @@ public class QuorumTest extends QuorumBase {
                 }
                 Thread.sleep(1000);
             }
-            assertTrue(oldWatcher.zkDisco);
+            Assert.assertTrue(oldWatcher.zkDisco);
         }
 
         ArrayList<ZooKeeper> toClose = new ArrayList<ZooKeeper>();
@@ -260,5 +264,5 @@ public class QuorumTest extends QuorumBase {
         }
         zk.close();
     }
-	// skip superhammer and clientcleanup as they are too expensive for quorum
+    // skip superhammer and clientcleanup as they are too expensive for quorum
 }

+ 16 - 22
src/java/test/org/apache/zookeeper/test/QuorumZxidSyncTest.java

@@ -20,34 +20,29 @@ package org.apache.zookeeper.test;
 
 import java.io.File;
 
-import junit.framework.TestCase;
-
 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;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-/**
- * Test what happens when logs fall behind the snapshots or a follower has a
- * higher epoch than a leader.
- */
-public class QuorumZxidSyncTest extends TestCase {
+public class QuorumZxidSyncTest extends ZKTestCase {
     QuorumBase qb = new QuorumBase();
-    
+
     @Before
-    @Override
-    protected void setUp() throws Exception {
-    	qb.setUp();
+    public void setUp() throws Exception {
+        qb.setUp();
     }
-    
-    @Test
+
     /**
      * find out what happens when a follower connects to leader that is behind
      */
+    @Test
     public void testBehindLeader() throws Exception {
         // crank up the epoch numbers
         ClientBase.waitForServerUp(qb.hostPort, 10000);
@@ -89,25 +84,25 @@ public class QuorumZxidSyncTest extends TestCase {
         qb.s2.start();
         qb.s3.start();
         qb.s4.start();
-        assertTrue("Servers didn't come up", ClientBase.waitForServerUp(qb.hostPort, 10000));
+        Assert.assertTrue("Servers didn't come up", ClientBase.waitForServerUp(qb.hostPort, 10000));
         qb.s5.start();
         String hostPort = "127.0.0.1:" + qb.s5.getClientPort();
-        assertFalse("Servers came up, but shouldn't have since it's ahead of leader",
+        Assert.assertFalse("Servers came up, but shouldn't have since it's ahead of leader",
                 ClientBase.waitForServerUp(hostPort, 10000));
     }
-    
+
     private void deleteFiles(File f) {
         File v = new File(f, "version-2");
         for(File c: v.listFiles()) {
             c.delete();
         }
     }
-    
-    @Test
+
     /**
      * find out what happens when the latest state is in the snapshots not
      * the logs.
      */
+    @Test
     public void testLateLogs() throws Exception {
         // crank up the epoch numbers
         ClientBase.waitForServerUp(qb.hostPort, 10000);
@@ -157,9 +152,9 @@ public class QuorumZxidSyncTest extends TestCase {
             }
         }
         zk.close();
-        assertTrue("Didn't see /2 (went back in time)", saw2);
+        Assert.assertTrue("Didn't see /2 (went back in time)", saw2);
     }
-    
+
     private void deleteLogs(File f) {
         File v = new File(f, "version-2");
         for(File c: v.listFiles()) {
@@ -168,9 +163,8 @@ public class QuorumZxidSyncTest extends TestCase {
             }
         }
     }
-    
+
     @After
-    @Override
     public void tearDown() throws Exception {
         qb.tearDown();
     }

+ 19 - 28
src/java/test/org/apache/zookeeper/test/RecoveryTest.java

@@ -25,13 +25,12 @@ import java.net.InetSocketAddress;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import junit.framework.TestCase;
-
 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.ZooKeeper;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
@@ -39,9 +38,10 @@ import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.SyncRequestProcessor;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class RecoveryTest extends TestCase implements Watcher {
+public class RecoveryTest extends ZKTestCase implements Watcher {
     protected static final Logger LOG = Logger.getLogger(RecoveryTest.class);
 
     private static final String HOSTPORT =
@@ -49,16 +49,6 @@ public class RecoveryTest extends TestCase implements Watcher {
 
     private volatile CountDownLatch startSignal;
 
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
-    }
-    @Override
-    protected void tearDown() throws Exception {
-        LOG.info("FINISHED " + getName());
-    }
-
-    @Test
     /**
      * Verify that if a server goes down that clients will reconnect
      * automatically after the server is restarted. Note that this requires the
@@ -71,6 +61,7 @@ public class RecoveryTest extends TestCase implements Watcher {
      * occurs after the server is down, but before the client recognizes
      * that the server is down (ping) then the op will throw connectionloss.
      */
+    @Test
     public void testRecovery() throws Exception {
         File tmpDir = ClientBase.createTmpDir();
 
@@ -86,7 +77,7 @@ public class RecoveryTest extends TestCase implements Watcher {
             f.startup(zks);
             LOG.info("starting up the the server, waiting");
 
-            assertTrue("waiting for server up",
+            Assert.assertTrue("waiting for server up",
                        ClientBase.waitForServerUp(HOSTPORT,
                                        CONNECTION_TIMEOUT));
 
@@ -94,7 +85,7 @@ public class RecoveryTest extends TestCase implements Watcher {
             ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
             startSignal.await(CONNECTION_TIMEOUT,
                     TimeUnit.MILLISECONDS);
-            assertTrue("count == 0", startSignal.getCount() == 0);
+            Assert.assertTrue("count == 0", startSignal.getCount() == 0);
             String path;
             LOG.info("starting creating nodes");
             for (int i = 0; i < 10; i++) {
@@ -115,7 +106,7 @@ public class RecoveryTest extends TestCase implements Watcher {
             }
 
             f.shutdown();
-            assertTrue("waiting for server down",
+            Assert.assertTrue("waiting for server down",
                        ClientBase.waitForServerDown(HOSTPORT,
                                           CONNECTION_TIMEOUT));
 
@@ -126,34 +117,34 @@ public class RecoveryTest extends TestCase implements Watcher {
 
             f.startup(zks);
 
-            assertTrue("waiting for server up",
+            Assert.assertTrue("waiting for server up",
                        ClientBase.waitForServerUp(HOSTPORT,
                                            CONNECTION_TIMEOUT));
 
             startSignal.await(CONNECTION_TIMEOUT,
                     TimeUnit.MILLISECONDS);
-            assertTrue("count == 0", startSignal.getCount() == 0);
+            Assert.assertTrue("count == 0", startSignal.getCount() == 0);
 
             Stat stat = new Stat();
             for (int i = 0; i < 10; i++) {
                 path = "/" + i;
                 LOG.info("Checking " + path);
-                assertEquals(new String(zk.getData(path, false, stat)), path
+                Assert.assertEquals(new String(zk.getData(path, false, stat)), path
                         + "!");
                 for (int j = 0; j < 10; j++) {
                     String subpath = path + "/" + j;
-                    assertEquals(new String(zk.getData(subpath, false, stat)),
+                    Assert.assertEquals(new String(zk.getData(subpath, false, stat)),
                             subpath + "!");
                     for (int k = 0; k < 20; k++) {
                         String subsubpath = subpath + "/" + k;
-                        assertEquals(new String(zk.getData(subsubpath, false,
+                        Assert.assertEquals(new String(zk.getData(subsubpath, false,
                                 stat)), subsubpath + "!");
                     }
                 }
             }
             f.shutdown();
 
-            assertTrue("waiting for server down",
+            Assert.assertTrue("waiting for server down",
                        ClientBase.waitForServerDown(HOSTPORT,
                                           ClientBase.CONNECTION_TIMEOUT));
 
@@ -164,26 +155,26 @@ public class RecoveryTest extends TestCase implements Watcher {
 
             f.startup(zks);
 
-            assertTrue("waiting for server up",
+            Assert.assertTrue("waiting for server up",
                        ClientBase.waitForServerUp(HOSTPORT,
                                CONNECTION_TIMEOUT));
 
             startSignal.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
-            assertTrue("count == 0", startSignal.getCount() == 0);
+            Assert.assertTrue("count == 0", startSignal.getCount() == 0);
 
             stat = new Stat();
             LOG.info("Check 2");
             for (int i = 0; i < 10; i++) {
                 path = "/" + i;
-                assertEquals(new String(zk.getData(path, false, stat)),
+                Assert.assertEquals(new String(zk.getData(path, false, stat)),
                              path + "!");
                 for (int j = 0; j < 10; j++) {
                     String subpath = path + "/" + j;
-                    assertEquals(new String(zk.getData(subpath, false, stat)),
+                    Assert.assertEquals(new String(zk.getData(subpath, false, stat)),
                             subpath + "!");
                     for (int k = 0; k < 20; k++) {
                         String subsubpath = subpath + "/" + k;
-                        assertEquals(new String(zk.getData(subsubpath, false,
+                        Assert.assertEquals(new String(zk.getData(subsubpath, false,
                                 stat)), subsubpath + "!");
                     }
                 }
@@ -192,7 +183,7 @@ public class RecoveryTest extends TestCase implements Watcher {
 
             f.shutdown();
 
-            assertTrue("waiting for server down",
+            Assert.assertTrue("waiting for server down",
                        ClientBase.waitForServerDown(HOSTPORT,
                                                     CONNECTION_TIMEOUT));
         } finally {

+ 5 - 9
src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java

@@ -20,20 +20,16 @@ package org.apache.zookeeper.test;
 
 import java.net.InetSocketAddress;
 
-import junit.framework.TestCase;
-
 import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.Assert;
 import org.junit.Test;
 
-/**
- * this test fails quorum peers and then brings up one of the node as
- * a standalone server
- */
-public class RepeatStartupTest extends TestCase {
+public class RepeatStartupTest extends ZKTestCase {
 
     /** bring up 5 quorum peers and then shut them down
      * and then bring one of the nodes as server
@@ -63,11 +59,11 @@ public class RepeatStartupTest extends TestCase {
 
         factory.startup(zks);
         System.out.println("Comment: starting factory");
-        assertTrue("waiting for server up",
+        Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                            QuorumTest.CONNECTION_TIMEOUT));
         factory.shutdown();
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                    ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                 QuorumTest.CONNECTION_TIMEOUT));
         System.out.println("Comment: shutting down standalone");

+ 32 - 33
src/java/test/org/apache/zookeeper/test/SessionTest.java

@@ -27,14 +27,13 @@ import java.util.LinkedList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 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.ZooKeeper;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -42,9 +41,12 @@ import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-public class SessionTest extends TestCase implements Watcher {
+public class SessionTest extends ZKTestCase implements Watcher {
     protected static final Logger LOG = Logger.getLogger(SessionTest.class);
 
     private static final String HOSTPORT = "127.0.0.1:" +
@@ -54,13 +56,11 @@ public class SessionTest extends TestCase implements Watcher {
     private CountDownLatch startSignal;
 
     File tmpDir;
-    
-    private final int TICK_TIME = 3000;
 
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
+    private final int TICK_TIME = 3000;
 
+    @Before
+    public void setUp() throws Exception {
         if (tmpDir == null) {
             tmpDir = ClientBase.createTmpDir();
         }
@@ -72,18 +72,17 @@ public class SessionTest extends TestCase implements Watcher {
         serverFactory = new NIOServerCnxn.Factory(new InetSocketAddress(PORT));
         serverFactory.startup(zs);
 
-        assertTrue("waiting for server up",
+        Assert.assertTrue("waiting for server up",
                    ClientBase.waitForServerUp(HOSTPORT,
                                               CONNECTION_TIMEOUT));
     }
-    @Override
-    protected void tearDown() throws Exception {
+
+    @After
+    public void tearDown() throws Exception {
         serverFactory.shutdown();
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                    ClientBase.waitForServerDown(HOSTPORT,
                                                 CONNECTION_TIMEOUT));
-
-        LOG.info("FINISHED " + getName());
     }
 
     private static class CountdownWatcher implements Watcher {
@@ -117,13 +116,13 @@ public class SessionTest extends TestCase implements Watcher {
         DisconnectableZooKeeper zk =
                 new DisconnectableZooKeeper(HOSTPORT, timeout, watcher);
         if(!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS)) {
-            fail("Unable to connect to server");
+            Assert.fail("Unable to connect to server");
         }
 
         return zk;
     }
 
-// FIXME this test is failing due to client close race condition fixing in separate patch for ZOOKEEPER-63
+// FIXME this test is Assert.failing due to client close race condition fixing in separate patch for ZOOKEEPER-63
 //    /**
 //     * this test checks to see if the sessionid that was created for the
 //     * first zookeeper client can be reused for the second one immidiately
@@ -150,17 +149,17 @@ public class SessionTest extends TestCase implements Watcher {
 //
 //        LOG.info("Opened reuse");
 //
-//        assertEquals(sessionId, zk.getSessionId());
+//        Assert.assertEquals(sessionId, zk.getSessionId());
 //
 //        zk.close();
 //    }
 
-    @Test
     /**
      * This test verifies that when the session id is reused, and the original
      * client is disconnected, but not session closed, that the server
      * will remove ephemeral nodes created by the original session.
      */
+    @Test
     public void testSession()
         throws IOException, InterruptedException, KeeperException
     {
@@ -189,16 +188,16 @@ public class SessionTest extends TestCase implements Watcher {
         zk.close();
 
         zk = createClient();
-        assertEquals(null, zk.exists("/e", false));
+        Assert.assertEquals(null, zk.exists("/e", false));
         LOG.info("before close zk with session id 0x"
                 + Long.toHexString(zk.getSessionId()) + "!");
         zk.close();
     }
 
-    @Test
     /**
      * Make sure ephemerals get cleaned up when a session times out.
      */
+    @Test
     public void testSessionTimeout() throws Exception {
         final int TIMEOUT = 5000;
         DisconnectableZooKeeper zk = createClient(TIMEOUT);
@@ -217,9 +216,9 @@ public class SessionTest extends TestCase implements Watcher {
         setUp();
 
         zk = createClient(TIMEOUT);
-        assertTrue(zk.exists("/stest", false) != null);
+        Assert.assertTrue(zk.exists("/stest", false) != null);
         Thread.sleep(TIMEOUT*2);
-        assertTrue(zk.exists("/stest", false) == null);
+        Assert.assertTrue(zk.exists("/stest", false) == null);
         zk.close();
     }
 
@@ -245,7 +244,7 @@ public class SessionTest extends TestCase implements Watcher {
             zknew.setData("/", new byte[1], -1);
             try {
                 zk.setData("/", new byte[1], -1);
-                fail("Should have lost the connection");
+                Assert.fail("Should have lost the connection");
             } catch(KeeperException.ConnectionLossException e) {
             }
             //zk.close();
@@ -253,7 +252,6 @@ public class SessionTest extends TestCase implements Watcher {
         }
         zk.close();
     }
-    @Test
     /**
      * This test makes sure that duplicate state changes are not communicated
      * to the client watcher. For example we should not notify state as
@@ -261,6 +259,7 @@ public class SessionTest extends TestCase implements Watcher {
      * we don't consider a dup state notification if the event type is
      * not "None" (ie non-None communicates an event).
      */
+    @Test
     public void testSessionStateNoDupStateReporting()
         throws IOException, InterruptedException, KeeperException
     {
@@ -280,20 +279,20 @@ public class SessionTest extends TestCase implements Watcher {
         // verify that the size is just 2 - ie connect then disconnect
         // if the client attempts reconnect and we are not handling current
         // state correctly (ie eventing on duplicate disconnects) then we'll
-        // see a disconnect for each failed connection attempt
-        assertEquals(2, watcher.states.size());
+        // see a disconnect for each Assert.failed connection attempt
+        Assert.assertEquals(2, watcher.states.size());
 
         zk.close();
     }
 
-    @Test
     /**
      * Verify access to the negotiated session timeout.
      */
+    @Test
     public void testSessionTimeoutAccess() throws Exception {
         // validate typical case - requested == negotiated
         DisconnectableZooKeeper zk = createClient(TICK_TIME * 4);
-        assertEquals(TICK_TIME * 4, zk.getSessionTimeout());
+        Assert.assertEquals(TICK_TIME * 4, zk.getSessionTimeout());
         // make sure tostring works in both cases
         LOG.info(zk.toString());
         zk.close();
@@ -301,14 +300,14 @@ public class SessionTest extends TestCase implements Watcher {
 
         // validate lower limit
         zk = createClient(TICK_TIME);
-        assertEquals(TICK_TIME * 2, zk.getSessionTimeout());
+        Assert.assertEquals(TICK_TIME * 2, zk.getSessionTimeout());
         LOG.info(zk.toString());
         zk.close();
         LOG.info(zk.toString());
 
         // validate upper limit
         zk = createClient(TICK_TIME * 30);
-        assertEquals(TICK_TIME * 20, zk.getSessionTimeout());
+        Assert.assertEquals(TICK_TIME * 20, zk.getSessionTimeout());
         LOG.info(zk.toString());
         zk.close();
         LOG.info(zk.toString());
@@ -345,7 +344,7 @@ public class SessionTest extends TestCase implements Watcher {
         // validate typical case - requested == negotiated
         int timeout = 120000;
         DisconnectableZooKeeper zk = createClient(timeout);
-        assertEquals(timeout, zk.getSessionTimeout());
+        Assert.assertEquals(timeout, zk.getSessionTimeout());
         // make sure tostring works in both cases
         LOG.info(zk.toString());
         zk.close();
@@ -353,14 +352,14 @@ public class SessionTest extends TestCase implements Watcher {
 
         // validate lower limit
         zk = createClient(MINSESS/2);
-        assertEquals(MINSESS, zk.getSessionTimeout());
+        Assert.assertEquals(MINSESS, zk.getSessionTimeout());
         LOG.info(zk.toString());
         zk.close();
         LOG.info(zk.toString());
 
         // validate upper limit
         zk = createClient(MAXSESS * 2);
-        assertEquals(MAXSESS, zk.getSessionTimeout());
+        Assert.assertEquals(MAXSESS, zk.getSessionTimeout());
         LOG.info(zk.toString());
         zk.close();
         LOG.info(zk.toString());

+ 80 - 80
src/java/test/org/apache/zookeeper/test/StatTest.java

@@ -25,35 +25,35 @@ import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
 import org.junit.Test;
 
-/**
- *
- */
 public class StatTest extends ClientBase {
     private ZooKeeper zk;
-    
-    protected void setUp() throws Exception {
+
+    @Override
+    public void setUp() throws Exception {
         super.setUp();
-        
+
         zk = createClient();
     }
 
-    protected void tearDown() throws Exception {
+    @Override
+    public void tearDown() throws Exception {
         super.tearDown();
-        
+
         zk.close();
     }
-    
+
     /**
-     * Create a new Stat, fill in dummy values trying to catch failure
+     * Create a new Stat, fill in dummy values trying to catch Assert.failure
      * to copy in client or server code.
-     * 
+     *
      * @return a new stat with dummy values
      */
     private Stat newStat() {
         Stat stat = new Stat();
-        
+
         stat.setAversion(100);
         stat.setCtime(100);
         stat.setCversion(100);
@@ -65,7 +65,7 @@ public class StatTest extends ClientBase {
         stat.setNumChildren(100);
         stat.setPzxid(100);
         stat.setVersion(100);
-        
+
         return stat;
     }
 
@@ -76,21 +76,21 @@ public class StatTest extends ClientBase {
         String name = "/foo";
         zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
-        
+
         Stat stat;
-        
+
         stat = newStat();
         zk.getData(name, false, stat);
-        
-        assertEquals(stat.getCzxid(), stat.getMzxid());
-        assertEquals(stat.getCzxid(), stat.getPzxid());
-        assertEquals(stat.getCtime(), stat.getMtime());
-        assertEquals(0, stat.getCversion());
-        assertEquals(0, stat.getVersion());
-        assertEquals(0, stat.getAversion());
-        assertEquals(0, stat.getEphemeralOwner());
-        assertEquals(name.length(), stat.getDataLength());
-        assertEquals(0, stat.getNumChildren());
+
+        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
+        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
+        Assert.assertEquals(stat.getCtime(), stat.getMtime());
+        Assert.assertEquals(0, stat.getCversion());
+        Assert.assertEquals(0, stat.getVersion());
+        Assert.assertEquals(0, stat.getAversion());
+        Assert.assertEquals(0, stat.getEphemeralOwner());
+        Assert.assertEquals(name.length(), stat.getDataLength());
+        Assert.assertEquals(0, stat.getNumChildren());
     }
 
     @Test
@@ -100,38 +100,38 @@ public class StatTest extends ClientBase {
         String name = "/foo";
         zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
-        
+
         String childname = name + "/bar";
         zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.EPHEMERAL);
 
         Stat stat;
-        
+
         stat = newStat();
         zk.getData(name, false, stat);
 
-        assertEquals(stat.getCzxid(), stat.getMzxid());
-        assertEquals(stat.getCzxid() + 1, stat.getPzxid());
-        assertEquals(stat.getCtime(), stat.getMtime());
-        assertEquals(1, stat.getCversion());
-        assertEquals(0, stat.getVersion());
-        assertEquals(0, stat.getAversion());
-        assertEquals(0, stat.getEphemeralOwner());
-        assertEquals(name.length(), stat.getDataLength());
-        assertEquals(1, stat.getNumChildren());
+        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
+        Assert.assertEquals(stat.getCzxid() + 1, stat.getPzxid());
+        Assert.assertEquals(stat.getCtime(), stat.getMtime());
+        Assert.assertEquals(1, stat.getCversion());
+        Assert.assertEquals(0, stat.getVersion());
+        Assert.assertEquals(0, stat.getAversion());
+        Assert.assertEquals(0, stat.getEphemeralOwner());
+        Assert.assertEquals(name.length(), stat.getDataLength());
+        Assert.assertEquals(1, stat.getNumChildren());
 
         stat = newStat();
         zk.getData(childname, false, stat);
 
-        assertEquals(stat.getCzxid(), stat.getMzxid());
-        assertEquals(stat.getCzxid(), stat.getPzxid());
-        assertEquals(stat.getCtime(), stat.getMtime());
-        assertEquals(0, stat.getCversion());
-        assertEquals(0, stat.getVersion());
-        assertEquals(0, stat.getAversion());
-        assertEquals(zk.getSessionId(), stat.getEphemeralOwner());
-        assertEquals(childname.length(), stat.getDataLength());
-        assertEquals(0, stat.getNumChildren());
+        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
+        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
+        Assert.assertEquals(stat.getCtime(), stat.getMtime());
+        Assert.assertEquals(0, stat.getCversion());
+        Assert.assertEquals(0, stat.getVersion());
+        Assert.assertEquals(0, stat.getAversion());
+        Assert.assertEquals(zk.getSessionId(), stat.getEphemeralOwner());
+        Assert.assertEquals(childname.length(), stat.getDataLength());
+        Assert.assertEquals(0, stat.getNumChildren());
     }
 
     @Test
@@ -141,26 +141,26 @@ public class StatTest extends ClientBase {
         String name = "/foo";
         zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
-        
+
         for(int i = 0; i < 10; i++) {
             String childname = name + "/bar" + i;
             zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE,
                     CreateMode.EPHEMERAL);
 
             Stat stat;
-            
+
             stat = newStat();
             zk.getData(name, false, stat);
-    
-            assertEquals(stat.getCzxid(), stat.getMzxid());
-            assertEquals(stat.getCzxid() + i + 1, stat.getPzxid());
-            assertEquals(stat.getCtime(), stat.getMtime());
-            assertEquals(i + 1, stat.getCversion());
-            assertEquals(0, stat.getVersion());
-            assertEquals(0, stat.getAversion());
-            assertEquals(0, stat.getEphemeralOwner());
-            assertEquals(name.length(), stat.getDataLength());
-            assertEquals(i + 1, stat.getNumChildren());
+
+            Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
+            Assert.assertEquals(stat.getCzxid() + i + 1, stat.getPzxid());
+            Assert.assertEquals(stat.getCtime(), stat.getMtime());
+            Assert.assertEquals(i + 1, stat.getCversion());
+            Assert.assertEquals(0, stat.getVersion());
+            Assert.assertEquals(0, stat.getAversion());
+            Assert.assertEquals(0, stat.getEphemeralOwner());
+            Assert.assertEquals(name.length(), stat.getDataLength());
+            Assert.assertEquals(i + 1, stat.getNumChildren());
         }
     }
 
@@ -171,35 +171,35 @@ public class StatTest extends ClientBase {
         String name = "/foo";
         zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
-        
+
         Stat stat;
-        
+
         stat = newStat();
         zk.getData(name, false, stat);
-        
-        assertEquals(stat.getCzxid(), stat.getMzxid());
-        assertEquals(stat.getCzxid(), stat.getPzxid());
-        assertEquals(stat.getCtime(), stat.getMtime());
-        assertEquals(0, stat.getCversion());
-        assertEquals(0, stat.getVersion());
-        assertEquals(0, stat.getAversion());
-        assertEquals(0, stat.getEphemeralOwner());
-        assertEquals(name.length(), stat.getDataLength());
-        assertEquals(0, stat.getNumChildren());
+
+        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
+        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
+        Assert.assertEquals(stat.getCtime(), stat.getMtime());
+        Assert.assertEquals(0, stat.getCversion());
+        Assert.assertEquals(0, stat.getVersion());
+        Assert.assertEquals(0, stat.getAversion());
+        Assert.assertEquals(0, stat.getEphemeralOwner());
+        Assert.assertEquals(name.length(), stat.getDataLength());
+        Assert.assertEquals(0, stat.getNumChildren());
 
         zk.setData(name, (name + name).getBytes(), -1);
-        
+
         stat = newStat();
         zk.getData(name, false, stat);
-        
-        assertNotSame(stat.getCzxid(), stat.getMzxid());
-        assertEquals(stat.getCzxid(), stat.getPzxid());
-        assertNotSame(stat.getCtime(), stat.getMtime());
-        assertEquals(0, stat.getCversion());
-        assertEquals(1, stat.getVersion());
-        assertEquals(0, stat.getAversion());
-        assertEquals(0, stat.getEphemeralOwner());
-        assertEquals(name.length() * 2, stat.getDataLength());
-        assertEquals(0, stat.getNumChildren());
+
+        Assert.assertNotSame(stat.getCzxid(), stat.getMzxid());
+        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
+        Assert.assertNotSame(stat.getCtime(), stat.getMtime());
+        Assert.assertEquals(0, stat.getCversion());
+        Assert.assertEquals(1, stat.getVersion());
+        Assert.assertEquals(0, stat.getAversion());
+        Assert.assertEquals(0, stat.getEphemeralOwner());
+        Assert.assertEquals(name.length() * 2, stat.getDataLength());
+        Assert.assertEquals(0, stat.getNumChildren());
     }
 }

+ 4 - 4
src/java/test/org/apache/zookeeper/test/SyncCallTest.java

@@ -27,15 +27,15 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
 import org.apache.zookeeper.AsyncCallback.Children2Callback;
+import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
 import org.junit.Test;
 
-
 public class SyncCallTest extends ClientBase
     implements ChildrenCallback, Children2Callback, StringCallback, VoidCallback
 {
@@ -67,10 +67,10 @@ public class SyncCallTest extends ClientBase
             LOG.info("Submitted all operations:" + (new Date()).toString());
             
             if(!opsCount.await(10000, TimeUnit.MILLISECONDS))
-                fail("Haven't received all confirmations" + opsCount.getCount());
+                Assert.fail("Haven't received all confirmations" + opsCount.getCount());
 
             for(int i = 0; i < limit ; i++){
-                assertEquals(0, (int) results.get(i));
+                Assert.assertEquals(0, (int) results.get(i));
             }
             
         } catch (IOException e) {

+ 5 - 5
src/java/test/org/apache/zookeeper/test/TruncateTest.java

@@ -23,13 +23,12 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.HashMap;
 
-import junit.framework.TestCase;
-
 import org.apache.log4j.Logger;
 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.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
@@ -38,10 +37,11 @@ import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class TruncateTest extends TestCase {
+public class TruncateTest extends ZKTestCase {
 	private static final Logger LOG = Logger.getLogger(TruncateTest.class);
     File dataDir1, dataDir2, dataDir3;
     final int baseHostPort = 12233;
@@ -115,7 +115,7 @@ public class TruncateTest extends TestCase {
         zk2.getData("/9", false, new Stat());
         try {
             zk2.getData("/10", false, new Stat());
-            fail("Should have gotten an error");
+            Assert.fail("Should have gotten an error");
         } catch(KeeperException.NoNodeException e) {
             // this is what we want
         }
@@ -134,7 +134,7 @@ public class TruncateTest extends TestCase {
         	// actually truncate the zxid for 10 creation
         	// but for 11 we will for sure
         	zk1.getData("/11", false, new Stat());
-            fail("Should have gotten an error");
+            Assert.fail("Should have gotten an error");
         } catch(KeeperException.NoNodeException e) {
             // this is what we want
         }

+ 9 - 16
src/java/test/org/apache/zookeeper/test/UpgradeTest.java

@@ -26,13 +26,12 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
-import junit.framework.TestCase;
-
 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.ZooKeeper;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
@@ -41,8 +40,10 @@ import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.SyncRequestProcessor;
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.upgrade.UpgradeMain;
+import org.junit.Assert;
+import org.junit.Test;
 
-public class UpgradeTest extends TestCase implements Watcher {
+public class UpgradeTest extends ZKTestCase implements Watcher {
     private final static Logger LOG = Logger.getLogger(UpgradeTest.class);
 
     private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
@@ -50,19 +51,11 @@ public class UpgradeTest extends TestCase implements Watcher {
             System.getProperty("test.data.dir", "build/test/data"));
     private CountDownLatch startSignal;
 
-    @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
-    }
-    @Override
-    protected void tearDown() throws Exception {
-        LOG.info("FINISHED " + getName());
-    }
-
     /**
      * test the upgrade
      * @throws Exception
      */
+    @Test
     public void testUpgrade() throws Exception {
         File upgradeDir = new File(testData, "upgrade");
         UpgradeMain upgrade = new UpgradeMain(upgradeDir, upgradeDir);
@@ -74,14 +67,14 @@ public class UpgradeTest extends TestCase implements Watcher {
                 new InetSocketAddress(PORT));
         f.startup(zks);
         LOG.info("starting up the zookeeper server .. waiting");
-        assertTrue("waiting for server being up",
+        Assert.assertTrue("waiting for server being up",
                 ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
         ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
         Stat stat = zk.exists("/", false);
         List<String> children = zk.getChildren("/", false);
         Collections.sort(children);
         for (int i = 0; i < 10; i++) {
-            assertTrue("data tree sanity check",
+            Assert.assertTrue("data tree sanity check",
                     ("test-" + i).equals(children.get(i)));
         }
         //try creating one node
@@ -89,14 +82,14 @@ public class UpgradeTest extends TestCase implements Watcher {
                 CreateMode.PERSISTENT);
         // check if its there
         if (zk.exists("/upgrade", false) == null) {
-            assertTrue(false);
+            Assert.assertTrue(false);
         }
 
         zk.close();
 
         // bring down the server
         f.shutdown();
-        assertTrue("waiting for server down",
+        Assert.assertTrue("waiting for server down",
                    ClientBase.waitForServerDown(HOSTPORT,
                            ClientBase.CONNECTION_TIMEOUT));
 

+ 13 - 13
src/java/test/org/apache/zookeeper/test/WatchedEventTest.java

@@ -20,15 +20,15 @@ package org.apache.zookeeper.test;
 
 import java.util.EnumSet;
 
-import junit.framework.TestCase;
-
 import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.proto.WatcherEvent;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class WatchedEventTest extends TestCase {
+public class WatchedEventTest extends ZKTestCase {
     
     @Test
     public void testCreatingWatchedEvent() {
@@ -42,9 +42,9 @@ public class WatchedEventTest extends TestCase {
         for(EventType et : allTypes) {
            for(KeeperState ks : allStates) {
                we = new WatchedEvent(et, ks, "blah");
-               assertEquals(et, we.getType());
-               assertEquals(ks, we.getState());
-               assertEquals("blah", we.getPath());
+               Assert.assertEquals(et, we.getType());
+               Assert.assertEquals(ks, we.getState());
+               Assert.assertEquals("blah", we.getPath());
            }
             
         }
@@ -63,9 +63,9 @@ public class WatchedEventTest extends TestCase {
            for(KeeperState ks : allStates) {
                wep = new WatcherEvent(et.getIntValue(), ks.getIntValue(), "blah");
                we = new WatchedEvent(wep);
-               assertEquals(et, we.getType());
-               assertEquals(ks, we.getState());
-               assertEquals("blah", we.getPath());
+               Assert.assertEquals(et, we.getType());
+               Assert.assertEquals(ks, we.getState());
+               Assert.assertEquals("blah", we.getPath());
            }
         }
     }
@@ -77,7 +77,7 @@ public class WatchedEventTest extends TestCase {
        try {
            WatcherEvent wep = new WatcherEvent(-2342, -252352, "foo");
            WatchedEvent we = new WatchedEvent(wep);
-           fail("Was able to create WatchedEvent from bad wrapper");
+           Assert.fail("Was able to create WatchedEvent from bad wrapper");
        } catch (RuntimeException re) {
            // we're good
        }
@@ -88,8 +88,8 @@ public class WatchedEventTest extends TestCase {
        WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah");
        WatcherEvent wew = we.getWrapper();
        
-       assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
-       assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
-       assertEquals("blah", wew.getPath());
+       Assert.assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
+       Assert.assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
+       Assert.assertEquals("blah", wew.getPath());
    }
 }

+ 109 - 101
src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java

@@ -33,6 +33,8 @@ import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.junit.Assert;
+import org.junit.Test;
 
 public class WatcherFuncTest extends ClientBase {
     private static class SimpleWatcher implements Watcher {
@@ -57,7 +59,7 @@ public class WatcherFuncTest extends ClientBase {
             try {
                 events.put(event);
             } catch (InterruptedException e) {
-                assertTrue("interruption unexpected", false);
+                Assert.assertTrue("interruption unexpected", false);
             }
         }
         public void verify(List<EventType> expected) throws InterruptedException{
@@ -66,10 +68,10 @@ public class WatcherFuncTest extends ClientBase {
             while (count < expected.size()
                     && (event = events.poll(30, TimeUnit.SECONDS)) != null)
             {
-                assertEquals(expected.get(count), event.getType());
+                Assert.assertEquals(expected.get(count), event.getType());
                 count++;
             }
-            assertEquals(expected.size(), count);
+            Assert.assertEquals(expected.size(), count);
             events.clear();
         }
     }
@@ -83,8 +85,7 @@ public class WatcherFuncTest extends ClientBase {
     private List<EventType> expected;
 
     @Override
-    protected void setUp() throws Exception {
-        LOG.info("STARTING " + getName());
+    public void setUp() throws Exception {
         super.setUp();
 
         client_latch = new CountDownLatch(1);
@@ -97,12 +98,12 @@ public class WatcherFuncTest extends ClientBase {
 
         expected = new ArrayList<EventType>();
     }
+
     @Override
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         client.close();
         lsnr.close();
         super.tearDown();
-        LOG.info("FINISHED " + getName());
     }
 
     protected ZooKeeper createClient(Watcher watcher, CountDownLatch latch)
@@ -110,7 +111,7 @@ public class WatcherFuncTest extends ClientBase {
     {
         ZooKeeper zk = new ZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
         if(!latch.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)){
-            fail("Unable to connect to server");
+            Assert.fail("Unable to connect to server");
         }
         return zk;
     }
@@ -119,11 +120,13 @@ public class WatcherFuncTest extends ClientBase {
         lsnr_dwatch.verify(expected);
         expected.clear();
     }
+
+    @Test
     public void testExistsSync()
         throws IOException, InterruptedException, KeeperException
     {
-        assertNull(lsnr.exists("/foo", true));
-        assertNull(lsnr.exists("/foo/bar", true));
+        Assert.assertNull(lsnr.exists("/foo", true));
+        Assert.assertNull(lsnr.exists("/foo/bar", true));
 
         client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(EventType.NodeCreated);
@@ -132,25 +135,25 @@ public class WatcherFuncTest extends ClientBase {
 
         verify();
 
-        assertNotNull(lsnr.exists("/foo", true));
-        assertNotNull(lsnr.exists("/foo/bar", true));
+        Assert.assertNotNull(lsnr.exists("/foo", true));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", true));
 
         try {
-            assertNull(lsnr.exists("/car", true));
+            Assert.assertNull(lsnr.exists("/car", true));
             client.setData("/car", "missing".getBytes(), -1);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/car", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/car", e.getPath());
         }
 
         try {
-            assertNull(lsnr.exists("/foo/car", true));
+            Assert.assertNull(lsnr.exists("/foo/car", true));
             client.setData("/foo/car", "missing".getBytes(), -1);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo/car", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo/car", e.getPath());
         }
 
         client.setData("/foo", "parent".getBytes(), -1);
@@ -160,8 +163,8 @@ public class WatcherFuncTest extends ClientBase {
 
         verify();
 
-        assertNotNull(lsnr.exists("/foo", true));
-        assertNotNull(lsnr.exists("/foo/bar", true));
+        Assert.assertNotNull(lsnr.exists("/foo", true));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", true));
 
         client.delete("/foo/bar", -1);
         expected.add(EventType.NodeDeleted);
@@ -171,28 +174,29 @@ public class WatcherFuncTest extends ClientBase {
         verify();
     }
 
+    @Test
     public void testGetDataSync()
         throws IOException, InterruptedException, KeeperException
     {
         try {
             lsnr.getData("/foo", true, null);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo", e.getPath());
         }
         try {
             lsnr.getData("/foo/bar", true, null);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo/bar", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo/bar", e.getPath());
         }
 
         client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        assertNotNull(lsnr.getData("/foo", true, null));
+        Assert.assertNotNull(lsnr.getData("/foo", true, null));
         client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        assertNotNull(lsnr.getData("/foo/bar", true, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", true, null));
 
         client.setData("/foo", "parent".getBytes(), -1);
         expected.add(EventType.NodeDataChanged);
@@ -201,8 +205,8 @@ public class WatcherFuncTest extends ClientBase {
 
         verify();
 
-        assertNotNull(lsnr.getData("/foo", true, null));
-        assertNotNull(lsnr.getData("/foo/bar", true, null));
+        Assert.assertNotNull(lsnr.getData("/foo", true, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", true, null));
 
         client.delete("/foo/bar", -1);
         expected.add(EventType.NodeDeleted);
@@ -212,40 +216,41 @@ public class WatcherFuncTest extends ClientBase {
         verify();
     }
 
+    @Test
     public void testGetChildrenSync()
         throws IOException, InterruptedException, KeeperException
     {
         try {
             lsnr.getChildren("/foo", true);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo", e.getPath());
         }
         try {
             lsnr.getChildren("/foo/bar", true);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo/bar", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo/bar", e.getPath());
         }
 
         client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        assertNotNull(lsnr.getChildren("/foo", true));
+        Assert.assertNotNull(lsnr.getChildren("/foo", true));
 
         client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(EventType.NodeChildrenChanged); // /foo
-        assertNotNull(lsnr.getChildren("/foo/bar", true));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", true));
 
 
         client.setData("/foo", "parent".getBytes(), -1);
         client.setData("/foo/bar", "child".getBytes(), -1);
 
 
-        assertNotNull(lsnr.exists("/foo", true));
+        Assert.assertNotNull(lsnr.exists("/foo", true));
 
-        assertNotNull(lsnr.getChildren("/foo", true));
-        assertNotNull(lsnr.getChildren("/foo/bar", true));
+        Assert.assertNotNull(lsnr.getChildren("/foo", true));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", true));
 
         client.delete("/foo/bar", -1);
         expected.add(EventType.NodeDeleted); // /foo/bar childwatch
@@ -256,6 +261,7 @@ public class WatcherFuncTest extends ClientBase {
         verify();
     }
 
+    @Test
     public void testExistsSyncWObj()
         throws IOException, InterruptedException, KeeperException
     {
@@ -266,13 +272,13 @@ public class WatcherFuncTest extends ClientBase {
 
         List<EventType> e2 = new ArrayList<EventType>();
 
-        assertNull(lsnr.exists("/foo", true));
-        assertNull(lsnr.exists("/foo", w1));
+        Assert.assertNull(lsnr.exists("/foo", true));
+        Assert.assertNull(lsnr.exists("/foo", w1));
 
-        assertNull(lsnr.exists("/foo/bar", w2));
-        assertNull(lsnr.exists("/foo/bar", w3));
-        assertNull(lsnr.exists("/foo/bar", w3));
-        assertNull(lsnr.exists("/foo/bar", w4));
+        Assert.assertNull(lsnr.exists("/foo/bar", w2));
+        Assert.assertNull(lsnr.exists("/foo/bar", w3));
+        Assert.assertNull(lsnr.exists("/foo/bar", w3));
+        Assert.assertNull(lsnr.exists("/foo/bar", w4));
 
         client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(EventType.NodeCreated);
@@ -288,12 +294,12 @@ public class WatcherFuncTest extends ClientBase {
         e2.clear();
 
         // default not registered
-        assertNotNull(lsnr.exists("/foo", w1));
+        Assert.assertNotNull(lsnr.exists("/foo", w1));
 
-        assertNotNull(lsnr.exists("/foo/bar", w2));
-        assertNotNull(lsnr.exists("/foo/bar", w3));
-        assertNotNull(lsnr.exists("/foo/bar", w4));
-        assertNotNull(lsnr.exists("/foo/bar", w4));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", w3));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
 
         client.setData("/foo", "parent".getBytes(), -1);
         expected.add(EventType.NodeDataChanged);
@@ -308,14 +314,14 @@ public class WatcherFuncTest extends ClientBase {
         expected.clear();
         e2.clear();
 
-        assertNotNull(lsnr.exists("/foo", true));
-        assertNotNull(lsnr.exists("/foo", w1));
-        assertNotNull(lsnr.exists("/foo", w1));
+        Assert.assertNotNull(lsnr.exists("/foo", true));
+        Assert.assertNotNull(lsnr.exists("/foo", w1));
+        Assert.assertNotNull(lsnr.exists("/foo", w1));
 
-        assertNotNull(lsnr.exists("/foo/bar", w2));
-        assertNotNull(lsnr.exists("/foo/bar", w2));
-        assertNotNull(lsnr.exists("/foo/bar", w3));
-        assertNotNull(lsnr.exists("/foo/bar", w4));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", w3));
+        Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
 
         client.delete("/foo/bar", -1);
         expected.add(EventType.NodeDeleted);
@@ -332,6 +338,7 @@ public class WatcherFuncTest extends ClientBase {
 
     }
 
+    @Test
     public void testGetDataSyncWObj()
         throws IOException, InterruptedException, KeeperException
     {
@@ -344,27 +351,27 @@ public class WatcherFuncTest extends ClientBase {
 
         try {
             lsnr.getData("/foo", w1, null);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo", e.getPath());
         }
         try {
             lsnr.getData("/foo/bar", w2, null);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo/bar", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo/bar", e.getPath());
         }
 
         client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        assertNotNull(lsnr.getData("/foo", true, null));
-        assertNotNull(lsnr.getData("/foo", w1, null));
+        Assert.assertNotNull(lsnr.getData("/foo", true, null));
+        Assert.assertNotNull(lsnr.getData("/foo", w1, null));
         client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        assertNotNull(lsnr.getData("/foo/bar", w2, null));
-        assertNotNull(lsnr.getData("/foo/bar", w3, null));
-        assertNotNull(lsnr.getData("/foo/bar", w4, null));
-        assertNotNull(lsnr.getData("/foo/bar", w4, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
 
         client.setData("/foo", "parent".getBytes(), -1);
         expected.add(EventType.NodeDataChanged);
@@ -379,12 +386,12 @@ public class WatcherFuncTest extends ClientBase {
         expected.clear();
         e2.clear();
 
-        assertNotNull(lsnr.getData("/foo", true, null));
-        assertNotNull(lsnr.getData("/foo", w1, null));
-        assertNotNull(lsnr.getData("/foo/bar", w2, null));
-        assertNotNull(lsnr.getData("/foo/bar", w3, null));
-        assertNotNull(lsnr.getData("/foo/bar", w3, null));
-        assertNotNull(lsnr.getData("/foo/bar", w4, null));
+        Assert.assertNotNull(lsnr.getData("/foo", true, null));
+        Assert.assertNotNull(lsnr.getData("/foo", w1, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
+        Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
 
         client.delete("/foo/bar", -1);
         expected.add(EventType.NodeDeleted);
@@ -400,6 +407,7 @@ public class WatcherFuncTest extends ClientBase {
         e2.clear();
     }
 
+    @Test
     public void testGetChildrenSyncWObj()
         throws IOException, InterruptedException, KeeperException
     {
@@ -412,46 +420,46 @@ public class WatcherFuncTest extends ClientBase {
 
         try {
             lsnr.getChildren("/foo", true);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo", e.getPath());
         }
         try {
             lsnr.getChildren("/foo/bar", true);
-            fail();
+            Assert.fail();
         } catch (KeeperException e) {
-            assertEquals(KeeperException.Code.NONODE, e.code());
-            assertEquals("/foo/bar", e.getPath());
+            Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+            Assert.assertEquals("/foo/bar", e.getPath());
         }
 
         client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        assertNotNull(lsnr.getChildren("/foo", true));
-        assertNotNull(lsnr.getChildren("/foo", w1));
+        Assert.assertNotNull(lsnr.getChildren("/foo", true));
+        Assert.assertNotNull(lsnr.getChildren("/foo", w1));
 
         client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(EventType.NodeChildrenChanged); // /foo
-        assertNotNull(lsnr.getChildren("/foo/bar", w2));
-        assertNotNull(lsnr.getChildren("/foo/bar", w2));
-        assertNotNull(lsnr.getChildren("/foo/bar", w3));
-        assertNotNull(lsnr.getChildren("/foo/bar", w4));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", w3));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
 
 
         client.setData("/foo", "parent".getBytes(), -1);
         client.setData("/foo/bar", "child".getBytes(), -1);
 
 
-        assertNotNull(lsnr.exists("/foo", true));
-        assertNotNull(lsnr.exists("/foo", w1));
-        assertNotNull(lsnr.exists("/foo", true));
-        assertNotNull(lsnr.exists("/foo", w1));
+        Assert.assertNotNull(lsnr.exists("/foo", true));
+        Assert.assertNotNull(lsnr.exists("/foo", w1));
+        Assert.assertNotNull(lsnr.exists("/foo", true));
+        Assert.assertNotNull(lsnr.exists("/foo", w1));
 
-        assertNotNull(lsnr.getChildren("/foo", true));
-        assertNotNull(lsnr.getChildren("/foo", w1));
-        assertNotNull(lsnr.getChildren("/foo/bar", w2));
-        assertNotNull(lsnr.getChildren("/foo/bar", w3));
-        assertNotNull(lsnr.getChildren("/foo/bar", w4));
-        assertNotNull(lsnr.getChildren("/foo/bar", w4));
+        Assert.assertNotNull(lsnr.getChildren("/foo", true));
+        Assert.assertNotNull(lsnr.getChildren("/foo", w1));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", w3));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
+        Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
 
         client.delete("/foo/bar", -1);
         e2.add(EventType.NodeDeleted); // /foo/bar childwatch

+ 31 - 30
src/java/test/org/apache/zookeeper/test/WatcherTest.java

@@ -36,6 +36,7 @@ import org.apache.zookeeper.Watcher.Event;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class WatcherTest extends ClientBase {
@@ -112,13 +113,13 @@ public class WatcherTest extends ClientBase {
             for (int i = 0; i < names.length; i++) {
                 String name = names[i];
                 WatchedEvent event = watcher.events.poll(10, TimeUnit.SECONDS);
-                assertEquals(name, event.getPath());
-                assertEquals(Event.EventType.NodeDataChanged, event.getType());
-                assertEquals(Event.KeeperState.SyncConnected, event.getState());
+                Assert.assertEquals(name, event.getPath());
+                Assert.assertEquals(Event.EventType.NodeDataChanged, event.getType());
+                Assert.assertEquals(Event.KeeperState.SyncConnected, event.getState());
                 event = watcher.events.poll(10, TimeUnit.SECONDS);
-                assertEquals(name, event.getPath());
-                assertEquals(Event.EventType.NodeDeleted, event.getType());
-                assertEquals(Event.KeeperState.SyncConnected, event.getState());
+                Assert.assertEquals(name, event.getPath());
+                Assert.assertEquals(Event.EventType.NodeDeleted, event.getType());
+                Assert.assertEquals(Event.KeeperState.SyncConnected, event.getState());
             }
         } finally {
             if (zk != null) {
@@ -162,19 +163,19 @@ public class WatcherTest extends ClientBase {
        }
        startServer();
        watches[COUNT/2-1].waitForConnected(60000);
-       assertEquals(null, zk.exists("/test", false));
+       Assert.assertEquals(null, zk.exists("/test", false));
        Thread.sleep(10);
        for(int i = 0; i < COUNT/2; i++) {
-           assertEquals("For " + i, 1, watches[i].events.size());
+           Assert.assertEquals("For " + i, 1, watches[i].events.size());
        }
        for(int i = COUNT/2; i < COUNT; i++) {
            if (cbs[i].rc == 0) {
-               assertEquals("For " +i, 1, watches[i].events.size());
+               Assert.assertEquals("For " +i, 1, watches[i].events.size());
            } else {
-               assertEquals("For " +i, 0, watches[i].events.size());
+               Assert.assertEquals("For " +i, 0, watches[i].events.size());
            }
        }
-       assertEquals(COUNT, count[0]);
+       Assert.assertEquals(COUNT, count[0]);
        zk.close();
     }
     
@@ -228,7 +229,7 @@ public class WatcherTest extends ClientBase {
             zk.exists("/watchtest/child2", localWatcher);
         }
 
-        assertTrue(localWatcher.events.isEmpty());
+        Assert.assertTrue(localWatcher.events.isEmpty());
 
         stopServer();
         globalWatcher.waitForDisconnected(3000);
@@ -239,7 +240,7 @@ public class WatcherTest extends ClientBase {
             localWatcher.waitForConnected(500);
         }
 
-        assertTrue(localWatcher.events.isEmpty());
+        Assert.assertTrue(localWatcher.events.isEmpty());
         zk.setData("/watchtest/child", new byte[1], -1);
         zk.create("/watchtest/child2", new byte[0], Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
@@ -247,8 +248,8 @@ public class WatcherTest extends ClientBase {
         WatchedEvent e;
         if (!ClientCnxn.getDisableAutoResetWatch()) {
             e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
-            assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType());
-            assertEquals("/watchtest/child", e.getPath());
+            Assert.assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType());
+            Assert.assertEquals("/watchtest/child", e.getPath());
         } else {
             // we'll catch this later if it does happen after timeout, so
             // why waste the time on poll
@@ -258,8 +259,8 @@ public class WatcherTest extends ClientBase {
             e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
             // The create will trigger the get children and the exist
             // watches
-            assertEquals(EventType.NodeCreated, e.getType());
-            assertEquals("/watchtest/child2", e.getPath());
+            Assert.assertEquals(EventType.NodeCreated, e.getType());
+            Assert.assertEquals("/watchtest/child2", e.getPath());
         } else {
             // we'll catch this later if it does happen after timeout, so
             // why waste the time on poll
@@ -267,25 +268,25 @@ public class WatcherTest extends ClientBase {
 
         if (!ClientCnxn.getDisableAutoResetWatch()) {
             e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
-            assertEquals(EventType.NodeChildrenChanged, e.getType());
-            assertEquals("/watchtest", e.getPath());
+            Assert.assertEquals(EventType.NodeChildrenChanged, e.getType());
+            Assert.assertEquals("/watchtest", e.getPath());
         } else {
             // we'll catch this later if it does happen after timeout, so
             // why waste the time on poll
         }
 
-        assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals
+        Assert.assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals
         stopServer();
         globalWatcher.waitForDisconnected(TIMEOUT);
         try {
             try {
                 localWatcher.waitForDisconnected(500);
                 if (!isGlobal && !ClientCnxn.getDisableAutoResetWatch()) {
-                    fail("Got an event when I shouldn't have");
+                    Assert.fail("Got an event when I shouldn't have");
                 }
             } catch(TimeoutException toe) {
                 if (ClientCnxn.getDisableAutoResetWatch()) {
-                    fail("Didn't get an event when I should have");
+                    Assert.fail("Didn't get an event when I should have");
                 }
                 // Else what we are expecting since there are no outstanding watches
             }
@@ -311,14 +312,14 @@ public class WatcherTest extends ClientBase {
         zk.delete("/watchtest/child2", -1);
 
         e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
-        assertEquals(EventType.NodeDeleted, e.getType());
-        assertEquals("/watchtest/child2", e.getPath());
+        Assert.assertEquals(EventType.NodeDeleted, e.getType());
+        Assert.assertEquals("/watchtest/child2", e.getPath());
 
         e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
-        assertEquals(EventType.NodeChildrenChanged, e.getType());
-        assertEquals("/watchtest", e.getPath());
+        Assert.assertEquals(EventType.NodeChildrenChanged, e.getType());
+        Assert.assertEquals("/watchtest", e.getPath());
 
-        assertTrue(localWatcher.events.isEmpty());
+        Assert.assertTrue(localWatcher.events.isEmpty());
 
         stopServer();
         globalWatcher.waitForDisconnected(TIMEOUT);
@@ -334,8 +335,8 @@ public class WatcherTest extends ClientBase {
 
         if (!ClientCnxn.getDisableAutoResetWatch()) {
             e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
-            assertEquals(EventType.NodeDeleted, e.getType());
-            assertEquals("/watchtest/child", e.getPath());
+            Assert.assertEquals(EventType.NodeDeleted, e.getType());
+            Assert.assertEquals("/watchtest/child", e.getPath());
         } else {
             // we'll catch this later if it does happen after timeout, so
             // why waste the time on poll
@@ -343,7 +344,7 @@ public class WatcherTest extends ClientBase {
 
         // Make sure nothing is straggling!
         Thread.sleep(1000);
-        assertTrue(localWatcher.events.isEmpty());
+        Assert.assertTrue(localWatcher.events.isEmpty());
 
     }
 

+ 21 - 16
src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java

@@ -32,32 +32,36 @@ import org.apache.zookeeper.server.SyncRequestProcessor;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
+import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
-
+import org.junit.Test;
 
 public class ZkDatabaseCorruptionTest extends QuorumBase {
     protected static final Logger LOG = Logger.getLogger(ZkDatabaseCorruptionTest.class);
     public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT;
-    
+
     private final QuorumBase qb = new QuorumBase();
-    
+
     @Before
     @Override
-    protected void setUp() throws Exception {
-    	LOG.info("STARTING " + getClass().getName());
+    public void setUp() throws Exception {
+        LOG.info("STARTING quorum " + getClass().getName());
         qb.setUp();
     }
-        
-    protected void tearDown() throws Exception {
-    	LOG.info("STOPPING " + getClass().getName());
+
+    @After
+    @Override
+    public void tearDown() throws Exception {
+        LOG.info("STOPPING quorum " + getClass().getName());
     }
-    
+
     private void corruptFile(File f) throws IOException {
         RandomAccessFile outFile = new RandomAccessFile(f, "rw");
         outFile.write("fail servers".getBytes());
         outFile.close();
     }
-    
+
     private void corruptAllSnapshots(File snapDir) throws IOException {
         File[] listFiles = snapDir.listFiles();
         for (File f: listFiles) {
@@ -66,7 +70,8 @@ public class ZkDatabaseCorruptionTest extends QuorumBase {
             }
         }
     }
-    
+
+    @Test
     public void testCorruption() throws Exception {
         ClientBase.waitForServerUp(qb.hostPort, 10000);
         ClientBase.waitForServerUp(qb.hostPort, 10000);
@@ -97,7 +102,7 @@ public class ZkDatabaseCorruptionTest extends QuorumBase {
         qb.s4.start();
         try {
             qb.s5.start();
-            assertTrue(false);
+            Assert.assertTrue(false);
         } catch(RuntimeException re) {
             LOG.info("Got an error: expected", re);
         }
@@ -105,12 +110,12 @@ public class ZkDatabaseCorruptionTest extends QuorumBase {
         String[] list = qb.hostPort.split(",");
         for (int i =0; i < 4; i++) {
             String hp = list[i];
-          assertTrue("waiting for server up",
+          Assert.assertTrue("waiting for server up",
                        ClientBase.waitForServerUp(hp,
                                     CONNECTION_TIMEOUT));
             LOG.info(hp + " is accepting client connections");
         }
-        
+
         zk = qb.createClient();
         SyncRequestProcessor.setSnapCount(100);
         for (int i = 2000; i < 4000; i++) {
@@ -121,7 +126,7 @@ public class ZkDatabaseCorruptionTest extends QuorumBase {
         QuorumBase.shutdown(qb.s2);
         QuorumBase.shutdown(qb.s3);
         QuorumBase.shutdown(qb.s4);
-    } 
+    }
+
 
-    
 }

+ 7 - 21
src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java

@@ -29,28 +29,14 @@ import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeperMain;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
+import org.junit.Test;
 
-/**
- * this class tests quota on a single
- * zookeeper server.
- *
- */
 public class ZooKeeperQuotaTest extends ClientBase {
     private static final Logger LOG = Logger.getLogger(
             ZooKeeperQuotaTest.class);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        LOG.info("STARTING " + getClass().getName());
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        LOG.info("STOPPING " + getClass().getName());
-    }
-
+    @Test
     public void testQuota() throws IOException,
         InterruptedException, KeeperException {
         final ZooKeeper zk = createClient();
@@ -73,13 +59,13 @@ public class ZooKeeperQuotaTest extends ClientBase {
         String absolutePath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode;
         byte[] data = zk.getData(absolutePath, false, new Stat());
         StatsTrack st = new StatsTrack(new String(data));
-        assertTrue("bytes are set", st.getBytes() == 1000L);
-        assertTrue("num count is set", st.getCount() == 1000);
+        Assert.assertTrue("bytes are set", st.getBytes() == 1000L);
+        Assert.assertTrue("num count is set", st.getCount() == 1000);
 
         String statPath = Quotas.quotaZookeeper + path + "/" + Quotas.statNode;
         byte[] qdata = zk.getData(statPath, false, new Stat());
         StatsTrack qst = new StatsTrack(new String(qdata));
-        assertTrue("bytes are set", qst.getBytes() == 8L);
-        assertTrue("cound is set", qst.getCount() == 2);
+        Assert.assertTrue("bytes are set", qst.getBytes() == 8L);
+        Assert.assertTrue("cound is set", qst.getCount() == 2);
     }
 }

+ 38 - 38
src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java

@@ -23,19 +23,19 @@ import java.util.List;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
-import junit.framework.TestCase;
-
 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.KeeperException.Code;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
 
-public class ZooKeeperTestClient extends TestCase implements Watcher {
+public class ZooKeeperTestClient extends ZKTestCase implements Watcher {
   protected String hostPort = "127.0.0.1:22801";
 
   protected static final String dirOnZK = "/test_dir";
@@ -70,11 +70,11 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     List<String> c2 = zk.getChildren(nodeName, false, stat);
 
     if (!children1.equals(c2)) {
-        fail("children lists from getChildren()/getChildren2() do not match");
+        Assert.fail("children lists from getChildren()/getChildren2() do not match");
     }
 
     if (!stat.equals(stat)) {
-        fail("stats from exists()/getChildren2() do not match");
+        Assert.fail("stats from exists()/getChildren2() do not match");
     }
 
     if (children1.size() == 0) {
@@ -95,7 +95,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     } catch (KeeperException.NodeExistsException ke) {
         // expected, sort of
     } catch (KeeperException ke) {
-        fail("Unexpected exception code for create " + dirOnZK + ": "
+        Assert.fail("Unexpected exception code for create " + dirOnZK + ": "
             + ke.getMessage());
     }
 
@@ -104,7 +104,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     } catch (KeeperException.NodeExistsException ke) {
         // expected, sort of
     } catch (KeeperException ke) {
-        fail("Unexpected exception code for create " + testDirOnZK + ": "
+        Assert.fail("Unexpected exception code for create " + testDirOnZK + ": "
             + ke.getMessage());
     }
 
@@ -123,7 +123,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       try {
         zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
       } catch (KeeperException ke) {
-        fail("Creating node " + parentName + ke.getMessage());
+        Assert.fail("Creating node " + parentName + ke.getMessage());
       }
     }
 
@@ -133,13 +133,13 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       Code code = ke.code();
       boolean valid = code == KeeperException.Code.NODEEXISTS;
       if (!valid) {
-        fail("Unexpected exception code for createin: " + ke.getMessage());
+        Assert.fail("Unexpected exception code for createin: " + ke.getMessage());
       }
     }
 
     stat = zk.exists(nodeName, false);
     if (stat == null) {
-      fail("node " + nodeName + " should exist");
+      Assert.fail("node " + nodeName + " should exist");
     }
     System.out.println("Closing client with sessionid: 0x"
             + Long.toHexString(zk.getSessionId()));
@@ -177,7 +177,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       try {
         zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
       } catch (KeeperException ke) {
-        fail("Creating node " + parentName + ke.getMessage());
+        Assert.fail("Creating node " + parentName + ke.getMessage());
       }
     }
 
@@ -191,7 +191,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
         boolean valid = code == KeeperException.Code.NONODE
             || code == KeeperException.Code.NOTEMPTY;
         if (!valid) {
-          fail("Unexpected exception code for delete: " + ke.getMessage());
+          Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
         }
       }
     }
@@ -201,11 +201,11 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     List<String> firstGen2 = zk_1.getChildren(parentName, true, stat);
 
     if (!firstGen1.equals(firstGen2)) {
-        fail("children lists from getChildren()/getChildren2() do not match");
+        Assert.fail("children lists from getChildren()/getChildren2() do not match");
     }
 
     if (!stat_parent.equals(stat)) {
-        fail("stat from exists()/getChildren() do not match");
+        Assert.fail("stat from exists()/getChildren() do not match");
     }
 
     try {
@@ -214,7 +214,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       Code code = ke.code();
       boolean valid = code == KeeperException.Code.NODEEXISTS;
       if (!valid) {
-        fail("Unexpected exception code for createin: " + ke.getMessage());
+        Assert.fail("Unexpected exception code for createin: " + ke.getMessage());
       }
     }
 
@@ -225,33 +225,33 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     }
     if (event.getType() != EventType.NodeChildrenChanged
         || !event.getPath().equalsIgnoreCase(parentName)) {
-      fail("Unexpected event was delivered: " + event.toString());
+      Assert.fail("Unexpected event was delivered: " + event.toString());
     }
 
     stat_node = zk_1.exists(nodeName, false);
     if (stat_node == null) {
-      fail("node " + nodeName + " should exist");
+      Assert.fail("node " + nodeName + " should exist");
     }
 
     try {
       zk.delete(parentName, -1);
-      fail("Should be impossible to delete a non-empty node " + parentName);
+      Assert.fail("Should be impossible to delete a non-empty node " + parentName);
     } catch (KeeperException ke) {
       Code code = ke.code();
       boolean valid = code == KeeperException.Code.NOTEMPTY;
       if (!valid) {
-        fail("Unexpected exception code for delete: " + code);
+        Assert.fail("Unexpected exception code for delete: " + code);
       }
     }
 
     try {
       zk.create(nodeName + "/def", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
-      fail("Should be impossible to create child off Ephemeral node " + nodeName);
+      Assert.fail("Should be impossible to create child off Ephemeral node " + nodeName);
     } catch (KeeperException ke) {
       Code code = ke.code();
       boolean valid = code == KeeperException.Code.NOCHILDRENFOREPHEMERALS;
       if (!valid) {
-        fail("Unexpected exception code for createin: " + code);
+        Assert.fail("Unexpected exception code for createin: " + code);
       }
     }
 
@@ -260,29 +260,29 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       List<String> children2 = zk.getChildren(nodeName, false, null);
 
       if (!children1.equals(children2)) {
-          fail("children lists from getChildren()/getChildren2() does not match");
+          Assert.fail("children lists from getChildren()/getChildren2() does not match");
       }
 
       if (children1.size() > 0) {
-        fail("ephemeral node " + nodeName + " should not have children");
+        Assert.fail("ephemeral node " + nodeName + " should not have children");
       }
     } catch (KeeperException ke) {
       Code code = ke.code();
       boolean valid = code == KeeperException.Code.NONODE;
       if (!valid) {
-        fail("Unexpected exception code for createin: " + code);
+        Assert.fail("Unexpected exception code for createin: " + code);
       }
     }
     firstGen1 = zk_1.getChildren(parentName, true);
     firstGen2 = zk_1.getChildren(parentName, true, null);
 
     if (!firstGen1.equals(firstGen2)) {
-        fail("children list from getChildren()/getChildren2() does not match");
+        Assert.fail("children list from getChildren()/getChildren2() does not match");
     }
 
     stat_node = zk_1.exists(nodeName, true);
     if (stat_node == null) {
-      fail("node " + nodeName + " should exist");
+      Assert.fail("node " + nodeName + " should exist");
     }
     System.out.println("session id of zk: " + zk.getSessionId());
     System.out.println("session id of zk_1: " + zk_1.getSessionId());
@@ -300,7 +300,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
            event.getPath().equalsIgnoreCase(nodeName)))) {
       System.out.print(parentName + " "
           + EventType.NodeChildrenChanged + " " + nodeName + " " + EventType.NodeDeleted);
-      fail("Unexpected first event was delivered: " + event.toString());
+      Assert.fail("Unexpected first event was delivered: " + event.toString());
     }
 
     event = this.getEvent(10);
@@ -314,16 +314,16 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
         event.getPath().equalsIgnoreCase(nodeName)))) {
       System.out.print(parentName + " "
           + EventType.NodeChildrenChanged + " " + nodeName + " " + EventType.NodeDeleted);
-      fail("Unexpected second event was delivered: " + event.toString());
+      Assert.fail("Unexpected second event was delivered: " + event.toString());
     }
 
     firstGen1 = zk_1.getChildren(parentName, false);
     stat_node = zk_1.exists(nodeName, false);
     if (stat_node != null) {
-      fail("node " + nodeName + " should have been deleted");
+      Assert.fail("node " + nodeName + " should have been deleted");
     }
     if (firstGen1.contains(nodeName)) {
-      fail("node " + nodeName + " should not be a children");
+      Assert.fail("node " + nodeName + " should not be a children");
     }
     deleteZKDir(zk_1, nodeName);
     zk_1.close();
@@ -342,7 +342,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       boolean valid = code == KeeperException.Code.NONODE
           || code == KeeperException.Code.NOTEMPTY;
       if (!valid) {
-        fail("Unexpected exception code for delete: " + ke.getMessage());
+        Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
       }
     }
     try {
@@ -351,15 +351,15 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       Code code = ke.code();
       boolean valid = code == KeeperException.Code.NODEEXISTS;
       if (!valid) {
-        fail("Unexpected exception code for create: " + ke.getMessage());
+        Assert.fail("Unexpected exception code for create: " + ke.getMessage());
       }
     }
     try {
       zk.setData(nodeName, "hi".getBytes(), 5700);
-      fail("Should have gotten BadVersion exception");
+      Assert.fail("Should have gotten BadVersion exception");
     } catch (KeeperException ke) {
       if (ke.code() != Code.BADVERSION) {
-        fail("Should have gotten BadVersion exception");
+        Assert.fail("Should have gotten BadVersion exception");
       }
     }
     zk.setData(nodeName, "hi".getBytes(), -1);
@@ -367,18 +367,18 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     byte[] bytes = zk.getData(nodeName, false, st);
     String retrieved = new String(bytes);
     if (!"hi".equals(retrieved)) {
-      fail("The retrieved data [" + retrieved
+      Assert.fail("The retrieved data [" + retrieved
           + "] is differented than the expected [hi]");
     }
     try {
       zk.delete(nodeName, 6800);
-      fail("Should have gotten BadVersion exception");
+      Assert.fail("Should have gotten BadVersion exception");
     } catch (KeeperException ke) {
       Code code = ke.code();
       boolean valid = code == KeeperException.Code.NOTEMPTY
           || code == KeeperException.Code.BADVERSION;
       if (!valid) {
-        fail("Unexpected exception code for delete: " + ke.getMessage());
+        Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
       }
     }
     try {
@@ -387,7 +387,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       Code code = ke.code();
       boolean valid = code == KeeperException.Code.NOTEMPTY;
       if (!valid) {
-        fail("Unexpected exception code for delete: " + code);
+        Assert.fail("Unexpected exception code for delete: " + code);
       }
     }
     deleteZKDir(zk, nodeName);