n, // number of nodes
3, // replicas
"MasterSlave", true); // do rebalance
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>();
errPartitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
errPartitions.put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
// start mock participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
participants[i] =
new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].setTransition(new ErrTransition(errPartitions));
} else {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
// verify cluster
Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>();
errStateMap.put("TestDB0", new HashMap<String, String>());
errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
boolean result =
ClusterStateVerifier
.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
clusterName, errStateMap)));
Assert.assertTrue(result, "Cluster verification fails");
// reset a non-exist partition, should throw exception
String hostName = "localhost_12918";
String instanceUrl = getInstanceUrl(clusterName, hostName);
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.resetPartition);
paramMap.put(JsonParameters.PARTITION, "TestDB0_nonExist");
paramMap.put(JsonParameters.RESOURCE, "TestDB0");
LOG.info("IGNORABLE exception: test reset non-exist partition");
TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, true);
// reset 2 error partitions
errPartitions.clear();
participants[0].setTransition(new ErrTransitionWithResetCnt(errPartitions));
clearStatusUpdate(clusterName, "localhost_12918", "TestDB0", "TestDB0_4");
_errToOfflineInvoked.set(0);
paramMap.put(JsonParameters.PARTITION, "TestDB0_4 TestDB0_8");
TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, false);
for (int i = 0; i < 10; i++) {
Thread.sleep(400); // wait reset to be done
LOG.info("IGNORABLE exception: test reset non-error partition");
TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, true);
result =
ClusterStateVerifier
.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
clusterName));
if (result == true) {
break;
}
}
Assert.assertTrue(result);
Assert.assertEquals(_errToOfflineInvoked.get(), 2, "reset() should be invoked 2 times");
// clean up
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));