// Start the cluster
final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
TEST_UTIL.startMiniDFSCluster(3);
TEST_UTIL.startMiniZKCluster();
TEST_UTIL.createRootDir();
final LocalHBaseCluster cluster =
new LocalHBaseCluster(conf, NUM_MASTERS, NUM_RS, HMaster.class, MockedRegionServer.class);
final MasterThread master = cluster.getMasters().get(0);
master.start();
try {
long startTime = System.currentTimeMillis();
while (!master.getMaster().isActiveMaster()) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
if (System.currentTimeMillis() > startTime + 30000) {
throw new RuntimeException("Master not active after 30 seconds");
}
}
masterActive = true;
cluster.getRegionServers().get(0).start();
cluster.getRegionServers().get(1).start();
Thread.sleep(10000);
List<ServerName> onlineServersList =
master.getMaster().getServerManager().getOnlineServersList();
while (onlineServersList.size() > 2) {
Thread.sleep(100);
onlineServersList = master.getMaster().getServerManager().getOnlineServersList();
}
assertEquals(onlineServersList.size(), 2);
cluster.shutdown();
} finally {
masterActive = false;
firstRS.set(true);
TEST_UTIL.shutdownMiniCluster();
}