hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r686389 [2/2] - in /hadoop/zookeeper/trunk/src/java: ./ jmx/org/apache/zookeeper/jmx/server/ main/org/apache/zookeeper/ main/org/apache/zookeeper/server/ main/org/apache/zookeeper/server/quorum/ test/org/apache/zookeeper/server/ test/org/ap...
Date Fri, 15 Aug 2008 22:02:29 GMT
Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java?rev=686389&r1=686388&r2=686389&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java Fri Aug 15
15:02:28 2008
@@ -18,15 +18,17 @@
 
 package org.apache.zookeeper.test;
 
+import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 
 import junit.framework.TestCase;
 
+import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -42,9 +44,7 @@
         // This test takes too long to run!
         if (true)
             return;
-        File tmpDir = File.createTempFile("test", ".junit");
-        tmpDir = new File(tmpDir + ".dir");
-        tmpDir.mkdirs();
+        File tmpDir = ClientBase.createTmpDir();
         // Grab some memory so that it is easier to cause an
         // OOM condition;
         ArrayList<byte[]> hog = new ArrayList<byte[]>();
@@ -56,10 +56,16 @@
                 break;
             }
         }
+        ClientBase.setupTestEnv();
         ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
-        NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(33221);
+        
+        final int PORT = 33221;
+        NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(PORT);
         f.startup(zks);
-        Thread.sleep(2000);
+        assertTrue("waiting for server up",
+                   ClientBase.waitForServerUp("127.0.0.1:" + PORT,
+                                              CONNECTION_TIMEOUT));
+
         System.err.println("OOM Stage 0");
         utestPrep();
         System.out.println("Free = " + Runtime.getRuntime().freeMemory()
@@ -90,7 +96,11 @@
                 + " total = " + Runtime.getRuntime().totalMemory() + " max = "
                 + Runtime.getRuntime().maxMemory());
         hog.get(0)[0] = (byte) 1;
+
         f.shutdown();
