http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/NonRecoverableErrorTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/NonRecoverableErrorTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/NonRecoverableErrorTest.java deleted file mode 100644 index 133d920..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/NonRecoverableErrorTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zookeeper.test; - -import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.UUID; - -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.PortAssignment; -import org.apache.zookeeper.ZooDefs.Ids; -import org.apache.zookeeper.ZooKeeper; -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.apache.zookeeper.server.quorum.QuorumPeerTestBase; -import org.apache.zookeeper.test.ClientBase.CountdownWatcher; -import org.junit.Assert; -import org.junit.Test; - -/** - * This class tests the non-recoverable error behavior of quorum server. - */ -public class NonRecoverableErrorTest extends QuorumPeerTestBase { - private static final String NODE_PATH = "/noLeaderIssue"; - - /** - * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2247. - * Test to verify that even after non recoverable error (error while - * writing transaction log), ZooKeeper is still available. - */ - @Test(timeout = 30000) - public void testZooKeeperServiceAvailableOnLeader() throws Exception { - int SERVER_COUNT = 3; - final int clientPorts[] = new int[SERVER_COUNT]; - StringBuilder sb = new StringBuilder(); - String server; - - for (int i = 0; i < SERVER_COUNT; i++) { - clientPorts[i] = PortAssignment.unique(); - server = "server." + i + "=127.0.0.1:" + PortAssignment.unique() - + ":" + PortAssignment.unique(); - sb.append(server + "\n"); - } - String currentQuorumCfgSection = sb.toString(); - MainThread mt[] = new MainThread[SERVER_COUNT]; - - for (int i = 0; i < SERVER_COUNT; i++) { - mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection); - mt[i].start(); - } - - // ensure server started - for (int i = 0; i < SERVER_COUNT; i++) { - Assert.assertTrue("waiting for server " + i + " being up", - ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], - CONNECTION_TIMEOUT)); - } - - CountdownWatcher watcher = new CountdownWatcher(); - ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[0], - ClientBase.CONNECTION_TIMEOUT, watcher); - watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT); - - String data = "originalData"; - zk.create(NODE_PATH, data.getBytes(), Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - - // get information of current leader - QuorumPeer leader = getLeaderQuorumPeer(mt); - assertNotNull("Leader must have been elected by now", leader); - - // inject problem in leader - FileTxnSnapLog snapLog = leader.getActiveServer().getTxnLogFactory(); - FileTxnSnapLog fileTxnSnapLogWithError = new FileTxnSnapLog( - snapLog.getDataDir(), snapLog.getSnapDir()) { - @Override - public void commit() throws IOException { - throw new IOException("Input/output error"); - } - }; - ZKDatabase originalZKDatabase = leader.getActiveServer() - .getZKDatabase(); - long leaderCurrentEpoch = leader.getCurrentEpoch(); - - ZKDatabase newDB = new ZKDatabase(fileTxnSnapLogWithError); - leader.getActiveServer().setZKDatabase(newDB); - - try { - // do create operation, so that injected IOException is thrown - zk.create(uniqueZnode(), data.getBytes(), Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - fail("IOException is expected due to error injected to transaction log commit"); - } catch (Exception e) { - // do nothing - } - - // resetting watcher so that this watcher can be again used to ensure - // that the zkClient is able to re-establish connection with the - // newly elected zookeeper quorum. - watcher.reset(); - waitForNewLeaderElection(leader, leaderCurrentEpoch); - - // ensure server started, give enough time, so that new leader election - // takes place - for (int i = 0; i < SERVER_COUNT; i++) { - Assert.assertTrue("waiting for server " + i + " being up", - ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], - CONNECTION_TIMEOUT)); - } - - // revert back the error - leader.getActiveServer().setZKDatabase(originalZKDatabase); - - // verify that now ZooKeeper service is up and running - leader = getLeaderQuorumPeer(mt); - assertNotNull("New leader must have been elected by now", leader); - - String uniqueNode = uniqueZnode(); - watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT); - String createNode = zk.create(uniqueNode, data.getBytes(), - Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - // if node is created successfully then it means that ZooKeeper service - // is available - assertEquals("Failed to create znode", uniqueNode, createNode); - zk.close(); - // stop all severs - for (int i = 0; i < SERVER_COUNT; i++) { - mt[i].shutdown(); - } - } - - private void waitForNewLeaderElection(QuorumPeer peer, - long leaderCurrentEpoch) throws IOException, InterruptedException { - LOG.info("Waiting for new LE cycle.."); - int count = 100; // giving a grace period of 10seconds - while (count > 0) { - if (leaderCurrentEpoch == peer.getCurrentEpoch()) { - Thread.sleep(100); - } - count--; - } - Assert.assertTrue("New LE cycle must have triggered", - leaderCurrentEpoch != peer.getCurrentEpoch()); - } - - private QuorumPeer getLeaderQuorumPeer(MainThread[] mt) { - for (int i = mt.length - 1; i >= 0; i--) { - QuorumPeer quorumPeer = mt[i].getQuorumPeer(); - if (null != quorumPeer - && ServerState.LEADING == quorumPeer.getPeerState()) { - return quorumPeer; - } - } - return null; - } - - private String uniqueZnode() { - UUID randomUUID = UUID.randomUUID(); - String node = NODE_PATH + "/" + randomUUID.toString(); - return node; - } -}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/NullDataTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/NullDataTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/NullDataTest.java deleted file mode 100644 index 8f1a1bb..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/NullDataTest.java +++ /dev/null @@ -1,75 +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.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.ZooKeeper; -import org.apache.zookeeper.AsyncCallback.StatCallback; -import org.apache.zookeeper.ZooDefs.Ids; -import org.apache.zookeeper.data.Stat; -import org.junit.Assert; -import org.junit.Test; - -public class NullDataTest extends ClientBase implements StatCallback { - String snapCount; - CountDownLatch cn = new CountDownLatch(1); - - @Override - public void setUp() throws Exception { - // Change the snapcount to happen more often - snapCount = System.getProperty("zookeeper.snapCount", "1024"); - System.setProperty("zookeeper.snapCount", "10"); - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - System.setProperty("zookeeper.snapCount", snapCount); - super.tearDown(); - } - - @Test - public void testNullData() throws IOException, - InterruptedException, KeeperException { - String path = "/SIZE"; - ZooKeeper zk = null; - zk = createClient(); - try { - zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - // try sync zk exists - zk.exists(path, false); - zk.exists(path, false, this , null); - cn.await(10, TimeUnit.SECONDS); - Assert.assertSame(0L, cn.getCount()); - } finally { - if(zk != null) - zk.close(); - } - - } - - public void processResult(int rc, String path, Object ctx, Stat stat) { - cn.countDown(); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/OOMTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/OOMTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/OOMTest.java deleted file mode 100644 index 465df98..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/OOMTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.test; - -import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; - -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.PortAssignment; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZKTestCase; -import org.apache.zookeeper.ZooKeeper; -import org.apache.zookeeper.ZooDefs.Ids; -import org.apache.zookeeper.data.Stat; -import org.apache.zookeeper.server.ServerCnxnFactory; -import org.apache.zookeeper.server.ZooKeeperServer; -import org.junit.Assert; -import org.junit.Test; - -public class OOMTest extends ZKTestCase implements Watcher { - @Test - public void testOOM() throws IOException, InterruptedException, KeeperException { - // This test takes too long tos run! - if (true) - return; - File tmpDir = ClientBase.createTmpDir(); - // Grab some memory so that it is easier to cause an - // OOM condition; - ArrayList<byte[]> hog = new ArrayList<byte[]>(); - while (true) { - try { - hog.add(new byte[1024 * 1024 * 2]); - } catch (OutOfMemoryError e) { - hog.remove(0); - break; - } - } - ClientBase.setupTestEnv(); - ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); - - final int PORT = PortAssignment.unique(); - ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); - f.startup(zks); - Assert.assertTrue("waiting for server up", - ClientBase.waitForServerUp("127.0.0.1:" + PORT, - CONNECTION_TIMEOUT)); - - System.err.println("OOM Stage 0"); - utestPrep(PORT); - System.out.println("Free = " + Runtime.getRuntime().freeMemory() - + " total = " + Runtime.getRuntime().totalMemory() + " max = " - + Runtime.getRuntime().maxMemory()); - System.err.println("OOM Stage 1"); - for (int i = 0; i < 1000; i++) { - System.out.println(i); - utestExists(PORT); - } - System.out.println("Free = " + Runtime.getRuntime().freeMemory() - + " total = " + Runtime.getRuntime().totalMemory() + " max = " - + Runtime.getRuntime().maxMemory()); - System.err.println("OOM Stage 2"); - for (int i = 0; i < 1000; i++) { - System.out.println(i); - utestGet(PORT); - } - System.out.println("Free = " + Runtime.getRuntime().freeMemory() - + " total = " + Runtime.getRuntime().totalMemory() + " max = " - + Runtime.getRuntime().maxMemory()); - System.err.println("OOM Stage 3"); - for (int i = 0; i < 1000; i++) { - System.out.println(i); - utestChildren(PORT); - } - System.out.println("Free = " + Runtime.getRuntime().freeMemory() - + " total = " + Runtime.getRuntime().totalMemory() + " max = " - + Runtime.getRuntime().maxMemory()); - hog.get(0)[0] = (byte) 1; - - f.shutdown(); - zks.shutdown(); - Assert.assertTrue("waiting for server down", - ClientBase.waitForServerDown("127.0.0.1:" + PORT, - CONNECTION_TIMEOUT)); - } - - private void utestExists(int port) - throws IOException, InterruptedException, KeeperException - { - ZooKeeper zk = - new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); - for (int i = 0; i < 10000; i++) { - zk.exists("/this/path/doesnt_exist!", true); - } - zk.close(); - } - - private void utestPrep(int port) - throws IOException, InterruptedException, KeeperException - { - ZooKeeper zk = - new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); - for (int i = 0; i < 10000; i++) { - zk.create("/" + i, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - } - zk.close(); - } - - private void utestGet(int port) - throws IOException, InterruptedException, KeeperException - { - ZooKeeper zk = - new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); - for (int i = 0; i < 10000; i++) { - Stat stat = new Stat(); - zk.getData("/" + i, true, stat); - } - zk.close(); - } - - private void utestChildren(int port) - throws IOException, InterruptedException, KeeperException - { - ZooKeeper zk = - new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); - for (int i = 0; i < 10000; i++) { - zk.getChildren("/" + i, true); - } - zk.close(); - } - - /* - * (non-Javadoc) - * - * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.proto.WatcherEvent) - */ - public void process(WatchedEvent event) { - System.err.println("Got event " + event.getType() + " " - + event.getState() + " " + event.getPath()); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/OSMXBeanTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/OSMXBeanTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/OSMXBeanTest.java deleted file mode 100644 index ce21ab8..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/OSMXBeanTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.test; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.Before; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.zookeeper.server.util.OSMXBean; - -public class OSMXBeanTest { - - private OSMXBean osMbean; - private Long ofdc = 0L; - private Long mfdc = 0L; - protected static final Logger LOG = LoggerFactory.getLogger(OSMXBeanTest.class); - - @Before - public void initialize() { - this.osMbean = new OSMXBean(); - Assert.assertNotNull("Could not initialize OSMXBean object!", osMbean); - } - - @Test - public final void testGetUnix() { - boolean isUnix = osMbean.getUnix(); - if (!isUnix) { - LOG.info("Running in a Windows system! Output won't be printed!"); - } else { - LOG.info("Running in a Unix or Linux system!"); - } - } - - @Test - public final void testGetOpenFileDescriptorCount() { - if (osMbean != null && osMbean.getUnix() == true) { - ofdc = osMbean.getOpenFileDescriptorCount(); - LOG.info("open fdcount is: " + ofdc); - } - Assert.assertFalse("The number of open file descriptor is negative",(ofdc < 0)); - } - - @Test - public final void testGetMaxFileDescriptorCount() { - if (osMbean != null && osMbean.getUnix() == true) { - mfdc = osMbean.getMaxFileDescriptorCount(); - LOG.info("max fdcount is: " + mfdc); - } - Assert.assertFalse("The max file descriptor number is negative",(mfdc < 0)); - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java deleted file mode 100644 index 9d373fc..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.test; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.zookeeper.server.quorum.QuorumPeer; -import org.junit.Test; - -public class ObserverHierarchicalQuorumTest extends HierarchicalQuorumTest { - private static final Logger LOG = LoggerFactory.getLogger(QuorumBase.class); - - /** - * startServers(true) puts two observers into a 5 peer ensemble - */ - void startServers() throws Exception { - startServers(true); - } - - protected void shutdown(QuorumPeer qp) { - QuorumBase.shutdown(qp); - } - - @Test - public void testHierarchicalQuorum() throws Throwable { - cht.runHammer(5, 10); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverLETest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverLETest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverLETest.java deleted file mode 100644 index 123ba0b..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverLETest.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zookeeper.test; - -import static org.junit.Assert.*; - -import java.util.Arrays; - -import org.apache.zookeeper.ZKTestCase; -import org.apache.zookeeper.server.quorum.QuorumPeer; -import org.apache.zookeeper.server.quorum.QuorumStats; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ObserverLETest extends ZKTestCase { - final QuorumBase qb = new QuorumBase(); - final ClientTest ct = new ClientTest(); - - @Before - public void establishThreeParticipantOneObserverEnsemble() throws Exception { - qb.setUp(true); - ct.hostPort = qb.hostPort; - ct.setUpAll(); - qb.s5.shutdown(); - } - - @After - public void shutdownQuorum() throws Exception { - ct.tearDownAll(); - qb.tearDown(); - } - - /** - * See ZOOKEEPER-1294. Confirms that an observer will not support the quorum - * of a leader by forming a 5-node, 2-observer ensemble (so quorum size is 2). - * When all but the leader and one observer are shut down, the leader should - * enter the 'looking' state, not stay in the 'leading' state. - */ - @Test - public void testLEWithObserver() throws Exception { - QuorumPeer leader = null; - for (QuorumPeer server : Arrays.asList(qb.s1, qb.s2, qb.s3)) { - if (server.getServerState().equals( - QuorumStats.Provider.FOLLOWING_STATE)) { - server.shutdown(); - assertTrue("Waiting for server down", ClientBase - .waitForServerDown("127.0.0.1:" - + server.getClientPort(), - ClientBase.CONNECTION_TIMEOUT)); - } else { - assertNull("More than one leader found", leader); - leader = server; - } - } - assertTrue("Leader is not in Looking state", ClientBase - .waitForServerState(leader, ClientBase.CONNECTION_TIMEOUT, - QuorumStats.Provider.LOOKING_STATE)); - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverQuorumHammerTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverQuorumHammerTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverQuorumHammerTest.java deleted file mode 100644 index 03b4000..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverQuorumHammerTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.test; -import org.junit.Before; -import org.junit.Test; - -public class ObserverQuorumHammerTest extends QuorumHammerTest { - public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; - - - @Before - @Override - public void setUp() throws Exception { - qb.setUp(true); - cht.hostPort = qb.hostPort; - cht.setUpAll(); - } - - @Test - public void testHammerBasic() throws Throwable { - cht.testHammerBasic(); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverTest.java deleted file mode 100644 index f7a82c6..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/ObserverTest.java +++ /dev/null @@ -1,233 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.test; - -import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; - -import java.util.concurrent.CountDownLatch; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException.ConnectionLossException; -import org.apache.zookeeper.PortAssignment; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.Watcher.Event.KeeperState; -import org.apache.zookeeper.ZooDefs.Ids; -import org.apache.zookeeper.ZooKeeper; -import org.apache.zookeeper.ZooKeeper.States; -import org.apache.zookeeper.server.quorum.QuorumPeerTestBase; -import org.junit.Assert; -import org.junit.Test; - -public class ObserverTest extends QuorumPeerTestBase implements Watcher{ - protected static final Logger LOG = - LoggerFactory.getLogger(ObserverTest.class); - - CountDownLatch latch; - ZooKeeper zk; - WatchedEvent lastEvent = null; - - /** - * This test ensures two things: - * 1. That Observers can successfully proxy requests to the ensemble. - * 2. That Observers don't participate in leader elections. - * The second is tested by constructing an ensemble where a leader would - * be elected if and only if an Observer voted. - * @throws Exception - */ - @Test - public void testObserver() throws Exception { - ClientBase.setupTestEnv(); - // We expect two notifications before we want to continue - latch = new CountDownLatch(2); - - final int PORT_QP1 = PortAssignment.unique(); - final int PORT_QP2 = PortAssignment.unique(); - final int PORT_OBS = PortAssignment.unique(); - final int PORT_QP_LE1 = PortAssignment.unique(); - final int PORT_QP_LE2 = PortAssignment.unique(); - final int PORT_OBS_LE = PortAssignment.unique(); - - final int CLIENT_PORT_QP1 = PortAssignment.unique(); - final int CLIENT_PORT_QP2 = PortAssignment.unique(); - final int CLIENT_PORT_OBS = PortAssignment.unique(); - - - String quorumCfgSection = - "electionAlg=3\n" + - "server.1=127.0.0.1:" + (PORT_QP1) - + ":" + (PORT_QP_LE1) - + "\nserver.2=127.0.0.1:" + (PORT_QP2) - + ":" + (PORT_QP_LE2) - + "\nserver.3=127.0.0.1:" - + (PORT_OBS)+ ":" + (PORT_OBS_LE) + ":observer"; - String obsCfgSection = quorumCfgSection + "\npeerType=observer"; - MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); - MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); - MainThread q3 = new MainThread(3, CLIENT_PORT_OBS, obsCfgSection); - q1.start(); - q2.start(); - q3.start(); - Assert.assertTrue("waiting for server 1 being up", - ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, - CONNECTION_TIMEOUT)); - Assert.assertTrue("waiting for server 2 being up", - ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, - CONNECTION_TIMEOUT)); - Assert.assertTrue("waiting for server 3 being up", - ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_OBS, - CONNECTION_TIMEOUT)); - - zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_OBS, - ClientBase.CONNECTION_TIMEOUT, this); - zk.create("/obstest", "test".getBytes(),Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - - // Assert that commands are getting forwarded correctly - Assert.assertEquals(new String(zk.getData("/obstest", null, null)), "test"); - - // Now check that other commands don't blow everything up - zk.sync("/", null, null); - zk.setData("/obstest", "test2".getBytes(), -1); - zk.getChildren("/", false); - - Assert.assertEquals(zk.getState(), States.CONNECTED); - - LOG.info("Shutting down server 2"); - // Now kill one of the other real servers - q2.shutdown(); - - Assert.assertTrue("Waiting for server 2 to shut down", - ClientBase.waitForServerDown("127.0.0.1:"+CLIENT_PORT_QP2, - ClientBase.CONNECTION_TIMEOUT)); - - LOG.info("Server 2 down"); - - // Now the resulting ensemble shouldn't be quorate - latch.await(); - Assert.assertNotSame("Client is still connected to non-quorate cluster", - KeeperState.SyncConnected,lastEvent.getState()); - - LOG.info("Latch returned"); - - try { - Assert.assertFalse("Shouldn't get a response when cluster not quorate!", - new String(zk.getData("/obstest", null, null)).equals("test")); - } - catch (ConnectionLossException c) { - LOG.info("Connection loss exception caught - ensemble not quorate (this is expected)"); - } - - latch = new CountDownLatch(1); - - LOG.info("Restarting server 2"); - - // Bring it back - q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); - q2.start(); - - LOG.info("Waiting for server 2 to come up"); - Assert.assertTrue("waiting for server 2 being up", - ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, - CONNECTION_TIMEOUT)); - - LOG.info("Server 2 started, waiting for latch"); - - latch.await(); - // It's possible our session expired - but this is ok, shows we - // were able to talk to the ensemble - Assert.assertTrue("Client didn't reconnect to quorate ensemble (state was" + - lastEvent.getState() + ")", - (KeeperState.SyncConnected==lastEvent.getState() || - KeeperState.Expired==lastEvent.getState())); - - LOG.info("Shutting down all servers"); - - q1.shutdown(); - q2.shutdown(); - q3.shutdown(); - - LOG.info("Closing zk client"); - - zk.close(); - Assert.assertTrue("Waiting for server 1 to shut down", - ClientBase.waitForServerDown("127.0.0.1:"+CLIENT_PORT_QP1, - ClientBase.CONNECTION_TIMEOUT)); - Assert.assertTrue("Waiting for server 2 to shut down", - ClientBase.waitForServerDown("127.0.0.1:"+CLIENT_PORT_QP2, - ClientBase.CONNECTION_TIMEOUT)); - Assert.assertTrue("Waiting for server 3 to shut down", - ClientBase.waitForServerDown("127.0.0.1:"+CLIENT_PORT_OBS, - ClientBase.CONNECTION_TIMEOUT)); - - } - - /** - * Implementation of watcher interface. - */ - public void process(WatchedEvent event) { - lastEvent = event; - latch.countDown(); - LOG.info("Latch got event :: " + event); - } - - /** - * This test ensures that an Observer does not elect itself as a leader, or - * indeed come up properly, if it is the lone member of an ensemble. - * @throws Exception - */ - @Test - public void testObserverOnly() throws Exception { - ClientBase.setupTestEnv(); - final int CLIENT_PORT_QP1 = PortAssignment.unique(); - - String quorumCfgSection = - "server.1=127.0.0.1:" + (PortAssignment.unique()) - + ":" + (PortAssignment.unique()) + ":observer\npeerType=observer\n"; - - MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); - q1.start(); - q1.join(ClientBase.CONNECTION_TIMEOUT); - Assert.assertFalse(q1.isAlive()); - } - - /** - * Ensure that observer only comes up when a proper ensemble is configured. - * (and will not come up with standalone server). - */ - @Test - public void testObserverWithStandlone() throws Exception { - ClientBase.setupTestEnv(); - final int CLIENT_PORT_QP1 = PortAssignment.unique(); - - String quorumCfgSection = - "server.1=127.0.0.1:" + (PortAssignment.unique()) - + ":" + (PortAssignment.unique()) + ":observer\n" - + "server.2=127.0.0.1:" + (PortAssignment.unique()) - + ":" + (PortAssignment.unique()) + "\npeerType=observer\n"; - - MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); - q1.start(); - q1.join(ClientBase.CONNECTION_TIMEOUT); - Assert.assertFalse(q1.isAlive()); - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumBase.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumBase.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumBase.java deleted file mode 100644 index 49cff35..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumBase.java +++ /dev/null @@ -1,341 +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.net.InetSocketAddress; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.zookeeper.PortAssignment; -import org.apache.zookeeper.TestableZooKeeper; -import org.apache.zookeeper.server.quorum.Election; -import org.apache.zookeeper.server.quorum.QuorumPeer; -import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; -import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; -import org.apache.zookeeper.server.util.OSMXBean; -import org.junit.Assert; -import org.junit.Test; - - -public class QuorumBase extends ClientBase { - private static final Logger LOG = LoggerFactory.getLogger(QuorumBase.class); - - File s1dir, s2dir, s3dir, s4dir, s5dir; - QuorumPeer s1, s2, s3, s4, s5; - protected int port1; - protected int port2; - protected int port3; - protected int port4; - protected int port5; - - protected int portLE1; - protected int portLE2; - protected int portLE3; - protected int portLE4; - protected int portLE5; - - @Test - // This just avoids complaints by junit - public void testNull() { - } - - @Override - public void setUp() throws Exception { - setUp(false); - } - - protected void setUp(boolean withObservers) throws Exception { - LOG.info("QuorumBase.setup " + getTestName()); - setupTestEnv(); - - JMXEnv.setUp(); - - setUpAll(); - - port1 = PortAssignment.unique(); - port2 = PortAssignment.unique(); - port3 = PortAssignment.unique(); - port4 = PortAssignment.unique(); - port5 = PortAssignment.unique(); - - portLE1 = PortAssignment.unique(); - portLE2 = PortAssignment.unique(); - portLE3 = PortAssignment.unique(); - portLE4 = PortAssignment.unique(); - portLE5 = PortAssignment.unique(); - - hostPort = "127.0.0.1:" + port1 - + ",127.0.0.1:" + port2 - + ",127.0.0.1:" + port3 - + ",127.0.0.1:" + port4 - + ",127.0.0.1:" + port5; - LOG.info("Ports are: " + hostPort); - - s1dir = ClientBase.createTmpDir(); - s2dir = ClientBase.createTmpDir(); - s3dir = ClientBase.createTmpDir(); - s4dir = ClientBase.createTmpDir(); - s5dir = ClientBase.createTmpDir(); - - startServers(withObservers); - - OSMXBean osMbean = new OSMXBean(); - if (osMbean.getUnix() == true) { - LOG.info("Initial fdcount is: " - + osMbean.getOpenFileDescriptorCount()); - } - - LOG.info("Setup finished"); - } - - void startServers() throws Exception { - startServers(false); - } - - void startServers(boolean withObservers) throws Exception { - int tickTime = 2000; - int initLimit = 3; - int syncLimit = 3; - HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(); - peers.put(Long.valueOf(1), new QuorumServer(1, "127.0.0.1", port1 + 1000, - portLE1 + 1000, - LearnerType.PARTICIPANT)); - peers.put(Long.valueOf(2), new QuorumServer(2, "127.0.0.1", port2 + 1000, - portLE2 + 1000, - LearnerType.PARTICIPANT)); - peers.put(Long.valueOf(3), new QuorumServer(3, "127.0.0.1", port3 + 1000, - portLE3 + 1000, - LearnerType.PARTICIPANT)); - peers.put(Long.valueOf(4), new QuorumServer(4, "127.0.0.1", port4 + 1000, - portLE4 + 1000, - LearnerType.PARTICIPANT)); - peers.put(Long.valueOf(5), new QuorumServer(5, "127.0.0.1", port5 + 1000, - portLE5 + 1000, - LearnerType.PARTICIPANT)); - - if (withObservers) { - peers.get(Long.valueOf(4)).type = LearnerType.OBSERVER; - peers.get(Long.valueOf(5)).type = LearnerType.OBSERVER; - } - - LOG.info("creating QuorumPeer 1 port " + port1); - s1 = new QuorumPeer(peers, s1dir, s1dir, port1, 3, 1, tickTime, initLimit, syncLimit); - Assert.assertEquals(port1, s1.getClientPort()); - LOG.info("creating QuorumPeer 2 port " + port2); - s2 = new QuorumPeer(peers, s2dir, s2dir, port2, 3, 2, tickTime, initLimit, syncLimit); - Assert.assertEquals(port2, s2.getClientPort()); - LOG.info("creating QuorumPeer 3 port " + port3); - s3 = new QuorumPeer(peers, s3dir, s3dir, port3, 3, 3, tickTime, initLimit, syncLimit); - Assert.assertEquals(port3, s3.getClientPort()); - LOG.info("creating QuorumPeer 4 port " + port4); - s4 = new QuorumPeer(peers, s4dir, s4dir, port4, 3, 4, tickTime, initLimit, syncLimit); - Assert.assertEquals(port4, s4.getClientPort()); - LOG.info("creating QuorumPeer 5 port " + port5); - s5 = new QuorumPeer(peers, s5dir, s5dir, port5, 3, 5, tickTime, initLimit, syncLimit); - Assert.assertEquals(port5, s5.getClientPort()); - - if (withObservers) { - s4.setLearnerType(LearnerType.OBSERVER); - s5.setLearnerType(LearnerType.OBSERVER); - } - - LOG.info("QuorumPeer 1 voting view: " + s1.getVotingView()); - LOG.info("QuorumPeer 2 voting view: " + s2.getVotingView()); - LOG.info("QuorumPeer 3 voting view: " + s3.getVotingView()); - LOG.info("QuorumPeer 4 voting view: " + s4.getVotingView()); - LOG.info("QuorumPeer 5 voting view: " + s5.getVotingView()); - - LOG.info("start QuorumPeer 1"); - s1.start(); - LOG.info("start QuorumPeer 2"); - s2.start(); - LOG.info("start QuorumPeer 3"); - s3.start(); - LOG.info("start QuorumPeer 4"); - s4.start(); - LOG.info("start QuorumPeer 5"); - s5.start(); - LOG.info("started QuorumPeer 5"); - - LOG.info ("Checking ports " + hostPort); - for (String hp : hostPort.split(",")) { - Assert.assertTrue("waiting for server up", - ClientBase.waitForServerUp(hp, - CONNECTION_TIMEOUT)); - LOG.info(hp + " is accepting client connections"); - } - - // interesting to see what's there... - JMXEnv.dump(); - // make sure we have these 5 servers listed - Set<String> ensureNames = new LinkedHashSet<String>(); - for (int i = 1; i <= 5; i++) { - ensureNames.add("InMemoryDataTree"); - } - for (int i = 1; i <= 5; i++) { - ensureNames.add("name0=ReplicatedServer_id" + i - + ",name1=replica." + i + ",name2="); - } - for (int i = 1; i <= 5; i++) { - for (int j = 1; j <= 5; j++) { - ensureNames.add("name0=ReplicatedServer_id" + i - + ",name1=replica." + j); - } - } - for (int i = 1; i <= 5; i++) { - ensureNames.add("name0=ReplicatedServer_id" + i); - } - JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()])); - } - - - public void setupServers() throws IOException { - setupServer(1); - setupServer(2); - setupServer(3); - setupServer(4); - setupServer(5); - } - - HashMap<Long,QuorumServer> peers = null; - public void setupServer(int i) throws IOException { - int tickTime = 2000; - int initLimit = 3; - int syncLimit = 3; - - if(peers == null){ - peers = new HashMap<Long,QuorumServer>(); - - peers.put(Long.valueOf(1), new QuorumServer(1, "127.0.0.1", port1 + 1000, - portLE1 + 1000, - LearnerType.PARTICIPANT)); - peers.put(Long.valueOf(2), new QuorumServer(2, "127.0.0.1", port2 + 1000, - portLE2 + 1000, - LearnerType.PARTICIPANT)); - peers.put(Long.valueOf(3), new QuorumServer(3, "127.0.0.1", port3 + 1000, - portLE3 + 1000, - LearnerType.PARTICIPANT)); - peers.put(Long.valueOf(4), new QuorumServer(4, "127.0.0.1", port4 + 1000, - portLE4 + 1000, - LearnerType.PARTICIPANT)); - peers.put(Long.valueOf(5), new QuorumServer(5, "127.0.0.1", port5 + 1000, - portLE5 + 1000, - LearnerType.PARTICIPANT)); - } - - switch(i){ - case 1: - LOG.info("creating QuorumPeer 1 port " + port1); - s1 = new QuorumPeer(peers, s1dir, s1dir, port1, 3, 1, tickTime, initLimit, syncLimit); - Assert.assertEquals(port1, s1.getClientPort()); - break; - case 2: - LOG.info("creating QuorumPeer 2 port " + port2); - s2 = new QuorumPeer(peers, s2dir, s2dir, port2, 3, 2, tickTime, initLimit, syncLimit); - Assert.assertEquals(port2, s2.getClientPort()); - break; - case 3: - LOG.info("creating QuorumPeer 3 port " + port3); - s3 = new QuorumPeer(peers, s3dir, s3dir, port3, 3, 3, tickTime, initLimit, syncLimit); - Assert.assertEquals(port3, s3.getClientPort()); - break; - case 4: - LOG.info("creating QuorumPeer 4 port " + port4); - s4 = new QuorumPeer(peers, s4dir, s4dir, port4, 3, 4, tickTime, initLimit, syncLimit); - Assert.assertEquals(port4, s4.getClientPort()); - break; - case 5: - LOG.info("creating QuorumPeer 5 port " + port5); - s5 = new QuorumPeer(peers, s5dir, s5dir, port5, 3, 5, tickTime, initLimit, syncLimit); - Assert.assertEquals(port5, s5.getClientPort()); - } - } - - @Override - public void tearDown() throws Exception { - LOG.info("TearDown started"); - - OSMXBean osMbean = new OSMXBean(); - if (osMbean.getUnix() == true) { - LOG.info("fdcount after test is: " - + osMbean.getOpenFileDescriptorCount()); - } - - shutdownServers(); - - for (String hp : hostPort.split(",")) { - Assert.assertTrue("waiting for server down", - ClientBase.waitForServerDown(hp, - ClientBase.CONNECTION_TIMEOUT)); - LOG.info(hp + " is no longer accepting client connections"); - } - - JMXEnv.tearDown(); - } - public void shutdownServers() { - shutdown(s1); - shutdown(s2); - shutdown(s3); - shutdown(s4); - shutdown(s5); - } - - public static void shutdown(QuorumPeer qp) { - try { - LOG.info("Shutting down quorum peer " + qp.getName()); - qp.shutdown(); - Election e = qp.getElectionAlg(); - if (e != null) { - LOG.info("Shutting down leader election " + qp.getName()); - e.shutdown(); - } else { - LOG.info("No election available to shutdown " + qp.getName()); - } - LOG.info("Waiting for " + qp.getName() + " to exit thread"); - long readTimeout = qp.getTickTime() * qp.getInitLimit(); - long connectTimeout = qp.getTickTime() * qp.getSyncLimit(); - long maxTimeout = Math.max(readTimeout, connectTimeout); - maxTimeout = Math.max(maxTimeout, ClientBase.CONNECTION_TIMEOUT); - qp.join(maxTimeout * 2); - if (qp.isAlive()) { - Assert.fail("QP failed to shutdown in " + (maxTimeout * 2) + " seconds: " + qp.getName()); - } - } catch (InterruptedException e) { - LOG.debug("QP interrupted: " + qp.getName(), e); - } - } - - protected TestableZooKeeper createClient() - throws IOException, InterruptedException - { - return createClient(hostPort); - } - - protected TestableZooKeeper createClient(String hp) - throws IOException, InterruptedException - { - CountdownWatcher watcher = new CountdownWatcher(); - return createClient(watcher, hp); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumHammerTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumHammerTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumHammerTest.java deleted file mode 100644 index e5b377e..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumHammerTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.test; -import org.apache.zookeeper.ZKTestCase; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class QuorumHammerTest extends ZKTestCase { - protected static final Logger LOG = LoggerFactory.getLogger(QuorumHammerTest.class); - public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; - - protected final QuorumBase qb = new QuorumBase(); - protected final ClientHammerTest cht = new ClientHammerTest(); - - @Before - public void setUp() throws Exception { - qb.setUp(); - cht.hostPort = qb.hostPort; - cht.setUpAll(); - } - - @After - public void tearDown() throws Exception { - cht.tearDownAll(); - qb.tearDown(); - } - - @Test - public void testHammerBasic() throws Throwable { - cht.testHammerBasic(); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumQuotaTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumQuotaTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumQuotaTest.java deleted file mode 100644 index bef1a33..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumQuotaTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.test; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.zookeeper.CreateMode; -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.junit.Assert; -import org.junit.Test; - -public class QuorumQuotaTest extends QuorumBase { - private static final Logger LOG = - LoggerFactory.getLogger(QuorumQuotaTest.class); - - @Test - public void testQuotaWithQuorum() throws Exception { - ZooKeeper zk = createClient(); - zk.setData("/", "some".getBytes(), -1); - zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - int i = 0; - for (i=0; i < 300;i++) { - zk.create("/a/" + i, "some".getBytes(), Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - } - ZooKeeperMain.createQuota(zk, "/a", 1000L, 5000); - String statPath = Quotas.quotaZookeeper + "/a"+ "/" + Quotas.statNode; - byte[] data = zk.getData(statPath, false, new Stat()); - StatsTrack st = new StatsTrack(new String(data)); - Assert.assertTrue("bytes are set", st.getBytes() == 1204L); - Assert.assertTrue("num count is set", st.getCount() == 301); - for (i=300; i < 600; i++) { - zk.create("/a/" + i, "some".getBytes(), Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - } - data = zk.getData(statPath, false, new Stat()); - st = new StatsTrack(new String(data)); - Assert.assertTrue("bytes are set", st.getBytes() == 2404L); - Assert.assertTrue("num count is set", st.getCount() == 601); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumTest.java deleted file mode 100644 index 6f827ec..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumTest.java +++ /dev/null @@ -1,296 +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.Arrays; -import java.util.List; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.apache.zookeeper.AsyncCallback; -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Op; -import org.apache.zookeeper.OpResult; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.Watcher.Event.KeeperState; -import org.apache.zookeeper.ZKTestCase; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.ZooDefs.Ids; -import org.apache.zookeeper.ZooKeeper; -import org.apache.zookeeper.data.Stat; -import org.apache.zookeeper.server.quorum.Leader; -import org.apache.zookeeper.server.quorum.LearnerHandler; -import org.apache.zookeeper.test.ClientBase.CountdownWatcher; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class QuorumTest extends ZKTestCase { - private static final Logger LOG = LoggerFactory.getLogger(QuorumTest.class); - public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; - - private final QuorumBase qb = new QuorumBase(); - private final ClientTest ct = new ClientTest(); - - @Before - public void setUp() throws Exception { - qb.setUp(); - ct.hostPort = qb.hostPort; - ct.setUpAll(); - } - - @After - public void tearDown() throws Exception { - ct.tearDownAll(); - qb.tearDown(); - } - - @Test - public void testDeleteWithChildren() throws Exception { - ct.testDeleteWithChildren(); - } - - @Test - public void testPing() throws Exception { - ct.testPing(); - } - - @Test - public void testSequentialNodeNames() - throws IOException, InterruptedException, KeeperException - { - ct.testSequentialNodeNames(); - } - - @Test - public void testACLs() throws Exception { - ct.testACLs(); - } - - @Test - public void testClientwithoutWatcherObj() throws IOException, - InterruptedException, KeeperException - { - ct.testClientwithoutWatcherObj(); - } - - @Test - public void testClientWithWatcherObj() throws IOException, - InterruptedException, KeeperException - { - ct.testClientWithWatcherObj(); - } - - @Test - public void testGetView() { - Assert.assertEquals(5,qb.s1.getView().size()); - Assert.assertEquals(5,qb.s2.getView().size()); - Assert.assertEquals(5,qb.s3.getView().size()); - Assert.assertEquals(5,qb.s4.getView().size()); - Assert.assertEquals(5,qb.s5.getView().size()); - } - - @Test - public void testViewContains() { - // Test view contains self - Assert.assertTrue(qb.s1.viewContains(qb.s1.getId())); - - // Test view contains other servers - Assert.assertTrue(qb.s1.viewContains(qb.s2.getId())); - - // Test view does not contain non-existant servers - Assert.assertFalse(qb.s1.viewContains(-1L)); - } - - volatile int counter = 0; - volatile int errors = 0; - @Test - public void testLeaderShutdown() throws IOException, InterruptedException, KeeperException { - ZooKeeper zk = new DisconnectableZooKeeper(qb.hostPort, ClientBase.CONNECTION_TIMEOUT, new Watcher() { - public void process(WatchedEvent event) { - }}); - zk.create("/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - zk.create("/blah/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - Leader leader = qb.s1.leader; - if (leader == null) leader = qb.s2.leader; - if (leader == null) leader = qb.s3.leader; - if (leader == null) leader = qb.s4.leader; - if (leader == null) leader = qb.s5.leader; - Assert.assertNotNull(leader); - for(int i = 0; i < 5000; i++) { - zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() { - public void processResult(int rc, String path, Object ctx, - Stat stat) { - counter++; - if (rc != 0) { - errors++; - } - } - }, null); - } - for(LearnerHandler f : leader.getForwardingFollowers()) { - f.getSocket().shutdownInput(); - } - for(int i = 0; i < 5000; i++) { - zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() { - public void processResult(int rc, String path, Object ctx, - Stat stat) { - counter++; - if (rc != 0) { - errors++; - } - } - }, null); - } - // check if all the followers are alive - Assert.assertTrue(qb.s1.isAlive()); - Assert.assertTrue(qb.s2.isAlive()); - Assert.assertTrue(qb.s3.isAlive()); - Assert.assertTrue(qb.s4.isAlive()); - Assert.assertTrue(qb.s5.isAlive()); - zk.close(); - } - - @Test - public void testMultipleWatcherObjs() throws IOException, - InterruptedException, KeeperException - { - ct.testMutipleWatcherObjs(); - } - - /** - * Make sure that we can change sessions - * from follower to leader. - * - * @throws IOException - * @throws InterruptedException - * @throws KeeperException - */ - @Test - public void testSessionMoved() throws Exception { - String hostPorts[] = qb.hostPort.split(","); - DisconnectableZooKeeper zk = new DisconnectableZooKeeper(hostPorts[0], - ClientBase.CONNECTION_TIMEOUT, new Watcher() { - public void process(WatchedEvent event) { - }}); - zk.create("/sessionMoveTest", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); - // we want to loop through the list twice - for(int i = 0; i < hostPorts.length*2; i++) { - zk.dontReconnect(); - // This should stomp the zk handle - DisconnectableZooKeeper zknew = - new DisconnectableZooKeeper(hostPorts[(i+1)%hostPorts.length], - ClientBase.CONNECTION_TIMEOUT, - new Watcher() {public void process(WatchedEvent event) { - }}, - zk.getSessionId(), - zk.getSessionPasswd()); - zknew.setData("/", new byte[1], -1); - final int result[] = new int[1]; - result[0] = Integer.MAX_VALUE; - zknew.sync("/", new AsyncCallback.VoidCallback() { - public void processResult(int rc, String path, Object ctx) { - synchronized(result) { result[0] = rc; result.notify(); } - } - }, null); - synchronized(result) { - if(result[0] == Integer.MAX_VALUE) { - result.wait(5000); - } - } - LOG.info(hostPorts[(i+1)%hostPorts.length] + " Sync returned " + result[0]); - Assert.assertTrue(result[0] == KeeperException.Code.OK.intValue()); - try { - zk.setData("/", new byte[1], -1); - Assert.fail("Should have lost the connection"); - } catch(KeeperException.ConnectionLossException e) { - } - zk = zknew; - } - zk.close(); - } - - private static class DiscoWatcher implements Watcher { - volatile boolean zkDisco = false; - public void process(WatchedEvent event) { - if (event.getState() == KeeperState.Disconnected) { - zkDisco = true; - } - } - } - - /** - * Connect to two different servers with two different handles using the same session and - * make sure we cannot do any changes. - */ - @Test - @Ignore - public void testSessionMove() throws Exception { - String hps[] = qb.hostPort.split(","); - DiscoWatcher oldWatcher = new DiscoWatcher(); - DisconnectableZooKeeper zk = new DisconnectableZooKeeper(hps[0], - ClientBase.CONNECTION_TIMEOUT, oldWatcher); - zk.create("/t1", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); - zk.dontReconnect(); - // This should stomp the zk handle - DiscoWatcher watcher = new DiscoWatcher(); - DisconnectableZooKeeper zknew = new DisconnectableZooKeeper(hps[1], - ClientBase.CONNECTION_TIMEOUT, watcher, zk.getSessionId(), - zk.getSessionPasswd()); - zknew.create("/t2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); - try { - zk.create("/t3", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); - Assert.fail("Should have lost the connection"); - } catch(KeeperException.ConnectionLossException e) { - // wait up to 30 seconds for the disco to be delivered - for (int i = 0; i < 30; i++) { - if (oldWatcher.zkDisco) { - break; - } - Thread.sleep(1000); - } - Assert.assertTrue(oldWatcher.zkDisco); - } - - ArrayList<ZooKeeper> toClose = new ArrayList<ZooKeeper>(); - toClose.add(zknew); - // Let's just make sure it can still move - for(int i = 0; i < 10; i++) { - zknew.dontReconnect(); - zknew = new DisconnectableZooKeeper(hps[1], - ClientBase.CONNECTION_TIMEOUT, new DiscoWatcher(), - zk.getSessionId(), zk.getSessionPasswd()); - toClose.add(zknew); - zknew.create("/t-"+i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); - } - for (ZooKeeper z: toClose) { - z.close(); - } - zk.close(); - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumUtil.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumUtil.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumUtil.java deleted file mode 100644 index 1f2dbbc..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumUtil.java +++ /dev/null @@ -1,261 +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.net.InetSocketAddress; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.zookeeper.PortAssignment; -import org.apache.zookeeper.server.quorum.Election; -import org.apache.zookeeper.server.quorum.QuorumPeer; -import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; -import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; -import org.apache.zookeeper.server.util.OSMXBean; -import org.junit.Assert; - -/** - * Utility for quorum testing. Setups 2n+1 peers and allows to start/stop all - * peers, particular peer, n peers etc. - */ -public class QuorumUtil { - - // TODO partitioning of peers and clients - - // TODO refactor QuorumBase to be special case of this - - private static final Logger LOG = LoggerFactory.getLogger(QuorumUtil.class); - - public class PeerStruct { - public int id; - public QuorumPeer peer; - public File dataDir; - public int clientPort; - } - - private final Map<Long, QuorumServer> peersView = new HashMap<Long, QuorumServer>(); - - private final Map<Integer, PeerStruct> peers = new HashMap<Integer, PeerStruct>(); - - public final int N; - - public final int ALL; - - private String hostPort; - - private int tickTime; - - private int initLimit; - - private int syncLimit; - - private int electionAlg; - - /** - * Initializes 2n+1 quorum peers which will form a ZooKeeper ensemble. - * - * @param n - * number of peers in the ensemble will be 2n+1 - */ - public QuorumUtil(int n, int syncLimit) throws RuntimeException { - try { - ClientBase.setupTestEnv(); - JMXEnv.setUp(); - - N = n; - ALL = 2 * N + 1; - tickTime = 2000; - initLimit = 3; - this.syncLimit = syncLimit; - electionAlg = 3; - hostPort = ""; - - for (int i = 1; i <= ALL; ++i) { - PeerStruct ps = new PeerStruct(); - ps.id = i; - ps.dataDir = ClientBase.createTmpDir(); - ps.clientPort = PortAssignment.unique(); - peers.put(i, ps); - - peersView.put(Long.valueOf(i), - new QuorumServer(i, "127.0.0.1", ps.clientPort + 1000, - PortAssignment.unique() + 1000, - LearnerType.PARTICIPANT)); - hostPort += "127.0.0.1:" + ps.clientPort + ((i == ALL) ? "" : ","); - } - for (int i = 1; i <= ALL; ++i) { - PeerStruct ps = peers.get(i); - LOG.info("Creating QuorumPeer " + i + "; public port " + ps.clientPort); - ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, - electionAlg, ps.id, tickTime, initLimit, syncLimit); - Assert.assertEquals(ps.clientPort, ps.peer.getClientPort()); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public QuorumUtil(int n) throws RuntimeException { - this(n, 3); - } - - public PeerStruct getPeer(int id) { - return peers.get(id); - } - - public void startAll() throws IOException { - shutdownAll(); - for (int i = 1; i <= ALL; ++i) { - start(i); - LOG.info("Started QuorumPeer " + i); - } - - LOG.info("Checking ports " + hostPort); - for (String hp : hostPort.split(",")) { - Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(hp, - ClientBase.CONNECTION_TIMEOUT)); - LOG.info(hp + " is accepting client connections"); - } - - // interesting to see what's there... - try { - JMXEnv.dump(); - // make sure we have all servers listed - Set<String> ensureNames = new LinkedHashSet<String>(); - for (int i = 1; i <= ALL; ++i) { - ensureNames.add("InMemoryDataTree"); - } - for (int i = 1; i <= ALL; ++i) { - ensureNames - .add("name0=ReplicatedServer_id" + i + ",name1=replica." + i + ",name2="); - } - for (int i = 1; i <= ALL; ++i) { - for (int j = 1; j <= ALL; ++j) { - ensureNames.add("name0=ReplicatedServer_id" + i + ",name1=replica." + j); - } - } - for (int i = 1; i <= ALL; ++i) { - ensureNames.add("name0=ReplicatedServer_id" + i); - } - JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()])); - } catch (IOException e) { - LOG.warn("IOException during JMXEnv operation", e); - } catch (InterruptedException e) { - LOG.warn("InterruptedException during JMXEnv operation", e); - } - } - - /** - * Start first N+1 peers. - */ - public void startQuorum() throws IOException { - shutdownAll(); - for (int i = 1; i <= N + 1; ++i) { - start(i); - } - for (int i = 1; i <= N + 1; ++i) { - Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" - + getPeer(i).clientPort, ClientBase.CONNECTION_TIMEOUT)); - } - } - - public void start(int id) throws IOException { - PeerStruct ps = getPeer(id); - LOG.info("Creating QuorumPeer " + ps.id + "; public port " + ps.clientPort); - ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, electionAlg, - ps.id, tickTime, initLimit, syncLimit); - Assert.assertEquals(ps.clientPort, ps.peer.getClientPort()); - - ps.peer.start(); - } - - public void restart(int id) throws IOException { - start(id); - Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" - + getPeer(id).clientPort, ClientBase.CONNECTION_TIMEOUT)); - } - - public void startThenShutdown(int id) throws IOException { - PeerStruct ps = getPeer(id); - LOG.info("Creating QuorumPeer " + ps.id + "; public port " + ps.clientPort); - ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, electionAlg, - ps.id, tickTime, initLimit, syncLimit); - Assert.assertEquals(ps.clientPort, ps.peer.getClientPort()); - - ps.peer.start(); - Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" - + getPeer(id).clientPort, ClientBase.CONNECTION_TIMEOUT)); - shutdown(id); - } - - public void shutdownAll() { - for (int i = 1; i <= ALL; ++i) { - shutdown(i); - } - for (String hp : hostPort.split(",")) { - Assert.assertTrue("Waiting for server down", ClientBase.waitForServerDown(hp, - ClientBase.CONNECTION_TIMEOUT)); - LOG.info(hp + " is no longer accepting client connections"); - } - } - - public void shutdown(int id) { - QuorumPeer qp = getPeer(id).peer; - try { - LOG.info("Shutting down quorum peer " + qp.getName()); - qp.shutdown(); - Election e = qp.getElectionAlg(); - if (e != null) { - LOG.info("Shutting down leader election " + qp.getName()); - e.shutdown(); - } else { - LOG.info("No election available to shutdown " + qp.getName()); - } - LOG.info("Waiting for " + qp.getName() + " to exit thread"); - qp.join(30000); - if (qp.isAlive()) { - Assert.fail("QP failed to shutdown in 30 seconds: " + qp.getName()); - } - } catch (InterruptedException e) { - LOG.debug("QP interrupted: " + qp.getName(), e); - } - } - - public String getConnString() { - return hostPort; - } - - public void tearDown() throws Exception { - LOG.info("TearDown started"); - - OSMXBean osMbean = new OSMXBean(); - if (osMbean.getUnix() == true) { - LOG.info("fdcount after test is: " + osMbean.getOpenFileDescriptorCount()); - } - - shutdownAll(); - JMXEnv.tearDown(); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/7291e47c/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumZxidSyncTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumZxidSyncTest.java b/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumZxidSyncTest.java deleted file mode 100644 index 6e46edc..0000000 --- a/zookeeper-common/src/test/java/org/apache/zookeeper/test/QuorumZxidSyncTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.test; - -import java.io.File; - -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZKTestCase; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.ZooKeeper; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class QuorumZxidSyncTest extends ZKTestCase { - QuorumBase qb = new QuorumBase(); - - @Before - public void setUp() throws Exception { - qb.setUp(); - } - - /** - * find out what happens when a follower connects to leader that is behind - */ - @Test - public void testBehindLeader() throws Exception { - // crank up the epoch numbers - ClientBase.waitForServerUp(qb.hostPort, 10000); - ClientBase.waitForServerUp(qb.hostPort, 10000); - ZooKeeper zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { - public void process(WatchedEvent event) { - }}); - zk.create("/0", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - zk.close(); - qb.shutdownServers(); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - qb.shutdownServers(); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { - public void process(WatchedEvent event) { - }}); - zk.create("/1", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - zk.close(); - qb.shutdownServers(); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - qb.shutdownServers(); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { - public void process(WatchedEvent event) { - }}); - zk.create("/2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - zk.close(); - qb.shutdownServers(); - deleteFiles(qb.s1dir); - deleteFiles(qb.s2dir); - deleteFiles(qb.s3dir); - deleteFiles(qb.s4dir); - qb.setupServers(); - qb.s1.start(); - qb.s2.start(); - qb.s3.start(); - qb.s4.start(); - Assert.assertTrue("Servers didn't come up", ClientBase.waitForServerUp(qb.hostPort, 10000)); - qb.s5.start(); - String hostPort = "127.0.0.1:" + qb.s5.getClientPort(); - Assert.assertFalse("Servers came up, but shouldn't have since it's ahead of leader", - ClientBase.waitForServerUp(hostPort, 10000)); - } - - private void deleteFiles(File f) { - File v = new File(f, "version-2"); - for(File c: v.listFiles()) { - c.delete(); - } - } - - /** - * find out what happens when the latest state is in the snapshots not - * the logs. - */ - @Test - public void testLateLogs() throws Exception { - // crank up the epoch numbers - ClientBase.waitForServerUp(qb.hostPort, 10000); - ClientBase.waitForServerUp(qb.hostPort, 10000); - ZooKeeper zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { - public void process(WatchedEvent event) { - }}); - zk.create("/0", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - zk.close(); - qb.shutdownServers(); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - qb.shutdownServers(); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { - public void process(WatchedEvent event) { - }}); - zk.create("/1", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - zk.close(); - qb.shutdownServers(); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - qb.shutdownServers(); - deleteLogs(qb.s1dir); - deleteLogs(qb.s2dir); - deleteLogs(qb.s3dir); - deleteLogs(qb.s4dir); - deleteLogs(qb.s5dir); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { - public void process(WatchedEvent event) { - }}); - zk.create("/2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - zk.close(); - qb.shutdownServers(); - qb.startServers(); - ClientBase.waitForServerUp(qb.hostPort, 10000); - zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { - public void process(WatchedEvent event) { - }}); - boolean saw2 = false; - for(String child: zk.getChildren("/", false)) { - if (child.equals("2")) { - saw2 = true; - } - } - zk.close(); - Assert.assertTrue("Didn't see /2 (went back in time)", saw2); - } - - private void deleteLogs(File f) { - File v = new File(f, "version-2"); - for(File c: v.listFiles()) { - if (c.getName().startsWith("log")) { - c.delete(); - } - } - } - - @After - public void tearDown() throws Exception { - qb.tearDown(); - } -}