Search in sources :

Example 86 with MockParticipantManager

use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.

the class TestNonOfflineInitState method testNonOfflineInitState.

@Test
public void testNonOfflineInitState() throws Exception {
    System.out.println("START testNonOfflineInitState at " + new Date(System.currentTimeMillis()));
    String clusterName = getShortClassName();
    setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    10, // number of nodes
    5, // replicas
    1, "Bootstrap", // do rebalance
    true);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    MockParticipantManager[] participants = new MockParticipantManager[5];
    for (int i = 0; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        // add a state model with non-OFFLINE initial state
        StateMachineEngine stateMach = participants[i].getStateMachineEngine();
        MockBootstrapModelFactory bootstrapFactory = new MockBootstrapModelFactory();
        stateMach.registerStateModelFactory("Bootstrap", bootstrapFactory);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END testNonOfflineInitState at " + new Date(System.currentTimeMillis()));
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) MockBootstrapModelFactory(org.apache.helix.mock.participant.MockBootstrapModelFactory) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 87 with MockParticipantManager

use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.

the class TestStateTransitionTimeout method testStateTransitionTimeOut.

@Test
public void testStateTransitionTimeOut() throws Exception {
    Map<String, SleepStateModelFactory> factories = new HashMap<String, SleepStateModelFactory>();
    IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, TEST_DB);
    for (int i = 0; i < NODE_NR; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        SleepStateModelFactory factory = new SleepStateModelFactory(1000);
        factories.put(instanceName, factory);
        for (String p : idealState.getPartitionSet()) {
            if (idealState.getPreferenceList(p).get(0).equals(instanceName)) {
                factory.addPartition(p);
            }
        }
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        _participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", factory);
        _participants[i].syncStart();
    }
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    HelixDataAccessor accessor = _participants[0].getHelixDataAccessor();
    Builder kb = accessor.keyBuilder();
    ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));
    for (String p : idealState.getPartitionSet()) {
        String idealMaster = idealState.getPreferenceList(p).get(0);
        Assert.assertTrue(ev.getStateMap(p).get(idealMaster).equals("ERROR"));
        TimeOutStateModel model = factories.get(idealMaster).getStateModel(TEST_DB, p);
        Assert.assertEquals(model._errorCallcount, 1);
        Assert.assertEquals(model._error.getCode(), ErrorCode.TIMEOUT);
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) Builder(org.apache.helix.PropertyKey.Builder) IdealState(org.apache.helix.model.IdealState) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HelixDataAccessor(org.apache.helix.HelixDataAccessor) Test(org.testng.annotations.Test)

Example 88 with MockParticipantManager

use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.

the class TestStateTransitionTimeoutWithResource method setParticipants.

private void setParticipants(String dbName) throws InterruptedException {
    _factories = new HashMap<>();
    IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, dbName);
    for (int i = 0; i < NODE_NR; i++) {
        if (_participants[i] != null) {
            _participants[i].syncStop();
        }
        Thread.sleep(1000);
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        SleepStateModelFactory factory = new SleepStateModelFactory(1000);
        _factories.put(instanceName, factory);
        for (String p : idealState.getPartitionSet()) {
            if (idealState.getPreferenceList(p).get(0).equals(instanceName)) {
                factory.addPartition(p);
            }
        }
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        _participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", factory);
        _participants[i].syncStart();
    }
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) IdealState(org.apache.helix.model.IdealState)

Example 89 with MockParticipantManager

use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.

the class TestCrushAutoRebalance method afterClass.

@AfterClass
public void afterClass() throws Exception {
    /**
     * shutdown order: 1) disconnect the controller 2) disconnect participants
     */
    _controller.syncStop();
    for (MockParticipantManager participant : _participants) {
        participant.syncStop();
    }
    _setupTool.deleteCluster(CLUSTER_NAME);
    System.out.println("END " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Date(java.util.Date) AfterClass(org.testng.annotations.AfterClass)

Example 90 with MockParticipantManager

use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.

the class TestCrushAutoRebalance method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(_gZkClient);
    _setupTool.addCluster(CLUSTER_NAME, true);
    for (int i = 0; i < NUM_NODE; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
        String zone = "zone-" + i % 3;
        String tag = "tag-" + i % 2;
        _setupTool.getClusterManagementTool().setInstanceZoneId(CLUSTER_NAME, storageNodeName, zone);
        _setupTool.getClusterManagementTool().addInstanceTag(CLUSTER_NAME, storageNodeName, tag);
        _nodeToZoneMap.put(storageNodeName, zone);
        _nodeToTagMap.put(storageNodeName, tag);
        _nodes.add(storageNodeName);
    }
    // start dummy participants
    for (String node : _nodes) {
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, node);
        participant.syncStart();
        _participants.add(participant);
    }
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
    enableTopologyAwareRebalance(_gZkClient, CLUSTER_NAME, true);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) Date(java.util.Date) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)167 Test (org.testng.annotations.Test)113 Date (java.util.Date)101 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)101 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)43 ZNRecord (org.apache.helix.ZNRecord)40 IdealState (org.apache.helix.model.IdealState)35 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)35 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)34 HashMap (java.util.HashMap)33 HelixDataAccessor (org.apache.helix.HelixDataAccessor)30 ClusterSetup (org.apache.helix.tools.ClusterSetup)28 BeforeClass (org.testng.annotations.BeforeClass)27 ExternalView (org.apache.helix.model.ExternalView)24 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)20 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)19 Map (java.util.Map)18 PropertyKey (org.apache.helix.PropertyKey)16 Builder (org.apache.helix.PropertyKey.Builder)15 ClusterDistributedController (org.apache.helix.integration.manager.ClusterDistributedController)15