zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject [27/51] [partial] zookeeper git commit: ZOOKEEPER-3032: MAVEN MIGRATION - zookeeper-server
Date Fri, 19 Oct 2018 12:40:25 GMT
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/SessionUpgradeTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/SessionUpgradeTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/SessionUpgradeTest.java
deleted file mode 100644
index be9ecb5..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/SessionUpgradeTest.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/**
- * 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.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Tests that session upgrade works from local to global sessions.
- * Expected behavior is that if global-only sessions are unset,
- * and no upgrade interval is specified, then sessions will be
- * created locally to the host.  They will be upgraded to global
- * sessions iff an operation is done on that session which requires
- * persistence, i.e. creating an ephemeral node.
- */
-public class SessionUpgradeTest extends ZKTestCase {
-    protected static final Logger LOG = LoggerFactory.getLogger(SessionUpgradeTest.class);
-    public static final int CONNECTION_TIMEOUT = ClientBase.CONNECTION_TIMEOUT;
-
-    private final QuorumBase qb = new QuorumBase();
-
-    @Before
-    public void setUp() throws Exception {
-        LOG.info("STARTING quorum " + getClass().getName());
-        qb.localSessionsEnabled = true;
-        qb.localSessionsUpgradingEnabled = true;
-        qb.setUp();
-        ClientBase.waitForServerUp(qb.hostPort, 10000);
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        LOG.info("STOPPING quorum " + getClass().getName());
-        qb.tearDown();
-    }
-
-    @Test
-    public void testLocalSessionsWithoutEphemeralOnFollower() throws Exception {
-        testLocalSessionsWithoutEphemeral(false);
-    }
-
-    @Test
-    public void testLocalSessionsWithoutEphemeralOnLeader() throws Exception {
-        testLocalSessionsWithoutEphemeral(true);
-    }
-
-    private void testLocalSessionsWithoutEphemeral(boolean testLeader)
-            throws Exception {
-        String nodePrefix = "/testLocalSessions-"
-            + (testLeader ? "leaderTest-" : "followerTest-");
-        int leaderIdx = qb.getLeaderIndex();
-        Assert.assertFalse("No leader in quorum?", leaderIdx == -1);
-        int followerIdx = (leaderIdx + 1) % 5;
-        int otherFollowerIdx = (leaderIdx + 2) % 5;
-        int testPeerIdx = testLeader ? leaderIdx : followerIdx;
-        String hostPorts[] = qb.hostPort.split(",");
-        CountdownWatcher watcher = new CountdownWatcher();
-        DisconnectableZooKeeper zk = new DisconnectableZooKeeper(
-                hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher);
-        watcher.waitForConnected(CONNECTION_TIMEOUT);
-
-        // Try creating some data.
-        for (int i = 0; i < 5; i++) {
-            zk.create(nodePrefix + i, new byte[0],
-                      ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        }
-
-        long localSessionId = zk.getSessionId();
-        byte[] localSessionPwd = zk.getSessionPasswd().clone();
-
-        // Try connecting with the same session id on a different
-        // server.  This should fail since it is a local sesion.
-        try {
-            watcher.reset();
-            DisconnectableZooKeeper zknew = new DisconnectableZooKeeper(
-                    hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher,
-                    localSessionId, localSessionPwd);
-
-            zknew.create(nodePrefix + "5", new byte[0],
-                         ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-            Assert.fail("Connection on the same session ID should fail.");
-        } catch (KeeperException.SessionExpiredException e) {
-        } catch (KeeperException.ConnectionLossException e) {
-        }
-
-        // If we're testing a follower, also check the session id on the
-        // leader. This should also fail
-        if (!testLeader) {
-            try {
-                watcher.reset();
-                DisconnectableZooKeeper zknew = new DisconnectableZooKeeper(
-                        hostPorts[leaderIdx], CONNECTION_TIMEOUT,
-                        watcher, localSessionId, localSessionPwd);
-
-                zknew.create(nodePrefix + "5", new byte[0],
-                             ZooDefs.Ids.OPEN_ACL_UNSAFE,
-                             CreateMode.PERSISTENT);
-                Assert.fail("Connection on the same session ID should fail.");
-            } catch (KeeperException.SessionExpiredException e) {
-            } catch (KeeperException.ConnectionLossException e) {
-            }
-        }
-
-        // However, we should be able to disconnect and reconnect to the same
-        // server with the same session id (as long as we do it quickly
-        // before expiration).
-        zk.disconnect();
-
-        watcher.reset();
-        zk = new DisconnectableZooKeeper(
-                hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher,
-                localSessionId, localSessionPwd);
-        watcher.waitForConnected(CONNECTION_TIMEOUT);
-
-        zk.create(nodePrefix + "6", new byte[0],
-                  ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
-        // If we explicitly close the session, then the session id should no
-        // longer be valid.
-        zk.close();
-        try {
-            watcher.reset();
-            zk = new DisconnectableZooKeeper(
-                    hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher,
-                    localSessionId, localSessionPwd);
-
-            zk.create(nodePrefix + "7", new byte[0],
-                      ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-            Assert.fail("Reconnecting to a closed session ID should fail.");
-        } catch (KeeperException.SessionExpiredException e) {
-        }
-    }
-
-    @Test
-    public void testUpgradeWithEphemeralOnFollower() throws Exception {
-        testUpgradeWithEphemeral(false);
-    }
-
-    @Test
-    public void testUpgradeWithEphemeralOnLeader() throws Exception {
-        testUpgradeWithEphemeral(true);
-    }
-
-    private void testUpgradeWithEphemeral(boolean testLeader)
-            throws Exception {
-        String nodePrefix = "/testUpgrade-"
-            + (testLeader ? "leaderTest-" : "followerTest-");
-        int leaderIdx = qb.getLeaderIndex();
-        Assert.assertFalse("No leader in quorum?", leaderIdx == -1);
-        int followerIdx = (leaderIdx + 1) % 5;
-        int otherFollowerIdx = (leaderIdx + 2) % 5;
-        int testPeerIdx = testLeader ? leaderIdx : followerIdx;
-        String hostPorts[] = qb.hostPort.split(",");
-
-        CountdownWatcher watcher = new CountdownWatcher();
-        DisconnectableZooKeeper zk = new DisconnectableZooKeeper(
-                hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher);
-        watcher.waitForConnected(CONNECTION_TIMEOUT);
-
-        // Create some ephemeral nodes.  This should force the session to
-        // be propagated to the other servers in the ensemble.
-        for (int i = 0; i < 5; i++) {
-            zk.create(nodePrefix + i, new byte[0],
-                      ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
-        }
-
-        // We should be able to reconnect with the same session id on a
-        // different server, since it has been propagated.
-        long localSessionId = zk.getSessionId();
-        byte[] localSessionPwd = zk.getSessionPasswd().clone();
-
-        zk.disconnect();
-        watcher.reset();
-        zk = new DisconnectableZooKeeper(
-                hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher,
-                localSessionId, localSessionPwd);
-        watcher.waitForConnected(CONNECTION_TIMEOUT);
-
-        // The created ephemeral nodes are still around.
-        for (int i = 0; i < 5; i++) {
-            Assert.assertNotNull(zk.exists(nodePrefix + i, null));
-        }
-
-        // When we explicitly close the session, we should not be able to
-        // reconnect with the same session id
-        zk.close();
-
-        try {
-            watcher.reset();
-            zk = new DisconnectableZooKeeper(
-                    hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher,
-                    localSessionId, localSessionPwd);
-            zk.exists(nodePrefix + "0", null);
-            Assert.fail("Reconnecting to a closed session ID should fail.");
-        } catch (KeeperException.SessionExpiredException e) {
-        }
-
-        watcher.reset();
-        // And the ephemeral nodes will be gone since the session died.
-        zk = new DisconnectableZooKeeper(
-                hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher);
-        watcher.waitForConnected(CONNECTION_TIMEOUT);
-        for (int i = 0; i < 5; i++) {
-            Assert.assertNull(zk.exists(nodePrefix + i, null));
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/SledgeHammer.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/SledgeHammer.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/SledgeHammer.java
deleted file mode 100644
index 9b16338..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/SledgeHammer.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * 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 java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.server.ExitCode;
-
-public class SledgeHammer extends Thread{
-    ZooKeeper zk;
-
-    int count;
-
-    int readsPerWrite;
-
-    public SledgeHammer(String hosts, int count, int readsPerWrite)
-            throws Exception {
-        zk = ClientBase.createZKClient(hosts, 10000);
-        this.count = count;
-        this.readsPerWrite = readsPerWrite;
-    }
-
-    public void run() {
-        try {
-            Stat stat = new Stat();
-            String path = zk.create("/hammers/hammer-", new byte[0],
-                    Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
-            byte tag[] = (path + " was here!").getBytes();
-            synchronized (this) {
-                String startPath = "/hammers/start";
-                System.out.println("Waiting for " + startPath);
-                while (zk.exists(startPath, true) == null) {
-                    wait();
-                }
-                System.out.println("Running");
-            }
-            for (int i = 0; i < count; i++) {
-                try {
-                    System.out.print(i + "\r");
-                    List<String> childs =
-                        zk.getChildren("/hammers", false);
-                    Collections.shuffle(childs);
-                    for (String s : childs) {
-                        if (s.startsWith("hammer-")) {
-                            s = "/hammers/" + s;
-                            zk.setData(s, tag, -1);
-                            for (int j = 0; j < readsPerWrite; j++) {
-                                zk.getData(s, false, stat);
-                            }
-                            break;
-                        }
-                    }
-                } catch (KeeperException.ConnectionLossException e) {
-                    // ignore connection loss
-                } catch (KeeperException e) {
-                    e.printStackTrace();
-                }
-            }
-            System.out.println();
-            zk.close();
-        } catch (RuntimeException e) {
-            e.printStackTrace();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        } catch (KeeperException e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     * @param args
-     * @throws IOException
-     * @throws KeeperException
-     * @throws NumberFormatException
-     */
-    public static void main(String[] args) throws NumberFormatException,
-            Exception {
-        if (args.length != 3) {
-            System.err
-                    .println("USAGE: SledgeHammer zookeeper_server reps reads_per_rep");
-            System.exit(ExitCode.UNABLE_TO_ACCESS_DATADIR.getValue());
-        }
-        SledgeHammer h = new SledgeHammer(args[0], Integer.parseInt(args[1]),
-                Integer.parseInt(args[2]));
-        h.start();
-        System.exit(ExitCode.EXECUTION_FINISHED.getValue());
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/StandaloneTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/StandaloneTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/StandaloneTest.java
deleted file mode 100644
index 3d57b6c..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/StandaloneTest.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/**
- * 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 static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.server.ServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.server.quorum.QuorumPeerTestBase;
-import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.admin.ZooKeeperAdmin;
-import org.junit.Before;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Standalone server tests.
- */
-public class StandaloneTest extends QuorumPeerTestBase implements Watcher{
-    protected static final Logger LOG =
-        LoggerFactory.getLogger(StandaloneTest.class);
-
-    @Before
-    public void setup() {
-        System.setProperty("zookeeper.DigestAuthenticationProvider.superDigest",
-                "super:D/InIHSb7yEEbrWz8b9l71RjZJU="/* password is 'test'*/);
-        QuorumPeerConfig.setReconfigEnabled(true);
-    }
-
-    /**
-     * This test wouldn't create any dynamic config.
-     * However, it adds a "clientPort=XXX" in static config file.
-     * It checks the standard way of standalone mode.
-     */
-    @Test
-    public void testNoDynamicConfig() throws Exception {
-        ClientBase.setupTestEnv();
-        final int CLIENT_PORT = PortAssignment.unique();
-
-        MainThread mt = new MainThread(
-                MainThread.UNSET_MYID, CLIENT_PORT, "", false);
-        verifyStandalone(mt, CLIENT_PORT);
-    }
-
-    /**
-     * This test creates a dynamic config of new format.
-     * The dynamic config is written in dynamic config file.
-     * It checks that the client port will be read from the dynamic config.
-     *
-     * This handles the case of HBase, which adds a single server line to the config.
-     * Maintain b/w compatibility.
-     */
-    @Test
-    public void testClientPortInDynamicFile() throws Exception {
-        ClientBase.setupTestEnv();
-        final int CLIENT_PORT = PortAssignment.unique();
-
-        String quorumCfgSection = "server.1=127.0.0.1:" +
-                (PortAssignment.unique()) + ":" + (PortAssignment.unique())
-                + ":participant;" + CLIENT_PORT + "\n";
-
-        MainThread mt = new MainThread(1, quorumCfgSection);
-        verifyStandalone(mt, CLIENT_PORT);
-    }
-
-    /**
-     * This test creates a dynamic config of new format.
-     * The dynamic config is written in static config file.
-     * It checks that the client port will be read from the dynamic config.
-     */
-    @Test
-    public void testClientPortInStaticFile() throws Exception {
-        ClientBase.setupTestEnv();
-        final int CLIENT_PORT = PortAssignment.unique();
-
-        String quorumCfgSection = "server.1=127.0.0.1:" +
-                (PortAssignment.unique()) + ":" + (PortAssignment.unique())
-                + ":participant;" + CLIENT_PORT + "\n";
-
-        MainThread mt = new MainThread(1, quorumCfgSection, false);
-        verifyStandalone(mt, CLIENT_PORT);
-    }
-
-    void verifyStandalone(MainThread mt, int clientPort) throws InterruptedException {
-        mt.start();
-        try {
-            Assert.assertTrue("waiting for server 1 being up",
-                    ClientBase.waitForServerUp("127.0.0.1:" + clientPort,
-                            CONNECTION_TIMEOUT));
-        } finally {
-            Assert.assertFalse("Error- MainThread started in Quorum Mode!",
-                    mt.isQuorumPeerRunning());
-            mt.shutdown();
-        }
-    }
-
-    /**
-     * Verify that reconfiguration in standalone mode fails with
-     * KeeperException.UnimplementedException.
-     */
-    @Test
-    public void testStandaloneReconfigFails() throws Exception {
-        ClientBase.setupTestEnv();
-
-        final int CLIENT_PORT = PortAssignment.unique();
-        final String HOSTPORT = "127.0.0.1:" + CLIENT_PORT;
-
-        File tmpDir = ClientBase.createTmpDir();
-        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
-
-        ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1);
-        f.startup(zks);
-        Assert.assertTrue("waiting for server being up ", ClientBase
-                .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
-
-        CountdownWatcher watcher = new CountdownWatcher();
-        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, watcher);
-        ZooKeeperAdmin zkAdmin = new ZooKeeperAdmin(HOSTPORT, CONNECTION_TIMEOUT, watcher);
-        watcher.waitForConnected(CONNECTION_TIMEOUT);
-
-        List<String> joiners = new ArrayList<String>();
-        joiners.add("server.2=localhost:1234:1235;1236");
-        // generate some transactions that will get logged
-        try {
-            zkAdmin.addAuthInfo("digest", "super:test".getBytes());
-            zkAdmin.reconfigure(joiners, null, null, -1, new Stat());
-            Assert.fail("Reconfiguration in standalone should trigger " +
-                        "UnimplementedException");
-        } catch (KeeperException.UnimplementedException ex) {
-            // expected
-        }
-        zk.close();
-
-        zks.shutdown();
-        f.shutdown();
-        Assert.assertTrue("waiting for server being down ", ClientBase
-                .waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/StatTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/StatTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/StatTest.java
deleted file mode 100644
index f4c01aa..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/StatTest.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
- * 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 java.io.IOException;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.data.Stat;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class StatTest extends ClientBase {
-    private ZooKeeper zk;
-
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-
-        zk = createClient();
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        super.tearDown();
-
-        zk.close();
-    }
-
-    /**
-     * Create a new Stat, fill in dummy values trying to catch Assert.failure
-     * to copy in client or server code.
-     *
-     * @return a new stat with dummy values
-     */
-    private Stat newStat() {
-        Stat stat = new Stat();
-
-        stat.setAversion(100);
-        stat.setCtime(100);
-        stat.setCversion(100);
-        stat.setCzxid(100);
-        stat.setDataLength(100);
-        stat.setEphemeralOwner(100);
-        stat.setMtime(100);
-        stat.setMzxid(100);
-        stat.setNumChildren(100);
-        stat.setPzxid(100);
-        stat.setVersion(100);
-
-        return stat;
-    }
-
-    @Test
-    public void testBasic()
-        throws IOException, KeeperException, InterruptedException
-    {
-        String name = "/foo";
-        zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE,
-                CreateMode.PERSISTENT);
-
-        Stat stat;
-
-        stat = newStat();
-        zk.getData(name, false, stat);
-
-        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
-        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
-        Assert.assertEquals(stat.getCtime(), stat.getMtime());
-        Assert.assertEquals(0, stat.getCversion());
-        Assert.assertEquals(0, stat.getVersion());
-        Assert.assertEquals(0, stat.getAversion());
-        Assert.assertEquals(0, stat.getEphemeralOwner());
-        Assert.assertEquals(name.length(), stat.getDataLength());
-        Assert.assertEquals(0, stat.getNumChildren());
-    }
-
-    @Test
-    public void testChild()
-        throws IOException, KeeperException, InterruptedException
-    {
-        String name = "/foo";
-        zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE,
-                CreateMode.PERSISTENT);
-
-        String childname = name + "/bar";
-        zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE,
-                CreateMode.EPHEMERAL);
-
-        Stat stat;
-
-        stat = newStat();
-        zk.getData(name, false, stat);
-
-        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
-        Assert.assertEquals(stat.getCzxid() + 1, stat.getPzxid());
-        Assert.assertEquals(stat.getCtime(), stat.getMtime());
-        Assert.assertEquals(1, stat.getCversion());
-        Assert.assertEquals(0, stat.getVersion());
-        Assert.assertEquals(0, stat.getAversion());
-        Assert.assertEquals(0, stat.getEphemeralOwner());
-        Assert.assertEquals(name.length(), stat.getDataLength());
-        Assert.assertEquals(1, stat.getNumChildren());
-
-        stat = newStat();
-        zk.getData(childname, false, stat);
-
-        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
-        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
-        Assert.assertEquals(stat.getCtime(), stat.getMtime());
-        Assert.assertEquals(0, stat.getCversion());
-        Assert.assertEquals(0, stat.getVersion());
-        Assert.assertEquals(0, stat.getAversion());
-        Assert.assertEquals(zk.getSessionId(), stat.getEphemeralOwner());
-        Assert.assertEquals(childname.length(), stat.getDataLength());
-        Assert.assertEquals(0, stat.getNumChildren());
-    }
-
-    @Test
-    public void testChildren()
-        throws IOException, KeeperException, InterruptedException
-    {
-        String name = "/foo";
-        zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE,
-                CreateMode.PERSISTENT);
-
-        for(int i = 0; i < 10; i++) {
-            String childname = name + "/bar" + i;
-            zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE,
-                    CreateMode.EPHEMERAL);
-
-            Stat stat;
-
-            stat = newStat();
-            zk.getData(name, false, stat);
-
-            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());
-        }
-    }
-
-    @Test
-    public void testDataSizeChange()
-        throws IOException, KeeperException, InterruptedException
-    {
-        String name = "/foo";
-        zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE,
-                CreateMode.PERSISTENT);
-
-        Stat stat;
-
-        stat = newStat();
-        zk.getData(name, false, stat);
-
-        Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
-        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
-        Assert.assertEquals(stat.getCtime(), stat.getMtime());
-        Assert.assertEquals(0, stat.getCversion());
-        Assert.assertEquals(0, stat.getVersion());
-        Assert.assertEquals(0, stat.getAversion());
-        Assert.assertEquals(0, stat.getEphemeralOwner());
-        Assert.assertEquals(name.length(), stat.getDataLength());
-        Assert.assertEquals(0, stat.getNumChildren());
-
-        zk.setData(name, (name + name).getBytes(), -1);
-
-        stat = newStat();
-        zk.getData(name, false, stat);
-
-        Assert.assertNotSame(stat.getCzxid(), stat.getMzxid());
-        Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
-        Assert.assertNotSame(stat.getCtime(), stat.getMtime());
-        Assert.assertEquals(0, stat.getCversion());
-        Assert.assertEquals(1, stat.getVersion());
-        Assert.assertEquals(0, stat.getAversion());
-        Assert.assertEquals(0, stat.getEphemeralOwner());
-        Assert.assertEquals(name.length() * 2, stat.getDataLength());
-        Assert.assertEquals(0, stat.getNumChildren());
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/StaticHostProviderTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/StaticHostProviderTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/StaticHostProviderTest.java
deleted file mode 100644
index 998d6e5..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/StaticHostProviderTest.java
+++ /dev/null
@@ -1,932 +0,0 @@
-/**
- * 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.zookeeper.ZKTestCase;
-import org.apache.zookeeper.client.HostProvider;
-import org.apache.zookeeper.client.StaticHostProvider;
-import org.apache.zookeeper.common.Time;
-import org.junit.Test;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-
-import static org.hamcrest.CoreMatchers.anyOf;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class StaticHostProviderTest extends ZKTestCase {
-    private Random r = new Random(1);
-
-    @Test
-    public void testNextGoesRound() {
-        HostProvider hostProvider = getHostProvider((byte) 2);
-        InetSocketAddress first = hostProvider.next(0);
-        assertTrue(first != null);
-        hostProvider.next(0);
-        assertEquals(first, hostProvider.next(0));
-    }
-
-    @Test
-    public void testNextGoesRoundAndSleeps() {
-        byte size = 2;
-        HostProvider hostProvider = getHostProvider(size);
-        while (size > 0) {
-            hostProvider.next(0);
-            --size;
-        }
-        long start = Time.currentElapsedTime();
-        hostProvider.next(1000);
-        long stop = Time.currentElapsedTime();
-        assertTrue(900 <= stop - start);
-    }
-
-    @Test
-    public void testNextDoesNotSleepForZero() {
-        byte size = 2;
-        HostProvider hostProvider = getHostProvider(size);
-        while (size > 0) {
-            hostProvider.next(0);
-            --size;
-        }
-        long start = Time.currentElapsedTime();
-        hostProvider.next(0);
-        long stop = Time.currentElapsedTime();
-        assertTrue(5 > stop - start);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testEmptyServerAddressesList() {
-        HostProvider hp = new StaticHostProvider(new ArrayList<>());
-    }
-
-    @Test
-    public void testInvalidHostAddresses() {
-        // Arrange
-        final List<InetSocketAddress> invalidAddresses = new ArrayList<>();
-        InetSocketAddress unresolved = InetSocketAddress.createUnresolved("a", 1234);
-        invalidAddresses.add(unresolved);
-        StaticHostProvider.Resolver resolver = new StaticHostProvider.Resolver() {
-            @Override
-            public InetAddress[] getAllByName(String name) throws UnknownHostException {
-                throw new UnknownHostException();
-            }
-        };
-        StaticHostProvider sp = new StaticHostProvider(invalidAddresses, resolver);
-
-        // Act & Assert
-        InetSocketAddress n1 = sp.next(0);
-        assertTrue("Provider should return unresolved address is host is unresolvable", n1.isUnresolved());
-        assertSame("Provider should return original address is host is unresolvable", unresolved, n1);
-    }
-
-    @Test
-    public void testTwoConsequitiveCallsToNextReturnDifferentElement() {
-        HostProvider hostProvider = getHostProvider((byte) 2);
-        assertNotSame(hostProvider.next(0), hostProvider.next(0));
-    }
-
-    @Test
-    public void testOnConnectDoesNotReset() {
-        HostProvider hostProvider = getHostProvider((byte) 2);
-        InetSocketAddress first = hostProvider.next(0);
-        hostProvider.onConnected();
-        InetSocketAddress second = hostProvider.next(0);
-        assertNotSame(first, second);
-    }
-
-    /* Reconfig tests with IP addresses */
-
-    private final double slackPercent = 10;
-    private final int numClients = 10000;
-
-    @Test
-    public void testUpdateClientMigrateOrNot() throws UnknownHostException {
-        HostProvider hostProvider = getHostProvider((byte) 4); // 10.10.10.4:1238, 10.10.10.3:1237, 10.10.10.2:1236, 10.10.10.1:1235
-        Collection<InetSocketAddress> newList = getServerAddresses((byte) 3); // 10.10.10.3:1237, 10.10.10.2:1236, 10.10.10.1:1235
-
-        InetSocketAddress myServer = new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, 3}), 1237);
-
-        // Number of machines becomes smaller, my server is in the new cluster
-        boolean disconnectRequired = hostProvider.updateServerList(newList, myServer);
-        assertFalse(disconnectRequired);
-        hostProvider.onConnected();
-        
-        // Number of machines stayed the same, my server is in the new cluster
-        disconnectRequired = hostProvider.updateServerList(newList, myServer);
-        assertFalse(disconnectRequired);
-        hostProvider.onConnected();
-
-        // Number of machines became smaller, my server is not in the new
-        // cluster
-        newList = getServerAddresses((byte) 2); // 10.10.10.2:1236, 10.10.10.1:1235
-        disconnectRequired = hostProvider.updateServerList(newList, myServer);
-        assertTrue(disconnectRequired);
-        hostProvider.onConnected();
-
-        // Number of machines stayed the same, my server is not in the new
-        // cluster
-        disconnectRequired = hostProvider.updateServerList(newList, myServer);
-        assertTrue(disconnectRequired);
-        hostProvider.onConnected();
-
-        // Number of machines increased, my server is not in the new cluster
-        newList = new ArrayList<InetSocketAddress>(3);
-        for (byte i = 4; i > 1; i--) { // 10.10.10.4:1238, 10.10.10.3:1237, 10.10.10.2:1236
-            newList.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i));
-        }
-        myServer = new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, 1}), 1235);
-        disconnectRequired = hostProvider.updateServerList(newList, myServer);
-        assertTrue(disconnectRequired);
-        hostProvider.onConnected();
-
-        // Number of machines increased, my server is in the new cluster
-        // Here whether to move or not depends on the difference of cluster
-        // sizes
-        // With probability 1 - |old|/|new} the client disconnects
-        // In the test below 1-9/10 = 1/10 chance of disconnecting
-        HostProvider[] hostProviderArray = new HostProvider[numClients];
-        newList = getServerAddresses((byte) 10);
-        int numDisconnects = 0;
-        for (int i = 0; i < numClients; i++) {
-            hostProviderArray[i] = getHostProvider((byte) 9);
-            disconnectRequired = hostProviderArray[i].updateServerList(newList, myServer);
-            if (disconnectRequired)
-                numDisconnects++;
-        }
-        hostProvider.onConnected();
-
-        // should be numClients/10 in expectation, we test that its numClients/10 +- slackPercent
-        assertTrue(numDisconnects < upperboundCPS(numClients, 10));
-    }
-
-    @Test
-    public void testUpdateMigrationGoesRound() throws UnknownHostException {
-        HostProvider hostProvider = getHostProvider((byte) 4);
-        // old list (just the ports): 1238, 1237, 1236, 1235
-        Collection<InetSocketAddress> newList = new ArrayList<InetSocketAddress>(10);
-        for (byte i = 12; i > 2; i--) { // 1246, 1245, 1244, 1243, 1242, 1241,
-                                       // 1240, 1239, 1238, 1237
-            newList.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i));
-        }
-
-        // servers from the old list that appear in the new list
-        Collection<InetSocketAddress> oldStaying = new ArrayList<InetSocketAddress>(2);
-        for (byte i = 4; i > 2; i--) { // 1238, 1237
-            oldStaying.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i));
-        }
-
-        // servers in the new list that are not in the old list
-        Collection<InetSocketAddress> newComing = new ArrayList<InetSocketAddress>(10);
-        for (byte i = 12; i > 4; i--) {// 1246, 1245, 1244, 1243, 1242, 1241, 1240, 1139
-            newComing.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i));
-        }
-
-        // Number of machines increases, my server is not in the new cluster
-        // load on old servers must be decreased, so must connect to one of the
-        // new servers
-        // i.e., pNew = 1.
-
-        boolean disconnectRequired = hostProvider.updateServerList(newList, new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, 1}), 1235));
-        assertTrue(disconnectRequired);
-
-        // This means reconfigMode = true, and nextHostInReconfigMode will be
-        // called from next
-        // Since pNew = 1 we should first try the new servers
-        ArrayList<InetSocketAddress> seen = new ArrayList<InetSocketAddress>();
-        for (int i = 0; i < newComing.size(); i++) {
-            InetSocketAddress addr = hostProvider.next(0);
-            assertTrue(newComing.contains(addr));
-            assertTrue(!seen.contains(addr));
-            seen.add(addr);
-        }
-
-        // Next the old servers
-        seen.clear();
-        for (int i = 0; i < oldStaying.size(); i++) {
-            InetSocketAddress addr = hostProvider.next(0);
-            assertTrue(oldStaying.contains(addr));
-            assertTrue(!seen.contains(addr));
-            seen.add(addr);
-        }
-
-        // And now it goes back to normal next() so it should be everything
-        // together like in testNextGoesRound()
-        InetSocketAddress first = hostProvider.next(0);
-        assertTrue(first != null);
-        for (int i = 0; i < newList.size() - 1; i++) {
-            hostProvider.next(0);
-        }
-
-        assertEquals(first, hostProvider.next(0));
-        hostProvider.onConnected();
-    }
-
-    @Test
-    public void testUpdateLoadBalancing() throws UnknownHostException {
-        // Start with 9 servers and 10000 clients
-        boolean disconnectRequired;
-        HostProvider[] hostProviderArray = new HostProvider[numClients];
-        InetSocketAddress[] curHostForEachClient = new InetSocketAddress[numClients];
-        int[] numClientsPerHost = new int[9];
-
-        // initialization
-        for (int i = 0; i < numClients; i++) {
-            hostProviderArray[i] = getHostProvider((byte) 9);
-            curHostForEachClient[i] = hostProviderArray[i].next(0);
-            numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++;
-            hostProviderArray[i].onConnected();
-        }
-
-        for (int i = 0; i < 9; i++) {
-            assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 9));
-            assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 9));
-            numClientsPerHost[i] = 0; // prepare for next test
-        }
-
-        // remove host number 8 (the last one in a list of 9 hosts)
-        Collection<InetSocketAddress> newList = getServerAddresses((byte) 8);
-
-        for (int i = 0; i < numClients; i++) {
-            disconnectRequired = hostProviderArray[i].updateServerList(newList, curHostForEachClient[i]);
-            if (disconnectRequired) curHostForEachClient[i] = hostProviderArray[i].next(0);
-            numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++;
-            hostProviderArray[i].onConnected();
-        }
-
-        for (int i = 0; i < 8; i++) {
-            assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 8));
-            assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 8));
-            numClientsPerHost[i] = 0; // prepare for next test
-        }
-        assertTrue(numClientsPerHost[8] == 0);
-
-        // remove hosts number 6 and 7 (the currently last two in the list)
-        newList = getServerAddresses((byte) 6);
-
-        for (int i = 0; i < numClients; i++) {
-            disconnectRequired = hostProviderArray[i].updateServerList(newList, curHostForEachClient[i]);
-            if (disconnectRequired) curHostForEachClient[i] = hostProviderArray[i].next(0);
-            numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++;
-            hostProviderArray[i].onConnected();
-        }
-
-        for (int i = 0; i < 6; i++) {
-            assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 6));
-            assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 6));
-            numClientsPerHost[i] = 0; // prepare for next test
-        }
-        assertTrue(numClientsPerHost[6] == 0);
-        assertTrue(numClientsPerHost[7] == 0);
-        assertTrue(numClientsPerHost[8] == 0);
-
-        // remove host number 0 (the first one in the current list)
-        // and add back hosts 6, 7 and 8
-        newList = new ArrayList<InetSocketAddress>(8);
-        for (byte i = 9; i > 1; i--) {
-            newList.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i));
-        }
-
-        for (int i = 0; i < numClients; i++) {
-            disconnectRequired = hostProviderArray[i].updateServerList(newList, curHostForEachClient[i]);
-            if (disconnectRequired) curHostForEachClient[i] = hostProviderArray[i].next(0);
-            numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++;
-            hostProviderArray[i].onConnected();
-        }
-
-        assertTrue(numClientsPerHost[0] == 0);
-
-        for (int i = 1; i < 9; i++) {
-            assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 8));
-            assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 8));
-            numClientsPerHost[i] = 0; // prepare for next test
-        }
-
-        // add back host number 0
-        newList = getServerAddresses((byte) 9);
-
-        for (int i = 0; i < numClients; i++) {
-            disconnectRequired = hostProviderArray[i].updateServerList(newList, curHostForEachClient[i]);
-            if (disconnectRequired) curHostForEachClient[i] = hostProviderArray[i].next(0);
-            numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++;
-            hostProviderArray[i].onConnected();
-        }
-
-        for (int i = 0; i < 9; i++) {
-            assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 9));
-            assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 9));
-        }
-    }
-
-    @Test
-    public void testNoCurrentHostDuringNormalMode() throws UnknownHostException {
-        // Start with 9 servers and 10000 clients
-        boolean disconnectRequired;
-        StaticHostProvider[] hostProviderArray = new StaticHostProvider[numClients];
-        InetSocketAddress[] curHostForEachClient = new InetSocketAddress[numClients];
-        int[] numClientsPerHost = new int[9];
-
-        // initialization
-        for (int i = 0; i < numClients; i++) {
-            hostProviderArray[i] = getHostProvider((byte) 9);
-            if (i >= (numClients / 2)) {
-                curHostForEachClient[i] = hostProviderArray[i].next(0);
-            } else {
-                // its supposed to be the first server on serverList.
-                // we'll set it later, see below (*)
-                curHostForEachClient[i] = null;
-            }
-        }
-
-        // remove hosts 7 and 8 (the last two in a list of 9 hosts)
-        Collection<InetSocketAddress> newList = getServerAddresses((byte) 7);
-
-        for (int i = 0; i < numClients; i++) {
-            // tests the case currentHost == null && lastIndex == -1
-            // calls next for clients with index < numClients/2
-            disconnectRequired = hostProviderArray[i].updateServerList(newList,
-                    curHostForEachClient[i]);
-            if (disconnectRequired)
-                curHostForEachClient[i] = hostProviderArray[i].next(0);
-            else if (curHostForEachClient[i] == null) {
-                // (*) setting it to what it should be
-                curHostForEachClient[i] = hostProviderArray[i]
-                        .getServerAtIndex(0);
-            }
-            numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++;
-            // sets lastIndex, resets reconfigMode
-            hostProviderArray[i].onConnected();
-        }
-
-        for (int i = 0; i < 7; i++) {
-            assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 7));
-            assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 7));
-            numClientsPerHost[i] = 0; // prepare for next test
-        }
-        assertTrue(numClientsPerHost[7] == 0);
-        assertTrue(numClientsPerHost[8] == 0);
-
-        // add back server 7
-        newList = getServerAddresses((byte) 8);
-
-        for (int i = 0; i < numClients; i++) {
-            InetSocketAddress myServer = (i < (numClients / 2)) ? null
-                    : curHostForEachClient[i];
-            // tests the case currentHost == null && lastIndex >= 0
-            disconnectRequired = hostProviderArray[i].updateServerList(newList,
-                    myServer);
-            if (disconnectRequired)
-                curHostForEachClient[i] = hostProviderArray[i].next(0);
-            numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++;
-            hostProviderArray[i].onConnected();
-        }
-
-        for (int i = 0; i < 8; i++) {
-            assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 8));
-            assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 8));
-        }
-    }
-
-    @Test
-    public void testReconfigDuringReconfigMode() throws UnknownHostException {
-        // Start with 9 servers and 10000 clients
-        boolean disconnectRequired;
-        StaticHostProvider[] hostProviderArray = new StaticHostProvider[numClients];
-        InetSocketAddress[] curHostForEachClient = new InetSocketAddress[numClients];
-        int[] numClientsPerHost = new int[9];
-
-        // initialization
-        for (int i = 0; i < numClients; i++) {
-            hostProviderArray[i] = getHostProvider((byte) 9);
-            curHostForEachClient[i] = hostProviderArray[i].next(0);
-        }
-
-        // remove hosts 7 and 8 (the last two in a list of 9 hosts)
-        Collection<InetSocketAddress> newList = getServerAddresses((byte) 7);
-
-        for (int i = 0; i < numClients; i++) {
-            // sets reconfigMode
-            hostProviderArray[i].updateServerList(newList,
-                    curHostForEachClient[i]);
-        }
-
-        // add back servers 7 and 8 while still in reconfigMode (we didn't call
-        // next)
-        newList = getServerAddresses((byte) 9);
-
-        for (int i = 0; i < numClients; i++) {
-            InetSocketAddress myServer = (i < (numClients / 2)) ? null
-                    : curHostForEachClient[i];
-            // for i < (numClients/2) this tests the case currentHost == null &&
-            // reconfigMode = true
-            // for i >= (numClients/2) this tests the case currentHost!=null &&
-            // reconfigMode = true
-            disconnectRequired = hostProviderArray[i].updateServerList(newList,
-                    myServer);
-            if (disconnectRequired)
-                curHostForEachClient[i] = hostProviderArray[i].next(0);
-            else {
-                // currentIndex was set by the call to updateServerList, which
-                // called next
-                curHostForEachClient[i] = hostProviderArray[i]
-                        .getServerAtCurrentIndex();
-            }
-            numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++;
-            hostProviderArray[i].onConnected();
-        }
-
-        for (int i = 0; i < 9; i++) {
-            assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 9));
-            assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 9));
-        }
-    }
-
-    private StaticHostProvider getHostProvider(byte size) {
-        return new StaticHostProvider(getServerAddresses(size), r.nextLong());
-    }
-
-    private Collection<InetSocketAddress> getServerAddresses(byte size)   {
-        ArrayList<InetSocketAddress> list = new ArrayList<InetSocketAddress>(
-                size);
-        while (size > 0) {
-            try {
-                list.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, size}), 1234 + size));
-            } catch (UnknownHostException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-            --size;
-        }
-        return list;
-    }
-
-    /* Reconfig test with unresolved hostnames */
-
-    /**
-     * Number of machines becomes smaller, my server is in the new cluster
-     */
-    @Test
-    public void testUpdateServerList_UnresolvedHostnames_NoDisconnection1() {
-        // Arrange
-        // [testhost-4.testdomain.com:1238, testhost-3.testdomain.com:1237, testhost-2.testdomain.com:1236, testhost-1.testdomain.com:1235]
-        HostProvider hostProvider = getHostProviderWithUnresolvedHostnames(4);
-        // [testhost-3.testdomain.com:1237, testhost-2.testdomain.com:1236, testhost-1.testdomain.com:1235]
-        Collection<InetSocketAddress> newList = getUnresolvedHostnames(3);
-        InetSocketAddress myServer = InetSocketAddress.createUnresolved("testhost-3.testdomain.com", 1237);
-
-        // Act
-        boolean disconnectRequired = hostProvider.updateServerList(newList, myServer);
-
-        // Assert
-        assertFalse(disconnectRequired);
-        hostProvider.onConnected();
-    }
-
-    /**
-     * Number of machines stayed the same, my server is in the new cluster
-     */
-    @Test
-    public void testUpdateServerList_UnresolvedHostnames_NoDisconnection2() {
-        // Arrange
-        // [testhost-3.testdomain.com:1237, testhost-2.testdomain.com:1236, testhost-1.testdomain.com:1235]
-        HostProvider hostProvider = getHostProviderWithUnresolvedHostnames(3);
-        // [testhost-3.testdomain.com:1237, testhost-2.testdomain.com:1236, testhost-1.testdomain.com:1235]
-        Collection<InetSocketAddress> newList = getUnresolvedHostnames(3);
-        InetSocketAddress myServer = InetSocketAddress.createUnresolved("testhost-3.testdomain.com", 1237);
-
-        // Act
-        boolean disconnectRequired = hostProvider.updateServerList(newList, myServer);
-
-        // Assert
-        assertFalse(disconnectRequired);
-        hostProvider.onConnected();
-    }
-
-    /**
-     * Number of machines became smaller, my server is not in the new cluster
-     */
-    @Test
-    public void testUpdateServerList_UnresolvedHostnames_Disconnection1() {
-        // Arrange
-        // [testhost-3.testdomain.com:1237, testhost-2.testdomain.com:1236, testhost-1.testdomain.com:1235]
-        HostProvider hostProvider = getHostProviderWithUnresolvedHostnames(3);
-        // [testhost-2.testdomain.com:1236, testhost-1.testdomain.com:1235]
-        Collection<InetSocketAddress> newList = getUnresolvedHostnames(2);
-        InetSocketAddress myServer = InetSocketAddress.createUnresolved("testhost-3.testdomain.com", 1237);
-
-        // Act
-        boolean disconnectRequired = hostProvider.updateServerList(newList, myServer);
-
-        // Assert
-        assertTrue(disconnectRequired);
-        hostProvider.onConnected();
-    }
-
-    /**
-     * Number of machines stayed the same, my server is not in the new cluster
-     */
-    @Test
-    public void testUpdateServerList_UnresolvedHostnames_Disconnection2() {
-        // Arrange
-        // [testhost-3.testdomain.com:1237, testhost-2.testdomain.com:1236, testhost-1.testdomain.com:1235]
-        HostProvider hostProvider = getHostProviderWithUnresolvedHostnames(3);
-        // [testhost-3.testdomain.com:1237, testhost-2.testdomain.com:1236, testhost-1.testdomain.com:1235]
-        Collection<InetSocketAddress> newList = getUnresolvedHostnames(3);
-        InetSocketAddress myServer = InetSocketAddress.createUnresolved("testhost-4.testdomain.com", 1237);
-
-        // Act
-        boolean disconnectRequired = hostProvider.updateServerList(newList, myServer);
-
-        // Assert
-        assertTrue(disconnectRequired);
-        hostProvider.onConnected();
-    }
-
-    @Test
-    public void testUpdateServerList_ResolvedWithUnResolvedAddress_ForceDisconnect() {
-        // Arrange
-        // Create a HostProvider with a list of unresolved server address(es)
-        List<InetSocketAddress> addresses = Collections.singletonList(
-                InetSocketAddress.createUnresolved("testhost-1.resolvable.zk", 1235)
-        );
-        HostProvider hostProvider = new StaticHostProvider(addresses, new TestResolver());
-        InetSocketAddress currentHost = hostProvider.next(100);
-        assertThat("CurrentHost is which the client is currently connecting to, it should be resolved",
-                currentHost.isUnresolved(), is(false));
-
-        // Act
-        InetSocketAddress replaceHost = InetSocketAddress.createUnresolved("testhost-1.resolvable.zk", 1235);
-        assertThat("Replace host must be unresolved in this test case", replaceHost.isUnresolved(), is(true));
-        boolean disconnect = hostProvider.updateServerList(new ArrayList<>(
-            Collections.singletonList(replaceHost)),
-            currentHost
-        );
-
-        // Assert
-        assertThat(disconnect, is(false));
-    }
-
-    @Test
-    public void testUpdateServerList_ResolvedWithResolvedAddress_NoDisconnect() throws UnknownHostException {
-        // Arrange
-        // Create a HostProvider with a list of unresolved server address(es)
-        List<InetSocketAddress> addresses = Collections.singletonList(
-                InetSocketAddress.createUnresolved("testhost-1.resolvable.zk", 1235)
-        );
-        HostProvider hostProvider = new StaticHostProvider(addresses, new TestResolver());
-        InetSocketAddress currentHost = hostProvider.next(100);
-        assertThat("CurrentHost is which the client is currently connecting to, it should be resolved",
-                currentHost.isUnresolved(), is(false));
-
-        // Act
-        InetSocketAddress replaceHost =
-                new InetSocketAddress(InetAddress.getByAddress(currentHost.getHostString(),
-                        currentHost.getAddress().getAddress()), currentHost.getPort());
-        assertThat("Replace host must be resolved in this test case", replaceHost.isUnresolved(), is(false));
-        boolean disconnect = hostProvider.updateServerList(new ArrayList<>(
-            Collections.singletonList(replaceHost)),
-            currentHost
-        );
-
-        // Assert
-        assertThat(disconnect, equalTo(false));
-    }
-
-    @Test
-    public void testUpdateServerList_UnResolvedWithUnResolvedAddress_ForceDisconnect() {
-        // Arrange
-        // Create a HostProvider with a list of unresolved server address(es)
-        List<InetSocketAddress> addresses = Collections.singletonList(
-                InetSocketAddress.createUnresolved("testhost-1.zookeepertest.zk", 1235)
-        );
-        HostProvider hostProvider = new StaticHostProvider(addresses, new TestResolver());
-        InetSocketAddress currentHost = hostProvider.next(100);
-        assertThat("CurrentHost is not resolvable in this test case",
-                currentHost.isUnresolved(), is(true));
-
-        // Act
-        InetSocketAddress replaceHost = InetSocketAddress.createUnresolved("testhost-1.resolvable.zk", 1235);
-        assertThat("Replace host must be unresolved in this test case", replaceHost.isUnresolved(), is(true));
-        boolean disconnect = hostProvider.updateServerList(new ArrayList<>(
-                        Collections.singletonList(replaceHost)),
-                currentHost
-        );
-
-        // Assert
-        assertThat(disconnect, is(true));
-    }
-
-    @Test
-    public void testUpdateServerList_UnResolvedWithResolvedAddress_ForceDisconnect() throws UnknownHostException {
-        // Arrange
-        // Create a HostProvider with a list of unresolved server address(es)
-        List<InetSocketAddress> addresses = Collections.singletonList(
-                InetSocketAddress.createUnresolved("testhost-1.zookeepertest.zk", 1235)
-        );
-        HostProvider hostProvider = new StaticHostProvider(addresses, new TestResolver());
-        InetSocketAddress currentHost = hostProvider.next(100);
-        assertThat("CurrentHost not resolvable in this test case",
-                currentHost.isUnresolved(), is(true));
-
-        // Act
-        byte[] addr = new byte[] { 10, 0, 0, 1 };
-        InetSocketAddress replaceHost =
-                new InetSocketAddress(InetAddress.getByAddress(currentHost.getHostString(), addr),
-                        currentHost.getPort());
-        assertThat("Replace host must be resolved in this test case", replaceHost.isUnresolved(), is(false));
-        boolean disconnect = hostProvider.updateServerList(new ArrayList<>(
-                        Collections.singletonList(replaceHost)),
-                currentHost
-        );
-
-        // Assert
-        assertThat(disconnect, equalTo(false));
-    }
-
-    private class TestResolver implements StaticHostProvider.Resolver {
-        private byte counter = 1;
-
-        @Override
-        public InetAddress[] getAllByName(String name) throws UnknownHostException {
-            if (name.contains("resolvable")) {
-                byte[] addr = new byte[] { 10, 0, 0, (byte)(counter++ % 10) };
-                return new InetAddress[] { InetAddress.getByAddress(name, addr) };
-            }
-            throw new UnknownHostException();
-        }
-    }
-
-    private double lowerboundCPS(int numClients, int numServers) {
-        return (1 - slackPercent/100.0) * numClients / numServers;
-    }
-
-    private double upperboundCPS(int numClients, int numServers) {
-        return (1 + slackPercent/100.0) * numClients / numServers;
-    }
-
-    /* DNS resolution tests */
-
-    @Test
-    public void testLiteralIPNoReverseNS() {
-        byte size = 30;
-        HostProvider hostProvider = getHostProviderUnresolved(size);
-        for (int i = 0; i < size; i++) {
-            InetSocketAddress next = hostProvider.next(0);
-            assertThat(next, instanceOf(InetSocketAddress.class));
-            assertFalse(next.isUnresolved());
-            assertTrue(next.toString().startsWith("/"));
-            // Do NOT trigger the reverse name service lookup.
-            String hostname = next.getHostString();
-            // In this case, the hostname equals literal IP address.
-            assertEquals(next.getAddress().getHostAddress(), hostname);
-        }
-    }
-
-    @Test
-    public void testReResolvingSingle() throws UnknownHostException {
-        // Arrange
-        byte size = 1;
-        ArrayList<InetSocketAddress> list = new ArrayList<InetSocketAddress>(size);
-
-        // Test a hostname that resolves to a single address
-        list.add(InetSocketAddress.createUnresolved("issues.apache.org", 1234));
-
-        final InetAddress issuesApacheOrg = mock(InetAddress.class);
-        when(issuesApacheOrg.getHostAddress()).thenReturn("192.168.1.1");
-        when(issuesApacheOrg.toString()).thenReturn("issues.apache.org");
-        when(issuesApacheOrg.getHostName()).thenReturn("issues.apache.org");
-
-        StaticHostProvider.Resolver resolver = new StaticHostProvider.Resolver() {
-            @Override
-            public InetAddress[] getAllByName(String name) {
-                return new InetAddress[] {
-                        issuesApacheOrg
-                };
-            }
-        };
-        StaticHostProvider.Resolver spyResolver = spy(resolver);
-
-        // Act
-        StaticHostProvider hostProvider = new StaticHostProvider(list, spyResolver);
-        for (int i = 0; i < 10; i++) {
-            InetSocketAddress next = hostProvider.next(0);
-            assertEquals(issuesApacheOrg, next.getAddress());
-        }
-
-        // Assert
-        // Resolver called 10 times, because we shouldn't cache the resolved addresses
-        verify(spyResolver, times(10)).getAllByName("issues.apache.org"); // resolution occurred
-    }
-
-    @Test
-    public void testReResolvingMultiple() throws UnknownHostException {
-        // Arrange
-        byte size = 1;
-        ArrayList<InetSocketAddress> list = new ArrayList<InetSocketAddress>(size);
-
-        // Test a hostname that resolves to multiple addresses
-        list.add(InetSocketAddress.createUnresolved("www.apache.org", 1234));
-
-        final InetAddress apacheOrg1 = mock(InetAddress.class);
-        when(apacheOrg1.getHostAddress()).thenReturn("192.168.1.1");
-        when(apacheOrg1.toString()).thenReturn("www.apache.org");
-        when(apacheOrg1.getHostName()).thenReturn("www.apache.org");
-
-        final InetAddress apacheOrg2 = mock(InetAddress.class);
-        when(apacheOrg2.getHostAddress()).thenReturn("192.168.1.2");
-        when(apacheOrg2.toString()).thenReturn("www.apache.org");
-        when(apacheOrg2.getHostName()).thenReturn("www.apache.org");
-
-        final List<InetAddress> resolvedAddresses = new ArrayList<InetAddress>();
-        resolvedAddresses.add(apacheOrg1);
-        resolvedAddresses.add(apacheOrg2);
-        StaticHostProvider.Resolver resolver = new StaticHostProvider.Resolver() {
-            @Override
-            public InetAddress[] getAllByName(String name) {
-                return resolvedAddresses.toArray(new InetAddress[resolvedAddresses.size()]);
-            }
-        };
-        StaticHostProvider.Resolver spyResolver = spy(resolver);
-
-        // Act & Assert
-        StaticHostProvider hostProvider = new StaticHostProvider(list, spyResolver);
-        assertEquals(1, hostProvider.size()); // single address not extracted
-
-        for (int i = 0; i < 10; i++) {
-            InetSocketAddress next = hostProvider.next(0);
-            assertThat("Bad IP address returned", next.getAddress().getHostAddress(), anyOf(equalTo(apacheOrg1.getHostAddress()), equalTo(apacheOrg2.getHostAddress())));
-            assertEquals(1, hostProvider.size()); // resolve() call keeps the size of provider
-        }
-        // Resolver called 10 times, because we shouldn't cache the resolved addresses
-        verify(spyResolver, times(10)).getAllByName("www.apache.org"); // resolution occurred
-    }
-
-    @Test
-    public void testReResolveMultipleOneFailing() throws UnknownHostException {
-        // Arrange
-        final List<InetSocketAddress> list = new ArrayList<InetSocketAddress>();
-        list.add(InetSocketAddress.createUnresolved("www.apache.org", 1234));
-        final List<String> ipList = new ArrayList<String>();
-        final List<InetAddress> resolvedAddresses = new ArrayList<InetAddress>();
-        for (int i = 0; i < 3; i++) {
-            ipList.add(String.format("192.168.1.%d", i+1));
-            final InetAddress apacheOrg = mock(InetAddress.class);
-            when(apacheOrg.getHostAddress()).thenReturn(String.format("192.168.1.%d", i+1));
-            when(apacheOrg.toString()).thenReturn(String.format("192.168.1.%d", i+1));
-            when(apacheOrg.getHostName()).thenReturn("www.apache.org");
-            resolvedAddresses.add(apacheOrg);
-        }
-
-        StaticHostProvider.Resolver resolver = new StaticHostProvider.Resolver() {
-            @Override
-            public InetAddress[] getAllByName(String name) {
-                return resolvedAddresses.toArray(new InetAddress[resolvedAddresses.size()]);
-            }
-        };
-        StaticHostProvider.Resolver spyResolver = spy(resolver);
-        StaticHostProvider hostProvider = new StaticHostProvider(list, spyResolver);
-
-        // Act & Assert
-        InetSocketAddress resolvedFirst = hostProvider.next(0);
-        assertFalse("HostProvider should return resolved addresses", resolvedFirst.isUnresolved());
-        assertThat("Bad IP address returned", ipList, hasItems(resolvedFirst.getAddress().getHostAddress()));
-
-        hostProvider.onConnected(); // first address worked
-
-        InetSocketAddress resolvedSecond = hostProvider.next(0);
-        assertFalse("HostProvider should return resolved addresses", resolvedSecond.isUnresolved());
-        assertThat("Bad IP address returned", ipList, hasItems(resolvedSecond.getAddress().getHostAddress()));
-
-        // Second address doesn't work, so we don't call onConnected() this time
-        // StaticHostProvider should try to re-resolve the address in this case
-
-        InetSocketAddress resolvedThird = hostProvider.next(0);
-        assertFalse("HostProvider should return resolved addresses", resolvedThird.isUnresolved());
-        assertThat("Bad IP address returned", ipList, hasItems(resolvedThird.getAddress().getHostAddress()));
-
-        verify(spyResolver, times(3)).getAllByName("www.apache.org");  // resolution occured every time
-    }
-
-    @Test
-    public void testEmptyResolution() throws UnknownHostException {
-        // Arrange
-        final List<InetSocketAddress> list = new ArrayList<InetSocketAddress>();
-        list.add(InetSocketAddress.createUnresolved("www.apache.org", 1234));
-        list.add(InetSocketAddress.createUnresolved("www.google.com", 1234));
-        final List<InetAddress> resolvedAddresses = new ArrayList<InetAddress>();
-
-        final InetAddress apacheOrg1 = mock(InetAddress.class);
-        when(apacheOrg1.getHostAddress()).thenReturn("192.168.1.1");
-        when(apacheOrg1.toString()).thenReturn("www.apache.org");
-        when(apacheOrg1.getHostName()).thenReturn("www.apache.org");
-
-        resolvedAddresses.add(apacheOrg1);
-
-        StaticHostProvider.Resolver resolver = new StaticHostProvider.Resolver() {
-            @Override
-            public InetAddress[] getAllByName(String name) {
-                if ("www.apache.org".equalsIgnoreCase(name)) {
-                    return resolvedAddresses.toArray(new InetAddress[resolvedAddresses.size()]);
-                } else {
-                    return new InetAddress[0];
-                }
-            }
-        };
-        StaticHostProvider.Resolver spyResolver = spy(resolver);
-        StaticHostProvider hostProvider = new StaticHostProvider(list, spyResolver);
-
-        // Act & Assert
-        for (int i = 0; i < 10; i++) {
-            InetSocketAddress resolved = hostProvider.next(0);
-            hostProvider.onConnected();
-            if (resolved.getHostName().equals("www.google.com")) {
-                assertTrue("HostProvider should return unresolved address if host is unresolvable", resolved.isUnresolved());
-            } else {
-                assertFalse("HostProvider should return resolved addresses", resolved.isUnresolved());
-                assertEquals("192.168.1.1", resolved.getAddress().getHostAddress());
-            }
-        }
-
-        verify(spyResolver, times(5)).getAllByName("www.apache.org");
-        verify(spyResolver, times(5)).getAllByName("www.google.com");
-    }
-
-    @Test
-    public void testReResolvingLocalhost() {
-        byte size = 2;
-        ArrayList<InetSocketAddress> list = new ArrayList<InetSocketAddress>(size);
-
-        // Test a hostname that resolves to multiple addresses
-        list.add(InetSocketAddress.createUnresolved("localhost", 1234));
-        list.add(InetSocketAddress.createUnresolved("localhost", 1235));
-        StaticHostProvider hostProvider = new StaticHostProvider(list);
-        int sizeBefore = hostProvider.size();
-        InetSocketAddress next = hostProvider.next(0);
-        next = hostProvider.next(0);
-        assertTrue("Different number of addresses in the list: " + hostProvider.size() +
-                " (after), " + sizeBefore + " (before)", hostProvider.size() == sizeBefore);
-    }
-
-    private StaticHostProvider getHostProviderUnresolved(byte size) {
-        return new StaticHostProvider(getUnresolvedServerAddresses(size), r.nextLong());
-    }
-
-    private Collection<InetSocketAddress> getUnresolvedServerAddresses(byte size) {
-        ArrayList<InetSocketAddress> list = new ArrayList<InetSocketAddress>(size);
-        while (size > 0) {
-            list.add(InetSocketAddress.createUnresolved("10.10.10." + size, 1234 + size));
-            --size;
-        }
-        return list;
-    }
-
-    private StaticHostProvider getHostProviderWithUnresolvedHostnames(int size) {
-        return new StaticHostProvider(getUnresolvedHostnames(size), r.nextLong());
-    }
-
-    private Collection<InetSocketAddress> getUnresolvedHostnames(int size) {
-        ArrayList<InetSocketAddress> list = new ArrayList<>(size);
-        while (size > 0) {
-            list.add(InetSocketAddress.createUnresolved(String.format("testhost-%d.testdomain.com", size), 1234 + size));
-            --size;
-        }
-        System.out.println(Arrays.toString(list.toArray()));
-        return list;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/StringUtilTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/StringUtilTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/StringUtilTest.java
deleted file mode 100644
index 29d197f..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/StringUtilTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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.zookeeper.ZKTestCase;
-import org.apache.zookeeper.common.StringUtils;
-import org.junit.Test;
-
-import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
-
-public class StringUtilTest extends ZKTestCase {
-
-    @Test
-    public void testStrings() {
-
-        String s1 = "   a  ,   b  , ";
-        assertEquals("[a, b]", StringUtils.split(s1, ",").toString());
-
-        String s2 = "";
-        assertEquals(0, StringUtils.split(s2, ",").size());
-
-        String s3 = "1, , 2";
-        assertEquals("[1, 2]", StringUtils.split(s3, ",").toString());
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/SyncCallTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/SyncCallTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/SyncCallTest.java
deleted file mode 100644
index dc7c9c5..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/SyncCallTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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 java.io.IOException;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.AsyncCallback.Children2Callback;
-import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
-import org.apache.zookeeper.AsyncCallback.Create2Callback;
-import org.apache.zookeeper.AsyncCallback.StringCallback;
-import org.apache.zookeeper.AsyncCallback.VoidCallback;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.data.Stat;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class SyncCallTest extends ClientBase
-    implements ChildrenCallback, Children2Callback,
-               StringCallback, VoidCallback, Create2Callback
-{
-    private CountDownLatch opsCount;
-    
-    List<Integer> results = new LinkedList<Integer>();
-    Integer limit = 100 + 1 + 100 + 100;
-    
-    @Test
-    public void testSync() throws Exception {
-        try {
-            LOG.info("Starting ZK:" + (new Date()).toString());
-            opsCount = new CountDownLatch(limit);
-            ZooKeeper zk = createClient();
-
-            LOG.info("Beginning test:" + (new Date()).toString());
-            for(int i = 0; i < 50; i++)
-                zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
-                          CreateMode.PERSISTENT, (StringCallback)this, results);
-
-            for(int i = 50; i < 100; i++) {
-              zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
-                        CreateMode.PERSISTENT, (Create2Callback)this, results);
-            }
-            zk.sync("/test", this, results);
-            for(int i = 0; i < 100; i++)
-                zk.delete("/test" + i, 0, this, results);
-            for(int i = 0; i < 100; i++)
-                zk.getChildren("/", new NullWatcher(), (ChildrenCallback)this,
-                        results);
-            for(int i = 0; i < 100; i++)
-                zk.getChildren("/", new NullWatcher(), (Children2Callback)this,
-                        results);
-            LOG.info("Submitted all operations:" + (new Date()).toString());
-            
-            if(!opsCount.await(10000, TimeUnit.MILLISECONDS))
-                Assert.fail("Haven't received all confirmations" + opsCount.getCount());
-
-            for(int i = 0; i < limit ; i++){
-                Assert.assertEquals(0, (int) results.get(i));
-            }
-            
-        } catch (IOException e) {
-            System.out.println(e.toString());
-        } 
-    }
-
-    @SuppressWarnings("unchecked")
-    public void processResult(int rc, String path, Object ctx,
-            List<String> children) { 
-        ((List<Integer>)ctx).add(rc);
-        opsCount.countDown();
-    }
-
-    @SuppressWarnings("unchecked")
-    public void processResult(int rc, String path, Object ctx,
-            List<String> children, Stat stat) { 
-        ((List<Integer>)ctx).add(rc);
-        opsCount.countDown();
-    }
-
-    @SuppressWarnings("unchecked")
-    public void processResult(int rc, String path, Object ctx, String name){
-        ((List<Integer>) ctx).add(rc);
-        opsCount.countDown();
-    
-    }
-
-    @SuppressWarnings("unchecked")
-    public void processResult(int rc, String path, Object ctx){
-        ((List<Integer>) ctx).add(rc);    
-        opsCount.countDown();
-    
-    }
-
-    @Override
-    public void processResult(int rc, String path, Object ctx, String name,
-        Stat stat) {
-      ((List<Integer>) ctx).add(rc);
-      opsCount.countDown();
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/TestHammer.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/TestHammer.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/TestHammer.java
deleted file mode 100644
index 3134209..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/TestHammer.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.zookeeper.CreateMode;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.AsyncCallback.VoidCallback;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.common.Time;
-
-public class TestHammer implements VoidCallback {
-
-    /**
-     * @param args
-     */
-    static int REPS = 50000;
-    public static void main(String[] args) {
-            long startTime = Time.currentElapsedTime();
-            ZooKeeper zk = null;
-            try {
-                zk = ClientBase.createZKClient(args[0], 10000);
-            } catch (Exception e1) {
-                e1.printStackTrace();
-                throw new RuntimeException(e1);
-            }
-            for(int i = 0; i < REPS; i++) {
-                try {
-                    String name = zk.create("/testFile-", new byte[16], Ids.OPEN_ACL_UNSAFE,
-                        CreateMode.EPHEMERAL_SEQUENTIAL);
-                    zk.delete(name, -1, new TestHammer(), null);
-                } catch(Exception e) {
-                    i--;
-                    e.printStackTrace();
-                }
-            }
-            System.out.println("creates/sec=" + (REPS*1000/(Time.currentElapsedTime()-startTime)));
-    }
-
-    public void processResult(int rc, String path, Object ctx) {
-        // TODO Auto-generated method stub
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/cb9f303b/zookeeper-common/src/test/java/org/apache/zookeeper/test/TestUtils.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/TestUtils.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/TestUtils.java
deleted file mode 100644
index 95f02ee..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/TestUtils.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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 java.io.File;
-
-import org.junit.Assert;
-
-/**
- * This class contains test utility methods
- */
-public class TestUtils {
-
-    /**
-     * deletes a folder recursively
-     * 
-     * @param file
-     *            folder to be deleted
-     * @param failOnError
-     *            if true file deletion success is ensured
-     */
-    public static boolean deleteFileRecursively(File file,
-            final boolean failOnError) {
-        if (file != null) {
-            if (file.isDirectory()) {
-                File[] files = file.listFiles();
-                int size = files.length;
-                for (int i = 0; i < size; i++) {
-                    File f = files[i];
-                    boolean deleted = deleteFileRecursively(files[i], failOnError);
-                    if(!deleted && failOnError)
-                    {
-                        Assert.fail("file '" + f.getAbsolutePath()+"' deletion failed");
-                    }
-                }
-            }
-            return file.delete();
-        }
-        return true;
-    }
-
-    public static boolean deleteFileRecursively(File file) {
-        return deleteFileRecursively(file, false);
-    }
-}


Mime
View raw message