use of org.apache.helix.model.Message in project helix by apache.
the class TestMessagingService method TestMessageSimpleSendReceiveAsync.
@Test()
public void TestMessageSimpleSendReceiveAsync() throws Exception {
String hostSrc = "localhost_" + START_PORT;
String hostDest = "localhost_" + (START_PORT + 1);
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
_participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageTypes(), factory);
_participants[0].getMessagingService().registerMessageHandlerFactory(factory.getMessageTypes(), factory);
String msgId = new UUID(123, 456).toString();
Message msg = new Message(factory.getMessageTypes().get(0), msgId);
msg.setMsgId(msgId);
msg.setSrcName(hostSrc);
msg.setTgtSessionId("*");
msg.setMsgState(MessageState.NEW);
String para = "Testing messaging para";
msg.getRecord().setSimpleField("TestMessagingPara", para);
Criteria cr = new Criteria();
cr.setInstanceName(hostDest);
cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
cr.setSessionSpecific(false);
TestAsyncCallback callback = new TestAsyncCallback(60000);
_participants[0].getMessagingService().send(cr, msg, callback, 60000);
Thread.sleep(2000);
// Thread.currentThread().join();
AssertJUnit.assertTrue(TestAsyncCallback._replyedMessageContents.contains("TestReplyMessage"));
AssertJUnit.assertTrue(callback.getMessageReplied().size() == 1);
TestAsyncCallback callback2 = new TestAsyncCallback(500);
_participants[0].getMessagingService().send(cr, msg, callback2, 500);
Thread.sleep(3000);
// Thread.currentThread().join();
AssertJUnit.assertTrue(callback2.isTimedOut());
cr = new Criteria();
cr.setInstanceName(hostDest);
cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
cr.setSessionSpecific(false);
cr.setDataSource(DataSource.IDEALSTATES);
callback = new TestAsyncCallback(60000);
_participants[0].getMessagingService().send(cr, msg, callback, 60000);
Thread.sleep(2000);
// Thread.currentThread().join();
AssertJUnit.assertTrue(TestAsyncCallback._replyedMessageContents.contains("TestReplyMessage"));
AssertJUnit.assertTrue(callback.getMessageReplied().size() == 1);
callback2 = new TestAsyncCallback(500);
_participants[0].getMessagingService().send(cr, msg, callback2, 500);
Thread.sleep(3000);
// Thread.currentThread().join();
AssertJUnit.assertTrue(callback2.isTimedOut());
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestMessagingService method TestBlockingSendReceive.
@Test()
public void TestBlockingSendReceive() throws Exception {
String hostSrc = "localhost_" + START_PORT;
String hostDest = "localhost_" + (START_PORT + 1);
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
_participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageTypes(), factory);
String msgId = new UUID(123, 456).toString();
Message msg = new Message(factory.getMessageTypes().get(0), msgId);
msg.setMsgId(msgId);
msg.setSrcName(hostSrc);
msg.setTgtSessionId("*");
msg.setMsgState(MessageState.NEW);
String para = "Testing messaging para";
msg.getRecord().setSimpleField("TestMessagingPara", para);
Criteria cr = new Criteria();
cr.setInstanceName(hostDest);
cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
cr.setSessionSpecific(false);
AsyncCallback asyncCallback = new MockAsyncCallback();
int messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback, 60000);
AssertJUnit.assertTrue(asyncCallback.getMessageReplied().get(0).getRecord().getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage").equals("TestReplyMessage"));
AssertJUnit.assertTrue(asyncCallback.getMessageReplied().size() == 1);
AsyncCallback asyncCallback2 = new MockAsyncCallback();
messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback2, 500);
AssertJUnit.assertTrue(asyncCallback2.isTimedOut());
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestMessagingService method TestMultiMessageCriteria.
@Test()
public void TestMultiMessageCriteria() throws Exception {
String hostSrc = "localhost_" + START_PORT;
for (int i = 0; i < NODE_NR; i++) {
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
String hostDest = "localhost_" + (START_PORT + i);
_participants[i].getMessagingService().registerMessageHandlerFactory(factory.getMessageTypes(), factory);
}
String msgId = new UUID(123, 456).toString();
Message msg = new Message(new TestMessagingHandlerFactory().getMessageTypes().get(0), msgId);
msg.setMsgId(msgId);
msg.setSrcName(hostSrc);
msg.setTgtSessionId("*");
msg.setMsgState(MessageState.NEW);
String para = "Testing messaging para";
msg.getRecord().setSimpleField("TestMessagingPara", para);
Criteria cr = new Criteria();
cr.setInstanceName("%");
cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
cr.setSessionSpecific(false);
AsyncCallback callback1 = new MockAsyncCallback();
int messageSent1 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);
AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord().getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage").equals("TestReplyMessage"));
AssertJUnit.assertTrue(callback1.getMessageReplied().size() == NODE_NR - 1);
AsyncCallback callback2 = new MockAsyncCallback();
int messageSent2 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback2, 500);
AssertJUnit.assertTrue(callback2.isTimedOut());
cr.setPartition("TestDB_17");
AsyncCallback callback3 = new MockAsyncCallback();
int messageSent3 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback3, 10000);
AssertJUnit.assertTrue(callback3.getMessageReplied().size() == _replica - 1);
cr.setPartition("TestDB_15");
AsyncCallback callback4 = new MockAsyncCallback();
int messageSent4 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback4, 10000);
AssertJUnit.assertTrue(callback4.getMessageReplied().size() == _replica);
cr.setPartitionState("SLAVE");
AsyncCallback callback5 = new MockAsyncCallback();
int messageSent5 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback5, 10000);
AssertJUnit.assertTrue(callback5.getMessageReplied().size() == _replica - 1);
cr.setDataSource(DataSource.IDEALSTATES);
AsyncCallback callback6 = new MockAsyncCallback();
int messageSent6 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback6, 10000);
AssertJUnit.assertTrue(callback6.getMessageReplied().size() == _replica - 1);
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestMessagingService method TestMessageSimpleSend.
@Test()
public void TestMessageSimpleSend() throws Exception {
String hostSrc = "localhost_" + START_PORT;
String hostDest = "localhost_" + (START_PORT + 1);
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
_participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageTypes(), factory);
String msgId = new UUID(123, 456).toString();
Message msg = new Message(factory.getMessageTypes().get(0), msgId);
msg.setMsgId(msgId);
msg.setSrcName(hostSrc);
msg.setTgtSessionId("*");
msg.setMsgState(MessageState.NEW);
String para = "Testing messaging para";
msg.getRecord().setSimpleField("TestMessagingPara", para);
Criteria cr = new Criteria();
cr.setInstanceName(hostDest);
cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
cr.setSessionSpecific(false);
// int nMsgs = _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg);
int nMsgs = _participants[0].getMessagingService().send(cr, msg);
AssertJUnit.assertTrue(nMsgs == 1);
Thread.sleep(2500);
// Thread.currentThread().join();
AssertJUnit.assertTrue(TestMessagingHandlerFactory._processedMsgIds.contains(para));
cr = new Criteria();
cr.setInstanceName(hostDest);
cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
cr.setSessionSpecific(false);
cr.setDataSource(DataSource.IDEALSTATES);
// nMsgs = _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg);
nMsgs = _participants[0].getMessagingService().send(cr, msg);
AssertJUnit.assertTrue(nMsgs == 1);
Thread.sleep(2500);
// Thread.currentThread().join();
AssertJUnit.assertTrue(TestMessagingHandlerFactory._processedMsgIds.contains(para));
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestParticipantErrorMessage method TestParticipantErrorMessageSend.
@Test()
public void TestParticipantErrorMessageSend() {
String participant1 = "localhost_" + START_PORT;
String participant2 = "localhost_" + (START_PORT + 1);
Message errorMessage1 = new Message(MessageType.PARTICIPANT_ERROR_REPORT, UUID.randomUUID().toString());
errorMessage1.setTgtSessionId("*");
errorMessage1.getRecord().setSimpleField(DefaultParticipantErrorMessageHandlerFactory.ACTIONKEY, ActionOnError.DISABLE_INSTANCE.toString());
Criteria recipientCriteria = new Criteria();
recipientCriteria.setRecipientInstanceType(InstanceType.CONTROLLER);
recipientCriteria.setSessionSpecific(false);
_participants[0].getMessagingService().send(recipientCriteria, errorMessage1);
Message errorMessage2 = new Message(MessageType.PARTICIPANT_ERROR_REPORT, UUID.randomUUID().toString());
errorMessage2.setTgtSessionId("*");
errorMessage2.setResourceName("TestDB");
errorMessage2.setPartitionName("TestDB_14");
errorMessage2.getRecord().setSimpleField(DefaultParticipantErrorMessageHandlerFactory.ACTIONKEY, ActionOnError.DISABLE_PARTITION.toString());
Criteria recipientCriteria2 = new Criteria();
recipientCriteria2.setRecipientInstanceType(InstanceType.CONTROLLER);
recipientCriteria2.setSessionSpecific(false);
_participants[1].getMessagingService().send(recipientCriteria2, errorMessage2);
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
LOG.error("Interrupted sleep", e);
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
Builder kb = _participants[1].getHelixDataAccessor().keyBuilder();
ExternalView externalView = _participants[1].getHelixDataAccessor().getProperty(kb.externalView("TestDB"));
for (String partitionName : externalView.getRecord().getMapFields().keySet()) {
for (String hostName : externalView.getRecord().getMapField(partitionName).keySet()) {
if (hostName.equals(participant1)) {
Assert.assertTrue(externalView.getRecord().getMapField(partitionName).get(hostName).equalsIgnoreCase("OFFLINE"));
}
}
}
Assert.assertTrue(externalView.getRecord().getMapField("TestDB_14").get(participant2).equalsIgnoreCase("OFFLINE"));
}
Aggregations