clusterAccessor.addResourceToCluster(new ResourceConfig.Builder(resourceId).rebalancerContext(
rebalancerCtx).build());
clusterAccessor.addParticipantToCluster(new ParticipantConfig.Builder(participantId).build());
// start controller
HelixController controller = connection.createController(clusterId, controllerId);
controller.startAsync();
// start participant
HelixParticipant participant = connection.createParticipant(clusterId, participantId);
participant.getStateMachineEngine().registerStateModelFactory(
StateModelDefId.from("MasterSlave"), new MockStateModelFactory());
participant.startAsync();
// verify
final HelixDataAccessor accessor = connection.createDataAccessor(clusterId);
final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
boolean success = TestHelper.verify(new TestHelper.Verifier() {
@Override
public boolean verify() throws Exception {
ExternalView externalView = accessor.getProperty(keyBuilder.externalView("testDB"));
Map<ParticipantId, State> stateMap = externalView.getStateMap(PartitionId.from("testDB_0"));
if (stateMap == null || !stateMap.containsKey(participantId)) {
return false;
}
return stateMap.get(participantId).equals(State.from("MASTER"));
}
}, 10 * 1000);
Assert.assertTrue(success);
// clean up
controller.stopAsync();
participant.stopAsync();
connection.disconnect();
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}