use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestDrop method testDropErrorPartitionAutoIS.
@Test
public void testDropErrorPartitionAutoIS() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
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()));
MockParticipantManager[] participants = new MockParticipantManager[n];
// 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();
// start participants
Map<String, Set<String>> errTransitions = new HashMap<String, Set<String>>();
errTransitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
errTransitions.put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
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(errTransitions));
} else {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
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");
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).setErrStates(errStateMap).build();
Assert.assertTrue(verifier.verify());
// drop resource containing error partitions should drop the partition successfully
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0" });
// make sure TestDB0_4 and TestDB0_8 partitions are dropped
verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(verifier.verify());
assertEmptyCSandEV(className, "TestDB0", participants);
// clean up
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.integration.manager.ClusterControllerManager in project helix by apache.
the class TestEntropyFreeNodeBounce method testBounceAll.
@Test
public void testBounceAll() throws Exception {
// pick numbers that don't divide evenly
final int NUM_PARTICIPANTS = 5;
final int NUM_PARTITIONS = 123;
final int NUM_REPLICAS = 1;
final String RESOURCE_PREFIX = "TestDB";
final String RESOURCE_NAME = RESOURCE_PREFIX + "0";
// create a cluster name based on this test name
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 FULL_AUTO mode to test node tagging
"OnlineOffline", // use FULL_AUTO mode to test node tagging
RebalanceMode.FULL_AUTO, // do rebalance
true);
// Start the participants
HelixManager[] participants = new HelixManager[NUM_PARTICIPANTS];
for (int i = 0; i < NUM_PARTICIPANTS; i++) {
final String instanceName = "localhost_" + (12918 + i);
participants[i] = createParticipant(clusterName, instanceName);
participants[i].connect();
}
// Start the controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// get an admin and accessor
HelixAdmin helixAdmin = new ZKHelixAdmin(_gZkClient);
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
// do the test
try {
Thread.sleep(1000);
// ensure that the external view coalesces
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
ExternalView stableExternalView = accessor.getProperty(keyBuilder.externalView(RESOURCE_NAME));
for (HelixManager participant : participants) {
// disable the controller, bounce the node, re-enable the controller, verify assignments
// remained the same
helixAdmin.enableCluster(clusterName, false);
participant.disconnect();
Thread.sleep(1000);
participant = createParticipant(clusterName, participant.getInstanceName());
participant.connect();
Thread.sleep(1000);
helixAdmin.enableCluster(clusterName, true);
Thread.sleep(1000);
result = ClusterStateVerifier.verifyByZkCallback(new MatchingExternalViewVerifier(stableExternalView, clusterName));
Assert.assertTrue(result);
}
} finally {
// clean up
controller.syncStop();
for (HelixManager participant : participants) {
participant.disconnect();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestErrorPartition method testErrorPartition.
@Test()
public void testErrorPartition() throws Exception {
String clusterName = getShortClassName();
MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START testErrorPartition() at " + new Date(System.currentTimeMillis()));
ZKHelixAdmin tool = new ZKHelixAdmin(_gZkClient);
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "TestDB", 1, 10, 5, 3, "MasterSlave", true);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
{
put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
}
};
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();
}
Map<String, Map<String, String>> errStates = new HashMap<String, Map<String, String>>();
errStates.put("TestDB0", new HashMap<String, String>());
errStates.get("TestDB0").put("TestDB0_4", "localhost_12918");
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
Map<String, Set<String>> errorStateMap = new HashMap<String, Set<String>>() {
{
put("TestDB0_4", TestHelper.setOf("localhost_12918"));
}
};
// verify "TestDB0_0", "localhost_12918" is in ERROR state
TestHelper.verifyState(clusterName, ZK_ADDR, errorStateMap, "ERROR");
// disable a partition on a node with error state
tool.enablePartition(false, clusterName, "localhost_12918", "TestDB0", Arrays.asList("TestDB0_4"));
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
TestHelper.verifyState(clusterName, ZK_ADDR, errorStateMap, "ERROR");
// disable a node with error state
tool.enableInstance(clusterName, "localhost_12918", false);
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
// make sure after restart stale ERROR state is gone
tool.enablePartition(true, clusterName, "localhost_12918", "TestDB0", Arrays.asList("TestDB0_4"));
tool.enableInstance(clusterName, "localhost_12918", true);
participants[0].syncStop();
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
new Thread(participants[0]).start();
result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.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 testErrorPartition() at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestBatchMessage method testBasic.
@Test
public void testBasic() 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
32, // number of nodes
n, // replicas
2, "MasterSlave", // do rebalance
true);
// enable batch message
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
idealState.setBatchMessageMode(true);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
// register a message listener so we know how many message generated
TestZkChildListener listener = new TestZkChildListener();
_gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; 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);
// Change to three is because there is an extra factory registered
// So one extra NO_OP message send
Assert.assertTrue(listener._maxNbOfChilds <= 3, "Should get no more than 2 messages (O->S and S->M)");
// clean up
// wait for all zk callbacks done
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.integration.manager.ClusterControllerManager in project helix by apache.
the class TestBatchMessage method testChangeBatchMessageMode.
// a non-batch-message run followed by a batch-message-enabled run
@Test
public void testChangeBatchMessageMode() 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
32, // number of nodes
n, // replicas
2, "MasterSlave", // do rebalance
true);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; 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);
// stop all participants
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
// enable batch message
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
idealState.setBatchMessageMode(true);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
// registry a message listener so we know how many message generated
TestZkChildListener listener = new TestZkChildListener();
_gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
// restart all participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// Change to three is because there is an extra factory registered
// So one extra NO_OP message send
Assert.assertTrue(listener._maxNbOfChilds <= 3, "Should get no more than 2 messages (O->S and S->M)");
// clean up
// wait for all zk callbacks done
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations