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=986575&r1=986574&r2=986575&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 Wed Aug 18 06:24:08 2010 @@ -21,7 +21,6 @@ package org.apache.zookeeper.test; import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; import java.io.File; -import java.net.InetSocketAddress; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -35,7 +34,7 @@ import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.Watcher.Event.KeeperState; import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.data.Stat; -import org.apache.zookeeper.server.NIOServerCnxn; +import org.apache.zookeeper.server.ServerCnxnFactory; import org.apache.zookeeper.server.SyncRequestProcessor; import org.apache.zookeeper.server.ZooKeeperServer; import org.junit.Assert; @@ -72,8 +71,7 @@ public class RecoveryTest extends ZKTest SyncRequestProcessor.setSnapCount(1000); try { final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); - NIOServerCnxn.Factory f = new NIOServerCnxn.Factory( - new InetSocketAddress(PORT)); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); f.startup(zks); LOG.info("starting up the the server, waiting"); @@ -111,7 +109,7 @@ public class RecoveryTest extends ZKTest CONNECTION_TIMEOUT)); zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); - f = new NIOServerCnxn.Factory(new InetSocketAddress(PORT)); + f = ServerCnxnFactory.createFactory(PORT, -1); startSignal = new CountDownLatch(1); @@ -149,7 +147,7 @@ public class RecoveryTest extends ZKTest ClientBase.CONNECTION_TIMEOUT)); zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); - f = new NIOServerCnxn.Factory(new InetSocketAddress(PORT)); + f = ServerCnxnFactory.createFactory(PORT, -1); startSignal = new CountDownLatch(1);
Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java?rev=986575&r1=986574&r2=986575&view=diff ============================================================================== --- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java (original) +++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java Wed Aug 18 06:24:08 2010 @@ -18,13 +18,11 @@ package org.apache.zookeeper.test; -import java.net.InetSocketAddress; - import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.ZKTestCase; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.ZooDefs.Ids; -import org.apache.zookeeper.server.NIOServerCnxn; +import org.apache.zookeeper.server.ServerCnxnFactory; import org.apache.zookeeper.server.ZooKeeperServer; import org.junit.Assert; import org.junit.Test; @@ -54,8 +52,7 @@ public class RepeatStartupTest extends Z ZooKeeperServer zks = new ZooKeeperServer(qb.s1.getTxnFactory().getSnapDir(), qb.s1.getTxnFactory().getDataDir(), 3000); final int PORT = Integer.parseInt(hp.split(":")[1]); - NIOServerCnxn.Factory factory = new NIOServerCnxn.Factory( - new InetSocketAddress(PORT)); + ServerCnxnFactory factory = ServerCnxnFactory.createFactory(PORT, -1); factory.startup(zks); System.out.println("Comment: starting factory"); 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=986575&r1=986574&r2=986575&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 Aug 18 06:24:08 2010 @@ -22,7 +22,6 @@ import static org.apache.zookeeper.test. import java.io.File; import java.io.IOException; -import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -35,25 +34,27 @@ import org.apache.zookeeper.KeeperExcept import org.apache.zookeeper.PortAssignment; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZKTestCase; -import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.Watcher.Event.EventType; import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.Stat; -import org.apache.zookeeper.server.NIOServerCnxn; +import org.apache.zookeeper.server.ServerCnxnFactory; import org.apache.zookeeper.server.ZooKeeperServer; import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; -public class SessionTest extends ZKTestCase implements Watcher { +public class SessionTest extends ZKTestCase { protected static final Logger LOG = Logger.getLogger(SessionTest.class); private static final String HOSTPORT = "127.0.0.1:" + PortAssignment.unique(); - private NIOServerCnxn.Factory serverFactory; + + private ServerCnxnFactory serverFactory; private CountDownLatch startSignal; @@ -71,7 +72,7 @@ public class SessionTest extends ZKTestC ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); - serverFactory = new NIOServerCnxn.Factory(new InetSocketAddress(PORT)); + serverFactory = ServerCnxnFactory.createFactory(PORT, -1); serverFactory.startup(zs); Assert.assertTrue("waiting for server up", @@ -156,6 +157,22 @@ public class SessionTest extends ZKTestC // zk.close(); // } + private class MyWatcher implements Watcher { + private String name; + public MyWatcher(String name) { + this.name = name; + } + public void process(WatchedEvent event) { + LOG.info(name + " event:" + event.getState() + " " + + event.getType() + " " + event.getPath()); + if (event.getState() == KeeperState.SyncConnected + && startSignal != null && startSignal.getCount() > 0) + { + startSignal.countDown(); + } + } + } + /** * This test verifies that when the session id is reused, and the original * client is disconnected, but not session closed, that the server @@ -178,9 +195,9 @@ public class SessionTest extends ZKTestC Stat stat = new Stat(); startSignal = new CountDownLatch(1); - zk = new DisconnectableZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this, - zk.getSessionId(), - zk.getSessionPasswd()); + zk = new DisconnectableZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, + new MyWatcher("testSession"), zk.getSessionId(), + zk.getSessionPasswd()); startSignal.await(); LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId()) @@ -270,14 +287,21 @@ public class SessionTest extends ZKTestC * @throws KeeperException */ @Test - public void testSessionMove() throws IOException, InterruptedException, KeeperException { + @Ignore + public void testSessionMove() throws Exception { String hostPorts[] = HOSTPORT.split(","); - ZooKeeper zk = new DisconnectableZooKeeper(hostPorts[0], CONNECTION_TIMEOUT, this); - zk.create("/sessionMoveTest", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + DisconnectableZooKeeper zk = new DisconnectableZooKeeper(hostPorts[0], + CONNECTION_TIMEOUT, new MyWatcher("0")); + zk.create("/sessionMoveTest", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); // we want to loop through the list twice for(int i = 0; i < hostPorts.length*2; i++) { + zk.dontReconnect(); // This should stomp the zk handle - ZooKeeper zknew = new DisconnectableZooKeeper(hostPorts[(i+1)%hostPorts.length], CONNECTION_TIMEOUT, this, + DisconnectableZooKeeper zknew = new DisconnectableZooKeeper( + hostPorts[(i+1)%hostPorts.length], + CONNECTION_TIMEOUT, + new MyWatcher(Integer.toString(i+1)), zk.getSessionId(), zk.getSessionPasswd()); zknew.setData("/", new byte[1], -1); @@ -285,6 +309,7 @@ public class SessionTest extends ZKTestC zk.setData("/", new byte[1], -1); Assert.fail("Should have lost the connection"); } catch(KeeperException.ConnectionLossException e) { + LOG.info("Got connection loss exception as expected"); } //zk.close(); zk = zknew; @@ -362,23 +387,16 @@ public class SessionTest extends ZKTestC } } - public void process(WatchedEvent event) { - LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath()); - if (event.getState() == KeeperState.SyncConnected - && startSignal != null && startSignal.getCount() > 0) - { - startSignal.countDown(); - } - } - @Test public void testMinMaxSessionTimeout() throws Exception { // override the defaults final int MINSESS = 20000; final int MAXSESS = 240000; - ZooKeeperServer zs = serverFactory.getZooKeeperServer(); - zs.setMinSessionTimeout(MINSESS); - zs.setMaxSessionTimeout(MAXSESS); + { + ZooKeeperServer zs = ClientBase.getServer(serverFactory); + zs.setMinSessionTimeout(MINSESS); + zs.setMaxSessionTimeout(MAXSESS); + } // validate typical case - requested == negotiated int timeout = 120000; 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=986575&r1=986574&r2=986575&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 Aug 18 06:24:08 2010 @@ -32,8 +32,9 @@ import org.apache.zookeeper.ZKTestCase; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.Stat; -import org.apache.zookeeper.server.NIOServerCnxn; +import org.apache.zookeeper.server.ServerCnxnFactory; import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; import org.apache.zookeeper.server.quorum.QuorumPeer; import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; import org.junit.After; @@ -71,13 +72,19 @@ public class TruncateTest extends ZKTest @Test public void testTruncate() throws IOException, InterruptedException, KeeperException { // Prime the server that is going to come in late with 50 txns - NIOServerCnxn.Factory factory = ClientBase.createNewServerInstance(dataDir1, null, "127.0.0.1:" + baseHostPort, 100); + ServerCnxnFactory factory = ClientBase.createNewServerInstance(dataDir1, null, "127.0.0.1:" + baseHostPort, 100); ZooKeeper zk = new ZooKeeper("127.0.0.1:" + baseHostPort, 15000, nullWatcher); for(int i = 0; i < 50; i++) { zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } zk.close(); - ZKDatabase zkDb = factory.getZooKeeperServer().getZKDatabase(); + + ZKDatabase zkDb; + { + ZooKeeperServer zs = ClientBase.getServer(factory); + + zkDb = zs.getZKDatabase(); + } factory.shutdown(); try { zkDb.close(); Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java?rev=986575&r1=986574&r2=986575&view=diff ============================================================================== --- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java (original) +++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java Wed Aug 18 06:24:08 2010 @@ -21,7 +21,6 @@ package org.apache.zookeeper.test; import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; import java.io.File; -import java.net.InetSocketAddress; import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -36,7 +35,7 @@ import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.Watcher.Event.KeeperState; import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.data.Stat; -import org.apache.zookeeper.server.NIOServerCnxn; +import org.apache.zookeeper.server.ServerCnxnFactory; import org.apache.zookeeper.server.SyncRequestProcessor; import org.apache.zookeeper.server.ZooKeeperServer; import org.apache.zookeeper.server.upgrade.UpgradeMain; @@ -63,8 +62,7 @@ public class UpgradeTest extends ZKTestC ZooKeeperServer zks = new ZooKeeperServer(upgradeDir, upgradeDir, 3000); SyncRequestProcessor.setSnapCount(1000); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); - NIOServerCnxn.Factory f = new NIOServerCnxn.Factory( - new InetSocketAddress(PORT)); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); f.startup(zks); LOG.info("starting up the zookeeper server .. waiting"); Assert.assertTrue("waiting for server being up", 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=986575&r1=986574&r2=986575&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 Aug 18 06:24:08 2010 @@ -148,7 +148,8 @@ public class WatcherTest extends ClientB zk1.getData("/watch-count-test-2", w1, stat); zk2.getData("/watch-count-test", w2, stat); - Assert.assertEquals(getServer().getZKDatabase().getDataTree().getWatchCount(), 3); + Assert.assertEquals(ClientBase.getServer(serverFactory) + .getZKDatabase().getDataTree().getWatchCount(), 3); } finally { if(zk1 != null) {