use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestInvalidResourceRebalance method testResourceRebalanceSkipped.
/**
* Ensure that the Helix controller doesn't attempt to rebalance resources with invalid ideal
* states
*/
@Test
public void testResourceRebalanceSkipped() throws Exception {
final int NUM_PARTICIPANTS = 2;
final int NUM_PARTITIONS = 4;
final int NUM_REPLICAS = 2;
final String RESOURCE_NAME = "TestDB0";
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// 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, // use SEMI_AUTO mode
"MasterSlave", // use SEMI_AUTO mode
RebalanceMode.SEMI_AUTO, // do rebalance
true);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// add the ideal state spec (prevents non-CUSTOMIZED MasterSlave ideal states)
HelixAdmin helixAdmin = controller.getClusterManagmentTool();
Map<String, String> properties = Maps.newHashMap();
properties.put("IdealStateRule!sampleRuleName", "IDEAL_STATE_MODE=CUSTOMIZED,STATE_MODEL_DEF_REF=MasterSlave");
helixAdmin.setConfig(new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build(), properties);
// 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();
}
Thread.sleep(1000);
boolean result = ClusterStateVerifier.verifyByZkCallback(new EmptyZkVerifier(clusterName, RESOURCE_NAME));
Assert.assertTrue(result, "External view and current state must be empty");
// cleanup
for (int i = 0; i < NUM_PARTICIPANTS; i++) {
participants[i].syncStop();
}
controller.syncStop();
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestNullReplica method testNullReplica.
@Test
public void testNullReplica() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[5];
// 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, "MasterSlave", // do rebalance
true);
// set replica in ideal state to null
String idealStatePath = PropertyPathBuilder.idealState(clusterName, "TestDB0");
ZNRecord idealState = _gZkClient.readData(idealStatePath);
idealState.getSimpleFields().remove(IdealState.IdealStateProperty.REPLICAS.toString());
_gZkClient.writeData(idealStatePath, idealState);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
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 TestPartitionMovementThrottle method beforeClass.
@Override
@BeforeClass
public void beforeClass() throws Exception {
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);
for (int i = 0; i < NODE_NR; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
// add 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.setTransition(new DelayedTransition());
_participants[i] = participant;
}
_configAccessor = new ConfigAccessor(_gZkClient);
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
setupThrottleConfig();
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestPartitionMovementThrottle method cleanupTest.
@AfterMethod
public void cleanupTest() throws InterruptedException {
for (String db : _dbs) {
_setupTool.dropResourceFromCluster(CLUSTER_NAME, db);
Thread.sleep(20);
}
_dbs.clear();
Thread.sleep(50);
for (int i = 0; i < _participants.length; i++) {
if (_participants[i].isConnected()) {
_participants[i].syncStop();
}
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _participants[i].getInstanceName());
}
DelayedTransition.clearThrottleRecord();
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestPauseSignal method testPauseSignal.
@Test()
public void testPauseSignal() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
final String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[5];
// 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, "MasterSlave", // do rebalance
true);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
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);
// pause the cluster and make sure pause is persistent
ZkClient zkClient = new ZkClient(ZK_ADDR);
zkClient.setZkSerializer(new ZNRecordSerializer());
final HelixDataAccessor tmpAccessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
String cmd = "-zkSvr " + ZK_ADDR + " -enableCluster " + clusterName + " false";
ClusterSetup.processCommandLineArgs(cmd.split(" "));
tmpAccessor.setProperty(tmpAccessor.keyBuilder().pause(), new PauseSignal("pause"));
zkClient.close();
// wait for controller to be signaled by pause
Thread.sleep(1000);
// add a new resource group
ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
setupTool.addResourceToCluster(clusterName, "TestDB1", 10, "MasterSlave");
setupTool.rebalanceStorageCluster(clusterName, "TestDB1", 3);
// make sure TestDB1 external view is empty
TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView", 1000, clusterName, "TestDB1", TestHelper.<String>setOf("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921", "localhost_12922"), ZK_ADDR);
// resume controller
final HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
cmd = "-zkSvr " + ZK_ADDR + " -enableCluster " + clusterName + " true";
ClusterSetup.processCommandLineArgs(cmd.split(" "));
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()));
}
Aggregations