HelixAdmin admin = new ZKHelixAdmin(_zkclient);
admin.setConstraint(clusterName, ConstraintType.MESSAGE_CONSTRAINT, "constraint1",
constraintItemBuilder.build());
MockController controller =
new MockController(_zkaddr, clusterName, "controller");
controller.syncStart();
// start 1st participant
MockParticipant[] participants = new MockParticipant[n];
String instanceName1 = "localhost_12918";
participants[0] = new MockParticipant(_zkaddr, clusterName, instanceName1);
participants[0].getStateMachineEngine().registerStateModelFactory(StateModelDefId.from("Bootstrap"),
new BootstrapStateModelFactory());
participants[0].syncStart();
boolean result =
ClusterStateVerifier
.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(_zkaddr,
clusterName));
Assert.assertTrue(result);
// start 2nd participant which will be the master for Test0_0
String instanceName2 = "localhost_12919";
participants[1] = new MockParticipant(_zkaddr, clusterName, instanceName2);
participants[1].getStateMachineEngine().registerStateModelFactory(StateModelDefId.from("Bootstrap"),
new BootstrapStateModelFactory());
participants[1].syncStart();
result =
ClusterStateVerifier
.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(_zkaddr,
clusterName));
Assert.assertTrue(result);
// check we received the message in the right order
Assert.assertEquals(_msgOrderList.size(), 7);
Message[] _msgOrderArray = _msgOrderList.toArray(new Message[0]);
assertMessage(_msgOrderArray[0], "OFFLINE", "BOOTSTRAP", instanceName1);
assertMessage(_msgOrderArray[1], "BOOTSTRAP", "SLAVE", instanceName1);
assertMessage(_msgOrderArray[2], "SLAVE", "MASTER", instanceName1);
// after we start the 2nd instance, the messages should be received in
// the following order:
// 1) offline->bootstrap for localhost_12919
// 2) bootstrap->slave for localhost_12919
// 3) master->slave for localhost_12918
// 4) slave->master for localhost_12919
assertMessage(_msgOrderArray[3], "OFFLINE", "BOOTSTRAP", instanceName2);
assertMessage(_msgOrderArray[4], "BOOTSTRAP", "SLAVE", instanceName2);
assertMessage(_msgOrderArray[5], "MASTER", "SLAVE", instanceName1);
assertMessage(_msgOrderArray[6], "SLAVE", "MASTER", instanceName2);
// clean up
// wait for all zk callbacks done
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));