use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestRebalancerPersistAssignments method testDisablePersist.
@Test(dataProvider = "rebalanceModes")
public void testDisablePersist(RebalanceMode rebalanceMode) throws Exception {
String testDb = "TestDB2-" + rebalanceMode.name();
_setupTool.addResourceToCluster(CLUSTER_NAME, testDb, 5, BuiltInStateModelDefinitions.LeaderStandby.name(), rebalanceMode.name());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, testDb, 3);
BestPossibleExternalViewVerifier.Builder verifierBuilder = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(new HashSet<String>(Collections.singleton(testDb)));
Assert.assertTrue(verifierBuilder.build().verify());
// kill 1 node
_participants[0].syncStop();
Set<String> liveInstances = new HashSet<String>(_instanceNames);
liveInstances.remove(_participants[0].getInstanceName());
verifierBuilder.setExpectLiveInstances(liveInstances);
Assert.assertTrue(verifierBuilder.build().verify());
IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, testDb);
Set<String> excludedInstances = new HashSet<String>();
excludedInstances.add(_participants[0].getInstanceName());
verifyAssignmentInIdealStateWithPersistDisabled(idealState, excludedInstances);
// clean up
_setupTool.getClusterManagementTool().dropResource(CLUSTER_NAME, testDb);
_participants[0] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _participants[0].getInstanceName());
_participants[0].syncStart();
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestRebalancerPersistAssignments method testEnablePersist.
@Test(dataProvider = "rebalanceModes", dependsOnMethods = { "testDisablePersist" })
public void testEnablePersist(RebalanceMode rebalanceMode) throws Exception {
String testDb = "TestDB1-" + rebalanceMode.name();
enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
_setupTool.addResourceToCluster(CLUSTER_NAME, testDb, 5, BuiltInStateModelDefinitions.LeaderStandby.name(), rebalanceMode.name());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, testDb, 3);
BestPossibleExternalViewVerifier.Builder verifierBuilder = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(new HashSet<String>(Collections.singleton(testDb)));
Assert.assertTrue(verifierBuilder.build().verify());
IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, testDb);
verifyAssignmentInIdealStateWithPersistEnabled(idealState, new HashSet<String>());
// kill 1 node
_participants[0].syncStop();
Set<String> liveInstances = new HashSet<String>(_instanceNames);
liveInstances.remove(_participants[0].getInstanceName());
verifierBuilder.setExpectLiveInstances(liveInstances);
Assert.assertTrue(verifierBuilder.build().verify());
idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, testDb);
// verify that IdealState contains updated assignment in it map fields.
Set<String> excludedInstances = new HashSet<String>();
excludedInstances.add(_participants[0].getInstanceName());
verifyAssignmentInIdealStateWithPersistEnabled(idealState, excludedInstances);
// clean up
_setupTool.getClusterManagementTool().dropResource(CLUSTER_NAME, testDb);
_participants[0] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _participants[0].getInstanceName());
_participants[0].syncStart();
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestReelectedPipelineCorrectness method testReelection.
@Test
public void testReelection() throws Exception {
final int NUM_CONTROLLERS = 2;
final int NUM_PARTICIPANTS = 4;
final int NUM_PARTITIONS = 8;
final int NUM_REPLICAS = 2;
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
// Set up cluster
// 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
NUM_PARTITIONS, // number of nodes
NUM_PARTICIPANTS, // replicas
NUM_REPLICAS, "MasterSlave", RebalanceMode.FULL_AUTO, // do rebalance
true);
// configure distributed controllers
String controllerCluster = clusterName + "_controllers";
setupTool.addCluster(controllerCluster, true);
for (int i = 0; i < NUM_CONTROLLERS; i++) {
setupTool.addInstanceToCluster(controllerCluster, "controller_" + i);
}
setupTool.activateCluster(clusterName, controllerCluster, true);
// start participants
MockParticipantManager[] participants = new MockParticipantManager[NUM_PARTICIPANTS];
for (int i = 0; i < NUM_PARTICIPANTS; i++) {
final String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
// start controllers
ClusterDistributedController[] controllers = new ClusterDistributedController[NUM_CONTROLLERS];
for (int i = 0; i < NUM_CONTROLLERS; i++) {
controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerCluster, "controller_" + i);
controllers[i].syncStart();
}
Thread.sleep(1000);
// Ensure a balanced cluster
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// Disable the leader, resulting in a leader election
HelixDataAccessor accessor = participants[0].getHelixDataAccessor();
LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
int totalWait = 0;
while (leader == null && totalWait < CHECK_TIMEOUT) {
Thread.sleep(CHECK_INTERVAL);
totalWait += CHECK_INTERVAL;
leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
}
if (totalWait >= CHECK_TIMEOUT) {
Assert.fail("No leader was ever elected!");
}
String leaderId = leader.getId();
String standbyId = (leaderId.equals("controller_0")) ? "controller_1" : "controller_0";
HelixAdmin admin = setupTool.getClusterManagementTool();
admin.enableInstance(controllerCluster, leaderId, false);
// Stop a participant to make sure that the leader election worked
Thread.sleep(500);
participants[0].syncStop();
Thread.sleep(500);
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// Disable the original standby (leaving 0 active controllers) and kill another participant
admin.enableInstance(controllerCluster, standbyId, false);
Thread.sleep(500);
participants[1].syncStop();
// Also change the ideal state
IdealState idealState = admin.getResourceIdealState(clusterName, "TestDB0");
idealState.setMaxPartitionsPerInstance(1);
admin.setResourceIdealState(clusterName, "TestDB0", idealState);
Thread.sleep(500);
// Also disable an instance in the main cluster
admin.enableInstance(clusterName, "localhost_12920", false);
// Re-enable the original leader
admin.enableInstance(controllerCluster, leaderId, true);
// Now check that both the ideal state and the live instances are adhered to by the rebalance
Thread.sleep(500);
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// cleanup
for (int i = 0; i < NUM_CONTROLLERS; i++) {
controllers[i].syncStop();
}
for (int i = 2; i < NUM_PARTICIPANTS; i++) {
participants[i].syncStop();
}
System.out.println("STOP " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestResetPartitionState method testResetPartitionState.
@Test()
public void testResetPartitionState() throws Exception {
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()));
// 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();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
{
put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
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
try {
String command = "--zkSvr " + ZK_ADDR + " --resetPartition " + clusterName + " localhost_12918 TestDB0 TestDB0_nonExist";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("Should throw exception on reset a non-exist partition");
} catch (Exception e) {
// OK
}
// reset one error partition
errPartitions.remove("SLAVE-MASTER");
participants[0].setTransition(new ErrTransitionWithResetCnt(errPartitions));
clearStatusUpdate(clusterName, "localhost_12918", "TestDB0", "TestDB0_4");
_errToOfflineInvoked = 0;
String command = "--zkSvr " + ZK_ADDR + " --resetPartition " + clusterName + " localhost_12918 TestDB0 TestDB0_4";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// wait reset to be done
Thread.sleep(200);
try {
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("Should throw exception on reset a partition not in ERROR state");
} catch (Exception e) {
// OK
}
errStateMap.get("TestDB0").remove("TestDB0_4");
result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStateMap)));
Assert.assertTrue(result, "Cluster verification fails");
Assert.assertEquals(_errToOfflineInvoked, 1);
// reset the other error partition
participants[0].setTransition(new ErrTransitionWithResetCnt(null));
clearStatusUpdate(clusterName, "localhost_12918", "TestDB0", "TestDB0_8");
command = "--zkSvr " + ZK_ADDR + " --resetPartition " + clusterName + " localhost_12918 TestDB0 TestDB0_8";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result, "Cluster verification fails");
Assert.assertEquals(_errToOfflineInvoked, 2, "Should reset 2 partitions");
// clean up
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestSchemataSM method testSchemataSM.
@Test
public void testSchemataSM() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
int n = 5;
MockParticipantManager[] participants = new MockParticipantManager[n];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant start port
TestHelper.setupCluster(// participant start port
clusterName, // participant start port
ZK_ADDR, // participant start port
12918, // participant name prefix
"localhost", // resource name prefix
"TestSchemata", // resources
1, // partitions per resource
1, // number of nodes
n, // replicas
0, "STORAGE_DEFAULT_SM_SCHEMATA", // don't rebalance
false);
// rebalance ideal-state to use ANY_LIVEINSTANCE for preference list
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
PropertyKey key = keyBuilder.idealStates("TestSchemata0");
IdealState idealState = accessor.getProperty(key);
idealState.setReplicas(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString());
idealState.getRecord().setListField("TestSchemata0_0", Arrays.asList(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString()));
accessor.setProperty(key, idealState);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// start n-1 participants
for (int i = 1; i < n; i++) {
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);
// start the remaining 1 participant
participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
participants[0].syncStart();
// make sure we have all participants in MASTER state
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
key = keyBuilder.externalView("TestSchemata0");
ExternalView externalView = accessor.getProperty(key);
Map<String, String> stateMap = externalView.getStateMap("TestSchemata0_0");
Assert.assertNotNull(stateMap);
Assert.assertEquals(stateMap.size(), n, "all " + n + " participants should be in Master state");
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
Assert.assertNotNull(stateMap.get(instanceName));
Assert.assertEquals(stateMap.get(instanceName), "MASTER");
}
// 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