HBASE-10317 getClientPort method of MiniZooKeeperCluster does not always return the correct value

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1561453 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2014-01-26 04:52:38 +00:00
parent 74b5a394f4
commit 2dedc95c9e
2 changed files with 15 additions and 7 deletions

View File

@ -60,8 +60,6 @@ public class MiniZooKeeperCluster {
/** The default port. If zero, we use a random port. */
private int defaultClientPort = 0;
private int clientPort;
private List<NIOServerCnxnFactory> standaloneServerFactoryList;
private List<ZooKeeperServer> zooKeeperServers;
private List<Integer> clientPortList;
@ -196,7 +194,7 @@ public class MiniZooKeeperCluster {
// set the first one to be active ZK; Others are backups
activeZKServerIndex = 0;
started = true;
clientPort = clientPortList.get(activeZKServerIndex);
int clientPort = clientPortList.get(activeZKServerIndex);
LOG.info("Started MiniZK Cluster and connect 1 ZK server " +
"on client port: " + clientPort);
return clientPort;
@ -394,6 +392,7 @@ public class MiniZooKeeperCluster {
}
public int getClientPort() {
return clientPort;
return activeZKServerIndex < 0 || activeZKServerIndex >= clientPortList.size() ? -1
: clientPortList.get(activeZKServerIndex);
}
}

View File

@ -162,8 +162,15 @@ public class TestHBaseTestingUtility {
assertEquals(4, cluster2.getBackupZooKeeperServerNum());
// killing the current active zk server
assertTrue((cluster2.killCurrentActiveZooKeeperServer() >= defaultClientPort));
assertTrue((cluster2.killCurrentActiveZooKeeperServer() >= defaultClientPort));
int currentActivePort = cluster2.killCurrentActiveZooKeeperServer();
assertTrue(currentActivePort >= defaultClientPort);
// Check if the client port is returning a proper value
assertTrue(cluster2.getClientPort() == currentActivePort);
// kill another active zk server
currentActivePort = cluster2.killCurrentActiveZooKeeperServer();
assertTrue(currentActivePort >= defaultClientPort);
assertTrue(cluster2.getClientPort() == currentActivePort);
assertEquals(2, cluster2.getBackupZooKeeperServerNum());
assertEquals(3, cluster2.getZooKeeperServerNum());
@ -174,7 +181,9 @@ public class TestHBaseTestingUtility {
assertEquals(1, cluster2.getZooKeeperServerNum());
// killing the last zk server
assertTrue((cluster2.killCurrentActiveZooKeeperServer() == -1));
currentActivePort = cluster2.killCurrentActiveZooKeeperServer();
assertTrue(currentActivePort == -1);
assertTrue(cluster2.getClientPort() == currentActivePort);
// this should do nothing.
cluster2.killOneBackupZooKeeperServer();
assertEquals(-1, cluster2.getBackupZooKeeperServerNum());