use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestSemiAutoRebalance method testStopAndReStartParticipant.
@Test(dependsOnMethods = "testAddParticipant")
public void testStopAndReStartParticipant() throws InterruptedException {
MockParticipantManager participant = _participants.get(0);
String instance = participant.getInstanceName();
Map<String, MasterSlaveSMD.States> affectedPartitions = new HashMap<String, MasterSlaveSMD.States>();
ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME));
for (String partition : externalView.getPartitionSet()) {
Map<String, String> stateMap = externalView.getStateMap(partition);
if (stateMap.containsKey(instance)) {
affectedPartitions.put(partition, MasterSlaveSMD.States.valueOf(stateMap.get(instance)));
}
}
stopParticipant(participant, affectedPartitions);
// create a new participant
participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance);
_participants.set(0, participant);
startParticipant(participant, affectedPartitions);
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestSemiAutoRebalance method beforeClass.
@BeforeClass
public void beforeClass() throws InterruptedException {
System.out.println("START " + getShortClassName() + " at " + new Date(System.currentTimeMillis()));
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
// setup storage cluster
_gSetupTool.addCluster(CLUSTER_NAME, true);
_gSetupTool.addResourceToCluster(CLUSTER_NAME, DB_NAME, PARTITION_NUMBER, STATE_MODEL, IdealState.RebalanceMode.SEMI_AUTO.toString());
_accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
_keyBuilder = _accessor.keyBuilder();
List<String> instances = new ArrayList<String>();
for (int i = 0; i < PARTICIPANT_NUMBER; i++) {
String instance = PARTICIPANT_PREFIX + "_" + (PARTICIPANT_START_PORT + i);
_gSetupTool.addInstanceToCluster(CLUSTER_NAME, instance);
instances.add(instance);
}
_gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, DB_NAME, REPLICA_NUMBER);
// start dummy participants
for (int i = 0; i < PARTICIPANT_NUMBER; i++) {
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instances.get(i));
participant.syncStart();
_participants.add(participant);
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
Thread.sleep(1000);
// verify ideal state and external view
IdealState idealState = _accessor.getProperty(_keyBuilder.idealStates(DB_NAME));
Assert.assertNotNull(idealState);
Assert.assertEquals(idealState.getNumPartitions(), PARTITION_NUMBER);
for (String partition : idealState.getPartitionSet()) {
List<String> preferenceList = idealState.getPreferenceList(partition);
Assert.assertNotNull(preferenceList);
Assert.assertEquals(preferenceList.size(), REPLICA_NUMBER);
}
ExternalView externalView = _accessor.getProperty(_keyBuilder.externalView(DB_NAME));
Assert.assertNotNull(externalView);
Assert.assertEquals(externalView.getPartitionSet().size(), PARTITION_NUMBER);
for (String partition : externalView.getPartitionSet()) {
Map<String, String> stateMap = externalView.getStateMap(partition);
Assert.assertEquals(stateMap.size(), REPLICA_NUMBER);
int masters = 0;
for (String state : stateMap.values()) {
if (state.equals(MasterSlaveSMD.States.MASTER.name())) {
++masters;
}
}
Assert.assertEquals(masters, 1);
}
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestAutoIsWithEmptyMap method testAutoIsWithEmptyMap.
@Test
public void testAutoIsWithEmptyMap() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
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
5, // replicas
3, "LeaderStandby", // do not rebalance
false);
// calculate and set custom ideal state
String idealPath = PropertyPathBuilder.idealState(clusterName, "TestDB0");
ZNRecord curIdealState = _gZkClient.readData(idealPath);
List<String> instanceNames = new ArrayList<String>(5);
for (int i = 0; i < 5; i++) {
int port = 12918 + i;
instanceNames.add("localhost_" + port);
}
ZNRecord idealState = DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10, 2, "TestDB0", "LEADER", "STANDBY");
// System.out.println(idealState);
// curIdealState.setSimpleField(IdealState.IdealStateProperty.IDEAL_STATE_MODE.toString(),
// "CUSTOMIZED");
curIdealState.setSimpleField(IdealState.IdealStateProperty.REPLICAS.toString(), "3");
curIdealState.setListFields(idealState.getListFields());
_gZkClient.writeData(idealPath, curIdealState);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
MockParticipantManager[] participants = new MockParticipantManager[5];
for (int i = 0; i < 5; 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);
// 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 TestAutoRebalance 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(_gZkClient);
// setup storage cluster
_setupTool.addCluster(CLUSTER_NAME, true);
_setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, _PARTITIONS, STATE_MODEL, RebalanceMode.FULL_AUTO + "");
_setupTool.addResourceToCluster(CLUSTER_NAME, db2, _PARTITIONS, "OnlineOffline", RebalanceMode.FULL_AUTO + "");
for (int i = 0; i < NODE_NR; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, _replica);
for (int i = 0; i < 3; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.getClusterManagementTool().addInstanceTag(CLUSTER_NAME, storageNodeName, _tag);
}
_setupTool.rebalanceCluster(CLUSTER_NAME, db2, 1, "ucpx", _tag);
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
participant.syncStart();
_participants[i] = participant;
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
boolean result = ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient, CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestAutoRebalancePartitionLimit 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);
_setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, 100, "OnlineOffline", RebalanceMode.FULL_AUTO + "", 0, 25);
for (int i = 0; i < NODE_NR; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 1);
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
// _startCMResultMap.get(controllerName)._manager;
HelixManager manager = _controller;
HelixDataAccessor accessor = manager.getHelixDataAccessor();
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
_participants[i].syncStart();
Thread.sleep(2000);
boolean result = ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient, CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
ExternalView ev = manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().externalView(TEST_DB));
System.out.println(ev.getPartitionSet().size());
if (i < 3) {
Assert.assertEquals(ev.getPartitionSet().size(), 25 * (i + 1));
} else {
Assert.assertEquals(ev.getPartitionSet().size(), 100);
}
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient, CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
}
Aggregations