use of org.apache.helix.manager.zk.CallbackHandler in project helix by apache.
the class TestDistributedControllerManager method expireController.
/**
* expire a controller and make sure the other takes the leadership
* @param expireController
* @param newController
* @throws Exception
*/
void expireController(ClusterDistributedController expireController, ClusterDistributedController newController) throws Exception {
String clusterName = expireController.getClusterName();
LOG.info("Expiring distributedController: " + expireController.getInstanceName() + ", session: " + expireController.getSessionId() + " ...");
String oldSessionId = expireController.getSessionId();
ZkTestHelper.expireSession(expireController.getZkClient());
String newSessionId = expireController.getSessionId();
LOG.debug("Expired distributedController: " + expireController.getInstanceName() + ", oldSessionId: " + oldSessionId + ", newSessionId: " + newSessionId);
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// verify leader changes to localhost_12919
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
Assert.assertNotNull(accessor.getProperty(keyBuilder.liveInstance(expireController.getInstanceName())));
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
Assert.assertNotNull(leader);
Assert.assertEquals(leader.getId(), newController.getInstanceName());
// check expired-controller has 2 handlers: message and data-accessor
LOG.debug(expireController.getInstanceName() + " handlers: " + TestHelper.printHandlers(expireController));
List<CallbackHandler> handlers = expireController.getHandlers();
Assert.assertEquals(handlers.size(), 2, "Distributed controller should have 1 handler (message) after lose leadership, but was " + handlers.size());
}
Aggregations