+        assertTrue("waiting for server down",
+                   ClientBase.waitForServerDown("127.0.0.1:" + PORT,
+                                                CONNECTION_TIMEOUT));
     }
 
     private void utestExists() throws IOException, InterruptedException, KeeperException
{

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java?rev=686389&r1=686388&r2=686389&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java Fri Aug
15 15:02:28 2008
@@ -24,38 +24,35 @@
 import java.util.ArrayList;
 
 import org.apache.log4j.Logger;
-import org.junit.After;
-import org.junit.Before;
-
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumStats;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
+import org.junit.After;
+import org.junit.Before;
 
 public class QuorumTest extends ClientTest {
     private static final Logger LOG = Logger.getLogger(QuorumTest.class);
 
-    static File baseTest = new File(System.getProperty("build.test.dir", "build"));
     File s1dir, s2dir, s3dir, s4dir, s5dir;
     QuorumPeer s1, s2, s3, s4, s5;
     @Before
+    @Override
     protected void setUp() throws Exception {
-        s1dir = File.createTempFile("test", ".junit", baseTest);
-        s1dir = new File(s1dir + ".dir");
-        s1dir.mkdirs();
-        s2dir = File.createTempFile("test", ".junit", baseTest);
-        s2dir = new File(s2dir + ".dir");
-        s2dir.mkdirs();
-        s3dir = File.createTempFile("test", ".junit", baseTest);
-        s3dir = new File(s3dir + ".dir");
-        s3dir.mkdirs();
-        s4dir = File.createTempFile("test", ".junit", baseTest);
-        s4dir = new File(s4dir + ".dir");
-        s4dir.mkdirs();
-        s5dir = File.createTempFile("test", ".junit", baseTest);
-        s5dir = new File(s5dir + ".dir");
-        s5dir.mkdirs();
+        LOG.info("STARTING " + getName());
+
+        setupTestEnv();
+
+        hostPort = "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184,127.0.0.1:2185";
+
+        s1dir = ClientBase.createTmpDir();
+        s2dir = ClientBase.createTmpDir();
+        s3dir = ClientBase.createTmpDir();
+        s4dir = ClientBase.createTmpDir();
+        s5dir = ClientBase.createTmpDir();
+        
         startServers();
-        LOG.warn("Setup finished");
+        
+        LOG.info("Setup finished");
     }
     void startServers() throws IOException, InterruptedException {
         QuorumStats.registerAsConcrete();
@@ -63,44 +60,70 @@
         int initLimit = 3;
         int syncLimit = 3;
         ArrayList<QuorumServer> peers = new ArrayList<QuorumServer>();
-        hostPort = "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184,127.0.0.1:2185";
         peers.add(new QuorumServer(1, new InetSocketAddress("127.0.0.1", 3181)));
         peers.add(new QuorumServer(2, new InetSocketAddress("127.0.0.1", 3182)));
         peers.add(new QuorumServer(3, new InetSocketAddress("127.0.0.1", 3183)));
         peers.add(new QuorumServer(4, new InetSocketAddress("127.0.0.1", 3184)));
         peers.add(new QuorumServer(5, new InetSocketAddress("127.0.0.1", 3185)));
-        LOG.warn("creating QuorumPeer 1");
+        LOG.info("creating QuorumPeer 1");
         s1 = new QuorumPeer(peers, s1dir, s1dir, 2181, 0,  1181, 1, tickTime, initLimit,
syncLimit);
-        LOG.warn("creating QuorumPeer 2");
+        LOG.info("creating QuorumPeer 2");
         s2 = new QuorumPeer(peers, s2dir, s2dir, 2182, 0, 1182, 2, tickTime, initLimit, syncLimit);
-        LOG.warn("creating QuorumPeer 3");
+        LOG.info("creating QuorumPeer 3");
         s3 = new QuorumPeer(peers, s3dir, s3dir, 2183, 0, 1183, 3, tickTime, initLimit, syncLimit);
-        LOG.warn("creating QuorumPeer 4");
+        LOG.info("creating QuorumPeer 4");
         s4 = new QuorumPeer(peers, s4dir, s4dir, 2184, 0, 1184, 4, tickTime, initLimit, syncLimit);
-        LOG.warn("creating QuorumPeer 5");
+        LOG.info("creating QuorumPeer 5");
         s5 = new QuorumPeer(peers, s5dir, s5dir, 2185, 0, 1185, 5, tickTime, initLimit, syncLimit);
-        LOG.warn("start QuorumPeer 1");
+        LOG.info("start QuorumPeer 1");
         s1.start();
-        LOG.warn("start QuorumPeer 2");
+        LOG.info("start QuorumPeer 2");
         s2.start();
-        LOG.warn("start QuorumPeer 3");
+        LOG.info("start QuorumPeer 3");
         s3.start();
-        LOG.warn("start QuorumPeer 4");
+        LOG.info("start QuorumPeer 4");
         s4.start();
-        LOG.warn("start QuorumPeer 5");
+        LOG.info("start QuorumPeer 5");
         s5.start();
-        LOG.warn("started QuorumPeer 5");
-        Thread.sleep(5000);
+        LOG.info("started QuorumPeer 5");
+
+        for (String hp : hostPort.split(",")) {
+            assertTrue("waiting for server up",
+                       ClientBase.waitForServerUp(hp,
+                                    CONNECTION_TIMEOUT));
+            LOG.info(hp + " is accepting client connections");
+        }
     }
     @After
+    @Override
     protected void tearDown() throws Exception {
-        LOG.warn("TearDown started");
-        s1.shutdown();
-        s2.shutdown();
-        s3.shutdown();
-        s4.shutdown();
-        s5.shutdown();
-        Thread.sleep(5000);
+        LOG.info("TearDown started");
+        shutdown(s1);
+        shutdown(s2);
+        shutdown(s3);
+        shutdown(s4);
+        shutdown(s5);
+
+        for (String hp : hostPort.split(",")) {
+            assertTrue("waiting for server down",
+                       ClientBase.waitForServerDown(hp,
+                                           ClientBase.CONNECTION_TIMEOUT));
+            LOG.info(hp + " is no longer accepting client connections");
+        }
+
         QuorumStats.unregister();
+        LOG.info("FINISHED " + getName());
+    }
+
+    private void shutdown(QuorumPeer qp) {
+        try {
+            qp.shutdown();
+            qp.join(30000);
+            if (qp.isAlive()) {
+                fail("QP failed to shutdown in 30 seconds");
+            }
+        } catch (InterruptedException e) {
+            LOG.debug("QP interrupted", e);
+        }
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java?rev=686389&r1=686388&r2=686389&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java Fri Aug
15 15:02:28 2008
@@ -18,57 +18,87 @@
 
 package org.apache.zookeeper.test;
 
+import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
+
 import java.io.File;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import junit.framework.TestCase;
 
-import org.junit.Test;
-
+import org.apache.log4j.Logger;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
+import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.ServerStats;
 import org.apache.zookeeper.server.SyncRequestProcessor;
-import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.Test;
 
 /**
  * @author breed
  *
  */
 public class RecoveryTest extends TestCase implements Watcher {
-    static File baseTest = new File(System.getProperty("build.test.dir",
-            "build"));
+    protected static final Logger LOG = Logger.getLogger(RecoveryTest.class);
+
+    private static String HOSTPORT = "127.0.0.1:2344";
+
+    private CountDownLatch startSignal;
+
+    @Override
     protected void setUp() throws Exception {
+        LOG.info("STARTING " + getName());
         ServerStats.registerAsConcrete();
     }
+    @Override
     protected void tearDown() throws Exception {
         ServerStats.unregister();
+        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
+     * server to restart within the connection timeout period.
+     *
+     * Also note that the client latches are used to eliminate any chance
+     * of spurrious connectionloss exceptions on the read ops. Specifically
+     * a sync operation will throw this exception if the server goes down
+     * (as recognized by the client) during the operation. If the operation
+     * occurs after the server is down, but before the client recognizes
+     * that the server is down (ping) then the op will throw connectionloss.
+     */
     public void testRecovery() throws Exception {
-        File tmpDir = File.createTempFile("test", ".junit", baseTest);
-        tmpDir = new File(tmpDir + ".dir");
-        tmpDir.mkdirs();
+        File tmpDir = ClientBase.createTmpDir();
+
+        ClientBase.setupTestEnv();
         ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
+
         int oldSnapCount = SyncRequestProcessor.snapCount;
         SyncRequestProcessor.snapCount = 1000;
         try {
-            NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(2344);
+            final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
+            NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(PORT);
             f.startup(zs);
-            System.out.println("starting up the the server -- sleeping");
-            Thread.sleep(1000);
-            ZooKeeper zk = new ZooKeeper("127.0.0.1:2344", 20000, this);
+            LOG.info("starting up the the server, waiting");
+
+            assertTrue("waiting for server up",
+                       ClientBase.waitForServerUp(HOSTPORT,
+                                       CONNECTION_TIMEOUT));
+
+            ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
             String path;
-            System.out.println("starting creating nodes");
+            LOG.info("starting creating nodes");
             for (int i = 0; i < 10; i++) {
                 path = "/" + i;
-                zk
-                        .create(path, (path + "!").getBytes(),
-                                Ids.OPEN_ACL_UNSAFE, 0);
+                zk.create(path,
+                          (path + "!").getBytes(),
+                          Ids.OPEN_ACL_UNSAFE, 0);
                 for (int j = 0; j < 10; j++) {
                     String subpath = path + "/" + j;
                     zk.create(subpath, (subpath + "!").getBytes(),
@@ -80,16 +110,32 @@
                     }
                 }
             }
+
             f.shutdown();
-            Thread.sleep(1000);
+
+            assertTrue("waiting for server down",
+                       ClientBase.waitForServerDown(HOSTPORT,
+                                          CONNECTION_TIMEOUT));
+
             zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
-            f = new NIOServerCnxn.Factory(2344);
+            f = new NIOServerCnxn.Factory(PORT);
+
+            startSignal = new CountDownLatch(1);
+
             f.startup(zs);
-            Thread.sleep(1000);
+
+            assertTrue("waiting for server up",
+                       ClientBase.waitForServerUp(HOSTPORT,
+                                           CONNECTION_TIMEOUT));
+
+            startSignal.await(CONNECTION_TIMEOUT,
+                    TimeUnit.MILLISECONDS);
+            assertTrue("count == 0", startSignal.getCount() == 0);
+
             Stat stat = new Stat();
             for (int i = 0; i < 10; i++) {
                 path = "/" + i;
-                System.out.println("Checking " + path);
+                LOG.info("Checking " + path);
                 assertEquals(new String(zk.getData(path, false, stat)), path
                         + "!");
                 for (int j = 0; j < 10; j++) {
@@ -104,17 +150,31 @@
                 }
             }
             f.shutdown();
-            Thread.sleep(2000);
+
+            assertTrue("waiting for server down",
+                       ClientBase.waitForServerDown(HOSTPORT,
+                                          ClientBase.CONNECTION_TIMEOUT));
+
             zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
-            f = new NIOServerCnxn.Factory(2344);
+            f = new NIOServerCnxn.Factory(PORT);
+
+            startSignal = new CountDownLatch(1);
+
             f.startup(zs);
-            Thread.sleep(4000);
+
+            assertTrue("waiting for server up",
+                       ClientBase.waitForServerUp(HOSTPORT,
+                               CONNECTION_TIMEOUT));
+
+            startSignal.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
+            assertTrue("count == 0", startSignal.getCount() == 0);
+
             stat = new Stat();
-            System.out.println("Check 2");
+            LOG.info("Check 2");
             for (int i = 0; i < 10; i++) {
                 path = "/" + i;
-                assertEquals(new String(zk.getData(path, false, stat)), path
-                        + "!");
+                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)),
@@ -127,6 +187,10 @@
                 }
             }
             f.shutdown();
+
+            assertTrue("waiting for server down",
+                       ClientBase.waitForServerDown(HOSTPORT,
+                                                    CONNECTION_TIMEOUT));
         } finally {
             SyncRequestProcessor.snapCount = oldSnapCount;
         }
@@ -138,7 +202,11 @@
      * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.proto.WatcherEvent)
      */
     public void process(WatcherEvent event) {
-        // TODO Auto-generated method stub
-
+        LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath());
+        if (event.getState() == Watcher.Event.KeeperStateSyncConnected
+                && startSignal != null && startSignal.getCount() > 0)
+        {
+            startSignal.countDown();
+        }
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java?rev=686389&r1=686388&r2=686389&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java Fri Aug
15 15:02:28 2008
@@ -18,9 +18,15 @@
 
 package org.apache.zookeeper.test;
 
+import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
+
 import java.io.File;
 import java.io.IOException;
-import org.junit.Test;
+import java.util.concurrent.CountDownLatch;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
@@ -31,88 +37,136 @@
 import org.apache.zookeeper.server.NIOServerCnxn;
 import org.apache.zookeeper.server.ServerStats;
 import org.apache.zookeeper.server.ZooKeeperServer;
-import junit.framework.TestCase;
+import org.junit.Test;
 
 public class SessionTest extends TestCase implements Watcher {
-    static File baseTest = new File(System.getProperty("build.test.dir",
-            "build"));
+    protected static final Logger LOG = Logger.getLogger(SessionTest.class);
+
+    private static final String HOSTPORT = "127.0.0.1:33299";
 
+    private CountDownLatch startSignal;
+
+    private NIOServerCnxn.Factory serverFactory;
+
+    @Override
     protected void setUp() throws Exception {
+        LOG.info("STARTING " + getName());
+
         ServerStats.registerAsConcrete();
+
+        File tmpDir = ClientBase.createTmpDir();
+
+        ClientBase.setupTestEnv();
+        ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
+        
+        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
+        serverFactory = new NIOServerCnxn.Factory(PORT);
+        serverFactory.startup(zs);
+
+        assertTrue("waiting for server up",
+                   ClientBase.waitForServerUp(HOSTPORT,
+                                              CONNECTION_TIMEOUT));
     }
+    @Override
     protected void tearDown() throws Exception {
+        serverFactory.shutdown();
+        assertTrue("waiting for server down",
+                   ClientBase.waitForServerDown(HOSTPORT,
+                                                CONNECTION_TIMEOUT));
+
         ServerStats.unregister();
+        LOG.info("FINISHED " + getName());
     }
-    /**
-     * this test checks to see if the sessionid that was created for the
-     * first zookeeper client can be reused for the second one immidiately
-     * after the first client closes and the new client resues them.
-     * @throws IOException
-     * @throws InterruptedException
-     * @throws KeeperException
-     */
-    public void testSessionReuse() throws IOException, InterruptedException {
-        File tmpDir = File.createTempFile("test", ".junit", baseTest);
-        tmpDir = new File(tmpDir + ".dir");
-        tmpDir.mkdirs();
-        ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
-        NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(33299);
-        f.startup(zs);
-        Thread.sleep(4000);
-        ZooKeeper zk = new ZooKeeper("127.0.0.1:33299", 3000, this);
 
-        long sessionId = zk.getSessionId();
-        byte[] passwd = zk.getSessionPasswd();
-        zk.close();
-        zk = new ZooKeeper("127.0.0.1:33299", 3000, this, sessionId, passwd);
-        assertEquals(sessionId, zk.getSessionId());
-        zk.close();
-        zs.shutdown();
-        f.shutdown();
+    private ZooKeeper createClient()
+        throws IOException, InterruptedException
+    {
+        startSignal = new CountDownLatch(1);
+        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        startSignal.await();
 
+        return zk;
     }
+
+// FIXME this test is 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
+//     * after the first client closes and the new client resues them.
+//     * @throws IOException
+//     * @throws InterruptedException
+//     * @throws KeeperException
+//     */
+//    public void testSessionReuse() throws IOException, InterruptedException {
+//        ZooKeeper zk = createClient();
+//
+//        long sessionId = zk.getSessionId();
+//        byte[] passwd = zk.getSessionPasswd();
+//        zk.close();
+//
+//        zk.close();
+//
+//        LOG.info("Closed first session");
+//
+//        startSignal = new CountDownLatch(1);
+//        zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this,
+//                sessionId, passwd);
+//        startSignal.await();
+//
+//        LOG.info("Opened reuse");
+//
+//        assertEquals(sessionId, zk.getSessionId());
+//
+//        zk.close();
+//    }
+
     @Test
-    public void testSession() throws IOException, InterruptedException, KeeperException {
-        File tmpDir = File.createTempFile("test", ".junit", baseTest);
-        tmpDir = new File(tmpDir + ".dir");
-        tmpDir.mkdirs();
-        ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, 3000);
-        NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(33299);
-        f.startup(zs);
-        Thread.sleep(2000);
-        ZooKeeper zk = new ZooKeeper("127.0.0.1:33299", 30000, this);
+    /**
+     * 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.
+     */
+    public void testSession()
+        throws IOException, InterruptedException, KeeperException
+    {
+        ZooKeeper zk = createClient();
         zk.create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE,
                         CreateFlags.EPHEMERAL);
-        System.out.println("zk with session id " + zk.getSessionId()
+        LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
                 + " was destroyed!");
-        // zk.close();
+
+        // disconnect the client by killing the socket, not sending the
+        // session disconnect to the server as usual. This allows the test
+        // to verify disconnect handling
+        zk.disconnect();
+
         Stat stat = new Stat();
-        try {
-            zk = new ZooKeeper("127.0.0.1:33299", 30000, this, zk
-                    .getSessionId(), zk.getSessionPasswd());
-            System.out.println("zk with session id " + zk.getSessionId()
-                    + " was created!");
-            zk.getData("/e", false, stat);
-            System.out.println("After get data /e");
-        } catch (KeeperException e) {
-            // the zk.close() above if uncommented will close the session on the
-            // server
-            // in such case we get an exception here because we've tried joining
-            // a closed session
-        }
+        startSignal = new CountDownLatch(1);
+        zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this,
+                           zk.getSessionId(),
+                           zk.getSessionPasswd());
+        startSignal.await();
+
+        LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
+                 + " was created!");
+        zk.getData("/e", false, stat);
+        LOG.info("After get data /e");
         zk.close();
-        Thread.sleep(10000);
-        zk = new ZooKeeper("127.0.0.1:33299", 30000, this);
+
+        zk = createClient();
         assertEquals(null, zk.exists("/e", false));
-        System.out.println("before close zk with session id "
-                + zk.getSessionId() + "!");
+        LOG.info("before close zk with session id 0x"
+                + Long.toHexString(zk.getSessionId()) + "!");
         zk.close();
-        System.out.println("before shutdown zs!");
-        zs.shutdown();
-        System.out.println("after shutdown zs!");
     }
 
     public void process(WatcherEvent event) {
+        LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath());
+        if (event.getState() == Watcher.Event.KeeperStateSyncConnected
+                && startSignal.getCount() > 0)
+        {
+            startSignal.countDown();
+        }
     }
 
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java?rev=686389&r1=686388&r2=686389&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java Fri Aug
15 15:02:28 2008
@@ -19,7 +19,6 @@
 package org.apache.zookeeper.test;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java?rev=686389&r1=686388&r2=686389&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java Fri Aug
