Modified: 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java?rev=815574&r1=815573&r2=815574&view=diff
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java 
(original)
+++ 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java 
Wed Sep 16 00:09:47 2009
@@ -20,6 +20,8 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
 import java.net.InetSocketAddress;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
@@ -32,6 +34,8 @@
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.junit.After;
 
+import com.sun.management.UnixOperatingSystemMXBean;
+
 public class QuorumBase extends ClientBase {
     private static final Logger LOG = Logger.getLogger(QuorumBase.class);
 
@@ -72,6 +76,15 @@
 
         startServers();
 
+        OperatingSystemMXBean osMbean =
+            ManagementFactory.getOperatingSystemMXBean();
+        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
+            UnixOperatingSystemMXBean unixos =
+                (UnixOperatingSystemMXBean)osMbean;
+            LOG.info("Initial fdcount is: "
+                    + unixos.getOpenFileDescriptorCount());
+        }
+
         LOG.info("Setup finished");
     }
     void startServers() throws Exception {
@@ -147,6 +160,16 @@
     @Override
     protected void tearDown() throws Exception {
         LOG.info("TearDown started");
+        
+        OperatingSystemMXBean osMbean =
+            ManagementFactory.getOperatingSystemMXBean();
+        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
+            UnixOperatingSystemMXBean unixos =
+                (UnixOperatingSystemMXBean)osMbean;
+            LOG.info("fdcount after test is: "
+                    + unixos.getOpenFileDescriptorCount());
+        }
+
         shutdown(s1);
         shutdown(s2);
         shutdown(s3);

Added: 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java?rev=815574&view=auto
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java
 (added)
+++ 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java
 Wed Sep 16 00:09:47 2009
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.test;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+
+public class QuorumHammerTest extends QuorumBase {
+    private static final Logger LOG = Logger.getLogger(QuorumHammerTest.class);
+    public static final long CONNECTION_TIMEOUT = 
ClientTest.CONNECTION_TIMEOUT;
+
+    private final QuorumBase qb = new QuorumBase();
+    private final ClientHammerTest cht = new ClientHammerTest();
+
+    @Before
+    @Override
+    protected void setUp() throws Exception {
+        qb.setUp();
+        cht.hostPort = qb.hostPort;
+        cht.setUpAll();
+    }
+
+    protected void tearDown() throws Exception {
+        cht.tearDownAll();
+        qb.tearDown();
+    }
+    
+    @Test
+    public void testHammerBasic() throws Throwable {
+        cht.testHammerBasic();
+    }
+}

Propchange: 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=815574&r1=815573&r2=815574&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 
Wed Sep 16 00:09:47 2009
@@ -17,8 +17,6 @@
  */
 
 package org.apache.zookeeper.test;
-import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
-
 import java.io.IOException;
 import java.util.ArrayList;
 
@@ -30,10 +28,10 @@
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.quorum.FollowerHandler;
 import org.apache.zookeeper.server.quorum.Leader;
-import org.apache.zookeeper.ZooDefs.Ids;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -63,11 +61,6 @@
     }
 
     @Test
-    public void testHammerBasic() throws Throwable {
-        ct.testHammerBasic();
-    }
-
-    @Test
     public void testPing() throws Exception {
         ct.testPing();
     }

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=815574&r1=815573&r2=815574&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 
Wed Sep 16 00:09:47 2009
@@ -100,6 +100,13 @@
         return createClient(CONNECTION_TIMEOUT, watcher);
     }
 
+    private DisconnectableZooKeeper createClient(int timeout)
+        throws IOException, InterruptedException
+    {
+        CountdownWatcher watcher = new CountdownWatcher();
+        return createClient(timeout, watcher);
+    }
+
     private DisconnectableZooKeeper createClient(int timeout,
             CountdownWatcher watcher)
         throws IOException, InterruptedException
