Search in sources :

Example 6 with ZKHelixManager

use of org.apache.helix.manager.zk.ZKHelixManager in project helix by apache.

the class TestDistributedControllerManager method simpleIntegrationTest.

@Test
public void simpleIntegrationTest() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    int n = 2;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // participant port
    TestHelper.setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    4, // number of nodes
    n, // replicas
    2, "MasterSlave", // do rebalance
    true);
    HelixManager[] distributedControllers = new HelixManager[n];
    for (int i = 0; i < n; i++) {
        int port = 12918 + i;
        distributedControllers[i] = new ZKHelixManager(clusterName, "localhost_" + port, InstanceType.CONTROLLER_PARTICIPANT, ZK_ADDR);
        distributedControllers[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", new MockMSModelFactory());
        distributedControllers[i].connect();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // disconnect first distributed-controller, and verify second takes leadership
    distributedControllers[0].disconnect();
    // verify leader changes to localhost_12919
    Thread.sleep(100);
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12918")));
    LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
    Assert.assertNotNull(leader);
    Assert.assertEquals(leader.getId(), "localhost_12919");
    // clean up
    distributedControllers[1].disconnect();
    Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12919")));
    Assert.assertNull(accessor.getProperty(keyBuilder.controllerLeader()));
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : HelixManager(org.apache.helix.HelixManager) ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) MockMSModelFactory(org.apache.helix.mock.participant.MockMSModelFactory) LiveInstance(org.apache.helix.model.LiveInstance) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Aggregations

ZKHelixManager (org.apache.helix.manager.zk.ZKHelixManager)6 HelixManager (org.apache.helix.HelixManager)5 Test (org.testng.annotations.Test)4 Date (java.util.Date)3 PropertyKey (org.apache.helix.PropertyKey)3 ZNRecord (org.apache.helix.ZNRecord)3 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)2 MockMSModelFactory (org.apache.helix.mock.participant.MockMSModelFactory)2 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ZkServer (org.I0Itec.zkclient.ZkServer)1 CommandLine (org.apache.commons.cli.CommandLine)1 ParseException (org.apache.commons.cli.ParseException)1 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)1 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)1 HelixManagerStateListener (org.apache.helix.manager.zk.HelixManagerStateListener)1 ZkBaseDataAccessor (org.apache.helix.manager.zk.ZkBaseDataAccessor)1 LiveInstance (org.apache.helix.model.LiveInstance)1 StateMachineEngine (org.apache.helix.participant.StateMachineEngine)1 ZkHelixPropertyStore (org.apache.helix.store.zk.ZkHelixPropertyStore)1