15 15:02:28 2008
@@ -39,6 +39,7 @@
             } catch (IOException e1) {
                 // TODO Auto-generated catch block
                 e1.printStackTrace();
+                throw new RuntimeException(e1);
             }
             for(int i = 0; i < REPS; i++) {
                 try {

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java?rev=686389&r1=686388&r2=686389&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java Fri
Aug 15 15:02:28 2008
@@ -79,7 +79,9 @@
 
     private List<Integer> expected;
 
+    @Override
     protected void setUp() throws Exception {
+        LOG.info("STARTING " + getName());
         super.setUp();
 
         client_latch = new CountDownLatch(1);
@@ -92,11 +94,12 @@
 
         expected = new ArrayList<Integer>();
     }
+    @Override
     protected void tearDown() throws Exception {
         client.close();
         lsnr.close();
-        Thread.sleep(5000);
         super.tearDown();
+        LOG.info("FINISHED " + getName());
     }
 
     protected ZooKeeper createClient(Watcher watcher, CountDownLatch latch)
@@ -132,7 +135,7 @@
         try {
             assertNull(lsnr.exists("/car", true));
             client.setData("/car", "missing".getBytes(), -1);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
@@ -140,7 +143,7 @@
         try {
             assertNull(lsnr.exists("/foo/car", true));
             client.setData("/foo/car", "missing".getBytes(), -1);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
@@ -168,13 +171,13 @@
     {
         try {
             lsnr.getData("/foo", true, null);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
         try {
             lsnr.getData("/foo/bar", true, null);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
@@ -207,13 +210,13 @@
     {
         try {
             lsnr.getChildren("/foo", true);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
         try {
             lsnr.getChildren("/foo/bar", true);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
@@ -332,13 +335,13 @@
 
         try {
             lsnr.getData("/foo", w1, null);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
         try {
             lsnr.getData("/foo/bar", w2, null);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
@@ -398,13 +401,13 @@
 
         try {
             lsnr.getChildren("/foo", true);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
         try {
             lsnr.getChildren("/foo/bar", true);
-            assertTrue(false);
+            fail();
         } catch (KeeperException e) {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java?rev=686389&r1=686388&r2=686389&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java
(original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java
Fri Aug 15 15:02:28 2008
@@ -23,6 +23,7 @@
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.junit.Test;
@@ -132,9 +133,8 @@
     if (stat == null) {
       fail("node " + nodeName + " should exist");
     }
-    long prevSessionId = zk.getSessionId();
-    byte[] prevSessionPasswd = zk.getSessionPasswd();
-    System.out.println("Closing client with sessioid:  " + prevSessionId);
+    System.out.println("Closing client with sessionid: 0x" 
+            + Long.toHexString(zk.getSessionId()));
     zk.close();
     zk = new ZooKeeper(hostPort, 10000, this);
 
@@ -263,7 +263,7 @@
 
     event = this.getEvent(10);
     if (event == null) {
-      fail("First event was not delivered promptly");
+      throw new AssertionFailedError("First event was not delivered promptly");
     }
     if (!((event.getType() == Watcher.Event.EventNodeChildrenChanged &&
            event.getPath().equalsIgnoreCase(parentName)) ||
@@ -277,7 +277,7 @@
     event = this.getEvent(10);
 
     if (event == null) {
-      fail("Second event was not delivered promptly");
+      throw new AssertionFailedError("Second event was not delivered promptly");
     }
     if (!((event.getType() == Watcher.Event.EventNodeChildrenChanged &&
         event.getPath().equalsIgnoreCase(parentName)) ||



Mime
View raw message