use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestBatchMessage method testParticipantIncompatibleWithBatchMsg.
@Test
public void testParticipantIncompatibleWithBatchMsg() 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
// --addResourceProperty <clusterName resourceName propertyName propertyValue>
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--addResourceProperty", clusterName, "TestDB0", HelixPropertyAttribute.BATCH_MESSAGE_MODE.toString(), "true" });
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
// 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();
// pause controller
// --enableCluster <clusterName true/false>
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--enableCluster", clusterName, "false" });
// 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();
}
// change localhost_12918 version to 0.5, so batch-message-mode will be ignored
LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance("localhost_12918"));
liveInstance.setHelixVersion("0.5");
accessor.setProperty(keyBuilder.liveInstance("localhost_12918"), liveInstance);
// resume controller
// --enableCluster <clusterName true/false>
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--enableCluster", clusterName, "true" });
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
Assert.assertTrue(listener._maxNbOfChilds > 16, "Should see more than 16 messages at the same time (32 O->S and 32 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.MockParticipantManager in project helix by apache.
the class TestBatchMessage method testSubMsgExecutionFail.
@Test
public void testSubMsgExecutionFail() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 5;
MockParticipantManager[] participants = new MockParticipantManager[n];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// resource#
TestHelper.setupCluster(// resource#
clusterName, // resource#
ZK_ADDR, // resource#
12918, // resource#
"localhost", // resource#
"TestDB", // resource#
1, // partition#
6, // nodes#
n, // replicas#
3, "MasterSlave", true);
// enable batch message
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
idealState.setBatchMessageMode(true);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
// get MASTER for errPartition
String errPartition = "TestDB0_0";
String masterOfPartition0 = null;
for (Map.Entry<String, String> entry : idealState.getInstanceStateMap(errPartition).entrySet()) {
if (entry.getValue().equals("MASTER")) {
masterOfPartition0 = entry.getKey();
break;
}
}
Assert.assertNotNull(masterOfPartition0);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
controller.syncStart();
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (instanceName.equals(masterOfPartition0)) {
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>();
errPartitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_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();
}
Map<String, Map<String, String>> errStates = new HashMap<String, Map<String, String>>();
errStates.put("TestDB0", new HashMap<String, String>());
errStates.get("TestDB0").put(errPartition, masterOfPartition0);
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates));
Assert.assertTrue(result);
Map<String, Set<String>> errorStateMap = new HashMap<String, Set<String>>();
errorStateMap.put(errPartition, TestHelper.setOf(masterOfPartition0));
// verify "TestDB0_0", masterOfPartition0 is in ERROR state
TestHelper.verifyState(clusterName, ZK_ADDR, errorStateMap, "ERROR");
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 TestBatchMessageWrapper method testBasic.
@Test
public void testBasic() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 2;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// startPort
TestHelper.setupCluster(// startPort
clusterName, // startPort
ZK_ADDR, // startPort
12918, // participantNamePrefix
"localhost", // resourceNamePrefix
"TestDB", // resourceNb
1, // partitionNb
2, // nodesNb
n, // replica
2, "MasterSlave", 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);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
MockParticipantManager[] participants = new MockParticipantManager[n];
TestMockMSModelFactory[] ftys = new TestMockMSModelFactory[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
ftys[i] = new TestMockMSModelFactory();
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", ftys[i]);
participants[i].syncStart();
// wait for each participant to complete state transitions, so we have deterministic results
HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Thread.sleep(100);
Assert.assertTrue(_clusterVerifier.verify(), "participant: " + instanceName + " fails to complete all transitions");
}
// check batch-msg-wrapper counts
MockBatchMsgWrapper wrapper = (MockBatchMsgWrapper) ftys[0].getBatchMessageWrapper("TestDB0");
// System.out.println("startCount: " + wrapper._startCount);
Assert.assertEquals(wrapper._startCount, 3, "Expect 3 batch.start: O->S, S->M, and M->S for 1st participant");
// System.out.println("endCount: " + wrapper._endCount);
Assert.assertEquals(wrapper._endCount, 3, "Expect 3 batch.end: O->S, S->M, and M->S for 1st participant");
wrapper = (MockBatchMsgWrapper) ftys[1].getBatchMessageWrapper("TestDB0");
// System.out.println("startCount: " + wrapper._startCount);
Assert.assertEquals(wrapper._startCount, 2, "Expect 2 batch.start: O->S and S->M for 2nd participant");
// System.out.println("endCount: " + wrapper._endCount);
Assert.assertEquals(wrapper._startCount, 2, "Expect 2 batch.end: O->S and S->M for 2nd participant");
// 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.MockParticipantManager in project helix by apache.
the class TestMessageThrottle method testMessageThrottle.
@Test()
public void testMessageThrottle() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String clusterName = getShortClassName();
MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant start
TestHelper.setupCluster(// participant start
clusterName, // participant start
ZK_ADDR, // participant start
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);
// setup message constraint
// "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=.*,CONSTRAINT_VALUE=1";
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
ConstraintItemBuilder builder = new ConstraintItemBuilder();
builder.addConstraintAttribute("MESSAGE_TYPE", "STATE_TRANSITION").addConstraintAttribute("INSTANCE", ".*").addConstraintAttribute("CONSTRAINT_VALUE", "1");
// Map<String, String> constraints = new TreeMap<String, String>();
// constraints.put("MESSAGE_TYPE", "STATE_TRANSITION");
// // constraints.put("TRANSITION", "OFFLINE-SLAVE");
// constraints.put("CONSTRAINT_VALUE", "1");
// constraints.put("INSTANCE", ".*");
admin.setConstraint(clusterName, ConstraintType.MESSAGE_CONSTRAINT, "constraint1", builder.build());
final ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
// make sure we never see more than 1 state transition message for each participant
final AtomicBoolean success = new AtomicBoolean(true);
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
String msgPath = PropertyPathBuilder.instanceMessage(clusterName, instanceName);
_gZkClient.subscribeChildChanges(msgPath, new IZkChildListener() {
@Override
public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
if (currentChilds != null && currentChilds.size() > 1) {
List<ZNRecord> records = accessor.getBaseDataAccessor().getChildren(parentPath, null, 0);
int transitionMsgCount = 0;
for (ZNRecord record : records) {
Message msg = new Message(record);
if (msg.getMsgType().equals(Message.MessageType.STATE_TRANSITION.name())) {
transitionMsgCount++;
}
}
if (transitionMsgCount > 1) {
success.set(false);
Assert.fail("Should not see more than 1 message");
}
}
}
});
}
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 MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
Assert.assertTrue(success.get());
// 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 TestParticipantNameCollision method testParticiptantNameCollision.
@Test()
public void testParticiptantNameCollision() throws Exception {
logger.info("RUN TestParticipantNameCollision() at " + new Date(System.currentTimeMillis()));
MockParticipantManager newParticipant = null;
for (int i = 0; i < 1; i++) {
String instanceName = "localhost_" + (START_PORT + i);
try {
// the call fails on getClusterManagerForParticipant()
// no threads start
newParticipant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
newParticipant.syncStart();
} catch (Exception e) {
e.printStackTrace();
}
}
Thread.sleep(30000);
TestHelper.verifyWithTimeout("verifyNotConnected", 30 * 1000, newParticipant);
logger.info("STOP TestParticipantNameCollision() at " + new Date(System.currentTimeMillis()));
}
Aggregations