@@ -190,28 +197,27 @@
      * Make sure ephemerals get cleaned up when a session times out.
      */
     public void testSessionTimeout() throws Exception {
-        int oldTimeout = CONNECTION_TIMEOUT;
-        CONNECTION_TIMEOUT = 5000;
-        try {
-            DisconnectableZooKeeper zk = createClient();
-            zk.create("/stest", new byte[0], Ids.OPEN_ACL_UNSAFE, 
CreateMode.EPHEMERAL);
-            zk.disconnect();
-            Thread.sleep(CONNECTION_TIMEOUT*2);
-            zk = createClient();
-            System.err.println("This test fails");
-            zk.create("/stest", new byte[0], Ids.OPEN_ACL_UNSAFE, 
CreateMode.EPHEMERAL);
-            tearDown();
-            zk.close();
-            zk.disconnect();
-            setUp();
-            zk = createClient();
-            assertTrue(zk.exists("/stest", false) != null);
-            Thread.sleep(CONNECTION_TIMEOUT * 2);
-            assertTrue(zk.exists("/stest", false) == null);
-            zk.close();
-        } finally {
-            CONNECTION_TIMEOUT = oldTimeout;
-        }
+        final int TIMEOUT = 5000;
+        DisconnectableZooKeeper zk = createClient(TIMEOUT);
+        zk.create("/stest", new byte[0], Ids.OPEN_ACL_UNSAFE,
+                CreateMode.EPHEMERAL);
+        zk.disconnect();
+
+        Thread.sleep(TIMEOUT*2);
+
+        zk = createClient(TIMEOUT);
+        zk.create("/stest", new byte[0], Ids.OPEN_ACL_UNSAFE,
+                CreateMode.EPHEMERAL);
+        tearDown();
+        zk.close();
+        zk.disconnect();
+        setUp();
+
+        zk = createClient(TIMEOUT);
+        assertTrue(zk.exists("/stest", false) != null);
+        Thread.sleep(TIMEOUT*2);
+        assertTrue(zk.exists("/stest", false) == null);
+        zk.close();
     }
 
     /**

Modified: 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TruncateTest.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TruncateTest.java?rev=815574&r1=815573&r2=815574&view=diff
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TruncateTest.java
 (original)
+++ 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TruncateTest.java
 Wed Sep 16 00:09:47 2009
@@ -23,6 +23,8 @@
 import java.net.InetSocketAddress;
 import java.util.HashMap;
 
+import junit.framework.TestCase;
+
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
@@ -32,13 +34,11 @@
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.NIOServerCnxn;
+import org.apache.zookeeper.server.quorum.QuorumPeer;
+import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.apache.zookeeper.server.quorum.QuorumPeer;
-import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
-
-import junit.framework.TestCase;
 
 public class TruncateTest extends TestCase {
        private static final Logger LOG = Logger.getLogger(TruncateTest.class);

Modified: 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java?rev=815574&r1=815573&r2=815574&view=diff
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java 
(original)
+++ 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java 
Wed Sep 16 00:09:47 2009
@@ -141,8 +141,8 @@
        MyStatCallback cbs[] = new MyStatCallback[COUNT];
        MyWatcher watcher = new MyWatcher();
        int count[] = new int[1];
-       TestableZooKeeper zk = createClient(watcher, hostPort);
-       ZooKeeper zk2 = createClient(watcher, hostPort);
+       TestableZooKeeper zk = createClient(watcher, hostPort, 6000);
+       ZooKeeper zk2 = createClient(watcher, hostPort, 5000);
        zk2.create("/test", new byte[0], Ids.OPEN_ACL_UNSAFE, 
CreateMode.EPHEMERAL);
        for(int i = 0; i < COUNT/2; i++) {
            watches[i] = new MyWatcher();
@@ -150,7 +150,7 @@
            zk.exists("/test", watches[i], cbs[i], count);
        }
        zk.exists("/test", false);
-       zk.pauseCnxn(4000);
+       zk.pauseCnxn(3000);
        Thread.sleep(50);
        zk2.close();
        stopServer();
@@ -177,12 +177,14 @@
        assertEquals(COUNT, count[0]);
        zk.close();
     }
+    
+    final int TIMEOUT = 5000;
 
     @Test
     public void testWatcherAutoResetWithGlobal() throws Exception {
         ZooKeeper zk = null;
         MyWatcher watcher = new MyWatcher();
-        zk = createClient(watcher, hostPort);
+        zk = createClient(watcher, hostPort, TIMEOUT);
         testWatcherAutoReset(zk, watcher, watcher);
         zk.close();
     }
@@ -191,7 +193,7 @@
     public void testWatcherAutoResetWithLocal() throws Exception {
         ZooKeeper zk = null;
         MyWatcher watcher = new MyWatcher();
-        zk = createClient(watcher, hostPort);
+        zk = createClient(watcher, hostPort, TIMEOUT);
         testWatcherAutoReset(zk, watcher, new MyWatcher());
         zk.close();
     }
@@ -212,8 +214,10 @@
             MyWatcher localWatcher) throws Exception {
         boolean isGlobal = (localWatcher == globalWatcher);
         // First test to see if the watch survives across reconnects
-        zk.create("/watchtest", new byte[0], Ids.OPEN_ACL_UNSAFE, 
CreateMode.PERSISTENT);
-        zk.create("/watchtest/child", new byte[0], Ids.OPEN_ACL_UNSAFE, 
CreateMode.EPHEMERAL);
+        zk.create("/watchtest", new byte[0], Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT);
+        zk.create("/watchtest/child", new byte[0], Ids.OPEN_ACL_UNSAFE,
+                CreateMode.EPHEMERAL);
         if (isGlobal) {
             zk.getChildren("/watchtest", true);
             zk.getData("/watchtest/child", true, new Stat());
@@ -240,56 +244,57 @@
         zk.create("/watchtest/child2", new byte[0], Ids.OPEN_ACL_UNSAFE,
                 CreateMode.PERSISTENT);
 
-        WatchedEvent e = localWatcher.events.poll(10, TimeUnit.SECONDS);
+        WatchedEvent e;
         if (!ClientCnxn.getDisableAutoResetWatch()) {
+            e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
             assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType());
             assertEquals("/watchtest/child", e.getPath());
         } else {
-            assertNull("unexpected event", e);
+            // we'll catch this later if it does happen after timeout, so
+            // why waste the time on poll
         }
 
-        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
         if (!ClientCnxn.getDisableAutoResetWatch()) {
+            e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
             // The create will trigger the get children and the exist
             // watches
             assertEquals(EventType.NodeCreated, e.getType());
             assertEquals("/watchtest/child2", e.getPath());
         } else {
-            assertNull("unexpected event", e);
+            // we'll catch this later if it does happen after timeout, so
+            // why waste the time on poll
         }
 
-        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
         if (!ClientCnxn.getDisableAutoResetWatch()) {
+            e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
             assertEquals(EventType.NodeChildrenChanged, e.getType());
             assertEquals("/watchtest", e.getPath());
         } else {
-            assertNull("unexpected event", e);
+            // we'll catch this later if it does happen after timeout, so
+            // why waste the time on poll
         }
 
-        // Make sure PINGs don't screw us up!
-        Thread.sleep(4000);
-
         assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals
         stopServer();
-        globalWatcher.waitForDisconnected(3000);
+        globalWatcher.waitForDisconnected(TIMEOUT);
         try {
-        try {
-            localWatcher.waitForDisconnected(500);
-            if (!isGlobal && !ClientCnxn.getDisableAutoResetWatch()) {
-                fail("Got an event when I shouldn't have");
-            }
-        } catch(TimeoutException toe) {
-            if (ClientCnxn.getDisableAutoResetWatch()) {
-                fail("Didn't get an event when I should have");
+            try {
+                localWatcher.waitForDisconnected(500);
+                if (!isGlobal && !ClientCnxn.getDisableAutoResetWatch()) {
+                    fail("Got an event when I shouldn't have");
+                }
+            } catch(TimeoutException toe) {
+                if (ClientCnxn.getDisableAutoResetWatch()) {
+                    fail("Didn't get an event when I should have");
+                }
+                // Else what we are expecting since there are no outstanding 
watches
             }
-            // Else what we are expecting since there are no outstanding 
watches
-        }
         } catch (Exception e1) {
             LOG.error("bad", e1);
             throw new RuntimeException(e1);
         }
         startServer();
-        globalWatcher.waitForConnected(3000);
+        globalWatcher.waitForConnected(TIMEOUT);
 
         if (isGlobal) {
             zk.getChildren("/watchtest", true);
@@ -305,21 +310,21 @@
         // it later
         zk.delete("/watchtest/child2", -1);
 
-        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
+        e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
         assertEquals(EventType.NodeDeleted, e.getType());
         assertEquals("/watchtest/child2", e.getPath());
 
-        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
+        e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
         assertEquals(EventType.NodeChildrenChanged, e.getType());
         assertEquals("/watchtest", e.getPath());
 
         assertTrue(localWatcher.events.isEmpty());
 
         stopServer();
-        globalWatcher.waitForDisconnected(3000);
+        globalWatcher.waitForDisconnected(TIMEOUT);
         localWatcher.waitForDisconnected(500);
         startServer();
-        globalWatcher.waitForConnected(3000);
+        globalWatcher.waitForConnected(TIMEOUT);
         if (!isGlobal && !ClientCnxn.getDisableAutoResetWatch()) {
             localWatcher.waitForConnected(500);
         }
@@ -327,12 +332,13 @@
         zk.delete("/watchtest/child", -1);
         zk.delete("/watchtest", -1);
 
-        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
         if (!ClientCnxn.getDisableAutoResetWatch()) {
+            e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
             assertEquals(EventType.NodeDeleted, e.getType());
             assertEquals("/watchtest/child", e.getPath());
         } else {
-            assertNull("unexpected event", e);
+            // we'll catch this later if it does happen after timeout, so
+            // why waste the time on poll
         }
 
         // Make sure nothing is straggling!


Reply via email to