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()));
}
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);
}
}
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();
}
}
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()));
}
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);
}
Aggregations