|
@@ -20,14 +20,23 @@ package org.apache.zookeeper.test;
|
|
|
|
|
|
import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.apache.zookeeper.KeeperException;
|
|
|
import org.apache.zookeeper.PortAssignment;
|
|
|
import org.apache.zookeeper.Watcher;
|
|
|
+import org.apache.zookeeper.ZooKeeper;
|
|
|
+import org.apache.zookeeper.data.Stat;
|
|
|
+import org.apache.zookeeper.server.ServerCnxnFactory;
|
|
|
+import org.apache.zookeeper.server.ZooKeeperServer;
|
|
|
import org.apache.zookeeper.server.quorum.QuorumPeerTestBase;
|
|
|
+import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
-import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
|
|
|
|
|
|
/**
|
|
|
* Standalone server tests.
|
|
@@ -65,4 +74,44 @@ public class StandaloneTest extends QuorumPeerTestBase implements Watcher{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Verify that reconfiguration in standalone mode fails with
|
|
|
+ * KeeperException.UnimplementedException.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testStandaloneReconfigFails() throws Exception {
|
|
|
+ ClientBase.setupTestEnv();
|
|
|
+
|
|
|
+ final int CLIENT_PORT = PortAssignment.unique();
|
|
|
+ final String HOSTPORT = "127.0.0.1:" + CLIENT_PORT;
|
|
|
+
|
|
|
+ File tmpDir = ClientBase.createTmpDir();
|
|
|
+ ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
|
|
|
+
|
|
|
+ ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1);
|
|
|
+ f.startup(zks);
|
|
|
+ Assert.assertTrue("waiting for server being up ", ClientBase
|
|
|
+ .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
|
|
|
+
|
|
|
+ CountdownWatcher watcher = new CountdownWatcher();
|
|
|
+ ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, watcher);
|
|
|
+ watcher.waitForConnected(CONNECTION_TIMEOUT);
|
|
|
+
|
|
|
+ List<String> joiners = new ArrayList<String>();
|
|
|
+ joiners.add("server.2=localhost:1234:1235;1236");
|
|
|
+ // generate some transactions that will get logged
|
|
|
+ try {
|
|
|
+ zk.reconfig(joiners, null, null, -1, new Stat());
|
|
|
+ Assert.fail("Reconfiguration in standalone should trigger " +
|
|
|
+ "UnimplementedException");
|
|
|
+ } catch (KeeperException.UnimplementedException ex) {
|
|
|
+ // expected
|
|
|
+ }
|
|
|
+ zk.close();
|
|
|
+
|
|
|
+ zks.shutdown();
|
|
|
+ f.shutdown();
|
|
|
+ Assert.assertTrue("waiting for server being down ", ClientBase
|
|
|
+ .waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
|
|
|
+ }
|
|
|
}
|