[test] Minor refactor for ZookeeperServerTest.
@@ -22,7 +22,6 @@ import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
-
import org.apache.zookeeper.server.NIOServerCnxnFactory;
import org.apache.zookeeper.server.ZooKeeperServer;
import org.slf4j.Logger;
@@ -35,24 +34,27 @@ public class ZookeeperServerTest implements Closeable {
private int zkPort;
private String hostPort;
+ static {
+ // Allow all commands on ZK control port
+ System.setProperty("zookeeper.4lw.commands.whitelist", "*");
+ // disable the admin server as to not have any port conflicts
+ System.setProperty("zookeeper.admin.enableServer", "false");
+ }
+
public ZookeeperServerTest(int zkPort) throws IOException {
this.zkTmpDir = File.createTempFile("zookeeper", "test");
log.info("**** Start GZK on {} ****", zkTmpDir);
if (!zkTmpDir.delete() || !zkTmpDir.mkdir()) {
throw new IOException("Couldn't create zk directory " + zkTmpDir);
}
- }
-
- public void start() throws IOException {
- try {
- // Allow all commands on ZK control port
- System.setProperty("zookeeper.4lw.commands.whitelist", "*");
- // disable the admin server as to not have any port conflicts
- System.setProperty("zookeeper.admin.enableServer", "false");
zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
zks.setMaxSessionTimeout(20000);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(new InetSocketAddress(zkPort), 1000);
+ }
+
+ public void start() throws IOException {
+ try {
serverFactory.startup(zks);
} catch (Exception e) {
log.error("Exception while instantiating ZooKeeper", e);
