You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2018/10/24 09:31:21 UTC
[26/51] [partial] zookeeper git commit: ZOOKEEPER-3032: MAVEN
MIGRATION - branch-3.5 - zookeeper-server
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/43d71c2e/zookeeper-common/src/test/java/org/apache/zookeeper/test/WatcherFuncTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/WatcherFuncTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/WatcherFuncTest.java
deleted file mode 100644
index a6c62e4..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/WatcherFuncTest.java
+++ /dev/null
@@ -1,478 +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.ArrayList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.Watcher.Event.EventType;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class WatcherFuncTest extends ClientBase {
- private static class SimpleWatcher implements Watcher {
- private LinkedBlockingQueue<WatchedEvent> events =
- new LinkedBlockingQueue<WatchedEvent>();
- private CountDownLatch latch;
-
- public SimpleWatcher(CountDownLatch latch) {
- this.latch = latch;
- }
-
- public void process(WatchedEvent event) {
- if (event.getState() == KeeperState.SyncConnected) {
- if (latch != null) {
- latch.countDown();
- }
- }
-
- if (event.getType() == EventType.None) {
- return;
- }
- try {
- events.put(event);
- } catch (InterruptedException e) {
- Assert.assertTrue("interruption unexpected", false);
- }
- }
- public void verify(List<EventType> expected) throws InterruptedException{
- WatchedEvent event;
- int count = 0;
- while (count < expected.size()
- && (event = events.poll(30, TimeUnit.SECONDS)) != null)
- {
- Assert.assertEquals(expected.get(count), event.getType());
- count++;
- }
- Assert.assertEquals(expected.size(), count);
- events.clear();
- }
- }
- private SimpleWatcher client_dwatch;
- private volatile CountDownLatch client_latch;
- private ZooKeeper client;
- private SimpleWatcher lsnr_dwatch;
- private volatile CountDownLatch lsnr_latch;
- private ZooKeeper lsnr;
-
- private List<EventType> expected;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- client_latch = new CountDownLatch(1);
- client_dwatch = new SimpleWatcher(client_latch);
- client = createClient(client_dwatch, client_latch);
-
- lsnr_latch = new CountDownLatch(1);
- lsnr_dwatch = new SimpleWatcher(lsnr_latch);
- lsnr = createClient(lsnr_dwatch, lsnr_latch);
-
- expected = new ArrayList<EventType>();
- }
-
- @Override
- public void tearDown() throws Exception {
- client.close();
- lsnr.close();
- super.tearDown();
- }
-
- protected ZooKeeper createClient(Watcher watcher, CountDownLatch latch)
- throws IOException, InterruptedException
- {
- ZooKeeper zk = new ZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
- if(!latch.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)){
- Assert.fail("Unable to connect to server");
- }
- return zk;
- }
-
- private void verify() throws InterruptedException {
- lsnr_dwatch.verify(expected);
- expected.clear();
- }
-
- @Test
- public void testExistsSync()
- throws IOException, InterruptedException, KeeperException
- {
- Assert.assertNull(lsnr.exists("/foo", true));
- Assert.assertNull(lsnr.exists("/foo/bar", true));
-
- client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- expected.add(EventType.NodeCreated);
- client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- expected.add(EventType.NodeCreated);
-
- verify();
-
- Assert.assertNotNull(lsnr.exists("/foo", true));
- Assert.assertNotNull(lsnr.exists("/foo/bar", true));
-
- try {
- Assert.assertNull(lsnr.exists("/car", true));
- client.setData("/car", "missing".getBytes(), -1);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/car", e.getPath());
- }
-
- try {
- Assert.assertNull(lsnr.exists("/foo/car", true));
- client.setData("/foo/car", "missing".getBytes(), -1);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo/car", e.getPath());
- }
-
- client.setData("/foo", "parent".getBytes(), -1);
- expected.add(EventType.NodeDataChanged);
- client.setData("/foo/bar", "child".getBytes(), -1);
- expected.add(EventType.NodeDataChanged);
-
- verify();
-
- Assert.assertNotNull(lsnr.exists("/foo", true));
- Assert.assertNotNull(lsnr.exists("/foo/bar", true));
-
- client.delete("/foo/bar", -1);
- expected.add(EventType.NodeDeleted);
- client.delete("/foo", -1);
- expected.add(EventType.NodeDeleted);
-
- verify();
- }
-
- @Test
- public void testGetDataSync()
- throws IOException, InterruptedException, KeeperException
- {
- try {
- lsnr.getData("/foo", true, null);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo", e.getPath());
- }
- try {
- lsnr.getData("/foo/bar", true, null);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo/bar", e.getPath());
- }
-
- client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- Assert.assertNotNull(lsnr.getData("/foo", true, null));
- client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- Assert.assertNotNull(lsnr.getData("/foo/bar", true, null));
-
- client.setData("/foo", "parent".getBytes(), -1);
- expected.add(EventType.NodeDataChanged);
- client.setData("/foo/bar", "child".getBytes(), -1);
- expected.add(EventType.NodeDataChanged);
-
- verify();
-
- Assert.assertNotNull(lsnr.getData("/foo", true, null));
- Assert.assertNotNull(lsnr.getData("/foo/bar", true, null));
-
- client.delete("/foo/bar", -1);
- expected.add(EventType.NodeDeleted);
- client.delete("/foo", -1);
- expected.add(EventType.NodeDeleted);
-
- verify();
- }
-
- @Test
- public void testGetChildrenSync()
- throws IOException, InterruptedException, KeeperException
- {
- try {
- lsnr.getChildren("/foo", true);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo", e.getPath());
- }
- try {
- lsnr.getChildren("/foo/bar", true);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo/bar", e.getPath());
- }
-
- client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- Assert.assertNotNull(lsnr.getChildren("/foo", true));
-
- client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- expected.add(EventType.NodeChildrenChanged); // /foo
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", true));
-
-
- client.setData("/foo", "parent".getBytes(), -1);
- client.setData("/foo/bar", "child".getBytes(), -1);
-
-
- Assert.assertNotNull(lsnr.exists("/foo", true));
-
- Assert.assertNotNull(lsnr.getChildren("/foo", true));
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", true));
-
- client.delete("/foo/bar", -1);
- expected.add(EventType.NodeDeleted); // /foo/bar childwatch
- expected.add(EventType.NodeChildrenChanged); // /foo
- client.delete("/foo", -1);
- expected.add(EventType.NodeDeleted);
-
- verify();
- }
-
- @Test
- public void testExistsSyncWObj()
- throws IOException, InterruptedException, KeeperException
- {
- SimpleWatcher w1 = new SimpleWatcher(null);
- SimpleWatcher w2 = new SimpleWatcher(null);
- SimpleWatcher w3 = new SimpleWatcher(null);
- SimpleWatcher w4 = new SimpleWatcher(null);
-
- List<EventType> e2 = new ArrayList<EventType>();
-
- Assert.assertNull(lsnr.exists("/foo", true));
- Assert.assertNull(lsnr.exists("/foo", w1));
-
- Assert.assertNull(lsnr.exists("/foo/bar", w2));
- Assert.assertNull(lsnr.exists("/foo/bar", w3));
- Assert.assertNull(lsnr.exists("/foo/bar", w3));
- Assert.assertNull(lsnr.exists("/foo/bar", w4));
-
- client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- expected.add(EventType.NodeCreated);
- client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- e2.add(EventType.NodeCreated);
-
- lsnr_dwatch.verify(expected);
- w1.verify(expected);
- w2.verify(e2);
- w3.verify(e2);
- w4.verify(e2);
- expected.clear();
- e2.clear();
-
- // default not registered
- Assert.assertNotNull(lsnr.exists("/foo", w1));
-
- Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
- Assert.assertNotNull(lsnr.exists("/foo/bar", w3));
- Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
- Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
-
- client.setData("/foo", "parent".getBytes(), -1);
- expected.add(EventType.NodeDataChanged);
- client.setData("/foo/bar", "child".getBytes(), -1);
- e2.add(EventType.NodeDataChanged);
-
- lsnr_dwatch.verify(new ArrayList<EventType>()); // not reg so should = 0
- w1.verify(expected);
- w2.verify(e2);
- w3.verify(e2);
- w4.verify(e2);
- expected.clear();
- e2.clear();
-
- Assert.assertNotNull(lsnr.exists("/foo", true));
- Assert.assertNotNull(lsnr.exists("/foo", w1));
- Assert.assertNotNull(lsnr.exists("/foo", w1));
-
- Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
- Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
- Assert.assertNotNull(lsnr.exists("/foo/bar", w3));
- Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
-
- client.delete("/foo/bar", -1);
- expected.add(EventType.NodeDeleted);
- client.delete("/foo", -1);
- e2.add(EventType.NodeDeleted);
-
- lsnr_dwatch.verify(expected);
- w1.verify(expected);
- w2.verify(e2);
- w3.verify(e2);
- w4.verify(e2);
- expected.clear();
- e2.clear();
-
- }
-
- @Test
- public void testGetDataSyncWObj()
- throws IOException, InterruptedException, KeeperException
- {
- SimpleWatcher w1 = new SimpleWatcher(null);
- SimpleWatcher w2 = new SimpleWatcher(null);
- SimpleWatcher w3 = new SimpleWatcher(null);
- SimpleWatcher w4 = new SimpleWatcher(null);
-
- List<EventType> e2 = new ArrayList<EventType>();
-
- try {
- lsnr.getData("/foo", w1, null);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo", e.getPath());
- }
- try {
- lsnr.getData("/foo/bar", w2, null);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo/bar", e.getPath());
- }
-
- client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- Assert.assertNotNull(lsnr.getData("/foo", true, null));
- Assert.assertNotNull(lsnr.getData("/foo", w1, null));
- client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null));
- Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
- Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
- Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
-
- client.setData("/foo", "parent".getBytes(), -1);
- expected.add(EventType.NodeDataChanged);
- client.setData("/foo/bar", "child".getBytes(), -1);
- e2.add(EventType.NodeDataChanged);
-
- lsnr_dwatch.verify(expected);
- w1.verify(expected);
- w2.verify(e2);
- w3.verify(e2);
- w4.verify(e2);
- expected.clear();
- e2.clear();
-
- Assert.assertNotNull(lsnr.getData("/foo", true, null));
- Assert.assertNotNull(lsnr.getData("/foo", w1, null));
- Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null));
- Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
- Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
- Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
-
- client.delete("/foo/bar", -1);
- expected.add(EventType.NodeDeleted);
- client.delete("/foo", -1);
- e2.add(EventType.NodeDeleted);
-
- lsnr_dwatch.verify(expected);
- w1.verify(expected);
- w2.verify(e2);
- w3.verify(e2);
- w4.verify(e2);
- expected.clear();
- e2.clear();
- }
-
- @Test
- public void testGetChildrenSyncWObj()
- throws IOException, InterruptedException, KeeperException
- {
- SimpleWatcher w1 = new SimpleWatcher(null);
- SimpleWatcher w2 = new SimpleWatcher(null);
- SimpleWatcher w3 = new SimpleWatcher(null);
- SimpleWatcher w4 = new SimpleWatcher(null);
-
- List<EventType> e2 = new ArrayList<EventType>();
-
- try {
- lsnr.getChildren("/foo", true);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo", e.getPath());
- }
- try {
- lsnr.getChildren("/foo/bar", true);
- Assert.fail();
- } catch (KeeperException e) {
- Assert.assertEquals(KeeperException.Code.NONODE, e.code());
- Assert.assertEquals("/foo/bar", e.getPath());
- }
-
- client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- Assert.assertNotNull(lsnr.getChildren("/foo", true));
- Assert.assertNotNull(lsnr.getChildren("/foo", w1));
-
- client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- expected.add(EventType.NodeChildrenChanged); // /foo
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", w3));
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
-
-
- client.setData("/foo", "parent".getBytes(), -1);
- client.setData("/foo/bar", "child".getBytes(), -1);
-
-
- Assert.assertNotNull(lsnr.exists("/foo", true));
- Assert.assertNotNull(lsnr.exists("/foo", w1));
- Assert.assertNotNull(lsnr.exists("/foo", true));
- Assert.assertNotNull(lsnr.exists("/foo", w1));
-
- Assert.assertNotNull(lsnr.getChildren("/foo", true));
- Assert.assertNotNull(lsnr.getChildren("/foo", w1));
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", w3));
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
- Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
-
- client.delete("/foo/bar", -1);
- e2.add(EventType.NodeDeleted); // /foo/bar childwatch
- expected.add(EventType.NodeChildrenChanged); // /foo
- client.delete("/foo", -1);
- expected.add(EventType.NodeDeleted);
-
- lsnr_dwatch.verify(expected);
- w1.verify(expected);
- w2.verify(e2);
- w3.verify(e2);
- w4.verify(e2);
- expected.clear();
- e2.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/43d71c2e/zookeeper-common/src/test/java/org/apache/zookeeper/test/WatcherTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/WatcherTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/WatcherTest.java
deleted file mode 100644
index 61d82f1..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/WatcherTest.java
+++ /dev/null
@@ -1,463 +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.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.TestableZooKeeper;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.AsyncCallback.StatCallback;
-import org.apache.zookeeper.AsyncCallback.VoidCallback;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.Watcher.Event;
-import org.apache.zookeeper.Watcher.Event.EventType;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.client.ZKClientConfig;
-import org.apache.zookeeper.data.Stat;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class WatcherTest extends ClientBase {
- protected static final Logger LOG = LoggerFactory.getLogger(WatcherTest.class);
-
- private long timeOfLastWatcherInvocation;
-
- private final static class MyStatCallback implements StatCallback {
- int rc;
- public void processResult(int rc, String path, Object ctx, Stat stat) {
- ((int[])ctx)[0]++;
- this.rc = rc;
- }
- }
-
- private class MyWatcher extends CountdownWatcher {
- LinkedBlockingQueue<WatchedEvent> events =
- new LinkedBlockingQueue<WatchedEvent>();
-
- public void process(WatchedEvent event) {
- super.process(event);
- if (event.getType() != Event.EventType.None) {
- timeOfLastWatcherInvocation = System.currentTimeMillis();
- try {
- events.put(event);
- } catch (InterruptedException e) {
- LOG.warn("ignoring interrupt during event.put");
- }
- }
- }
- }
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
- // Reset to default value since some test cases set this to true.
- // Needed for JDK7 since unit test can run is random order
- System.setProperty(ZKClientConfig.DISABLE_AUTO_WATCH_RESET, "false");
- }
-
- /**
- * Verify that we get all of the events we expect to get. This particular
- * case verifies that we see all of the data events on a particular node.
- * There was a bug (ZOOKEEPER-137) that resulted in events being dropped
- * in some cases (timing).
- *
- * @throws IOException
- * @throws InterruptedException
- * @throws KeeperException
- */
- @Test
- public void testWatcherCorrectness()
- throws IOException, InterruptedException, KeeperException
- {
- ZooKeeper zk = null;
- try {
- MyWatcher watcher = new MyWatcher();
- zk = createClient(watcher, hostPort);
-
- StatCallback scb = new StatCallback() {
- public void processResult(int rc, String path, Object ctx,
- Stat stat) {
- // don't do anything
- }
- };
- VoidCallback vcb = new VoidCallback() {
- public void processResult(int rc, String path, Object ctx) {
- // don't do anything
- }
- };
-
- String names[] = new String[10];
- for (int i = 0; i < names.length; i++) {
- String name = zk.create("/tc-", "initialvalue".getBytes(),
- Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
- names[i] = name;
-
- Stat stat = new Stat();
- zk.getData(name, watcher, stat);
- zk.setData(name, "new".getBytes(), stat.getVersion(), scb, null);
- stat = zk.exists(name, watcher);
- zk.delete(name, stat.getVersion(), vcb, null);
- }
-
- for (int i = 0; i < names.length; i++) {
- String name = names[i];
- WatchedEvent event = watcher.events.poll(10, TimeUnit.SECONDS);
- Assert.assertEquals(name, event.getPath());
- Assert.assertEquals(Event.EventType.NodeDataChanged, event.getType());
- Assert.assertEquals(Event.KeeperState.SyncConnected, event.getState());
- event = watcher.events.poll(10, TimeUnit.SECONDS);
- Assert.assertEquals(name, event.getPath());
- Assert.assertEquals(Event.EventType.NodeDeleted, event.getType());
- Assert.assertEquals(Event.KeeperState.SyncConnected, event.getState());
- }
- } finally {
- if (zk != null) {
- zk.close();
- }
- }
- }
-
- @Test
- public void testWatcherDisconnectOnClose()
- throws IOException, InterruptedException, KeeperException
- {
- ZooKeeper zk = null;
- try {
- final BlockingQueue<WatchedEvent> queue = new LinkedBlockingQueue<>();
-
- MyWatcher connWatcher = new MyWatcher();
-
- Watcher watcher = new Watcher(){
- @Override
- public void process(WatchedEvent event) {
- try {
- queue.put(event);
- } catch (InterruptedException e) {
- // Oh well, never mind
- }
- }
-
- };
-
- zk = createClient(connWatcher, hostPort);
-
- StatCallback scb = new StatCallback() {
- public void processResult(int rc, String path, Object ctx,
- Stat stat) {
- // don't do anything
- }
- };
-
- // Register a watch on the node
- zk.exists("/missing", watcher, scb, null);
-
- // Close the client without changing the node
- zk.close();
-
-
- WatchedEvent event = queue.poll(10, TimeUnit.SECONDS);
-
- Assert.assertNotNull("No watch event was received after closing the Zookeeper client. A 'Closed' event should have occurred", event);
- Assert.assertEquals("Closed events are not generated by the server, and so should have a type of 'None'", Event.EventType.None, event.getType());
- Assert.assertEquals("A 'Closed' event was expected as the Zookeeper client was closed without altering the node it was watching", Event.KeeperState.Closed, event.getState());
- } finally {
- if (zk != null) {
- zk.close();
- }
- }
-
- }
-
- @Test
- public void testWatcherCount()
- throws IOException, InterruptedException, KeeperException {
- ZooKeeper zk1 = null, zk2 = null;
- try {
- MyWatcher w1 = new MyWatcher();
- zk1 = createClient(w1, hostPort);
-
- MyWatcher w2 = new MyWatcher();
- zk2 = createClient(w2, hostPort);
-
- Stat stat = new Stat();
- zk1.create("/watch-count-test", "value".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
- zk1.create("/watch-count-test-2", "value".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
-
- zk1.getData("/watch-count-test", w1, stat);
- zk1.getData("/watch-count-test-2", w1, stat);
- zk2.getData("/watch-count-test", w2, stat);
-
- Assert.assertEquals(ClientBase.getServer(serverFactory)
- .getZKDatabase().getDataTree().getWatchCount(), 3);
-
- } finally {
- if(zk1 != null) {
- zk1.close();
- }
- if(zk2 != null) {
- zk2.close();
- }
- }
-
- }
-
- final static int COUNT = 100;
- /**
- * This test checks that watches for pending requests do not get triggered,
- * but watches set by previous requests do.
- *
- * @throws Exception
- */
- @Test
- public void testWatchAutoResetWithPending() throws Exception {
- MyWatcher watches[] = new MyWatcher[COUNT];
- MyStatCallback cbs[] = new MyStatCallback[COUNT];
- MyWatcher watcher = new MyWatcher();
- int count[] = new int[1];
- TestableZooKeeper zk = createClient(watcher, hostPort, 6000);
- ZooKeeper zk2 = createClient(watcher, hostPort, 5000);
- zk2.create("/test", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
- for(int i = 0; i < COUNT/2; i++) {
- watches[i] = new MyWatcher();
- cbs[i] = new MyStatCallback();
- zk.exists("/test", watches[i], cbs[i], count);
- }
- zk.exists("/test", false);
- Assert.assertTrue("Failed to pause the connection!", zk.pauseCnxn(3000));
- zk2.close();
- stopServer();
- watches[0].waitForDisconnected(60000);
- for(int i = COUNT/2; i < COUNT; i++) {
- watches[i] = new MyWatcher();
- cbs[i] = new MyStatCallback();
- zk.exists("/test", watches[i], cbs[i], count);
- }
- startServer();
- watches[COUNT/2-1].waitForConnected(60000);
- Assert.assertEquals(null, zk.exists("/test", false));
- waitForAllWatchers();
- for(int i = 0; i < COUNT/2; i++) {
- Assert.assertEquals("For " + i, 1, watches[i].events.size());
- }
- for(int i = COUNT/2; i < COUNT; i++) {
- if (cbs[i].rc == 0) {
- Assert.assertEquals("For " +i, 1, watches[i].events.size());
- } else {
- Assert.assertEquals("For " +i, 0, watches[i].events.size());
- }
- }
- Assert.assertEquals(COUNT, count[0]);
- zk.close();
- }
-
- /**
- * Wait until no watcher has been fired in the last second to ensure that all watches
- * that are waiting to be fired have been fired
- * @throws Exception
- */
- private void waitForAllWatchers() throws Exception {
- timeOfLastWatcherInvocation = System.currentTimeMillis();
- while (System.currentTimeMillis() - timeOfLastWatcherInvocation < 1000) {
- Thread.sleep(1000);
- }
- }
-
- final int TIMEOUT = 5000;
-
- @Test
- public void testWatcherAutoResetWithGlobal() throws Exception {
- ZooKeeper zk = null;
- MyWatcher watcher = new MyWatcher();
- zk = createClient(watcher, hostPort, TIMEOUT);
- testWatcherAutoReset(zk, watcher, watcher);
- zk.close();
- }
-
- @Test
- public void testWatcherAutoResetWithLocal() throws Exception {
- ZooKeeper zk = null;
- MyWatcher watcher = new MyWatcher();
- zk = createClient(watcher, hostPort, TIMEOUT);
- testWatcherAutoReset(zk, watcher, new MyWatcher());
- zk.close();
- }
-
- @Test
- public void testWatcherAutoResetDisabledWithGlobal() throws Exception {
- /**
- * When ZooKeeper is created this property will get used.
- */
- System.setProperty(ZKClientConfig.DISABLE_AUTO_WATCH_RESET, "true");
- testWatcherAutoResetWithGlobal();
- }
-
- @Test
- public void testWatcherAutoResetDisabledWithLocal() throws Exception {
- System.setProperty(ZKClientConfig.DISABLE_AUTO_WATCH_RESET, "true");
- testWatcherAutoResetWithLocal();
- }
-
- private void testWatcherAutoReset(ZooKeeper zk, MyWatcher globalWatcher,
- MyWatcher localWatcher) throws Exception {
- boolean isGlobal = (localWatcher == globalWatcher);
- // First test to see if the watch survives across reconnects
- zk.create("/watchtest", new byte[0], Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
- zk.create("/watchtest/child", new byte[0], Ids.OPEN_ACL_UNSAFE,
- CreateMode.EPHEMERAL);
- if (isGlobal) {
- zk.getChildren("/watchtest", true);
- zk.getData("/watchtest/child", true, new Stat());
- zk.exists("/watchtest/child2", true);
- } else {
- zk.getChildren("/watchtest", localWatcher);
- zk.getData("/watchtest/child", localWatcher, new Stat());
- zk.exists("/watchtest/child2", localWatcher);
- }
-
- Assert.assertTrue(localWatcher.events.isEmpty());
-
- stopServer();
- globalWatcher.waitForDisconnected(3000);
- localWatcher.waitForDisconnected(500);
- startServer();
- globalWatcher.waitForConnected(3000);
- boolean disableAutoWatchReset = zk.getClientConfig().getBoolean(ZKClientConfig.DISABLE_AUTO_WATCH_RESET);
- if (!isGlobal && !disableAutoWatchReset) {
- localWatcher.waitForConnected(500);
- }
-
- Assert.assertTrue(localWatcher.events.isEmpty());
- zk.setData("/watchtest/child", new byte[1], -1);
- zk.create("/watchtest/child2", new byte[0], Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
-
- WatchedEvent e;
- if (!disableAutoWatchReset) {
- e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- Assert.assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType());
- Assert.assertEquals("/watchtest/child", e.getPath());
- } else {
- // we'll catch this later if it does happen after timeout, so
- // why waste the time on poll
- }
-
- if (!disableAutoWatchReset) {
- e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- // The create will trigger the get children and the exist
- // watches
- Assert.assertEquals(EventType.NodeCreated, e.getType());
- Assert.assertEquals("/watchtest/child2", e.getPath());
- } else {
- // we'll catch this later if it does happen after timeout, so
- // why waste the time on poll
- }
-
- if (!disableAutoWatchReset) {
- e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- Assert.assertEquals(EventType.NodeChildrenChanged, e.getType());
- Assert.assertEquals("/watchtest", e.getPath());
- } else {
- // we'll catch this later if it does happen after timeout, so
- // why waste the time on poll
- }
-
- Assert.assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals
- stopServer();
- globalWatcher.waitForDisconnected(TIMEOUT);
- try {
- try {
- localWatcher.waitForDisconnected(500);
- if (!isGlobal && !disableAutoWatchReset) {
- Assert.fail("Got an event when I shouldn't have");
- }
- } catch(TimeoutException toe) {
- if (disableAutoWatchReset) {
- Assert.fail("Didn't get an event when I should have");
- }
- // Else what we are expecting since there are no outstanding watches
- }
- } catch (Exception e1) {
- LOG.error("bad", e1);
- throw new RuntimeException(e1);
- }
- startServer();
- globalWatcher.waitForConnected(TIMEOUT);
-
- if (isGlobal) {
- zk.getChildren("/watchtest", true);
- zk.getData("/watchtest/child", true, new Stat());
- zk.exists("/watchtest/child2", true);
- } else {
- zk.getChildren("/watchtest", localWatcher);
- zk.getData("/watchtest/child", localWatcher, new Stat());
- zk.exists("/watchtest/child2", localWatcher);
- }
-
- // Do trigger an event to make sure that we do not get
- // it later
- zk.delete("/watchtest/child2", -1);
-
- e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- Assert.assertEquals(EventType.NodeDeleted, e.getType());
- Assert.assertEquals("/watchtest/child2", e.getPath());
-
- e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- Assert.assertEquals(EventType.NodeChildrenChanged, e.getType());
- Assert.assertEquals("/watchtest", e.getPath());
-
- Assert.assertTrue(localWatcher.events.isEmpty());
-
- stopServer();
- globalWatcher.waitForDisconnected(TIMEOUT);
- localWatcher.waitForDisconnected(500);
- startServer();
- globalWatcher.waitForConnected(TIMEOUT);
- if (!isGlobal && !disableAutoWatchReset) {
- localWatcher.waitForConnected(500);
- }
-
- zk.delete("/watchtest/child", -1);
- zk.delete("/watchtest", -1);
-
- if (!disableAutoWatchReset) {
- e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- Assert.assertEquals(EventType.NodeDeleted, e.getType());
- Assert.assertEquals("/watchtest/child", e.getPath());
- } else {
- // we'll catch this later if it does happen after timeout, so
- // why waste the time on poll
- }
-
- // Make sure nothing is straggling!
- Thread.sleep(1000);
- Assert.assertTrue(localWatcher.events.isEmpty());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/43d71c2e/zookeeper-common/src/test/java/org/apache/zookeeper/test/X509AuthTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/X509AuthTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/X509AuthTest.java
deleted file mode 100644
index 4982cf3..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/X509AuthTest.java
+++ /dev/null
@@ -1,290 +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.test;
-
-import java.math.BigInteger;
-import java.net.Socket;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Principal;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.SignatureException;
-import java.security.cert.CertificateEncodingException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateExpiredException;
-import java.security.cert.CertificateNotYetValidException;
-import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.Set;
-
-import javax.net.ssl.X509KeyManager;
-import javax.net.ssl.X509TrustManager;
-import javax.security.auth.x500.X500Principal;
-
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.server.MockServerCnxn;
-import org.apache.zookeeper.server.auth.X509AuthenticationProvider;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class X509AuthTest extends ZKTestCase {
- private static TestCertificate clientCert;
- private static TestCertificate superCert;
- private static TestCertificate unknownCert;
-
- @Before
- public void setUp() {
- System.setProperty("zookeeper.X509AuthenticationProvider.superUser",
- "CN=SUPER");
- System.setProperty("zookeeper.ssl.keyManager",
- "org.apache.zookeeper.test.X509AuthTest.TestKeyManager");
- System.setProperty("zookeeper.ssl.trustManager",
- "org.apache.zookeeper.test.X509AuthTest.TestTrustManager");
-
- clientCert = new TestCertificate("CLIENT");
- superCert = new TestCertificate("SUPER");
- unknownCert = new TestCertificate("UNKNOWN");
- }
-
- @Test
- public void testTrustedAuth() {
- X509AuthenticationProvider provider = createProvider(clientCert);
- MockServerCnxn cnxn = new MockServerCnxn();
- cnxn.clientChain = new X509Certificate[] { clientCert };
- Assert.assertEquals(KeeperException.Code.OK, provider.handleAuthentication(cnxn, null));
- }
-
- @Test
- public void testSuperAuth() {
- X509AuthenticationProvider provider = createProvider(superCert);
- MockServerCnxn cnxn = new MockServerCnxn();
- cnxn.clientChain = new X509Certificate[] { superCert };
- Assert.assertEquals(KeeperException.Code.OK, provider.handleAuthentication(cnxn, null));
- Assert.assertEquals("super", cnxn.getAuthInfo().get(0).getScheme());
- }
-
- @Test
- public void testUntrustedAuth() {
- X509AuthenticationProvider provider = createProvider(clientCert);
- MockServerCnxn cnxn = new MockServerCnxn();
- cnxn.clientChain = new X509Certificate[] { unknownCert };
- Assert.assertEquals(KeeperException.Code.AUTHFAILED, provider.handleAuthentication(cnxn, null));
- }
-
- private static class TestPublicKey implements PublicKey {
- private static final long serialVersionUID = 1L;
- @Override
- public String getAlgorithm() {
- return null;
- }
- @Override
- public String getFormat() {
- return null;
- }
- @Override
- public byte[] getEncoded() {
- return null;
- }
- }
- private static class TestCertificate extends X509Certificate {
- private byte[] encoded;
- private X500Principal principal;
- private PublicKey publicKey;
- public TestCertificate(String name) {
- encoded = name.getBytes();
- principal = new X500Principal("CN=" + name);
- publicKey = new TestPublicKey();
- }
- @Override
- public boolean hasUnsupportedCriticalExtension() {
- return false;
- }
- @Override
- public Set<String> getCriticalExtensionOIDs() {
- return null;
- }
- @Override
- public Set<String> getNonCriticalExtensionOIDs() {
- return null;
- }
- @Override
- public byte[] getExtensionValue(String oid) {
- return null;
- }
- @Override
- public void checkValidity() throws CertificateExpiredException,
- CertificateNotYetValidException {
- }
- @Override
- public void checkValidity(Date date)
- throws CertificateExpiredException,
- CertificateNotYetValidException {
- }
- @Override
- public int getVersion() {
- return 0;
- }
- @Override
- public BigInteger getSerialNumber() {
- return null;
- }
- @Override
- public Principal getIssuerDN() {
- return null;
- }
- @Override
- public Principal getSubjectDN() {
- return null;
- }
- @Override
- public Date getNotBefore() {
- return null;
- }
- @Override
- public Date getNotAfter() {
- return null;
- }
- @Override
- public byte[] getTBSCertificate() throws CertificateEncodingException {
- return null;
- }
- @Override
- public byte[] getSignature() {
- return null;
- }
- @Override
- public String getSigAlgName() {
- return null;
- }
- @Override
- public String getSigAlgOID() {
- return null;
- }
- @Override
- public byte[] getSigAlgParams() {
- return null;
- }
- @Override
- public boolean[] getIssuerUniqueID() {
- return null;
- }
- @Override
- public boolean[] getSubjectUniqueID() {
- return null;
- }
- @Override
- public boolean[] getKeyUsage() {
- return null;
- }
- @Override
- public int getBasicConstraints() {
- return 0;
- }
- @Override
- public byte[] getEncoded() throws CertificateEncodingException {
- return encoded;
- }
- @Override
- public void verify(PublicKey key) throws CertificateException,
- NoSuchAlgorithmException, InvalidKeyException,
- NoSuchProviderException, SignatureException {
- }
- @Override
- public void verify(PublicKey key, String sigProvider)
- throws CertificateException, NoSuchAlgorithmException,
- InvalidKeyException, NoSuchProviderException,
- SignatureException {
- }
- @Override
- public String toString() {
- return null;
- }
- @Override
- public PublicKey getPublicKey() {
- return publicKey;
- }
- @Override
- public X500Principal getSubjectX500Principal() {
- return principal;
- }
- }
- public static class TestKeyManager implements X509KeyManager {
- @Override
- public String chooseClientAlias(String[] keyType, Principal[] issuers,
- Socket socket) {
- return null;
- }
- @Override
- public String chooseServerAlias(String keyType, Principal[] issuers,
- Socket socket) {
- return null;
- }
- @Override
- public X509Certificate[] getCertificateChain(String alias) {
- return null;
- }
- @Override
- public String[] getClientAliases(String keyType, Principal[] issuers) {
- return null;
- }
- @Override
- public PrivateKey getPrivateKey(String alias) {
- return null;
- }
- @Override
- public String[] getServerAliases(String keyType, Principal[] issuers) {
- return null;
- }
- }
- public static class TestTrustManager implements X509TrustManager {
- X509Certificate cert;
- public TestTrustManager(X509Certificate testCert) {
- cert = testCert;
- }
- @Override
- public void checkClientTrusted(X509Certificate[] chain, String authType)
- throws CertificateException {
- if (!Arrays.equals(cert.getEncoded(), chain[0].getEncoded())) {
- throw new CertificateException("Client cert not trusted");
- }
- }
- @Override
- public void checkServerTrusted(X509Certificate[] chain, String authType)
- throws CertificateException {
- if (!Arrays.equals(cert.getEncoded(), chain[0].getEncoded())) {
- throw new CertificateException("Server cert not trusted");
- }
- }
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- }
-
- protected X509AuthenticationProvider createProvider(X509Certificate trustedCert) {
- return new X509AuthenticationProvider(
- new TestTrustManager(trustedCert),
- new TestKeyManager());
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/43d71c2e/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java
deleted file mode 100644
index c757fc3..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java
+++ /dev/null
@@ -1,170 +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 java.io.IOException;
-import java.io.RandomAccessFile;
-import java.util.Arrays;
-
-import org.apache.zookeeper.AsyncCallback;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.server.SyncRequestProcessor;
-import org.apache.zookeeper.server.ZKDatabase;
-import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
-import org.apache.zookeeper.server.quorum.QuorumPeer;
-import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.Assert.assertEquals;
-
-public class ZkDatabaseCorruptionTest extends ZKTestCase {
- protected static final Logger LOG = LoggerFactory.getLogger(ZkDatabaseCorruptionTest.class);
- public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT;
-
- private final QuorumBase qb = new QuorumBase();
-
- @Before
- public void setUp() throws Exception {
- LOG.info("STARTING quorum " + getClass().getName());
- qb.setUp();
- }
-
- @After
- public void tearDown() throws Exception {
- LOG.info("STOPPING quorum " + getClass().getName());
- }
-
- private void corruptFile(File f) throws IOException {
- RandomAccessFile outFile = new RandomAccessFile(f, "rw");
- outFile.write("fail servers".getBytes());
- outFile.close();
- }
-
- private void corruptAllSnapshots(File snapDir) throws IOException {
- File[] listFiles = snapDir.listFiles();
- for (File f: listFiles) {
- if (f.getName().startsWith("snapshot")) {
- corruptFile(f);
- }
- }
- }
-
- private class NoopStringCallback implements AsyncCallback.StringCallback {
- @Override
- public void processResult(int rc, String path, Object ctx,
- String name) {
- }
- }
-
- @Test
- public void testCorruption() throws Exception {
- ClientBase.waitForServerUp(qb.hostPort, 10000);
- ClientBase.waitForServerUp(qb.hostPort, 10000);
- ZooKeeper zk = ClientBase.createZKClient(qb.hostPort, 10000);
- SyncRequestProcessor.setSnapCount(100);
- for (int i = 0; i < 2000; i++) {
- zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT, new NoopStringCallback(), null);
- }
- zk.close();
-
- long leaderSid = 1;
- QuorumPeer leader = null;
- //find out who is the leader and kill it
- for (QuorumPeer quorumPeer : Arrays.asList(qb.s1, qb.s2, qb.s3, qb.s4, qb.s5)) {
- if (quorumPeer.getPeerState() == ServerState.LEADING) {
- leader = quorumPeer;
- break;
- }
- ++leaderSid;
- }
-
- Assert.assertNotNull("Cannot find the leader.", leader);
- leader.shutdown();
-
- // now corrupt the leader's database
- FileTxnSnapLog snapLog = leader.getTxnFactory();
- File snapDir= snapLog.getSnapDir();
- //corrupt all the snapshot in the snapshot directory
- corruptAllSnapshots(snapDir);
- qb.shutdownServers();
- qb.setupServers();
-
- if (leaderSid != 1)qb.s1.start(); else leader = qb.s1;
- if (leaderSid != 2)qb.s2.start(); else leader = qb.s2;
- if (leaderSid != 3)qb.s3.start(); else leader = qb.s3;
- if (leaderSid != 4)qb.s4.start(); else leader = qb.s4;
- if (leaderSid != 5)qb.s5.start(); else leader = qb.s5;
-
- try {
- leader.start();
- Assert.assertTrue(false);
- } catch(RuntimeException re) {
- LOG.info("Got an error: expected", re);
- }
- //wait for servers to be up
- String[] list = qb.hostPort.split(",");
- for (int i = 0; i < 5; i++) {
- if(leaderSid != (i + 1)) {
- String hp = list[i];
- Assert.assertTrue("waiting for server up",
- ClientBase.waitForServerUp(hp,
- CONNECTION_TIMEOUT));
- LOG.info("{} is accepting client connections", hp);
- } else {
- LOG.info("Skipping the leader");
- }
- }
-
- zk = qb.createClient();
- SyncRequestProcessor.setSnapCount(100);
- for (int i = 2000; i < 4000; i++) {
- zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT, new NoopStringCallback(), null);
- }
- zk.close();
-
- if (leaderSid != 1)QuorumBase.shutdown(qb.s1);
- if (leaderSid != 2)QuorumBase.shutdown(qb.s2);
- if (leaderSid != 3)QuorumBase.shutdown(qb.s3);
- if (leaderSid != 4)QuorumBase.shutdown(qb.s4);
- if (leaderSid != 5)QuorumBase.shutdown(qb.s5);
- }
-
- @Test
- public void testAbsentRecentSnapshot() throws IOException {
- ZKDatabase zkDatabase = new ZKDatabase(new FileTxnSnapLog(new File("foo"), new File("bar")){
- @Override
- public File findMostRecentSnapshot() throws IOException {
- return null;
- }
- });
- assertEquals(0, zkDatabase.calculateTxnLogSizeLimit());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/43d71c2e/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZooKeeperQuotaTest.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZooKeeperQuotaTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZooKeeperQuotaTest.java
deleted file mode 100644
index 70a1486..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZooKeeperQuotaTest.java
+++ /dev/null
@@ -1,79 +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.Quotas;
-import org.apache.zookeeper.StatsTrack;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.ZooKeeperMain;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class ZooKeeperQuotaTest extends ClientBase {
-
- @Test
- public void testQuota() throws IOException,
- InterruptedException, KeeperException, Exception {
- final ZooKeeper zk = createClient();
- final String path = "/a/b/v";
- // making sure setdata works on /
- zk.setData("/", "some".getBytes(), -1);
- zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
-
- zk.create("/a/b", "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
-
- zk.create("/a/b/v", "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
-
- zk.create("/a/b/v/d", "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
- ZooKeeperMain.createQuota(zk, path, 5L, 10);
-
- // see if its set
- String absolutePath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode;
- byte[] data = zk.getData(absolutePath, false, new Stat());
- StatsTrack st = new StatsTrack(new String(data));
- Assert.assertTrue("bytes are set", st.getBytes() == 5L);
- Assert.assertTrue("num count is set", st.getCount() == 10);
-
- String statPath = Quotas.quotaZookeeper + path + "/" + Quotas.statNode;
- byte[] qdata = zk.getData(statPath, false, new Stat());
- StatsTrack qst = new StatsTrack(new String(qdata));
- Assert.assertTrue("bytes are set", qst.getBytes() == 8L);
- Assert.assertTrue("count is set", qst.getCount() == 2);
-
- //force server to restart and load from snapshot, not txn log
- stopServer();
- startServer();
- stopServer();
- startServer();
- ZooKeeperServer server = getServer(serverFactory);
- Assert.assertNotNull("Quota is still set",
- server.getZKDatabase().getDataTree().getMaxPrefixWithQuota(path) != null);
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/43d71c2e/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZooKeeperTestClient.java
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZooKeeperTestClient.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZooKeeperTestClient.java
deleted file mode 100644
index a0cba91..0000000
--- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ZooKeeperTestClient.java
+++ /dev/null
@@ -1,467 +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 java.io.IOException;
-import java.util.List;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.Watcher.Event.EventType;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.common.Time;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.server.ServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.junit.Assert;
-
-public class ZooKeeperTestClient extends ZKTestCase implements Watcher {
- protected String hostPort = "127.0.0.1:22801";
-
- protected static final String dirOnZK = "/test_dir";
-
- protected String testDirOnZK = dirOnZK + "/" + Time.currentElapsedTime();
-
- LinkedBlockingQueue<WatchedEvent> events = new LinkedBlockingQueue<WatchedEvent>();
-
- private WatchedEvent getEvent(int numTries) throws InterruptedException {
- WatchedEvent event = null;
- for (int i = 0; i < numTries; i++) {
- System.out.println("i = " + i);
- event = events.poll(10, TimeUnit.SECONDS);
- if (event != null) {
- break;
- }
- Thread.sleep(5000);
- }
- return event;
-
- }
-
- private void deleteZKDir(ZooKeeper zk, String nodeName)
- throws IOException, InterruptedException, KeeperException {
-
- Stat stat = zk.exists(nodeName, false);
- if (stat == null) {
- return;
- }
-
- List<String> children1 = zk.getChildren(nodeName, false);
- List<String> c2 = zk.getChildren(nodeName, false, stat);
-
- if (!children1.equals(c2)) {
- Assert.fail("children lists from getChildren()/getChildren2() do not match");
- }
-
- if (!stat.equals(stat)) {
- Assert.fail("stats from exists()/getChildren2() do not match");
- }
-
- if (children1.size() == 0) {
- zk.delete(nodeName, -1);
- return;
- }
- for (String n : children1) {
- deleteZKDir(zk, n);
- }
- }
-
- private void checkRoot() throws IOException,
- InterruptedException {
- ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
-
- try {
- zk.create(dirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- } catch (KeeperException.NodeExistsException ke) {
- // expected, sort of
- } catch (KeeperException ke) {
- Assert.fail("Unexpected exception code for create " + dirOnZK + ": "
- + ke.getMessage());
- }
-
- try {
- zk.create(testDirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- } catch (KeeperException.NodeExistsException ke) {
- // expected, sort of
- } catch (KeeperException ke) {
- Assert.fail("Unexpected exception code for create " + testDirOnZK + ": "
- + ke.getMessage());
- }
-
- zk.close();
- }
-
- private void enode_test_1() throws IOException,
- InterruptedException, KeeperException {
- checkRoot();
- String parentName = testDirOnZK;
- String nodeName = parentName + "/enode_abc";
- ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
-
- Stat stat = zk.exists(parentName, false);
- if (stat == null) {
- try {
- zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- } catch (KeeperException ke) {
- Assert.fail("Creating node " + parentName + ke.getMessage());
- }
- }
-
- try {
- zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NODEEXISTS;
- if (!valid) {
- Assert.fail("Unexpected exception code for createin: " + ke.getMessage());
- }
- }
-
- stat = zk.exists(nodeName, false);
- if (stat == null) {
- Assert.fail("node " + nodeName + " should exist");
- }
- System.out.println("Closing client with sessionid: 0x"
- + Long.toHexString(zk.getSessionId()));
- zk.close();
- zk = new ZooKeeper(hostPort, 10000, this);
-
- for (int i = 0; i < 10; i++) {
- System.out.println("i = " + i);
- stat = zk.exists(nodeName, false);
- if (stat != null) {
- System.out.println("node " + nodeName
- + " should not exist after reconnection close");
- } else {
- System.out.println("node " + nodeName
- + " is gone after reconnection close!");
- break;
- }
- Thread.sleep(5000);
- }
- deleteZKDir(zk, nodeName);
- zk.close();
-
- }
-
- private void enode_test_2() throws IOException,
- InterruptedException, KeeperException {
- checkRoot();
- String parentName = testDirOnZK;
- String nodeName = parentName + "/enode_abc";
- ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
- ZooKeeper zk_1 = new ZooKeeper(hostPort, 10000, this);
-
- Stat stat_parent = zk_1.exists(parentName, false);
- if (stat_parent == null) {
- try {
- zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- } catch (KeeperException ke) {
- Assert.fail("Creating node " + parentName + ke.getMessage());
- }
- }
-
- Stat stat_node = zk_1.exists(nodeName, false);
- if (stat_node != null) {
-
- try {
- zk.delete(nodeName, -1);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NONODE
- || code == KeeperException.Code.NOTEMPTY;
- if (!valid) {
- Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
- }
- }
- }
-
- List<String> firstGen1 = zk_1.getChildren(parentName, true);
- Stat stat = new Stat();
- List<String> firstGen2 = zk_1.getChildren(parentName, true, stat);
-
- if (!firstGen1.equals(firstGen2)) {
- Assert.fail("children lists from getChildren()/getChildren2() do not match");
- }
-
- if (!stat_parent.equals(stat)) {
- Assert.fail("stat from exists()/getChildren() do not match");
- }
-
- try {
- zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NODEEXISTS;
- if (!valid) {
- Assert.fail("Unexpected exception code for createin: " + ke.getMessage());
- }
- }
-
- Thread.sleep(5000);
- WatchedEvent event = events.poll(10, TimeUnit.SECONDS);
- if (event == null) {
- throw new IOException("No event was delivered promptly");
- }
- if (event.getType() != EventType.NodeChildrenChanged
- || !event.getPath().equalsIgnoreCase(parentName)) {
- Assert.fail("Unexpected event was delivered: " + event.toString());
- }
-
- stat_node = zk_1.exists(nodeName, false);
- if (stat_node == null) {
- Assert.fail("node " + nodeName + " should exist");
- }
-
- try {
- zk.delete(parentName, -1);
- Assert.fail("Should be impossible to delete a non-empty node " + parentName);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NOTEMPTY;
- if (!valid) {
- Assert.fail("Unexpected exception code for delete: " + code);
- }
- }
-
- try {
- zk.create(nodeName + "/def", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
- Assert.fail("Should be impossible to create child off Ephemeral node " + nodeName);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NOCHILDRENFOREPHEMERALS;
- if (!valid) {
- Assert.fail("Unexpected exception code for createin: " + code);
- }
- }
-
- try {
- List<String> children1 = zk.getChildren(nodeName, false);
- List<String> children2 = zk.getChildren(nodeName, false, null);
-
- if (!children1.equals(children2)) {
- Assert.fail("children lists from getChildren()/getChildren2() does not match");
- }
-
- if (children1.size() > 0) {
- Assert.fail("ephemeral node " + nodeName + " should not have children");
- }
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NONODE;
- if (!valid) {
- Assert.fail("Unexpected exception code for createin: " + code);
- }
- }
- firstGen1 = zk_1.getChildren(parentName, true);
- firstGen2 = zk_1.getChildren(parentName, true, null);
-
- if (!firstGen1.equals(firstGen2)) {
- Assert.fail("children list from getChildren()/getChildren2() does not match");
- }
-
- stat_node = zk_1.exists(nodeName, true);
- if (stat_node == null) {
- Assert.fail("node " + nodeName + " should exist");
- }
- System.out.println("session id of zk: " + zk.getSessionId());
- System.out.println("session id of zk_1: " + zk_1.getSessionId());
- zk.close();
-
- zk_1.exists("nosuchnode", false);
-
- event = this.getEvent(10);
- if (event == null) {
- throw new Error("First event was not delivered promptly");
- }
- if (!((event.getType() == EventType.NodeChildrenChanged &&
- event.getPath().equalsIgnoreCase(parentName)) ||
- (event.getType() == EventType.NodeDeleted &&
- event.getPath().equalsIgnoreCase(nodeName)))) {
- System.out.print(parentName + " "
- + EventType.NodeChildrenChanged + " " + nodeName + " " + EventType.NodeDeleted);
- Assert.fail("Unexpected first event was delivered: " + event.toString());
- }
-
- event = this.getEvent(10);
-
- if (event == null) {
- throw new Error("Second event was not delivered promptly");
- }
- if (!((event.getType() == EventType.NodeChildrenChanged &&
- event.getPath().equalsIgnoreCase(parentName)) ||
- (event.getType() == EventType.NodeDeleted &&
- event.getPath().equalsIgnoreCase(nodeName)))) {
- System.out.print(parentName + " "
- + EventType.NodeChildrenChanged + " " + nodeName + " " + EventType.NodeDeleted);
- Assert.fail("Unexpected second event was delivered: " + event.toString());
- }
-
- firstGen1 = zk_1.getChildren(parentName, false);
- stat_node = zk_1.exists(nodeName, false);
- if (stat_node != null) {
- Assert.fail("node " + nodeName + " should have been deleted");
- }
- if (firstGen1.contains(nodeName)) {
- Assert.fail("node " + nodeName + " should not be a children");
- }
- deleteZKDir(zk_1, nodeName);
- zk_1.close();
- }
-
- private void delete_create_get_set_test_1() throws
- IOException, InterruptedException, KeeperException {
- checkRoot();
- ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
- String parentName = testDirOnZK;
- String nodeName = parentName + "/benwashere";
- try {
- zk.delete(nodeName, -1);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NONODE
- || code == KeeperException.Code.NOTEMPTY;
- if (!valid) {
- Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
- }
- }
- try {
- zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NODEEXISTS;
- if (!valid) {
- Assert.fail("Unexpected exception code for create: " + ke.getMessage());
- }
- }
- try {
- zk.setData(nodeName, "hi".getBytes(), 5700);
- Assert.fail("Should have gotten BadVersion exception");
- } catch (KeeperException ke) {
- if (ke.code() != Code.BADVERSION) {
- Assert.fail("Should have gotten BadVersion exception");
- }
- }
- zk.setData(nodeName, "hi".getBytes(), -1);
- Stat st = new Stat();
- byte[] bytes = zk.getData(nodeName, false, st);
- String retrieved = new String(bytes);
- if (!"hi".equals(retrieved)) {
- Assert.fail("The retrieved data [" + retrieved
- + "] is differented than the expected [hi]");
- }
- try {
- zk.delete(nodeName, 6800);
- Assert.fail("Should have gotten BadVersion exception");
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NOTEMPTY
- || code == KeeperException.Code.BADVERSION;
- if (!valid) {
- Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
- }
- }
- try {
- zk.delete(nodeName, -1);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NOTEMPTY;
- if (!valid) {
- Assert.fail("Unexpected exception code for delete: " + code);
- }
- }
- deleteZKDir(zk, nodeName);
- zk.close();
- }
-
- private void deleteNodeIfExists(ZooKeeper zk, String nodeName)
- throws InterruptedException {
- try {
- zk.delete(nodeName, -1);
- } catch (KeeperException ke) {
- Code code = ke.code();
- boolean valid = code == KeeperException.Code.NONODE ||
- code == KeeperException.Code.NOTEMPTY;
- if (!valid) {
- Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
- }
- }
- }
-
- private void create_get_stat_test()
- throws IOException, InterruptedException, KeeperException {
- checkRoot();
- ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
- String parentName = testDirOnZK;
- String nodeName = parentName + "/create_with_stat_tmp";
- deleteNodeIfExists(zk, nodeName);
- deleteNodeIfExists(zk, nodeName + "_2");
- Stat stat = new Stat();
- zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT,
- stat);
- Assert.assertNotNull(stat);
- Assert.assertTrue(stat.getCzxid() > 0);
- Assert.assertTrue(stat.getCtime() > 0);
-
- Stat stat2 = new Stat();
- zk.create(nodeName + "_2", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT,
- stat2);
- Assert.assertNotNull(stat2);
- Assert.assertTrue(stat2.getCzxid() > stat.getCzxid());
- Assert.assertTrue(stat2.getCtime() > stat.getCtime());
-
- deleteNodeIfExists(zk, nodeName);
- deleteNodeIfExists(zk, nodeName + "_2");
- zk.close();
- }
-
- public void my_test_1() throws IOException,
- InterruptedException, KeeperException {
- enode_test_1();
- enode_test_2();
- delete_create_get_set_test_1();
- create_get_stat_test();
- }
-
- synchronized public void process(WatchedEvent event) {
- try {
- System.out.println("Got an event " + event.toString());
- events.put(event);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- public static void main(String[] args) {
- ZooKeeperTestClient zktc = new ZooKeeperTestClient();
- try {
- zktc.my_test_1();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/43d71c2e/zookeeper-common/src/test/resources/check_compatibility.py
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/resources/check_compatibility.py b/zookeeper-common/src/test/resources/check_compatibility.py
deleted file mode 100644
index cad8195..0000000
--- a/zookeeper-common/src/test/resources/check_compatibility.py
+++ /dev/null
@@ -1,204 +0,0 @@
-#!/usr/bin/env python
-#
-# 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.
-
-# Script which checks Java API compatibility between two revisions of the
-# Java client.
-#
-# Based on the compatibility checker from the HBase project, but ported to
-# Python for better readability.
-
-# Lifted from Kudu: https://github.com/apache/kudu/blob/master/build-support/check_compatibility.py
-
-import logging
-import optparse
-import os
-import shutil
-import subprocess
-import sys
-
-JAVA_ACC_GIT_URL = "https://github.com/lvc/japi-compliance-checker.git"
-
-# The annotations for what we consider our public API.
-PUBLIC_ANNOTATIONS = ["org.apache.yetus.audience.InterfaceAudience.LimitedPrivate",
- "org.apache.yetus.audience.InterfaceAudience.Public"]
-
-# Various relative paths
-PATH_TO_REPO_DIR = "../../../../"
-PATH_TO_BUILD_DIR = PATH_TO_REPO_DIR + "build/compat-check"
-PATH_TO_JACC_DIR = PATH_TO_REPO_DIR + "build/jacc"
-
-def check_output(*popenargs, **kwargs):
- # r"""Run command with arguments and return its output as a byte string.
- # Backported from Python 2.7 as it's implemented as pure python on stdlib.
- # >>> check_output(['/usr/bin/python', '--version'])
- # Python 2.6.2
- # """
- process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
- output, unused_err = process.communicate()
- retcode = process.poll()
- if retcode:
- cmd = kwargs.get("args")
- if cmd is None:
- cmd = popenargs[0]
- error = subprocess.CalledProcessError(retcode, cmd)
- error.output = output
- raise error
- return output
-
-def get_repo_dir():
- """ Return the path to the top of the repo. """
- dirname, _ = os.path.split(os.path.abspath(__file__))
- return os.path.abspath(os.path.join(dirname, PATH_TO_REPO_DIR))
-
-
-def get_scratch_dir():
- """ Return the path to the scratch dir that we build within. """
- dirname, _ = os.path.split(os.path.abspath(__file__))
- return os.path.abspath(os.path.join(dirname, PATH_TO_BUILD_DIR))
-
-
-def get_java_acc_dir():
- dirname, _ = os.path.split(os.path.abspath(__file__))
- return os.path.abspath(os.path.join(dirname, PATH_TO_JACC_DIR))
-
-
-def clean_scratch_dir(scratch_dir):
- """ Clean up and re-create the scratch directory. """
- if os.path.exists(scratch_dir):
- logging.info("Removing scratch dir %s...", scratch_dir)
- shutil.rmtree(scratch_dir)
- logging.info("Creating empty scratch dir %s...", scratch_dir)
- os.makedirs(scratch_dir)
-
-
-def checkout_tree(rev, path):
- """ Check out the Java source tree for the given revision into the given path. """
- logging.info("Checking out %s in %s", rev, path)
- os.makedirs(path)
- # Extract java source
- subprocess.check_call(["bash", '-o', 'pipefail', "-c",
- ("git archive --format=tar %s | " +
- "tar -C \"%s\" -xf -") % (rev, path)],
- cwd=get_repo_dir())
-
-
-def get_git_hash(revname):
- """ Convert 'revname' to its SHA-1 hash. """
- return check_output(["git", "rev-parse", revname],
- cwd=get_repo_dir()).strip()
-
-
-def build_tree(path):
- """ Run the Java build within 'path'. """
- logging.info("Building in %s...", path)
- subprocess.check_call(["ant", "jar"], cwd=path)
-
-
-def checkout_java_acc(force):
- """
- Check out the Java API Compliance Checker. If 'force' is true, will re-download even if the
- directory exists.
- """
- acc_dir = get_java_acc_dir()
- if os.path.exists(acc_dir):
- logging.info("Java JAVA_ACC is already downloaded.")
- if not force:
- return
- logging.info("Forcing re-download.")
- shutil.rmtree(acc_dir)
- logging.info("Checking out Java JAVA_ACC...")
- subprocess.check_call(["git", "clone", "-b", "2.1", "--single-branch", "--depth=1", JAVA_ACC_GIT_URL, acc_dir])
-
-
-def find_client_jars(path):
- """ Return a list of jars within 'path' to be checked for compatibility. """
- return check_output(["find", path, "-name", "zookeeper*.jar"]).rstrip('\n')
-
-
-def run_java_acc(src_name, src, dst_name, dst):
- """ Run the compliance checker to compare 'src' and 'dst'. """
- src_jar = find_client_jars(src)
- dst_jar = find_client_jars(dst)
- logging.info("Will check compatibility between original jars:\n%s\n" +
- "and new jars:\n%s",
- src_jar, dst_jar)
-
- annotations_path = os.path.join(get_scratch_dir(), "annotations.txt")
- with file(annotations_path, "w") as f:
- for ann in PUBLIC_ANNOTATIONS:
- print >>f, ann
-
- java_acc_path = os.path.join(get_java_acc_dir(), "japi-compliance-checker.pl")
-
- out_path = os.path.join(get_scratch_dir(), "report.html")
- subprocess.check_call(["perl", java_acc_path,
- "-lib", "ZooKeeper",
- "-v1", src_name,
- "-v2", dst_name,
- "-d1", src_jar,
- "-d2", dst_jar,
- "-annotations-list", annotations_path,
- "-report-path", out_path])
-
-
-def main(argv):
- logging.basicConfig(level=logging.INFO)
- parser = optparse.OptionParser(
- usage="usage: %prog SRC..[DST]")
- parser.add_option("-f", "--force-download", dest="force_download_deps",
- help=("Download dependencies (i.e. Java JAVA_ACC) even if they are " +
- "already present"))
- opts, args = parser.parse_args()
-
- if len(args) != 1:
- parser.error("no src/dst revision specified")
- sys.exit(1)
-
- src_rev, dst_rev = args[0].split("..", 1)
- if dst_rev == "":
- dst_rev = "HEAD"
- src_rev = get_git_hash(src_rev)
- dst_rev = get_git_hash(dst_rev)
-
- logging.info("Source revision: %s", src_rev)
- logging.info("Destination revision: %s", dst_rev)
-
- # Download deps.
- checkout_java_acc(opts.force_download_deps)
-
- # Set up the build.
- scratch_dir = get_scratch_dir()
- clean_scratch_dir(scratch_dir)
-
- # Check out the src and dst source trees.
- src_dir = os.path.join(scratch_dir, "src")
- dst_dir = os.path.join(scratch_dir, "dst")
- checkout_tree(src_rev, src_dir)
- checkout_tree(dst_rev, dst_dir)
-
- # Run the build in each.
- build_tree(src_dir)
- build_tree(dst_dir)
-
- run_java_acc(src_rev, src_dir + "/build",
- dst_rev, dst_dir + "/build")
-
-
-if __name__ == "__main__":
- main(sys.argv)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/43d71c2e/zookeeper-common/src/test/resources/checkstyle-noframes-sorted.xsl
----------------------------------------------------------------------
diff --git a/zookeeper-common/src/test/resources/checkstyle-noframes-sorted.xsl b/zookeeper-common/src/test/resources/checkstyle-noframes-sorted.xsl
deleted file mode 100644
index 5f9e93b..0000000
--- a/zookeeper-common/src/test/resources/checkstyle-noframes-sorted.xsl
+++ /dev/null
@@ -1,178 +0,0 @@
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-<xsl:output method="html" indent="yes"/>
-<xsl:decimal-format decimal-separator="." grouping-separator="," />
-
-<xsl:key name="files" match="file" use="@name" />
-
-<!-- Checkstyle XML Style Sheet by Stephane Bailliez <sb...@apache.org> -->
-<!-- Part of the Checkstyle distribution found at http://checkstyle.sourceforge.net -->
-<!-- Usage (generates checkstyle_report.html): -->
-<!-- <checkstyle failonviolation="false" config="${check.config}"> -->
-<!-- <fileset dir="${src.dir}" includes="**/*.java"/> -->
-<!-- <formatter type="xml" toFile="${doc.dir}/checkstyle_report.xml"/> -->
-<!-- </checkstyle> -->
-<!-- <style basedir="${doc.dir}" destdir="${doc.dir}" -->
-<!-- includes="checkstyle_report.xml" -->
-<!-- style="${doc.dir}/checkstyle-noframes-sorted.xsl"/> -->
-
-<xsl:template match="checkstyle">
- <html>
- <head>
- <style type="text/css">
- .bannercell {
- border: 0px;
- padding: 0px;
- }
- body {
- margin-left: 10;
- margin-right: 10;
- font:normal 80% arial,helvetica,sanserif;
- background-color:#FFFFFF;
- color:#000000;
- }
- .a td {
- background: #efefef;
- }
- .b td {
- background: #fff;
- }
- th, td {
- text-align: left;
- vertical-align: top;
- }
- th {
- font-weight:bold;
- background: #ccc;
- color: black;
- }
- table, th, td {
- font-size:100%;
- border: none
- }
- table.log tr td, tr th {
-
- }
- h2 {
- font-weight:bold;
- font-size:140%;
- margin-bottom: 5;
- }
- h3 {
- font-size:100%;
- font-weight:bold;
- background: #525D76;
- color: white;
- text-decoration: none;
- padding: 5px;
- margin-right: 2px;
- margin-left: 2px;
- margin-bottom: 0;
- }
- </style>
- </head>
- <body>
- <a name="top"></a>
- <!-- jakarta logo -->
- <table border="0" cellpadding="0" cellspacing="0" width="100%">
- <tr>
- <td class="bannercell" rowspan="2">
- <!--a href="http://jakarta.apache.org/">
- <img src="http://jakarta.apache.org/images/jakarta-logo.gif" alt="http://jakarta.apache.org" align="left" border="0"/>
- </a-->
- </td>
- <td class="text-align:right"><h2>CheckStyle Audit</h2></td>
- </tr>
- <tr>
- <td class="text-align:right">Designed for use with <a href='http://checkstyle.sourceforge.net/'>CheckStyle</a> and <a href='http://jakarta.apache.org'>Ant</a>.</td>
- </tr>
- </table>
- <hr size="1"/>
-
- <!-- Summary part -->
- <xsl:apply-templates select="." mode="summary"/>
- <hr size="1" width="100%" align="left"/>
-
- <!-- Package List part -->
- <xsl:apply-templates select="." mode="filelist"/>
- <hr size="1" width="100%" align="left"/>
-
- <!-- For each package create its part -->
- <xsl:apply-templates select="file[@name and generate-id(.) = generate-id(key('files', @name))]" />
-
- <hr size="1" width="100%" align="left"/>
-
-
- </body>
- </html>
-</xsl:template>
-
-
-
- <xsl:template match="checkstyle" mode="filelist">
- <h3>Files</h3>
- <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
- <tr>
- <th>Name</th>
- <th>Errors</th>
- </tr>
- <xsl:for-each select="file[@name and generate-id(.) = generate-id(key('files', @name))]">
- <xsl:sort data-type="number" order="descending" select="count(key('files', @name)/error)"/>
- <xsl:variable name="errorCount" select="count(error)"/>
- <tr>
- <xsl:call-template name="alternated-row"/>
- <td><a href="#f-{@name}"><xsl:value-of select="@name"/></a></td>
- <td><xsl:value-of select="$errorCount"/></td>
- </tr>
- </xsl:for-each>
- </table>
- </xsl:template>
-
-
- <xsl:template match="file">
- <a name="f-{@name}"></a>
- <h3>File <xsl:value-of select="@name"/></h3>
-
- <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
- <tr>
- <th>Error Description</th>
- <th>Line</th>
- </tr>
- <xsl:for-each select="key('files', @name)/error">
- <xsl:sort data-type="number" order="ascending" select="@line"/>
- <tr>
- <xsl:call-template name="alternated-row"/>
- <td><xsl:value-of select="@message"/></td>
- <td><xsl:value-of select="@line"/></td>
- </tr>
- </xsl:for-each>
- </table>
- <a href="#top">Back to top</a>
- </xsl:template>
-
-
- <xsl:template match="checkstyle" mode="summary">
- <h3>Summary</h3>
- <xsl:variable name="fileCount" select="count(file[@name and generate-id(.) = generate-id(key('files', @name))])"/>
- <xsl:variable name="errorCount" select="count(file/error)"/>
- <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
- <tr>
- <th>Files</th>
- <th>Errors</th>
- </tr>
- <tr>
- <xsl:call-template name="alternated-row"/>
- <td><xsl:value-of select="$fileCount"/></td>
- <td><xsl:value-of select="$errorCount"/></td>
- </tr>
- </table>
- </xsl:template>
-
- <xsl:template name="alternated-row">
- <xsl:attribute name="class">
- <xsl:if test="position() mod 2 = 1">a</xsl:if>
- <xsl:if test="position() mod 2 = 0">b</xsl:if>
- </xsl:attribute>
- </xsl:template>
-</xsl:stylesheet>
-
-