Search in sources :

Example 6 with CallbackHandler

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());
}
Also used : CallbackHandler(org.apache.helix.manager.zk.CallbackHandler) LiveInstance(org.apache.helix.model.LiveInstance) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor)

Aggregations

CallbackHandler (org.apache.helix.manager.zk.CallbackHandler)6 Set (java.util.Set)2 IZkChildListener (org.I0Itec.zkclient.IZkChildListener)2 IZkDataListener (org.I0Itec.zkclient.IZkDataListener)2 PropertyKey (org.apache.helix.PropertyKey)2 ZNRecord (org.apache.helix.ZNRecord)2 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)2 LiveInstance (org.apache.helix.model.LiveInstance)2 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 HelixDataAccessor (org.apache.helix.HelixDataAccessor)1 MockMSModelFactory (org.apache.helix.mock.participant.MockMSModelFactory)1 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)1 Test (org.testng.annotations.Test)1