use of org.apache.helix.participant.HelixStateMachineEngine in project helix by apache.
the class TestStateModelLeak method testDrop.
/**
* test drop resource should remove all state models
* @throws Exception
*/
@Test
public void testDrop() 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);
participants[i].syncStart();
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
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", "SLAVE");
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.participant.HelixStateMachineEngine 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()));
}
Aggregations