Search in sources :

Example 1 with MockDelayMSStateModelFactory

use of org.apache.helix.mock.participant.MockDelayMSStateModelFactory in project helix by apache.

the class TestSemiAutoStateTransition method testOfflineToSecondTopState.

@Test
public void testOfflineToSecondTopState() throws Exception {
    _participants[0].syncStop();
    Thread.sleep(2000L);
    ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(WorkflowGenerator.DEFAULT_TGT_DB + "0"));
    Map<String, String> stateMap = externalView.getStateMap(WorkflowGenerator.DEFAULT_TGT_DB + "0_0");
    Assert.assertEquals("MASTER", stateMap.get(PARTICIPANT_PREFIX + "_" + (_startPort + 1)));
    Assert.assertEquals("SLAVE", stateMap.get(PARTICIPANT_PREFIX + "_" + (_startPort + 2)));
    String instanceName = PARTICIPANT_PREFIX + "_" + _startPort;
    _participants[0] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
    // add a state model with non-OFFLINE initial state
    StateMachineEngine stateMach = _participants[0].getStateMachineEngine();
    MockDelayMSStateModelFactory delayFactory = new MockDelayMSStateModelFactory().setDelay(300000L);
    stateMach.registerStateModelFactory(MASTER_SLAVE_STATE_MODEL, delayFactory);
    _participants[0].syncStart();
    Thread.sleep(2000L);
    externalView = _accessor.getProperty(_keyBuilder.externalView(WorkflowGenerator.DEFAULT_TGT_DB + "0"));
    stateMap = externalView.getStateMap(WorkflowGenerator.DEFAULT_TGT_DB + "0_0");
    Assert.assertEquals("OFFLINE", stateMap.get(PARTICIPANT_PREFIX + "_" + _startPort));
    Assert.assertEquals("MASTER", stateMap.get(PARTICIPANT_PREFIX + "_" + (_startPort + 1)));
    Assert.assertEquals("SLAVE", stateMap.get(PARTICIPANT_PREFIX + "_" + (_startPort + 2)));
}
Also used : ExternalView(org.apache.helix.model.ExternalView) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockDelayMSStateModelFactory(org.apache.helix.mock.participant.MockDelayMSStateModelFactory) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) Test(org.testng.annotations.Test)

Example 2 with MockDelayMSStateModelFactory

use of org.apache.helix.mock.participant.MockDelayMSStateModelFactory in project helix by apache.

the class TestRoutingTableProviderFromTargetEV method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    String namespace = "/" + CLUSTER_NAME;
    _participants = new MockParticipantManager[NUM_NODES];
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(ZK_ADDR);
    _setupTool.addCluster(CLUSTER_NAME, true);
    _participants = new MockParticipantManager[NUM_NODES];
    for (int i = 0; i < NUM_NODES; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    _setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_PARTITIONS, MASTER_SLAVE_STATE_MODEL, IdealState.RebalanceMode.FULL_AUTO.name());
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_REPLICAS);
    for (int i = 0; i < NUM_NODES; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        // add a delayed state model
        StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
        MockDelayMSStateModelFactory delayFactory = new MockDelayMSStateModelFactory().setDelay(-300000L);
        stateMachine.registerStateModelFactory(MASTER_SLAVE_STATE_MODEL, delayFactory);
        _participants[i].syncStart();
    }
    _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
    _manager.connect();
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    _configAccessor = new ConfigAccessor(_gZkClient);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockDelayMSStateModelFactory(org.apache.helix.mock.participant.MockDelayMSStateModelFactory) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)2 MockDelayMSStateModelFactory (org.apache.helix.mock.participant.MockDelayMSStateModelFactory)2 StateMachineEngine (org.apache.helix.participant.StateMachineEngine)2 ConfigAccessor (org.apache.helix.ConfigAccessor)1 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)1 ExternalView (org.apache.helix.model.ExternalView)1 ClusterSetup (org.apache.helix.tools.ClusterSetup)1 BeforeClass (org.testng.annotations.BeforeClass)1 Test (org.testng.annotations.Test)1