n, // number of nodes
3, // replicas
"MasterSlave", true); // do rebalance
// start controller
ClusterControllerManager controller =
new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
Map<String, Set<String>> errTransitions = new HashMap<String, Set<String>>();
errTransitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
errTransitions.put("ERROR-DROPPED", TestHelper.setOf("TestDB0_4"));
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(errTransitions));
} else {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
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");
boolean result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
clusterName, errStateMap));
Assert.assertTrue(result);
// drop resource containing error partitions should invoke error->dropped transition
// if error happens during error->dropped transition, partition should be disabled
ClusterSetup.processCommandLineArgs(new String[] {
"--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0"
});
// make sure TestDB0_4 stay in ERROR state and is disabled
result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
clusterName, errStateMap));
Assert.assertTrue(result);
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig("localhost_12918"));
List<String> disabledPartitions = config.getDisabledPartitions();
// System.out.println("disabledPartitions: " + disabledPartitions);
Assert.assertEquals(disabledPartitions.size(), 1, "TestDB0_4 should be disabled");
Assert.assertEquals(disabledPartitions.get(0), "TestDB0_4");
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));