use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.
the class TestMasterAddressTracker method setupMasterTracker.
/**
* create an address tracker instance
* @param sn if not-null set the active master
* @param infoPort if there is an active master, set its info port.
*/
private MasterAddressTracker setupMasterTracker(final ServerName sn, final int infoPort) throws Exception {
ZooKeeperWatcher zk = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(), name.getMethodName(), null);
ZKUtil.createAndFailSilent(zk, zk.znodePaths.baseZNode);
// Should not have a master yet
MasterAddressTracker addressTracker = new MasterAddressTracker(zk, null);
addressTracker.start();
assertFalse(addressTracker.hasMaster());
zk.registerListener(addressTracker);
// Use a listener to capture when the node is actually created
NodeCreationListener listener = new NodeCreationListener(zk, zk.znodePaths.masterAddressZNode);
zk.registerListener(listener);
if (sn != null) {
LOG.info("Creating master node");
MasterAddressTracker.setMasterAddress(zk, zk.znodePaths.masterAddressZNode, sn, infoPort);
// Wait for the node to be created
LOG.info("Waiting for master address manager to be notified");
listener.waitForCreation();
LOG.info("Master node created");
}
return addressTracker;
}
use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.
the class TestMasterAddressTracker method testDeleteIfEquals.
@Test
public void testDeleteIfEquals() throws Exception {
final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis());
final MasterAddressTracker addressTracker = setupMasterTracker(sn, 1772);
try {
assertFalse("shouldn't have deleted wrong master server.", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), "some other string."));
} finally {
assertTrue("Couldn't clean up master", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString()));
}
}
Aggregations