use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestDistributedCMMain method testDistributedCMMain.
@Test
public void testDistributedCMMain() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterNamePrefix = className + "_" + methodName;
final int n = 5;
final int clusterNb = 10;
System.out.println("START " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
// setup 10 clusters
for (int i = 0; i < clusterNb; i++) {
String clusterName = clusterNamePrefix + "0_" + i;
String participantName = "localhost" + i;
String resourceName = "TestDB" + i;
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
participantName, // resource name prefix
resourceName, // resources
1, // partitions per resource
8, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
}
// setup controller cluster
final String controllerClusterName = "CONTROLLER_" + clusterNamePrefix;
// controller
TestHelper.setupCluster(// controller
"CONTROLLER_" + clusterNamePrefix, // controller
ZK_ADDR, // controller
0, // participant name prefix
"controller", // resource name prefix
clusterNamePrefix, // resources
1, // partitions per resource
clusterNb, // number of nodes
n, // replicas
3, "LeaderStandby", // do rebalance
true);
// start distributed cluster controllers
ClusterDistributedController[] controllers = new ClusterDistributedController[n + n];
for (int i = 0; i < n; i++) {
controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName), 30000);
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
// start first cluster
MockParticipantManager[] participants = new MockParticipantManager[n];
final String firstClusterName = clusterNamePrefix + "0_0";
for (int i = 0; i < n; i++) {
String instanceName = "localhost0_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, firstClusterName, instanceName);
participants[i].syncStart();
}
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
Assert.assertTrue(result, "first cluster NOT in ideal state");
// add more controllers to controller cluster
ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
for (int i = 0; i < n; i++) {
String controller = "controller_" + (n + i);
setupTool.addInstanceToCluster(controllerClusterName, controller);
}
setupTool.rebalanceStorageCluster(controllerClusterName, clusterNamePrefix + "0", 6);
for (int i = n; i < 2 * n; i++) {
controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
// verify controller cluster
result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
// verify first cluster
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
Assert.assertTrue(result, "first cluster NOT in ideal state");
// stop controller_0-5
ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(controllerClusterName, baseAccessor);
Builder keyBuilder = accessor.keyBuilder();
for (int i = 0; i < n; i++) {
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
String leaderName = leader.getId();
int j = Integer.parseInt(leaderName.substring(leaderName.lastIndexOf('_') + 1));
controllers[j].syncStop();
result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
Assert.assertTrue(result, "first cluster NOT in ideal state");
}
// clean up
// wait for all zk callbacks done
System.out.println("Cleaning up...");
for (int i = 0; i < 5; i++) {
result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
controllers[i].syncStop();
}
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestDistributedClusterController method testDistributedClusterController.
@Test
public void testDistributedClusterController() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterNamePrefix = className + "_" + methodName;
final int n = 5;
final int clusterNb = 10;
System.out.println("START " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
// setup 10 clusters
for (int i = 0; i < clusterNb; i++) {
String clusterName = clusterNamePrefix + "0_" + i;
String participantName = "localhost" + i;
String resourceName = "TestDB" + i;
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
participantName, // resource name prefix
resourceName, // resources
1, // partitions per resource
8, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
}
// setup controller cluster
final String controllerClusterName = "CONTROLLER_" + clusterNamePrefix;
// controller
TestHelper.setupCluster(// controller
"CONTROLLER_" + clusterNamePrefix, // controller
ZK_ADDR, // controller
0, // participant name prefix
"controller", // resource name prefix
clusterNamePrefix, // resources
1, // partitions per resource
clusterNb, // number of nodes
n, // replicas
3, "LeaderStandby", // do rebalance
true);
// start distributed cluster controllers
ClusterDistributedController[] controllers = new ClusterDistributedController[n];
for (int i = 0; i < n; i++) {
controllers[i] = new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName), 30000);
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
// start first cluster
MockParticipantManager[] participants = new MockParticipantManager[n];
final String firstClusterName = clusterNamePrefix + "0_0";
for (int i = 0; i < n; i++) {
String instanceName = "localhost0_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, firstClusterName, instanceName);
participants[i].syncStart();
}
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, firstClusterName));
Assert.assertTrue(result, "first cluster NOT in ideal state");
// stop current leader in controller cluster
ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(controllerClusterName, baseAccessor);
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
String leaderName = leader.getId();
int j = Integer.parseInt(leaderName.substring(leaderName.lastIndexOf('_') + 1));
controllers[j].syncStop();
// setup the second cluster
MockParticipantManager[] participants2 = new MockParticipantManager[n];
final String secondClusterName = clusterNamePrefix + "0_1";
for (int i = 0; i < n; i++) {
String instanceName = "localhost1_" + (12918 + i);
participants2[i] = new MockParticipantManager(ZK_ADDR, secondClusterName, instanceName);
participants2[i].syncStart();
}
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, secondClusterName));
Assert.assertTrue(result, "second cluster NOT in ideal state");
// clean up
// wait for all zk callbacks done
System.out.println("Cleaning up...");
for (int i = 0; i < 5; i++) {
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, controllerClusterName));
controllers[i].syncStop();
}
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterNamePrefix + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestDriver method stopDummyParticipant.
public static void stopDummyParticipant(String uniqClusterName, long beginTime, int instanceId) throws Exception {
if (!_testInfoMap.containsKey(uniqClusterName)) {
String errMsg = "test cluster hasn't been setup:" + uniqClusterName;
throw new Exception(errMsg);
}
TestInfo testInfo = _testInfoMap.get(uniqClusterName);
String failHost = PARTICIPANT_PREFIX + "_" + (START_PORT + instanceId);
MockParticipantManager participant = (MockParticipantManager) testInfo._managers.remove(failHost);
// TODO need sync
if (participant == null) {
String errMsg = "Dummy participant:" + failHost + " seems not running";
LOG.error(errMsg);
} else {
// System.err.println("try to stop participant: " +
// result._manager.getInstanceName());
// NodeOpArg arg = new NodeOpArg(result._manager, result._thread);
// TestCommand command = new TestCommand(CommandType.STOP, new TestTrigger(beginTime), arg);
// List<TestCommand> commandList = new ArrayList<TestCommand>();
// commandList.add(command);
// TestExecutor.executeTestAsync(commandList, ZK_ADDR);
participant.syncStop();
}
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestDriver method stopCluster.
public static void stopCluster(String uniqClusterName) throws Exception {
if (!_testInfoMap.containsKey(uniqClusterName)) {
String errMsg = "test cluster hasn't been setup:" + uniqClusterName;
throw new IllegalArgumentException(errMsg);
}
TestInfo testInfo = _testInfoMap.remove(uniqClusterName);
// stop controller first
for (String instanceName : testInfo._managers.keySet()) {
if (instanceName.startsWith(CONTROLLER_PREFIX)) {
ClusterControllerManager controller = (ClusterControllerManager) testInfo._managers.get(instanceName);
controller.syncStop();
}
}
Thread.sleep(1000);
for (String instanceName : testInfo._managers.keySet()) {
if (!instanceName.startsWith(CONTROLLER_PREFIX)) {
MockParticipantManager participant = (MockParticipantManager) testInfo._managers.get(instanceName);
participant.syncStop();
}
}
testInfo._zkClient.close();
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestRebalancerPersistAssignments method beforeClass.
@Override
@BeforeClass
public void beforeClass() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
// setup storage cluster
_setupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < NODE_NR; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_instanceNames.add(instanceName);
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
_participants[i].syncStart();
}
}
Aggregations