zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject [13/51] [partial] zookeeper git commit: ZOOKEEPER-3032: MAVEN MIGRATION - branch-3.5 - move java server, client
Date Fri, 05 Oct 2018 13:36:41 GMT
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/CRCTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/CRCTest.java b/src/java/test/org/apache/zookeeper/server/CRCTest.java
deleted file mode 100644
index da4ebaf..0000000
--- a/src/java/test/org/apache/zookeeper/server/CRCTest.java
+++ /dev/null
@@ -1,175 +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.server;
-
-import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.zip.Adler32;
-import java.util.zip.CheckedInputStream;
-
-import org.apache.jute.BinaryInputArchive;
-import org.apache.jute.InputArchive;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.server.persistence.FileSnap;
-import org.apache.zookeeper.server.persistence.FileTxnLog;
-import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator;
-import org.apache.zookeeper.test.ClientBase;
-import org.junit.Assert;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class CRCTest extends ZKTestCase{
-    private static final Logger LOG = LoggerFactory.getLogger(CRCTest.class);
-
-    private static final String HOSTPORT =
-        "127.0.0.1:" + PortAssignment.unique();
-    /**
-     * corrupt a file by writing m at 500 b
-     * offset
-     * @param file the file to be corrupted
-     * @throws IOException
-     */
-    private void corruptFile(File file) throws IOException {
-        // corrupt the logfile
-        RandomAccessFile raf  = new RandomAccessFile(file, "rw");
-        byte[] b = "mahadev".getBytes();
-        long writeLen = 500L;
-        raf.seek(writeLen);
-        //corrupting the data
-        raf.write(b);
-        raf.close();
-    }
-
-    /** return if checksum matches for a snapshot **/
-    private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
-        DataTree dt = new DataTree();
-        Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
-        InputStream snapIS = new BufferedInputStream(new FileInputStream(
-                snapFile));
-        CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
-        InputArchive ia = BinaryInputArchive.getArchive(crcIn);
-        try {
-            snap.deserialize(dt, sessions, ia);
-        } catch (IOException ie) {
-            // we failed on the most recent snapshot
-            // must be incomplete
-            // try reading the next one
-            // after corrupting
-            snapIS.close();
-            crcIn.close();
-            throw ie;
-        }
-
-        long checksum = crcIn.getChecksum().getValue();
-        long val = ia.readLong("val");
-        snapIS.close();
-        crcIn.close();
-        return (val != checksum);
-    }
-
-    /** test checksums for the logs and snapshots.
-     * the reader should fail on reading
-     * a corrupt snapshot and a corrupt log
-     * file
-     * @throws Exception
-     */
-    @Test
-    public void testChecksums() throws Exception {
-        File tmpDir = ClientBase.createTmpDir();
-        ClientBase.setupTestEnv();
-        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
-        SyncRequestProcessor.setSnapCount(150);
-        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
-        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
-        f.startup(zks);
-        LOG.info("starting up the zookeeper server .. waiting");
-        Assert.assertTrue("waiting for server being up",
-                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
-        ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
-        try {
-            for (int i =0; i < 2000; i++) {
-                zk.create("/crctest- " + i , ("/crctest- " + i).getBytes(),
-                        Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-            }
-        } finally {
-            zk.close();
-        }
-        f.shutdown();
-        zks.shutdown();
-        Assert.assertTrue("waiting for server down",
-                   ClientBase.waitForServerDown(HOSTPORT,
-                           ClientBase.CONNECTION_TIMEOUT));
-
-        File versionDir = new File(tmpDir, "version-2");
-        File[] list = versionDir.listFiles();
-        //there should be only two files
-        // one the snapshot and the other logFile
-        File snapFile = null;
-        File logFile = null;
-        for (File file: list) {
-            LOG.info("file is " + file);
-            if (file.getName().startsWith("log")) {
-                logFile = file;
-                corruptFile(logFile);
-            }
-        }
-        FileTxnLog flog = new FileTxnLog(versionDir);
-        TxnIterator itr = flog.read(1);
-        //we will get a checksum failure
-        try {
-            while (itr.next()) {
-            }
-            Assert.assertTrue(false);
-        } catch(IOException ie) {
-            LOG.info("crc corruption", ie);
-        }
-        itr.close();
-        // find the last snapshot
-        FileSnap snap = new FileSnap(versionDir);
-        List<File> snapFiles = snap.findNRecentSnapshots(2);
-        snapFile = snapFiles.get(0);
-        corruptFile(snapFile);
-        boolean cfile = false;
-        try {
-            cfile = getCheckSum(snap, snapFile);
-        } catch(IOException ie) {
-            //the last snapshot seems incompelte
-            // corrupt the last but one
-            // and use that
-            snapFile = snapFiles.get(1);
-            corruptFile(snapFile);
-            cfile = getCheckSum(snap, snapFile);
-        }
-        Assert.assertTrue(cfile);
-   }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/CreateContainerTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/CreateContainerTest.java b/src/java/test/org/apache/zookeeper/server/CreateContainerTest.java
deleted file mode 100644
index 4889684..0000000
--- a/src/java/test/org/apache/zookeeper/server/CreateContainerTest.java
+++ /dev/null
@@ -1,281 +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.server;
-
-import org.apache.zookeeper.*;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.test.ClientBase;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.*;
-
-public class CreateContainerTest 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();
-    }
-
-    @Test(timeout = 30000)
-    public void testCreate()
-            throws KeeperException, InterruptedException {
-        createNoStatVerifyResult("/foo");
-        createNoStatVerifyResult("/foo/child");
-    }
-
-    @Test(timeout = 30000)
-    public void testCreateWithStat()
-            throws KeeperException, InterruptedException {
-        Stat stat = createWithStatVerifyResult("/foo");
-        Stat childStat = createWithStatVerifyResult("/foo/child");
-        // Don't expect to get the same stats for different creates.
-        Assert.assertFalse(stat.equals(childStat));
-    }
-
-    @SuppressWarnings("ConstantConditions")
-    @Test(timeout = 30000)
-    public void testCreateWithNullStat()
-            throws KeeperException, InterruptedException {
-        final String name = "/foo";
-        Assert.assertNull(zk.exists(name, false));
-
-        Stat stat = null;
-        // If a null Stat object is passed the create should still
-        // succeed, but no Stat info will be returned.
-        zk.create(name, name.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, stat);
-        Assert.assertNull(stat);
-        Assert.assertNotNull(zk.exists(name, false));
-    }
-
-    @Test(timeout = 30000)
-    public void testSimpleDeletion()
-            throws KeeperException, InterruptedException {
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER);
-        zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        zk.delete("/foo/bar", -1);  // should cause "/foo" to get deleted when checkContainers() is called
-
-        ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer()
-                .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100);
-        containerManager.checkContainers();
-
-        Thread.sleep(1000);
-
-        Assert.assertNull("Container should have been deleted", zk.exists("/foo", false));
-    }
-
-    @Test(timeout = 30000)
-    public void testMultiWithContainerSimple()
-            throws KeeperException, InterruptedException {
-        Op createContainer = Op.create("/foo", new byte[0],
-                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER);
-        zk.multi(Collections.singletonList(createContainer));
-
-        DataTree dataTree = serverFactory.getZooKeeperServer().getZKDatabase().getDataTree();
-        Assert.assertEquals(dataTree.getContainers().size(), 1);
-    }
-
-    @Test(timeout = 30000)
-    public void testMultiWithContainer()
-            throws KeeperException, InterruptedException {
-        Op createContainer = Op.create("/foo", new byte[0],
-                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER);
-        Op createChild = Op.create("/foo/bar", new byte[0],
-                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        zk.multi(Arrays.asList(createContainer, createChild));
-
-        DataTree dataTree = serverFactory.getZooKeeperServer().getZKDatabase().getDataTree();
-        Assert.assertEquals(dataTree.getContainers().size(), 1);
-
-        zk.delete("/foo/bar", -1);  // should cause "/foo" to get deleted when checkContainers() is called
-
-        ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer()
-                .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100);
-        containerManager.checkContainers();
-
-        Thread.sleep(1000);
-
-        Assert.assertNull("Container should have been deleted", zk.exists("/foo", false));
-
-        createContainer = Op.create("/foo", new byte[0],
-                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER);
-        createChild = Op.create("/foo/bar", new byte[0],
-                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        Op deleteChild = Op.delete("/foo/bar", -1);
-        zk.multi(Arrays.asList(createContainer, createChild, deleteChild));
-
-        containerManager.checkContainers();
-
-        Thread.sleep(1000);
-
-        Assert.assertNull("Container should have been deleted", zk.exists("/foo", false));
-    }
-
-    @Test(timeout = 30000)
-    public void testSimpleDeletionAsync()
-            throws KeeperException, InterruptedException {
-        final CountDownLatch latch = new CountDownLatch(1);
-        AsyncCallback.Create2Callback cb = new AsyncCallback.Create2Callback() {
-            @Override
-            public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
-                Assert.assertEquals(ctx, "context");
-                latch.countDown();
-            }
-        };
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, cb, "context");
-        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
-        zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        zk.delete("/foo/bar", -1);  // should cause "/foo" to get deleted when checkContainers() is called
-
-        ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer()
-                .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100);
-        containerManager.checkContainers();
-
-        Thread.sleep(1000);
-
-        Assert.assertNull("Container should have been deleted", zk.exists("/foo", false));
-    }
-
-    @Test(timeout = 30000)
-    public void testCascadingDeletion()
-            throws KeeperException, InterruptedException {
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER);
-        zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER);
-        zk.create("/foo/bar/one", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        zk.delete("/foo/bar/one", -1);  // should cause "/foo/bar" and "/foo" to get deleted when checkContainers() is called
-
-        ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer()
-                .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100);
-        containerManager.checkContainers();
-        Thread.sleep(1000);
-        containerManager
-                .checkContainers();
-        Thread.sleep(1000);
-
-        Assert.assertNull("Container should have been deleted", zk.exists("/foo/bar", false));
-        Assert.assertNull("Container should have been deleted", zk.exists("/foo", false));
-    }
-
-    @Test(timeout = 30000)
-    public void testFalseEmpty()
-            throws KeeperException, InterruptedException {
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER);
-        zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
-        ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer()
-                .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100) {
-            @Override
-            protected Collection<String> getCandidates() {
-                return Collections.singletonList("/foo");
-            }
-        };
-        containerManager.checkContainers();
-        Thread.sleep(1000);
-
-        Assert.assertNotNull("Container should have not been deleted", zk.exists("/foo", false));
-    }
-
-    @Test(timeout = 30000)
-    public void testMaxPerMinute()
-            throws InterruptedException {
-        final BlockingQueue<String> queue = new LinkedBlockingQueue<String>();
-        RequestProcessor processor = new RequestProcessor() {
-            @Override
-            public void processRequest(Request request) {
-                queue.add(new String(request.request.array()));
-            }
-
-            @Override
-            public void shutdown() {
-            }
-        };
-        final ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer()
-                .getZKDatabase(), processor, 1, 2) {
-            @Override
-            protected long getMinIntervalMs() {
-                return 1000;
-            }
-
-            @Override
-            protected Collection<String> getCandidates() {
-                return Arrays.asList("/one", "/two", "/three", "/four");
-            }
-        };
-        Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
-            @Override
-            public Void call() throws Exception {
-                containerManager.checkContainers();
-                return null;
-            }
-        });
-        Assert.assertEquals(queue.poll(5, TimeUnit.SECONDS), "/one");
-        Assert.assertEquals(queue.poll(5, TimeUnit.SECONDS), "/two");
-        Assert.assertEquals(queue.size(), 0);
-        Thread.sleep(500);
-        Assert.assertEquals(queue.size(), 0);
-
-        Assert.assertEquals(queue.poll(5, TimeUnit.SECONDS), "/three");
-        Assert.assertEquals(queue.poll(5, TimeUnit.SECONDS), "/four");
-    }
-
-    private void createNoStatVerifyResult(String newName)
-            throws KeeperException, InterruptedException {
-        Assert.assertNull("Node existed before created", zk.exists(newName, false));
-        zk.create(newName, newName.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER);
-        Assert.assertNotNull("Node was not created as expected",
-                zk.exists(newName, false));
-    }
-
-    private Stat createWithStatVerifyResult(String newName)
-            throws KeeperException, InterruptedException {
-        Assert.assertNull("Node existed before created", zk.exists(newName, false));
-        Stat stat = new Stat();
-        zk.create(newName, newName.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, stat);
-        validateCreateStat(stat, newName);
-
-        Stat referenceStat = zk.exists(newName, false);
-        Assert.assertNotNull("Node was not created as expected", referenceStat);
-        Assert.assertEquals(referenceStat, stat);
-
-        return stat;
-    }
-
-    private void validateCreateStat(Stat stat, String name) {
-        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());
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/CreateTTLTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/CreateTTLTest.java b/src/java/test/org/apache/zookeeper/server/CreateTTLTest.java
deleted file mode 100644
index 2440030..0000000
--- a/src/java/test/org/apache/zookeeper/server/CreateTTLTest.java
+++ /dev/null
@@ -1,267 +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.server;
-
-import org.apache.zookeeper.AsyncCallback;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.Op;
-import org.apache.zookeeper.OpResult;
-import org.apache.zookeeper.TestableZooKeeper;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.proto.CreateResponse;
-import org.apache.zookeeper.proto.CreateTTLRequest;
-import org.apache.zookeeper.proto.ReplyHeader;
-import org.apache.zookeeper.proto.RequestHeader;
-import org.apache.zookeeper.test.ClientBase;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
-public class CreateTTLTest extends ClientBase {
-    private TestableZooKeeper zk;
-
-    private static final Collection<String> disabledTests = Collections.singleton("testDisabled");
-
-    @Override
-    public void setUp() throws Exception {
-        System.setProperty(EphemeralType.EXTENDED_TYPES_ENABLED_PROPERTY, disabledTests.contains(getTestName()) ? "false" : "true");
-        super.setUpWithServerId(254);
-        zk = createClient();
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        System.clearProperty(EphemeralType.EXTENDED_TYPES_ENABLED_PROPERTY);
-        super.tearDown();
-        zk.close();
-    }
-
-    @Test
-    public void testCreate()
-            throws KeeperException, InterruptedException {
-        Stat stat = new Stat();
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100);
-        Assert.assertEquals(0, stat.getEphemeralOwner());
-
-        final AtomicLong fakeElapsed = new AtomicLong(0);
-        ContainerManager containerManager = newContainerManager(fakeElapsed);
-        containerManager.checkContainers();
-        Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
-
-        fakeElapsed.set(1000);
-        containerManager.checkContainers();
-        Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false));
-    }
-
-    @Test
-    public void testBadTTLs() throws InterruptedException, KeeperException {
-        RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.createTTL);
-
-        String path = "/bad_ttl";
-        CreateTTLRequest request = new CreateTTLRequest(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
-                                                        CreateMode.PERSISTENT_WITH_TTL.toFlag(), -100);
-        CreateResponse response = new CreateResponse();
-        ReplyHeader r = zk.submitRequest(h, request, response, null);
-        Assert.assertEquals("An invalid CreateTTLRequest should throw BadArguments",
-                            r.getErr(), Code.BADARGUMENTS.intValue());
-        Assert.assertNull("An invalid CreateTTLRequest should not result in znode creation",
-                          zk.exists(path, false));
-
-        request = new CreateTTLRequest(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
-                CreateMode.PERSISTENT_WITH_TTL.toFlag(), EphemeralType.TTL.maxValue() + 1);
-        response = new CreateResponse();
-        r = zk.submitRequest(h, request, response, null);
-        Assert.assertEquals("An invalid CreateTTLRequest should throw BadArguments",
-                r.getErr(), Code.BADARGUMENTS.intValue());
-        Assert.assertNull("An invalid CreateTTLRequest should not result in znode creation",
-                zk.exists(path, false));
-    }
-
-    @Test
-    public void testMaxTTLs() throws InterruptedException, KeeperException {
-        RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.createTTL);
-
-        String path = "/bad_ttl";
-        CreateTTLRequest request = new CreateTTLRequest(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
-                                                        CreateMode.PERSISTENT_WITH_TTL.toFlag(), EphemeralType.TTL.maxValue());
-        CreateResponse response = new CreateResponse();
-        ReplyHeader r = zk.submitRequest(h, request, response, null);
-        Assert.assertEquals("EphemeralType.getMaxTTL() should succeed",
-                            r.getErr(), Code.OK.intValue());
-        Assert.assertNotNull("Node should exist",
-                          zk.exists(path, false));
-    }
-
-    @Test
-    public void testCreateSequential()
-            throws KeeperException, InterruptedException {
-        Stat stat = new Stat();
-        String path = zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, stat, 100);
-        Assert.assertEquals(0, stat.getEphemeralOwner());
-
-        final AtomicLong fakeElapsed = new AtomicLong(0);
-        ContainerManager containerManager = newContainerManager(fakeElapsed);
-        containerManager.checkContainers();
-        Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists(path, false));
-
-        fakeElapsed.set(1000);
-        containerManager.checkContainers();
-        Assert.assertNull("Ttl node should have been deleted", zk.exists(path, false));
-    }
-
-    @Test
-    public void testCreateAsync()
-            throws KeeperException, InterruptedException {
-        AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback() {
-            @Override
-            public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
-                // NOP
-            }
-        };
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, callback, null, 100);
-
-        final AtomicLong fakeElapsed = new AtomicLong(0);
-        ContainerManager containerManager = newContainerManager(fakeElapsed);
-        containerManager.checkContainers();
-        Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
-
-        fakeElapsed.set(1000);
-        containerManager.checkContainers();
-        Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false));
-    }
-
-    @Test
-    public void testModifying()
-            throws KeeperException, InterruptedException {
-        Stat stat = new Stat();
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100);
-        Assert.assertEquals(0, stat.getEphemeralOwner());
-
-        final AtomicLong fakeElapsed = new AtomicLong(0);
-        ContainerManager containerManager = newContainerManager(fakeElapsed);
-        containerManager.checkContainers();
-        Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
-
-        for ( int i = 0; i < 10; ++i ) {
-            fakeElapsed.set(50);
-            zk.setData("/foo", new byte[i + 1], -1);
-            containerManager.checkContainers();
-            Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
-        }
-
-        fakeElapsed.set(200);
-        containerManager.checkContainers();
-        Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false));
-    }
-
-    @Test
-    public void testMulti()
-            throws KeeperException, InterruptedException {
-        Op createTtl = Op.create("/a", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, 100);
-        Op createTtlSequential = Op.create("/b", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, 200);
-        Op createNonTtl = Op.create("/c", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-        List<OpResult> results = zk.multi(Arrays.asList(createTtl, createTtlSequential, createNonTtl));
-        String sequentialPath = ((OpResult.CreateResult)results.get(1)).getPath();
-
-        final AtomicLong fakeElapsed = new AtomicLong(0);
-        ContainerManager containerManager = newContainerManager(fakeElapsed);
-        containerManager.checkContainers();
-        Assert.assertNotNull("node should not have been deleted yet", zk.exists("/a", false));
-        Assert.assertNotNull("node should not have been deleted yet", zk.exists(sequentialPath, false));
-        Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));
-
-        fakeElapsed.set(110);
-        containerManager.checkContainers();
-        Assert.assertNull("node should have been deleted", zk.exists("/a", false));
-        Assert.assertNotNull("node should not have been deleted yet", zk.exists(sequentialPath, false));
-        Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));
-
-        fakeElapsed.set(210);
-        containerManager.checkContainers();
-        Assert.assertNull("node should have been deleted", zk.exists("/a", false));
-        Assert.assertNull("node should have been deleted", zk.exists(sequentialPath, false));
-        Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));
-    }
-
-    @Test
-    public void testBadUsage() throws KeeperException, InterruptedException {
-        for ( CreateMode createMode : CreateMode.values() ) {
-            try {
-                zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode, new Stat(), createMode.isTTL() ? 0 : 100);
-                Assert.fail("should have thrown IllegalArgumentException");
-            } catch (IllegalArgumentException dummy) {
-                // correct
-            }
-        }
-
-        for ( CreateMode createMode : CreateMode.values() ) {
-            AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback() {
-                @Override
-                public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
-                    // NOP
-                }
-            };
-            try {
-                zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode, callback, null, createMode.isTTL() ? 0 : 100);
-                Assert.fail("should have thrown IllegalArgumentException");
-            } catch (IllegalArgumentException dummy) {
-                // correct
-            }
-        }
-
-        try {
-            Op op = Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, 0);
-            zk.multi(Collections.singleton(op));
-            Assert.fail("should have thrown IllegalArgumentException");
-        } catch (IllegalArgumentException dummy) {
-            // correct
-        }
-        try {
-            Op op = Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, 0);
-            zk.multi(Collections.singleton(op));
-            Assert.fail("should have thrown IllegalArgumentException");
-        } catch (IllegalArgumentException dummy) {
-            // correct
-        }
-    }
-
-    @Test(expected = KeeperException.UnimplementedException.class)
-    public void testDisabled() throws KeeperException, InterruptedException {
-        // note, setUp() enables this test based on the test name
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, new Stat(), 100);
-    }
-
-    private ContainerManager newContainerManager(final AtomicLong fakeElapsed) {
-        return new ContainerManager(serverFactory.getZooKeeperServer()
-                .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100) {
-            @Override
-            protected long getElapsed(DataNode node) {
-                return fakeElapsed.get();
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/DataNodeTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/DataNodeTest.java b/src/java/test/org/apache/zookeeper/server/DataNodeTest.java
deleted file mode 100644
index 6289766..0000000
--- a/src/java/test/org/apache/zookeeper/server/DataNodeTest.java
+++ /dev/null
@@ -1,65 +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.server;
-
-import static org.junit.Assert.*;
-
-import java.util.Set;
-
-import org.junit.Test;
-
-public class DataNodeTest {
-
-    @Test
-    public void testGetChildrenShouldReturnEmptySetWhenThereAreNoChidren() {
-        // create DataNode and call getChildren
-        DataNode dataNode = new DataNode();
-        Set<String> children = dataNode.getChildren();
-        assertNotNull(children);
-        assertEquals(0, children.size());
-
-        // add child,remove child and then call getChildren
-        String child = "child";
-        dataNode.addChild(child);
-        dataNode.removeChild(child);
-        children = dataNode.getChildren();
-        assertNotNull(children);
-        assertEquals(0, children.size());
-
-        // Returned empty set must not be modifiable
-        children = dataNode.getChildren();
-        try {
-            children.add("new child");
-            fail("UnsupportedOperationException is expected");
-        } catch (UnsupportedOperationException e) {
-            // do nothing
-        }
-    }
-
-    @Test
-    public void testGetChildrenReturnsImmutableEmptySet() {
-        DataNode dataNode = new DataNode();
-        Set<String> children = dataNode.getChildren();
-        try {
-            children.add("new child");
-            fail("UnsupportedOperationException is expected");
-        } catch (UnsupportedOperationException e) {
-            // do nothing
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/DataTreeTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/DataTreeTest.java b/src/java/test/org/apache/zookeeper/server/DataTreeTest.java
deleted file mode 100644
index 57497ce..0000000
--- a/src/java/test/org/apache/zookeeper/server/DataTreeTest.java
+++ /dev/null
@@ -1,284 +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.server;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.apache.zookeeper.KeeperException.NodeExistsException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.data.ACL;
-import org.apache.zookeeper.data.Stat;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.apache.zookeeper.Quotas;
-import org.apache.jute.BinaryInputArchive;
-import org.apache.jute.BinaryOutputArchive;
-import org.apache.jute.Record;
-import org.apache.zookeeper.common.PathTrie;
-import java.lang.reflect.*;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.List;
-import java.util.ArrayList;
-
-public class DataTreeTest extends ZKTestCase {
-    protected static final Logger LOG = LoggerFactory.getLogger(DataTreeTest.class);
-
-    private DataTree dt;
-
-    @Before
-    public void setUp() throws Exception {
-        dt=new DataTree();
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        dt=null;
-    }
-
-    /**
-     * For ZOOKEEPER-1755 - Test race condition when taking dumpEphemerals and
-     * removing the session related ephemerals from DataTree structure
-     */
-    @Test(timeout = 60000)
-    public void testDumpEphemerals() throws Exception {
-        int count = 1000;
-        long session = 1000;
-        long zxid = 2000;
-        final DataTree dataTree = new DataTree();
-        LOG.info("Create {} zkclient sessions and its ephemeral nodes", count);
-        createEphemeralNode(session, dataTree, count);
-        final AtomicBoolean exceptionDuringDumpEphemerals = new AtomicBoolean(
-                false);
-        final AtomicBoolean running = new AtomicBoolean(true);
-        Thread thread = new Thread() {
-            public void run() {
-                PrintWriter pwriter = new PrintWriter(new StringWriter());
-                try {
-                    while (running.get()) {
-                        dataTree.dumpEphemerals(pwriter);
-                    }
-                } catch (Exception e) {
-                    LOG.error("Received exception while dumpEphemerals!", e);
-                    exceptionDuringDumpEphemerals.set(true);
-                }
-            };
-        };
-        thread.start();
-        LOG.debug("Killing {} zkclient sessions and its ephemeral nodes", count);
-        killZkClientSession(session, zxid, dataTree, count);
-        running.set(false);
-        thread.join();
-        Assert.assertFalse("Should have got exception while dumpEphemerals!",
-                exceptionDuringDumpEphemerals.get());
-    }
-
-    private void killZkClientSession(long session, long zxid,
-            final DataTree dataTree, int count) {
-        for (int i = 0; i < count; i++) {
-            dataTree.killSession(session + i, zxid);
-        }
-    }
-
-    private void createEphemeralNode(long session, final DataTree dataTree,
-            int count) throws NoNodeException, NodeExistsException {
-        for (int i = 0; i < count; i++) {
-            dataTree.createNode("/test" + i, new byte[0], null, session + i,
-                    dataTree.getNode("/").stat.getCversion() + 1, 1, 1);
-        }
-    }
-
-    @Test(timeout = 60000)
-    public void testRootWatchTriggered() throws Exception {
-        class MyWatcher implements Watcher{
-            boolean fired=false;
-            public void process(WatchedEvent event) {
-                if(event.getPath().equals("/"))
-                    fired=true;
-            }
-        }
-        MyWatcher watcher=new MyWatcher();
-        // set a watch on the root node
-        dt.getChildren("/", new Stat(), watcher);
-        // add a new node, should trigger a watch
-        dt.createNode("/xyz", new byte[0], null, 0, dt.getNode("/").stat.getCversion()+1, 1, 1);
-        Assert.assertFalse("Root node watch not triggered",!watcher.fired);
-    }
-
-    /**
-     * For ZOOKEEPER-1046 test if cversion is getting incremented correctly.
-     */
-    @Test(timeout = 60000)
-    public void testIncrementCversion() throws Exception {
-        dt.createNode("/test", new byte[0], null, 0, dt.getNode("/").stat.getCversion()+1, 1, 1);
-        DataNode zk = dt.getNode("/test");
-        int prevCversion = zk.stat.getCversion();
-        long prevPzxid = zk.stat.getPzxid();
-        dt.setCversionPzxid("/test/",  prevCversion + 1, prevPzxid + 1);
-        int newCversion = zk.stat.getCversion();
-        long newPzxid = zk.stat.getPzxid();
-        Assert.assertTrue("<cversion, pzxid> verification failed. Expected: <" +
-                (prevCversion + 1) + ", " + (prevPzxid + 1) + ">, found: <" +
-                newCversion + ", " + newPzxid + ">",
-                (newCversion == prevCversion + 1 && newPzxid == prevPzxid + 1));
-    }
-
-    @Test(timeout = 60000)
-    public void testPathTrieClearOnDeserialize() throws Exception {
-
-        //Create a DataTree with quota nodes so PathTrie get updated
-        DataTree dserTree = new DataTree();
-
-        dserTree.createNode("/bug", new byte[20], null, -1, 1, 1, 1);
-        dserTree.createNode(Quotas.quotaZookeeper+"/bug", null, null, -1, 1, 1, 1);
-        dserTree.createNode(Quotas.quotaPath("/bug"), new byte[20], null, -1, 1, 1, 1);
-        dserTree.createNode(Quotas.statPath("/bug"), new byte[20], null, -1, 1, 1, 1);
-
-        //deserialize a DataTree; this should clear the old /bug nodes and pathTrie
-        DataTree tree = new DataTree();
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
-        tree.serialize(oa, "test");
-        baos.flush();
-
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        BinaryInputArchive ia = BinaryInputArchive.getArchive(bais);
-        dserTree.deserialize(ia, "test");
-
-        Field pfield = DataTree.class.getDeclaredField("pTrie");
-        pfield.setAccessible(true);
-        PathTrie pTrie = (PathTrie)pfield.get(dserTree);
-
-        //Check that the node path is removed from pTrie
-        Assert.assertEquals("/bug is still in pTrie", "", pTrie.findMaxPrefix("/bug"));
-    }
-
-    /*
-     * ZOOKEEPER-2201 - OutputArchive.writeRecord can block for long periods of
-     * time, we must call it outside of the node lock.
-     * We call tree.serialize, which calls our modified writeRecord method that
-     * blocks until it can verify that a separate thread can lock the DataNode
-     * currently being written, i.e. that DataTree.serializeNode does not hold
-     * the DataNode lock while calling OutputArchive.writeRecord.
-     */
-    @Test(timeout = 60000)
-    public void testSerializeDoesntLockDataNodeWhileWriting() throws Exception {
-        DataTree tree = new DataTree();
-        tree.createNode("/marker", new byte[] {42}, null, -1, 1, 1, 1);
-        final DataNode markerNode = tree.getNode("/marker");
-        final AtomicBoolean ranTestCase = new AtomicBoolean();
-        DataOutputStream out = new DataOutputStream(new ByteArrayOutputStream());
-        BinaryOutputArchive oa = new BinaryOutputArchive(out) {
-            @Override
-            public void writeRecord(Record r, String tag) throws IOException {
-                // Need check if the record is a DataNode instance because of changes in ZOOKEEPER-2014
-                // which adds default ACL to config node.
-                if (r instanceof DataNode) {
-                    DataNode node = (DataNode) r;
-                    if (node.data.length == 1 && node.data[0] == 42) {
-                        final Semaphore semaphore = new Semaphore(0);
-                        new Thread(new Runnable() {
-                            @Override
-                            public void run() {
-                                synchronized (markerNode) {
-                                    //When we lock markerNode, allow writeRecord to continue
-                                    semaphore.release();
-                                }
-                            }
-                        }).start();
-
-                        try {
-                            boolean acquired = semaphore.tryAcquire(30, TimeUnit.SECONDS);
-                            //This is the real assertion - could another thread lock
-                            //the DataNode we're currently writing
-                            Assert.assertTrue("Couldn't acquire a lock on the DataNode while we were calling tree.serialize", acquired);
-                        } catch (InterruptedException e1) {
-                            throw new RuntimeException(e1);
-                        }
-                        ranTestCase.set(true);
-                    }
-                }
-
-                super.writeRecord(r, tag);
-            }
-        };
-
-        tree.serialize(oa, "test");
-
-        //Let's make sure that we hit the code that ran the real assertion above
-        Assert.assertTrue("Didn't find the expected node", ranTestCase.get());
-    }
-
-    @Test(timeout = 60000)
-    public void testReconfigACLClearOnDeserialize() throws Exception {
-
-        DataTree tree = new DataTree();
-        // simulate the upgrading scenario, where the reconfig znode
-        // doesn't exist and the acl cache is empty
-        tree.deleteNode(ZooDefs.CONFIG_NODE, 1);
-        tree.getReferenceCountedAclCache().aclIndex = 0;
-
-        Assert.assertEquals(
-            "expected to have 1 acl in acl cache map", 0, tree.aclCacheSize());
-
-        // serialize the data with one znode with acl
-        tree.createNode(
-            "/bug", new byte[20], ZooDefs.Ids.OPEN_ACL_UNSAFE, -1, 1, 1, 1);
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
-        tree.serialize(oa, "test");
-        baos.flush();
-
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        BinaryInputArchive ia = BinaryInputArchive.getArchive(bais);
-        tree.deserialize(ia, "test");
-
-        Assert.assertEquals(
-            "expected to have 1 acl in acl cache map", 1, tree.aclCacheSize());
-        Assert.assertEquals(
-            "expected to have the same acl", ZooDefs.Ids.OPEN_ACL_UNSAFE,
-            tree.getACL("/bug", new Stat()));
-
-        // simulate the upgrading case where the config node will be created
-        // again after leader election
-        tree.addConfigNode();
-
-        Assert.assertEquals(
-            "expected to have 2 acl in acl cache map", 2, tree.aclCacheSize());
-        Assert.assertEquals(
-            "expected to have the same acl", ZooDefs.Ids.OPEN_ACL_UNSAFE,
-            tree.getACL("/bug", new Stat()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/DatadirCleanupManagerTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/DatadirCleanupManagerTest.java b/src/java/test/org/apache/zookeeper/server/DatadirCleanupManagerTest.java
deleted file mode 100644
index 9d93013..0000000
--- a/src/java/test/org/apache/zookeeper/server/DatadirCleanupManagerTest.java
+++ /dev/null
@@ -1,92 +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.server;
-
-import static org.apache.zookeeper.server.DatadirCleanupManager.PurgeTaskStatus.COMPLETED;
-import static org.apache.zookeeper.server.DatadirCleanupManager.PurgeTaskStatus.NOT_STARTED;
-import static org.apache.zookeeper.server.DatadirCleanupManager.PurgeTaskStatus.STARTED;
-
-import java.io.File;
-
-
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.test.ClientBase;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class DatadirCleanupManagerTest extends ZKTestCase {
-
-    private DatadirCleanupManager purgeMgr;
-    private File snapDir;
-    private File dataLogDir;
-
-    @Before
-    public void setUp() throws Exception {
-        File dataDir = ClientBase.createTmpDir();
-        snapDir = dataDir;
-        dataLogDir = dataDir;
-    }
-
-    @Test
-    public void testPurgeTask() throws Exception {
-        purgeMgr = new DatadirCleanupManager(snapDir, dataLogDir, 3, 1);
-        purgeMgr.start();
-        Assert.assertEquals("Data log directory is not set as configured",
-                dataLogDir, purgeMgr.getDataLogDir());
-        Assert.assertEquals("Snapshot directory is not set as configured",
-                snapDir, purgeMgr.getSnapDir());
-        Assert.assertEquals("Snapshot retain count is not set as configured",
-                3, purgeMgr.getSnapRetainCount());
-        Assert.assertEquals("Purge task is not started", STARTED, purgeMgr.getPurgeTaskStatus());
-        purgeMgr.shutdown();
-        Assert.assertEquals("Purge task is still running after shutdown", COMPLETED,
-                purgeMgr.getPurgeTaskStatus());
-    }
-
-    @Test
-    public void testWithZeroPurgeInterval() throws Exception {
-        purgeMgr = new DatadirCleanupManager(snapDir, dataLogDir, 3, 0);
-        purgeMgr.start();
-        Assert.assertEquals("Purge task is scheduled with zero purge interval", NOT_STARTED,
-                purgeMgr.getPurgeTaskStatus());
-        purgeMgr.shutdown();
-        Assert.assertEquals("Purge task is scheduled with zero purge interval", NOT_STARTED,
-                purgeMgr.getPurgeTaskStatus());
-    }
-
-    @Test
-    public void testWithNegativePurgeInterval() throws Exception {
-        purgeMgr = new DatadirCleanupManager(snapDir, dataLogDir, 3, -1);
-        purgeMgr.start();
-        Assert.assertEquals("Purge task is scheduled with negative purge interval",
-                NOT_STARTED, purgeMgr.getPurgeTaskStatus());
-        purgeMgr.shutdown();
-        Assert.assertEquals("Purge task is scheduled with negative purge interval", NOT_STARTED,
-                purgeMgr.getPurgeTaskStatus());
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        if (purgeMgr != null) {
-            purgeMgr.shutdown();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java b/src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java
deleted file mode 100644
index b9f1df8..0000000
--- a/src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java
+++ /dev/null
@@ -1,119 +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.server;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-import org.apache.jute.BinaryInputArchive;
-import org.apache.jute.BinaryOutputArchive;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZKTestCase;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class DeserializationPerfTest extends ZKTestCase {
-    protected static final Logger LOG = LoggerFactory.getLogger(DeserializationPerfTest.class);
-
-    private static void deserializeTree(int depth, int width, int len)
-            throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        BinaryInputArchive ia;
-        int count;
-        {
-            DataTree tree = new DataTree();
-            SerializationPerfTest.createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]);
-            count = tree.getNodeCount();
-
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
-            tree.serialize(oa, "test");
-            baos.flush();
-
-            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-            ia = BinaryInputArchive.getArchive(bais);
-        }
-
-        DataTree dserTree = new DataTree();
-
-        System.gc();
-        long start = System.nanoTime();
-        dserTree.deserialize(ia, "test");
-        long end = System.nanoTime();
-        long durationms = (end - start) / 1000000L;
-        long pernodeus = ((end - start) / 1000L) / count;
-
-        Assert.assertEquals(count, dserTree.getNodeCount());
-
-        LOG.info("Deserialized " + count + " nodes in " + durationms
-                + " ms (" + pernodeus + "us/node), depth=" + depth + " width="
-                + width + " datalen=" + len);
-    }
-
-    @Test
-    public void testSingleDeserialize() throws
-            InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        deserializeTree(1, 0, 20);
-    }
-
-    @Test
-    public void testWideDeserialize() throws
-            InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        deserializeTree(2, 10000, 20);
-    }
-
-    @Test
-    public void testDeepDeserialize() throws
-            InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        deserializeTree(400, 1, 20);
-    }
-
-    @Test
-    public void test10Wide5DeepDeserialize() throws
-            InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        deserializeTree(5, 10, 20);
-    }
-
-    @Test
-    public void test15Wide5DeepDeserialize() throws
-            InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        deserializeTree(5, 15, 20);
-    }
-
-    @Test
-    public void test25Wide4DeepDeserialize() throws
-            InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        deserializeTree(4, 25, 20);
-    }
-
-    @Test
-    public void test40Wide4DeepDeserialize() throws
-            InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        deserializeTree(4, 40, 20);
-    }
-
-    @Test
-    public void test300Wide3DeepDeserialize() throws
-            InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
-        deserializeTree(3, 300, 20);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java b/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java
deleted file mode 100644
index c601a27..0000000
--- a/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java
+++ /dev/null
@@ -1,95 +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.server;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.TestableZooKeeper;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.test.ClientBase;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-public class Emulate353TTLTest extends ClientBase {
-    private TestableZooKeeper zk;
-
-    @Override
-    public void setUp() throws Exception {
-        System.setProperty(EphemeralType.EXTENDED_TYPES_ENABLED_PROPERTY, "true");
-        System.setProperty(EphemeralType.TTL_3_5_3_EMULATION_PROPERTY, "true");
-        super.setUp();
-        zk = createClient();
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        System.clearProperty(EphemeralType.EXTENDED_TYPES_ENABLED_PROPERTY);
-        System.clearProperty(EphemeralType.TTL_3_5_3_EMULATION_PROPERTY);
-        super.tearDown();
-        zk.close();
-    }
-
-    @Test
-    public void testCreate()
-            throws KeeperException, InterruptedException {
-        Stat stat = new Stat();
-        zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100);
-        Assert.assertEquals(0, stat.getEphemeralOwner());
-
-        final AtomicLong fakeElapsed = new AtomicLong(0);
-        ContainerManager containerManager = newContainerManager(fakeElapsed);
-        containerManager.checkContainers();
-        Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
-
-        fakeElapsed.set(1000);
-        containerManager.checkContainers();
-        Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false));
-    }
-
-    @Test
-    public void test353TTL()
-            throws KeeperException, InterruptedException {
-        DataTree dataTree = serverFactory.zkServer.getZKDatabase().dataTree;
-        long ephemeralOwner = EphemeralTypeEmulate353.ttlToEphemeralOwner(100);
-        dataTree.createNode("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, ephemeralOwner,
-                dataTree.getNode("/").stat.getCversion()+1, 1, 1);
-
-        final AtomicLong fakeElapsed = new AtomicLong(0);
-        ContainerManager containerManager = newContainerManager(fakeElapsed);
-        containerManager.checkContainers();
-        Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
-
-        fakeElapsed.set(1000);
-        containerManager.checkContainers();
-        Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false));
-    }
-
-    private ContainerManager newContainerManager(final AtomicLong fakeElapsed) {
-        return new ContainerManager(serverFactory.getZooKeeperServer()
-                .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100) {
-            @Override
-            protected long getElapsed(DataNode node) {
-                return fakeElapsed.get();
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/EphemeralTypeTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/EphemeralTypeTest.java b/src/java/test/org/apache/zookeeper/server/EphemeralTypeTest.java
deleted file mode 100644
index 40863f5..0000000
--- a/src/java/test/org/apache/zookeeper/server/EphemeralTypeTest.java
+++ /dev/null
@@ -1,84 +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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.server;
-
-import org.apache.zookeeper.CreateMode;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class EphemeralTypeTest {
-    @Before
-    public void setUp() {
-        System.setProperty(EphemeralType.EXTENDED_TYPES_ENABLED_PROPERTY, "true");
-    }
-
-    @After
-    public void tearDown() {
-        System.clearProperty(EphemeralType.EXTENDED_TYPES_ENABLED_PROPERTY);
-    }
-
-    @Test
-    public void testTtls() {
-        long ttls[] = {100, 1, EphemeralType.TTL.maxValue()};
-        for (long ttl : ttls) {
-            long ephemeralOwner = EphemeralType.TTL.toEphemeralOwner(ttl);
-            Assert.assertEquals(EphemeralType.TTL, EphemeralType.get(ephemeralOwner));
-            Assert.assertEquals(ttl, EphemeralType.TTL.getValue(ephemeralOwner));
-        }
-
-        EphemeralType.validateTTL(CreateMode.PERSISTENT_WITH_TTL, 100);
-        EphemeralType.validateTTL(CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, 100);
-
-        try {
-            EphemeralType.validateTTL(CreateMode.EPHEMERAL, 100);
-            Assert.fail("Should have thrown IllegalArgumentException");
-        } catch (IllegalArgumentException dummy) {
-            // expected
-        }
-    }
-
-    @Test
-    public void testContainerValue() {
-        Assert.assertEquals(Long.MIN_VALUE, EphemeralType.CONTAINER_EPHEMERAL_OWNER);
-        Assert.assertEquals(EphemeralType.CONTAINER, EphemeralType.get(EphemeralType.CONTAINER_EPHEMERAL_OWNER));
-    }
-
-    @Test
-    public void testNonSpecial() {
-        Assert.assertEquals(EphemeralType.VOID, EphemeralType.get(0));
-        Assert.assertEquals(EphemeralType.NORMAL, EphemeralType.get(1));
-        Assert.assertEquals(EphemeralType.NORMAL, EphemeralType.get(Long.MAX_VALUE));
-    }
-
-    @Test
-    public void testServerIds() {
-        for ( int i = 0; i < 255; ++i ) {
-            Assert.assertEquals(EphemeralType.NORMAL, EphemeralType.get(SessionTrackerImpl.initializeNextSession(i)));
-        }
-        try {
-            Assert.assertEquals(EphemeralType.TTL, EphemeralType.get(SessionTrackerImpl.initializeNextSession(255)));
-            Assert.fail("Should have thrown IllegalArgumentException");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-        Assert.assertEquals(EphemeralType.NORMAL, EphemeralType.get(SessionTrackerImpl.initializeNextSession(EphemeralType.MAX_EXTENDED_SERVER_ID)));
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java b/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java
deleted file mode 100644
index cd5af81..0000000
--- a/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java
+++ /dev/null
@@ -1,123 +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.server;
-
-import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.common.PathUtils;
-import org.apache.zookeeper.test.ClientBase;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test stand-alone server.
- *
- */
-public class InvalidSnapCountTest extends ZKTestCase implements Watcher {
-    protected static final Logger LOG =
-        LoggerFactory.getLogger(InvalidSnapCountTest.class);
-
-    public static class MainThread extends Thread {
-        final File confFile;
-        final TestMain main;
-
-        public MainThread(int clientPort) throws IOException {
-            super("Standalone server with clientPort:" + clientPort);
-            File tmpDir = ClientBase.createTmpDir();
-            confFile = new File(tmpDir, "zoo.cfg");
-
-            FileWriter fwriter = new FileWriter(confFile);
-            fwriter.write("tickTime=2000\n");
-            fwriter.write("initLimit=10\n");
-            fwriter.write("syncLimit=5\n");
-            fwriter.write("snapCount=1\n");
-
-            File dataDir = new File(tmpDir, "data");
-            if (!dataDir.mkdir()) {
-                throw new IOException("unable to mkdir " + dataDir);
-            }
-            
-            // Convert windows path to UNIX to avoid problems with "\"
-            String dir = PathUtils.normalizeFileSystemPath(dataDir.toString());
-            fwriter.write("dataDir=" + dir + "\n");
-            
-            fwriter.write("clientPort=" + clientPort + "\n");
-            fwriter.flush();
-            fwriter.close();
-
-            main = new TestMain();
-        }
-
-        public void run() {
-            String args[] = new String[1];
-            args[0] = confFile.toString();
-            try {
-                main.initializeAndRun(args);
-            } catch (Exception e) {
-                // test will still fail even though we just log/ignore
-                LOG.error("unexpected exception in run", e);
-            }
-        }
-
-        public void shutdown() {
-            main.shutdown();
-        }
-    }
-
-    public static  class TestMain extends ZooKeeperServerMain {
-        public void shutdown() {
-            super.shutdown();
-        }
-    }
-
-    /**
-     * Verify the ability to start a standalone server instance.
-     */
-    @Test
-    public void testInvalidSnapCount() throws Exception {
-
-        final int CLIENT_PORT = 3181;
-
-        MainThread main = new MainThread(CLIENT_PORT);
-        main.start();
-
-        Assert.assertTrue("waiting for server being up",
-                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
-                        CONNECTION_TIMEOUT));
-
-        Assert.assertEquals(SyncRequestProcessor.getSnapCount(), 2);
-
-        main.shutdown();
-
-    }
-
-    public void process(WatchedEvent event) {
-        // ignore for this test
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java b/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
deleted file mode 100644
index 97ad792..0000000
--- a/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
+++ /dev/null
@@ -1,84 +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.server;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.RandomAccessFile;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.test.ClientBase;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This test checks that the server works even if the last snapshot is
- * invalidated by corruption or if the server crashes while generating the
- * snapshot.
- */
-public class InvalidSnapshotTest extends ClientBase {
-    private static final Logger LOG =
-            LoggerFactory.getLogger(InvalidSnapshotTest.class);
-
-    public InvalidSnapshotTest() {
-        SyncRequestProcessor.setSnapCount(100);
-    }
-
-    /**
-     * Validate that the server can come up on an invalid snapshot - by
-     * reverting to a prior snapshot + associated logs.
-     */
-    @Test
-    public void testInvalidSnapshot() throws Exception {
-        ZooKeeper zk = createClient();
-        try {
-            for (int i = 0; i < 2000; i++) {
-                zk.create("/invalidsnap-" + i, new byte[0],
-                        Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-            }
-        } finally {
-            zk.close();
-        }
-        NIOServerCnxnFactory factory = (NIOServerCnxnFactory)serverFactory;
-        stopServer();
-
-        // now corrupt the snapshot
-        File snapFile = factory.zkServer.getTxnLogFactory().findMostRecentSnapshot();
-        LOG.info("Corrupting " + snapFile);
-        RandomAccessFile raf = new RandomAccessFile(snapFile, "rws");
-        raf.setLength(3);
-        raf.close();
-
-        // now restart the server
-        startServer();
-
-        // verify that the expected data exists and wasn't lost
-        zk = createClient();
-        try {
-            assertTrue("the node should exist",
-                    (zk.exists("/invalidsnap-1999", false) != null));
-        } finally {
-            zk.close();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/MockNIOServerCnxn.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/MockNIOServerCnxn.java b/src/java/test/org/apache/zookeeper/server/MockNIOServerCnxn.java
deleted file mode 100644
index 40eab0a..0000000
--- a/src/java/test/org/apache/zookeeper/server/MockNIOServerCnxn.java
+++ /dev/null
@@ -1,45 +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.server;
-
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
-import java.io.IOException;
-import org.apache.zookeeper.server.NIOServerCnxnFactory.SelectorThread;
-
-public class MockNIOServerCnxn extends NIOServerCnxn {
-
-    public MockNIOServerCnxn(ZooKeeperServer zk, SocketChannel sock,
-                         SelectionKey sk, NIOServerCnxnFactory factory,
-                         SelectorThread selectorThread) throws IOException {
-        super(zk, sock, sk, factory, selectorThread);
-    }
-
-    /**
-     * Handles read/write IO on connection.
-     */
-    public void doIO(SelectionKey k) throws InterruptedException {
-        super.doIO(k);
-    }
-
-    @Override
-    protected boolean isSocketOpen() {
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/MockSelectorThread.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/MockSelectorThread.java b/src/java/test/org/apache/zookeeper/server/MockSelectorThread.java
deleted file mode 100644
index db66bc9..0000000
--- a/src/java/test/org/apache/zookeeper/server/MockSelectorThread.java
+++ /dev/null
@@ -1,32 +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.server;
-
-import java.io.IOException;
-import java.nio.channels.SelectionKey;
-
-public class MockSelectorThread extends NIOServerCnxnFactory.SelectorThread {
-    public MockSelectorThread(NIOServerCnxnFactory fact) throws IOException {
-        fact.super(0);
-    }
-
-    public boolean addInterestOpsUpdateRequest(SelectionKey sk) {
-        return super.addInterestOpsUpdateRequest(sk);
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/MockServerCnxn.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/MockServerCnxn.java b/src/java/test/org/apache/zookeeper/server/MockServerCnxn.java
deleted file mode 100644
index 2e37272..0000000
--- a/src/java/test/org/apache/zookeeper/server/MockServerCnxn.java
+++ /dev/null
@@ -1,113 +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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.server;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.security.cert.Certificate;
-import org.apache.jute.Record;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.proto.ReplyHeader;
-
-public class MockServerCnxn extends ServerCnxn {
-    public Certificate[] clientChain;
-    public boolean secure;
-
-    @Override
-    int getSessionTimeout() {
-        return 0;
-    }
-
-    @Override
-    void close() {
-    }
-
-    @Override
-    public void sendResponse(ReplyHeader h, Record r, String tag)
-            throws IOException {
-    }
-
-    @Override
-    void sendCloseSession() {
-    }
-
-    @Override
-    public void process(WatchedEvent event) {
-    }
-
-    @Override
-    public long getSessionId() {
-        return 0;
-    }
-
-    @Override
-    void setSessionId(long sessionId) {
-    }
-
-    @Override
-    public boolean isSecure() {
-        return secure;
-    }
-
-    @Override
-    public Certificate[] getClientCertificateChain() {
-        return clientChain;
-    }
-
-    @Override
-    public void setClientCertificateChain(Certificate[] chain) {
-        clientChain = chain;
-    }
-
-    @Override
-    void sendBuffer(ByteBuffer closeConn) {
-    }
-
-    @Override
-    void enableRecv() {
-    }
-
-    @Override
-    void disableRecv() {
-    }
-
-    @Override
-    void setSessionTimeout(int sessionTimeout) {
-    }
-
-    @Override
-    protected ServerStats serverStats() {
-        return null;
-    }
-
-    @Override
-    public long getOutstandingRequests() {
-        return 0;
-    }
-
-    @Override
-    public InetSocketAddress getRemoteSocketAddress() {
-        return null;
-    }
-
-    @Override
-    public int getInterestOps() {
-        return 0;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/3ce1b18b/src/java/test/org/apache/zookeeper/server/MultiOpSessionUpgradeTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/MultiOpSessionUpgradeTest.java b/src/java/test/org/apache/zookeeper/server/MultiOpSessionUpgradeTest.java
deleted file mode 100644
index 0426e22..0000000
--- a/src/java/test/org/apache/zookeeper/server/MultiOpSessionUpgradeTest.java
+++ /dev/null
@@ -1,136 +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.server;
-
-import org.apache.jute.BinaryOutputArchive;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.Op;
-import org.apache.zookeeper.OpResult;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.Id;
-import org.apache.zookeeper.proto.CreateRequest;
-import org.apache.zookeeper.proto.GetDataRequest;
-import org.apache.zookeeper.server.quorum.QuorumPeer;
-import org.apache.zookeeper.server.quorum.QuorumZooKeeperServer;
-import org.apache.zookeeper.server.quorum.UpgradeableSessionTracker;
-import org.apache.zookeeper.test.QuorumBase;
-import org.junit.Assert;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class MultiOpSessionUpgradeTest extends QuorumBase {
-    protected static final Logger LOG = LoggerFactory.getLogger(MultiOpSessionUpgradeTest.class);
-
-    @Override
-    public void setUp() throws Exception {
-        localSessionsEnabled = true;
-        localSessionsUpgradingEnabled = true;
-        super.setUp();
-    }
-
-    @Test
-    public void ephemeralCreateMultiOpTest() throws KeeperException, InterruptedException, IOException {
-        final ZooKeeper zk = createClient();
-
-        String data = "test";
-        String path = "/ephemeralcreatemultiop";
-        zk.create(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
-        QuorumZooKeeperServer server = getConnectedServer(zk.getSessionId());
-        Assert.assertNotNull("unable to find server interlocutor", server);
-        UpgradeableSessionTracker sessionTracker = (UpgradeableSessionTracker)server.getSessionTracker();
-        Assert.assertFalse("session already global", sessionTracker.isGlobalSession(zk.getSessionId()));
-
-        List<OpResult> multi = null;
-        try {
-            multi = zk.multi(Arrays.asList(
-                    Op.setData(path, data.getBytes(), 0),
-                    Op.create(path + "/e", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL),
-                    Op.create(path + "/p", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
-                    Op.create(path + "/q", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL)
-            ));
-        } catch (KeeperException.SessionExpiredException e) {
-            // the scenario that inspired this unit test
-            Assert.fail("received session expired for a session promotion in a multi-op");
-        }
-
-        Assert.assertNotNull(multi);
-        Assert.assertEquals(4, multi.size());
-        Assert.assertEquals(data, new String(zk.getData(path + "/e", false, null)));
-        Assert.assertEquals(data, new String(zk.getData(path + "/p", false, null)));
-        Assert.assertEquals(data, new String(zk.getData(path + "/q", false, null)));
-        Assert.assertTrue("session not promoted", sessionTracker.isGlobalSession(zk.getSessionId()));
-    }
-
-    @Test
-    public void directCheckUpgradeSessionTest() throws IOException, InterruptedException, KeeperException {
-        final ZooKeeper zk = createClient();
-
-        String path = "/directcheckupgradesession";
-        zk.create(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
-        QuorumZooKeeperServer server = getConnectedServer(zk.getSessionId());
-        Assert.assertNotNull("unable to find server interlocutor", server);
-
-        Request readRequest = makeGetDataRequest(path, zk.getSessionId());
-        Request createRequest = makeCreateRequest(path + "/e", zk.getSessionId());
-        Assert.assertNull("tried to upgrade on a read", server.checkUpgradeSession(readRequest));
-        Assert.assertNotNull("failed to upgrade on a create", server.checkUpgradeSession(createRequest));
-        Assert.assertNull("tried to upgrade after successful promotion",
-                server.checkUpgradeSession(createRequest));
-    }
-
-    private Request makeGetDataRequest(String path, long sessionId) throws IOException {
-        ByteArrayOutputStream boas = new ByteArrayOutputStream();
-        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
-        GetDataRequest getDataRequest = new GetDataRequest(path, false);
-        getDataRequest.serialize(boa, "request");
-        ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
-        return new Request(null, sessionId, 1, ZooDefs.OpCode.getData, bb, new ArrayList<Id>());
-    }
-
-    private Request makeCreateRequest(String path, long sessionId) throws IOException {
-        ByteArrayOutputStream boas = new ByteArrayOutputStream();
-        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
-        CreateRequest createRequest = new CreateRequest(path,
-                "data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag());
-        createRequest.serialize(boa, "request");
-        ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
-        return new Request(null, sessionId, 1, ZooDefs.OpCode.create2, bb, new ArrayList<Id>());
-    }
-
-    private QuorumZooKeeperServer getConnectedServer(long sessionId) {
-        for (QuorumPeer peer : getPeerList()) {
-            if (peer.getActiveServer().getSessionTracker().isTrackingSession(sessionId)) {
-                return (QuorumZooKeeperServer)peer.getActiveServer();
-            }
-        }
-        return null;
-    }
-}


Mime
View raw message