// setup grand cluster
final String grandClusterName = "GRAND_" + clusterName;
TestHelper.setupCluster(grandClusterName, ZK_ADDR, 0, "controller", null, 0, 0, 1, 0,
null, true);
ClusterDistributedController distController =
new ClusterDistributedController(ZK_ADDR, grandClusterName, "controller_0");
distController.syncStart();
// setup cluster
_gSetupTool.addCluster(clusterName, true);
_gSetupTool.activateCluster(clusterName, "GRAND_" + clusterName, true); // addCluster2
boolean result;
result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, "GRAND_" + clusterName));
Assert.assertTrue(result);
// add node/resource, and do rebalance
final int nodeNr = 2;
for (int i = 0; i < nodeNr - 1; i++) {
int port = 12918 + i;
_gSetupTool.addInstanceToCluster(clusterName, "localhost_" + port);
}
_gSetupTool.addResourceToCluster(clusterName, "TestDB0", 1, "LeaderStandby");
_gSetupTool.rebalanceStorageCluster(clusterName, "TestDB0", 1);
MockParticipantManager[] participants = new MockParticipantManager[nodeNr];
for (int i = 0; i < nodeNr - 1; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, clusterName));
Assert.assertTrue(result);
// check if controller_0 has message listener for localhost_12918
String msgPath =
PropertyPathConfig.getPath(PropertyType.MESSAGES, clusterName, "localhost_12918");
int numberOfListeners = ZkTestHelper.numberOfListeners(ZK_ADDR, msgPath);
// System.out.println("numberOfListeners(" + msgPath + "): " + numberOfListeners);
Assert.assertEquals(numberOfListeners, 2); // 1 of participant, and 1 of controller
_gSetupTool.addInstanceToCluster(clusterName, "localhost_12919");
_gSetupTool.rebalanceStorageCluster(clusterName, "TestDB0", 2);
participants[nodeNr - 1] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12919");
participants[nodeNr - 1].syncStart();
result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, clusterName));
Assert.assertTrue(result);
// check if controller_0 has message listener for localhost_12919
msgPath = PropertyPathConfig.getPath(PropertyType.MESSAGES, clusterName, "localhost_12919");
numberOfListeners = ZkTestHelper.numberOfListeners(ZK_ADDR, msgPath);
// System.out.println("numberOfListeners(" + msgPath + "): " + numberOfListeners);
Assert.assertEquals(numberOfListeners, 2); // 1 of participant, and 1 of controller
// clean up
distController.syncStop();
for (int i = 0; i < nodeNr; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));