This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new afb6232 Adding multi-node ZKCluster test util class
afb6232 is described below
commit afb62329a85ef8c28c013a9f8a195dc22cbd3ad9
Author: Charan Reddy Guttapalem <[email protected]>
AuthorDate: Thu Oct 25 05:12:27 2018 -0700
Adding multi-node ZKCluster test util class
Descriptions of the changes in this PR:
- adding multi-node ZKCluster util class
- adding new interface for ZKCluster util and having separate
implementaions for
single node ZKCluster and multi-node ZKCluster
### Motivation
This helps in adding more test coverage to Zookeeper aspects.
Author: Sijie Guo <[email protected]>
Author: Charan Reddy Guttapalem <[email protected]>
Author: cguttapalem <[email protected]>
Author: Andrey Yegorov <[email protected]>
Author: Samuel Just <[email protected]>
Reviewers: Sijie Guo <[email protected]>, Enrico Olivelli
<[email protected]>
This closes #1753 from reddycharan/multinodezkcluster
---
.../bookie/BookieInitializationTest.java | 2 +-
.../bookie/LedgerStorageCheckpointTest.java | 4 +-
.../apache/bookkeeper/client/BookKeeperTest.java | 4 +-
.../meta/TestLongZkLedgerIdGenerator.java | 4 +-
.../bookkeeper/meta/TestZkLedgerIdGenerator.java | 4 +-
.../TestLedgerUnderreplicationManager.java | 4 +-
.../bookkeeper/test/BookKeeperClusterTestCase.java | 19 ++-
.../apache/bookkeeper/test/ZooKeeperCluster.java | 79 ++++++++++++
.../bookkeeper/test/ZooKeeperClusterUtil.java | 140 +++++++++++++++++++++
.../org/apache/bookkeeper/test/ZooKeeperUtil.java | 53 +++-----
.../org/apache/bookkeeper/util/TestZkUtils.java | 4 +-
.../bookkeeper/zookeeper/TestZooKeeperClient.java | 36 +++++-
12 files changed, 297 insertions(+), 56 deletions(-)
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
index 6500e0b..530969b 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
@@ -568,7 +568,7 @@ public class BookieInitializationTest extends
BookKeeperClusterTestCase {
*/
@Test
public void testStartBookieWithoutZKServer() throws Exception {
- zkUtil.killServer();
+ zkUtil.killCluster();
File tmpDir = createTempDir("bookie", "test");
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/LedgerStorageCheckpointTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/LedgerStorageCheckpointTest.java
index 921d310..89a5063 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/LedgerStorageCheckpointTest.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/LedgerStorageCheckpointTest.java
@@ -143,7 +143,7 @@ public class LedgerStorageCheckpointTest {
* @throws Exception
*/
protected void startZKCluster() throws Exception {
- zkUtil.startServer();
+ zkUtil.startCluster();
}
/**
@@ -152,7 +152,7 @@ public class LedgerStorageCheckpointTest {
* @throws Exception
*/
protected void stopZKCluster() throws Exception {
- zkUtil.killServer();
+ zkUtil.killCluster();
}
protected void cleanupTempDirs() throws Exception {
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java
index 1a22e61..0471e50 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTest.java
@@ -72,7 +72,7 @@ public class BookKeeperTest extends BookKeeperClusterTestCase
{
.setZkTimeout(20000);
CountDownLatch l = new CountDownLatch(1);
- zkUtil.sleepServer(200, TimeUnit.MILLISECONDS, l);
+ zkUtil.sleepCluster(200, TimeUnit.MILLISECONDS, l);
l.await();
BookKeeper bkc = new BookKeeper(conf);
@@ -87,7 +87,7 @@ public class BookKeeperTest extends BookKeeperClusterTestCase
{
.setZkTimeout(20000);
CountDownLatch l = new CountDownLatch(1);
- zkUtil.sleepServer(200, TimeUnit.MILLISECONDS, l);
+ zkUtil.sleepCluster(200, TimeUnit.MILLISECONDS, l);
l.await();
ZooKeeper zk = new ZooKeeper(
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLongZkLedgerIdGenerator.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLongZkLedgerIdGenerator.java
index bc6ac03..7245cc1 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLongZkLedgerIdGenerator.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLongZkLedgerIdGenerator.java
@@ -58,7 +58,7 @@ public class TestLongZkLedgerIdGenerator extends TestCase {
super.setUp();
zkutil = new ZooKeeperUtil();
- zkutil.startServer();
+ zkutil.startCluster();
zk = zkutil.getZooKeeperClient();
ZkLedgerIdGenerator shortLedgerIdGenerator = new
ZkLedgerIdGenerator(zk,
@@ -73,7 +73,7 @@ public class TestLongZkLedgerIdGenerator extends TestCase {
LOG.info("Tearing down test");
ledgerIdGenerator.close();
zk.close();
- zkutil.killServer();
+ zkutil.killCluster();
super.tearDown();
}
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestZkLedgerIdGenerator.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestZkLedgerIdGenerator.java
index 3779af4..5c5f6b6 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestZkLedgerIdGenerator.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestZkLedgerIdGenerator.java
@@ -55,7 +55,7 @@ public class TestZkLedgerIdGenerator extends TestCase {
super.setUp();
zkutil = new ZooKeeperUtil();
- zkutil.startServer();
+ zkutil.startCluster();
zk = zkutil.getZooKeeperClient();
ledgerIdGenerator = new ZkLedgerIdGenerator(zk,
@@ -68,7 +68,7 @@ public class TestZkLedgerIdGenerator extends TestCase {
LOG.info("Tearing down test");
ledgerIdGenerator.close();
zk.close();
- zkutil.killServer();
+ zkutil.killCluster();
super.tearDown();
}
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestLedgerUnderreplicationManager.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestLedgerUnderreplicationManager.java
index 2628578..e84113b 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestLedgerUnderreplicationManager.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestLedgerUnderreplicationManager.java
@@ -93,7 +93,7 @@ public class TestLedgerUnderreplicationManager {
@Before
public void setupZooKeeper() throws Exception {
zkUtil = new ZooKeeperUtil();
- zkUtil.startServer();
+ zkUtil.startCluster();
conf = TestBKConfiguration.newServerConfiguration();
conf.setMetadataServiceUri(zkUtil.getMetadataServiceUri());
@@ -134,7 +134,7 @@ public class TestLedgerUnderreplicationManager {
@After
public void teardownZooKeeper() throws Exception {
if (zkUtil != null) {
- zkUtil.killServer();
+ zkUtil.killCluster();
zkUtil = null;
}
if (executor != null) {
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
index 932abd9..b1feef0 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
@@ -79,7 +79,7 @@ public abstract class BookKeeperClusterTestCase {
public final Timeout globalTimeout;
// Metadata service related variables
- protected final ZooKeeperUtil zkUtil = new ZooKeeperUtil();
+ protected final ZooKeeperCluster zkUtil;
protected ZooKeeper zkc;
protected String metadataServiceUri;
@@ -118,8 +118,21 @@ public abstract class BookKeeperClusterTestCase {
}
public BookKeeperClusterTestCase(int numBookies, int testTimeoutSecs) {
+ this(numBookies, 1, 120);
+ }
+
+ public BookKeeperClusterTestCase(int numBookies, int numOfZKNodes, int
testTimeoutSecs) {
this.numBookies = numBookies;
this.globalTimeout = Timeout.seconds(testTimeoutSecs);
+ if (numOfZKNodes == 1) {
+ zkUtil = new ZooKeeperUtil();
+ } else {
+ try {
+ zkUtil = new ZooKeeperClusterUtil(numOfZKNodes);
+ } catch (IOException | KeeperException | InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
@Before
@@ -202,7 +215,7 @@ public abstract class BookKeeperClusterTestCase {
* @throws Exception
*/
protected void startZKCluster() throws Exception {
- zkUtil.startServer();
+ zkUtil.startCluster();
zkc = zkUtil.getZooKeeperClient();
}
@@ -212,7 +225,7 @@ public abstract class BookKeeperClusterTestCase {
* @throws Exception
*/
protected void stopZKCluster() throws Exception {
- zkUtil.killServer();
+ zkUtil.killCluster();
}
/**
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperCluster.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperCluster.java
new file mode 100644
index 0000000..7713503
--- /dev/null
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperCluster.java
@@ -0,0 +1,79 @@
+/*
+ *
+ * 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.bookkeeper.test;
+
+import static org.apache.bookkeeper.util.BookKeeperConstants.AVAILABLE_NODE;
+import static org.apache.bookkeeper.util.BookKeeperConstants.READONLY;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.Transaction;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
+
+/**
+ * Interface for ZooKeeperCluster.
+ */
+public interface ZooKeeperCluster {
+ ZooKeeper getZooKeeperClient();
+
+ String getZooKeeperConnectString();
+
+ String getMetadataServiceUri();
+
+ String getMetadataServiceUri(String zkLedgersRootPath);
+
+ String getMetadataServiceUri(String zkLedgersRootPath, String type);
+
+ void startCluster() throws Exception;
+
+ void stopCluster() throws Exception;
+
+ void restartCluster() throws Exception;
+
+ void killCluster() throws Exception;
+
+ void sleepCluster(final int time, final TimeUnit timeUnit, final
CountDownLatch l)
+ throws InterruptedException, IOException;
+
+ default void expireSession(ZooKeeper zk) throws Exception {
+ long id = zk.getSessionId();
+ byte[] password = zk.getSessionPasswd();
+ ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(10000);
+ ZooKeeper zk2 = new ZooKeeper(getZooKeeperConnectString(),
zk.getSessionTimeout(), w, id, password);
+ w.waitForConnection();
+ zk2.close();
+ }
+
+ default void createBKEnsemble(String ledgersPath) throws KeeperException,
InterruptedException {
+ Transaction txn = getZooKeeperClient().transaction();
+ txn.create(ledgersPath, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
+ txn.create(ledgersPath + "/" + AVAILABLE_NODE, new byte[0],
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ txn.create(ledgersPath + "/" + AVAILABLE_NODE + "/" + READONLY, new
byte[0], Ids.OPEN_ACL_UNSAFE,
+ CreateMode.PERSISTENT);
+ txn.commit();
+ }
+}
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperClusterUtil.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperClusterUtil.java
new file mode 100644
index 0000000..5eef1d0
--- /dev/null
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperClusterUtil.java
@@ -0,0 +1,140 @@
+/*
+ *
+ * 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.bookkeeper.test;
+
+import com.google.common.io.Files;
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.meta.LongHierarchicalLedgerManagerFactory;
+import org.apache.bookkeeper.zookeeper.ZooKeeperClient;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.test.QuorumUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides multi node zookeeper cluster.
+ */
+@Slf4j
+public class ZooKeeperClusterUtil implements ZooKeeperCluster {
+
+ static {
+ enableZookeeperTestEnvVariables();
+ }
+
+ static final Logger LOG =
LoggerFactory.getLogger(ZooKeeperClusterUtil.class);
+ private final int numOfZKNodes;
+ public QuorumUtil quorumUtil;
+ String connectString;
+ protected ZooKeeper zkc; // zookeeper client
+
+ public static void enableZookeeperTestEnvVariables() {
+ /*
+ * org.apache.zookeeper.test.ClientBase uses FourLetterWordMain, from
+ * 3.5.3 four letter words are disabled by default due to security
+ * reasons
+ */
+ System.setProperty("zookeeper.4lw.commands.whitelist", "*");
+ System.setProperty("zookeeper.admin.enableServer", "false");
+ try {
+ System.setProperty("build.test.dir",
Files.createTempDir().getCanonicalPath());
+ } catch (IOException e) {
+ log.error("Failed to create temp dir, so setting build.test.dir
system property to /tmp");
+ System.setProperty("build.test.dir", "/tmp");
+ }
+ }
+
+ public ZooKeeperClusterUtil(int numOfZKNodes) throws IOException,
KeeperException, InterruptedException {
+ if ((numOfZKNodes < 3) || (numOfZKNodes % 2 == 0)) {
+ throw new IllegalArgumentException("numOfZKNodes should be atleast
3 and it should not be even number");
+ }
+ this.numOfZKNodes = numOfZKNodes;
+ }
+
+ @Override
+ public String getZooKeeperConnectString() {
+ return connectString;
+ }
+
+ @Override
+ public String getMetadataServiceUri() {
+ return getMetadataServiceUri("/ledgers");
+ }
+
+ @Override
+ public String getMetadataServiceUri(String zkLedgersRootPath) {
+ return getMetadataServiceUri(zkLedgersRootPath,
LongHierarchicalLedgerManagerFactory.NAME);
+ }
+
+ @Override
+ public String getMetadataServiceUri(String zkLedgersRootPath, String type)
{
+ /*
+ * URI doesn't accept ',', for more info. check
+ * AbstractConfiguration.getMetadataServiceUri()
+ */
+ return "zk+" + type + "://" + connectString.replace(",", ";") +
zkLedgersRootPath;
+ }
+
+ @Override
+ public ZooKeeper getZooKeeperClient() {
+ return zkc;
+ }
+
+ @Override
+ public void startCluster() throws Exception {
+ // QuorumUtil will start 2*n+1 nodes.
+ quorumUtil = new QuorumUtil(numOfZKNodes / 2);
+ quorumUtil.startAll();
+ connectString = quorumUtil.getConnString();
+ // create a zookeeper client
+ LOG.debug("Instantiate ZK Client");
+ zkc =
ZooKeeperClient.newBuilder().connectString(getZooKeeperConnectString()).sessionTimeoutMs(10000).build();
+
+ // create default bk ensemble
+ createBKEnsemble("/ledgers");
+ }
+
+ @Override
+ public void stopCluster() throws Exception {
+ if (zkc != null) {
+ zkc.close();
+ }
+ quorumUtil.shutdownAll();
+ }
+
+ @Override
+ public void restartCluster() throws Exception {
+ quorumUtil.startAll();
+ }
+
+ @Override
+ public void killCluster() throws Exception {
+ quorumUtil.tearDown();
+ }
+
+ @Override
+ public void sleepCluster(int time, TimeUnit timeUnit, CountDownLatch l)
throws InterruptedException, IOException {
+ throw new UnsupportedOperationException("sleepServer operation is not
supported for ZooKeeperClusterUtil");
+ }
+}
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
index 09f5049..6868f92 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
@@ -21,8 +21,6 @@
package org.apache.bookkeeper.test;
-import static org.apache.bookkeeper.util.BookKeeperConstants.AVAILABLE_NODE;
-import static org.apache.bookkeeper.util.BookKeeperConstants.READONLY;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -34,12 +32,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.bookkeeper.util.IOUtils;
import org.apache.bookkeeper.zookeeper.ZooKeeperClient;
-import org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase;
import org.apache.commons.io.FileUtils;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.Transaction;
-import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.server.NIOServerCnxnFactory;
import org.apache.zookeeper.server.ZooKeeperServer;
@@ -50,7 +43,7 @@ import org.slf4j.LoggerFactory;
/**
* Test the zookeeper utilities.
*/
-public class ZooKeeperUtil {
+public class ZooKeeperUtil implements ZooKeeperCluster {
static {
// org.apache.zookeeper.test.ClientBase uses FourLetterWordMain, from
3.5.3 four letter words
@@ -75,50 +68,47 @@ public class ZooKeeperUtil {
connectString = loopbackIPAddr + ":" + zooKeeperPort;
}
+ @Override
public ZooKeeper getZooKeeperClient() {
return zkc;
}
+ @Override
public String getZooKeeperConnectString() {
return connectString;
}
+ @Override
public String getMetadataServiceUri() {
return getMetadataServiceUri("/ledgers");
}
+ @Override
public String getMetadataServiceUri(String zkLedgersRootPath) {
return "zk://" + connectString + zkLedgersRootPath;
}
+ @Override
public String getMetadataServiceUri(String zkLedgersRootPath, String type)
{
return "zk+" + type + "://" + connectString + zkLedgersRootPath;
}
- public void startServer() throws Exception {
+ @Override
+ public void startCluster() throws Exception {
// create a ZooKeeper server(dataDir, dataLogDir, port)
LOG.debug("Running ZK server");
ClientBase.setupTestEnv();
zkTmpDir = IOUtils.createTempDir("zookeeper", "test");
// start the server and client.
- restartServer();
+ restartCluster();
// create default bk ensemble
createBKEnsemble("/ledgers");
}
- public void createBKEnsemble(String ledgersPath) throws KeeperException,
InterruptedException {
- Transaction txn = zkc.transaction();
- txn.create(ledgersPath, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
- txn.create(ledgersPath + "/" + AVAILABLE_NODE,
- new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- txn.create(ledgersPath + "/" + AVAILABLE_NODE + "/" + READONLY,
- new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- txn.commit();
- }
-
- public void restartServer() throws Exception {
+ @Override
+ public void restartCluster() throws Exception {
zks = new ZooKeeperServer(zkTmpDir, zkTmpDir,
ZooKeeperServer.DEFAULT_TICK_TIME);
serverFactory = new NIOServerCnxnFactory();
@@ -143,7 +133,8 @@ public class ZooKeeperUtil {
.build();
}
- public void sleepServer(final int time,
+ @Override
+ public void sleepCluster(final int time,
final TimeUnit timeUnit,
final CountDownLatch l)
throws InterruptedException, IOException {
@@ -171,17 +162,8 @@ public class ZooKeeperUtil {
throw new IOException("ZooKeeper thread not found");
}
- public void expireSession(ZooKeeper zk) throws Exception {
- long id = zk.getSessionId();
- byte[] password = zk.getSessionPasswd();
- ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(10000);
- ZooKeeper zk2 = new ZooKeeper(getZooKeeperConnectString(),
- zk.getSessionTimeout(), w, id, password);
- w.waitForConnection();
- zk2.close();
- }
-
- public void stopServer() throws Exception {
+ @Override
+ public void stopCluster() throws Exception {
if (zkc != null) {
zkc.close();
}
@@ -198,8 +180,9 @@ public class ZooKeeperUtil {
}
}
- public void killServer() throws Exception {
- stopServer();
+ @Override
+ public void killCluster() throws Exception {
+ stopCluster();
FileUtils.deleteDirectory(zkTmpDir);
}
}
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/util/TestZkUtils.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/util/TestZkUtils.java
index 527a384..cdc936d 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/util/TestZkUtils.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/util/TestZkUtils.java
@@ -49,13 +49,13 @@ public class TestZkUtils extends TestCase {
@Override
public void setUp() throws Exception {
logger.info("Setting up test {}.", getName());
- zkUtil.startServer();
+ zkUtil.startCluster();
}
@After
@Override
public void tearDown() throws Exception {
- zkUtil.killServer();
+ zkUtil.killCluster();
logger.info("Teared down test {}.", getName());
}
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
index bb9554a..fca65ba 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
@@ -22,6 +22,8 @@ package org.apache.bookkeeper.zookeeper;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@@ -32,6 +34,8 @@ import java.util.concurrent.atomic.AtomicReference;
import junit.framework.TestCase;
import org.apache.bookkeeper.stats.NullStatsLogger;
+import org.apache.bookkeeper.test.ZooKeeperCluster;
+import org.apache.bookkeeper.test.ZooKeeperClusterUtil;
import org.apache.bookkeeper.test.ZooKeeperUtil;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.AsyncCallback.ACLCallback;
@@ -54,30 +58,52 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test the wrapper of {@link org.apache.zookeeper.ZooKeeper} client.
*/
+@RunWith(Parameterized.class)
public class TestZooKeeperClient extends TestCase {
+ static {
+ ZooKeeperClusterUtil.enableZookeeperTestEnvVariables();
+ }
+
private static final Logger logger =
LoggerFactory.getLogger(TestZooKeeperClient.class);
// ZooKeeper related variables
- protected ZooKeeperUtil zkUtil = new ZooKeeperUtil();
+ protected ZooKeeperCluster zkUtil;
+
+ @Parameters
+ public static Collection<Object[]> zooKeeperUtilClass() {
+ return Arrays.asList(new Object[][] { { ZooKeeperUtil.class }, {
ZooKeeperClusterUtil.class } });
+ }
+
+ public TestZooKeeperClient(Class<? extends ZooKeeperCluster>
zooKeeperUtilClass)
+ throws IOException, KeeperException, InterruptedException {
+ if (zooKeeperUtilClass.equals(ZooKeeperUtil.class)) {
+ zkUtil = new ZooKeeperUtil();
+ } else {
+ zkUtil = new ZooKeeperClusterUtil(3);
+ }
+ }
@Before
@Override
public void setUp() throws Exception {
logger.info("Setting up test {}.", getName());
- zkUtil.startServer();
+ zkUtil.startCluster();
}
@After
@Override
public void tearDown() throws Exception {
- zkUtil.killServer();
+ zkUtil.killCluster();
logger.info("Teared down test {}.", getName());
}
@@ -121,7 +147,7 @@ public class TestZooKeeperClient extends TestCase {
public void process(WatchedEvent event) {
if (event.getType() == EventType.None && event.getState() ==
KeeperState.Expired) {
try {
- zkUtil.stopServer();
+ zkUtil.stopCluster();
} catch (Exception e) {
logger.error("Failed to stop zookeeper server : ", e);
}
@@ -175,7 +201,7 @@ public class TestZooKeeperClient extends TestCase {
// expected
}
- zkUtil.restartServer();
+ zkUtil.restartCluster();
// wait for a reconnect cycle
Thread.sleep(2 * timeout);