zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r929377 [2/4] - in /hadoop/zookeeper/trunk: ./ src/java/test/org/apache/zookeeper/server/ src/java/test/org/apache/zookeeper/server/quorum/ src/java/test/org/apache/zookeeper/test/
Date Wed, 31 Mar 2010 04:26:30 GMT
Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java Wed Mar 31 04:26:29 2010
@@ -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.UnixOperatingS
 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 ClientBa
             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 ClientBa
                 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 ClientBa
             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 ClientBa
             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 ClientBa
             //   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 ClientBa
             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 ClientBa
             //  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 ClientBa
             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 ClientBa
             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 ClientBa
             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 ClientBa
 
             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 ClientBa
                     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 ClientBa
             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 ClientBa
             }
             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 ClientBa
                 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 ClientBa
             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 ClientBa
             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 ClientBa
                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 ClientBa
             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 ClientBa
                     + "/" + 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 ClientBa
             // 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 ClientBa
         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 ClientBa
         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 ClientBa
         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 ClientBa
         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 ClientBa
                     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 ClientBa
 
         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);
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java Wed Mar 31 04:26:29 2010
@@ -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 Test
             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 Test
                 } 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 Test
                 }
             } 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 Test
         } 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");
         }
     }
-    
-    
-    
+
+
+
 }
\ No newline at end of file

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java Wed Mar 31 04:26:29 2010
@@ -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 Test
         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 Test
     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());
         }
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/DataTreeTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/DataTreeTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/DataTreeTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/DataTreeTest.java Wed Mar 31 04:26:29 2010
@@ -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 TestCa
         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);
     }
 
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java Wed Mar 31 04:26:29 2010
@@ -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

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/EventTypeTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/EventTypeTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/EventTypeTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/EventTypeTest.java Wed Mar 31 04:26:29 2010
@@ -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 TestC
         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 TestC
     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.
         }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java Wed Mar 31 04:26:29 2010
@@ -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 
     
     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 
                 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 
 
                 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 
     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 
         mockServer();
         thread.join(5000);
         if (thread.isAlive()) {
-            fail("Threads didn't join");
+            Assert.fail("Threads didn't join");
         }
     }
         

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java Wed Mar 31 04:26:29 2010
@@ -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 Tes
     Semaphore start0;
     Semaphore finish3, finish0;
 
-    @Override
+    @Before
     public void setUp() throws Exception {
         count = 3;
 
@@ -65,16 +67,13 @@ public class FLENewEpochTest extends Tes
         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 Tes
                     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 Tes
 
           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 Tes
               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 Tes
           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");
               }
 
           }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java Wed Mar 31 04:26:29 2010
@@ -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 Test
     //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 Test
         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 Test
         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 Test
             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");
             }
 
         }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java Wed Mar 31 04:26:29 2010
@@ -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);
        }
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java Wed Mar 31 04:26:29 2010
@@ -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 T
 
 
     @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 T
         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 T
             // 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 T
 
                     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 T
     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 T
             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");
             }
         }
     }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java Wed Mar 31 04:26:29 2010
@@ -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 e
             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));
             }
         }
     }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java Wed Mar 31 04:26:29 2010
@@ -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
         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));
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GetChildren2Test.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GetChildren2Test.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GetChildren2Test.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GetChildren2Test.java Wed Mar 31 04:26:29 2010
@@ -28,26 +28,26 @@ import org.apache.zookeeper.KeeperExcept
 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 Cl
         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 Cl
             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);
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java Wed Mar 31 04:26:29 2010
@@ -32,18 +32,9 @@ import org.apache.zookeeper.TestableZooK
 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 exte
     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 exte
         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 exte
         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 exte
         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 exte
 
         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 exte
         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 exte
         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) {

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java Wed Mar 31 04:26:29 2010
@@ -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
             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
                 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));
 

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/KeeperStateTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/KeeperStateTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/KeeperStateTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/KeeperStateTest.java Wed Mar 31 04:26:29 2010
@@ -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 Tes
         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 Tes
     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 Tes
         int test = 1;
         switch (test) {
         case Code.Ok:
-            assertTrue(true);
+            Assert.assertTrue(true);
             break;
         }
     }
@@ -69,7 +69,7 @@ public class KeeperStateTest extends Tes
         Code test = Code.OK;
         switch (test) {
         case OK:
-            assertTrue(true);
+            Assert.assertTrue(true);
             break;
         }
     }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java Wed Mar 31 04:26:29 2010
@@ -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.quoru
 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 
                  */
                 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 
     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 
                 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 
      */
     @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 
                     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 
         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];

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LETest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LETest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LETest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LETest.java Wed Mar 31 04:26:29 2010
@@ -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);
                 }
             }
         }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java Wed Mar 31 04:26:29 2010
@@ -27,18 +27,21 @@ import java.util.concurrent.atomic.Atomi
 
 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 Client
             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 Client
                 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());
     }
 }



Mime
View raw message