use of org.apache.helix.mock.participant.ErrTransition in project helix by apache.
the class TestDrop method testDropErrorPartitionAutoIS.
@Test
public void testDropErrorPartitionAutoIS() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 5;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[n];
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
10, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
// 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("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
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");
errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).setErrStates(errStateMap).build();
Assert.assertTrue(verifier.verify());
// drop resource containing error partitions should drop the partition successfully
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0" });
// make sure TestDB0_4 and TestDB0_8 partitions are dropped
verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(verifier.verify());
assertEmptyCSandEV(className, "TestDB0", participants);
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.mock.participant.ErrTransition in project helix by apache.
the class TestErrorPartition method testErrorPartition.
@Test()
public void testErrorPartition() throws Exception {
String clusterName = getShortClassName();
MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START testErrorPartition() at " + new Date(System.currentTimeMillis()));
ZKHelixAdmin tool = new ZKHelixAdmin(_gZkClient);
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "TestDB", 1, 10, 5, 3, "MasterSlave", true);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
{
put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
}
};
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();
}
Map<String, Map<String, String>> errStates = new HashMap<String, Map<String, String>>();
errStates.put("TestDB0", new HashMap<String, String>());
errStates.get("TestDB0").put("TestDB0_4", "localhost_12918");
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
Map<String, Set<String>> errorStateMap = new HashMap<String, Set<String>>() {
{
put("TestDB0_4", TestHelper.setOf("localhost_12918"));
}
};
// verify "TestDB0_0", "localhost_12918" is in ERROR state
TestHelper.verifyState(clusterName, ZK_ADDR, errorStateMap, "ERROR");
// disable a partition on a node with error state
tool.enablePartition(false, clusterName, "localhost_12918", "TestDB0", Arrays.asList("TestDB0_4"));
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
TestHelper.verifyState(clusterName, ZK_ADDR, errorStateMap, "ERROR");
// disable a node with error state
tool.enableInstance(clusterName, "localhost_12918", false);
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
// make sure after restart stale ERROR state is gone
tool.enablePartition(true, clusterName, "localhost_12918", "TestDB0", Arrays.asList("TestDB0_4"));
tool.enableInstance(clusterName, "localhost_12918", true);
participants[0].syncStop();
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
new Thread(participants[0]).start();
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// clean up
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END testErrorPartition() at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.mock.participant.ErrTransition in project helix by apache.
the class TestBatchMessage method testSubMsgExecutionFail.
@Test
public void testSubMsgExecutionFail() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 5;
MockParticipantManager[] participants = new MockParticipantManager[n];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// resource#
TestHelper.setupCluster(// resource#
clusterName, // resource#
ZK_ADDR, // resource#
12918, // resource#
"localhost", // resource#
"TestDB", // resource#
1, // partition#
6, // nodes#
n, // replicas#
3, "MasterSlave", true);
// enable batch message
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
idealState.setBatchMessageMode(true);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
// get MASTER for errPartition
String errPartition = "TestDB0_0";
String masterOfPartition0 = null;
for (Map.Entry<String, String> entry : idealState.getInstanceStateMap(errPartition).entrySet()) {
if (entry.getValue().equals("MASTER")) {
masterOfPartition0 = entry.getKey();
break;
}
}
Assert.assertNotNull(masterOfPartition0);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
controller.syncStart();
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (instanceName.equals(masterOfPartition0)) {
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>();
errPartitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_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();
}
Map<String, Map<String, String>> errStates = new HashMap<String, Map<String, String>>();
errStates.put("TestDB0", new HashMap<String, String>());
errStates.get("TestDB0").put(errPartition, masterOfPartition0);
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
Map<String, Set<String>> errorStateMap = new HashMap<String, Set<String>>();
errorStateMap.put(errPartition, TestHelper.setOf(masterOfPartition0));
// verify "TestDB0_0", masterOfPartition0 is in ERROR state
TestHelper.verifyState(clusterName, ZK_ADDR, errorStateMap, "ERROR");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.mock.participant.ErrTransition in project helix by apache.
the class TestStateModelLeak method testDropErrorPartition.
/**
* test drop resource in error state should remove all state-models
* @throws Exception
*/
@Test
public void testDropErrorPartition() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
int n = 2;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
4, // number of nodes
n, // replicas
2, "MasterSlave", // do rebalance
true);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
final String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
if (i == 0) {
Map<String, Set<String>> errTransitionMap = new HashMap<String, Set<String>>();
Set<String> partitions = new HashSet<String>();
partitions.add("TestDB0_0");
errTransitionMap.put("OFFLINE-SLAVE", partitions);
participants[0].setTransition(new ErrTransition(errTransitionMap));
}
participants[i].syncStart();
}
Map<String, Map<String, String>> errStates = new HashMap<String, Map<String, String>>();
errStates.put("TestDB0", new HashMap<String, String>());
errStates.get("TestDB0").put("TestDB0_0", "localhost_12918");
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
// check state-models in state-machine
HelixStateMachineEngine stateMachine = (HelixStateMachineEngine) participants[0].getStateMachineEngine();
StateModelFactory<? extends StateModel> fty = stateMachine.getStateModelFactory("MasterSlave");
Map<String, String> expectStateModelMap = new TreeMap<String, String>();
expectStateModelMap.put("TestDB0_0", "ERROR");
expectStateModelMap.put("TestDB0_1", "MASTER");
expectStateModelMap.put("TestDB0_2", "SLAVE");
expectStateModelMap.put("TestDB0_3", "MASTER");
checkStateModelMap(fty, expectStateModelMap);
// drop resource
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.dropResource(clusterName, "TestDB0");
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// check state models have been dropped also
Assert.assertTrue(fty.getPartitionSet("TestDB0").isEmpty(), "All state-models should be dropped, but was " + fty.getPartitionSet("TestDB0"));
// cleanup
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.mock.participant.ErrTransition in project helix by apache.
the class TestDrop method testDropErrorPartitionCustomIS.
@Test
public void testDropErrorPartitionCustomIS() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 2;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[n];
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
2, // number of nodes
n, // replicas
2, "MasterSlave", // do rebalance
false);
// set custom ideal-state
CustomModeISBuilder isBuilder = new CustomModeISBuilder("TestDB0");
isBuilder.setNumPartitions(2);
isBuilder.setNumReplica(2);
isBuilder.setStateModel("MasterSlave");
isBuilder.assignInstanceAndState("TestDB0_0", "localhost_12918", "MASTER");
isBuilder.assignInstanceAndState("TestDB0_0", "localhost_12919", "SLAVE");
isBuilder.assignInstanceAndState("TestDB0_1", "localhost_12919", "MASTER");
isBuilder.assignInstanceAndState("TestDB0_1", "localhost_12918", "SLAVE");
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates("TestDB0"), isBuilder.build());
// 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_0"));
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_0", "localhost_12918");
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).setErrStates(errStateMap).build();
Assert.assertTrue(verifier.verify());
// drop resource containing error partitions should drop the partition successfully
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0" });
// make sure TestDB0_0 partition is dropped
verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(verifier.verify(), "Should be empty exeternal-view");
assertEmptyCSandEV(clusterName, "TestDB0", participants);
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations