Search in sources :

Example 1 with AsyncCallback

use of org.apache.helix.messaging.AsyncCallback 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());
}
Also used : Message(org.apache.helix.model.Message) AsyncCallback(org.apache.helix.messaging.AsyncCallback) Criteria(org.apache.helix.Criteria) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 2 with AsyncCallback

use of org.apache.helix.messaging.AsyncCallback 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);
}
Also used : Message(org.apache.helix.model.Message) AsyncCallback(org.apache.helix.messaging.AsyncCallback) Criteria(org.apache.helix.Criteria) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 3 with AsyncCallback

use of org.apache.helix.messaging.AsyncCallback in project helix by apache.

the class TestMessagingService method TestControllerMessage.

@Test()
public void TestControllerMessage() 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(MessageType.CONTROLLER_MSG, 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.CONTROLLER);
    cr.setSessionSpecific(false);
    AsyncCallback callback1 = new MockAsyncCallback();
    int messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);
    AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord().getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult").indexOf(hostSrc) != -1);
    AssertJUnit.assertTrue(callback1.getMessageReplied().size() == 1);
    msgId = UUID.randomUUID().toString();
    msg.setMsgId(msgId);
    cr.setPartition("TestDB_17");
    AsyncCallback callback2 = new MockAsyncCallback();
    messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, callback2, 10000);
    AssertJUnit.assertTrue(callback2.getMessageReplied().get(0).getRecord().getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult").indexOf(hostSrc) != -1);
    AssertJUnit.assertTrue(callback2.getMessageReplied().size() == 1);
    msgId = UUID.randomUUID().toString();
    msg.setMsgId(msgId);
    cr.setPartitionState("SLAVE");
    AsyncCallback callback3 = new MockAsyncCallback();
    messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, callback3, 10000);
    AssertJUnit.assertTrue(callback3.getMessageReplied().get(0).getRecord().getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult").indexOf(hostSrc) != -1);
    AssertJUnit.assertTrue(callback3.getMessageReplied().size() == 1);
}
Also used : Message(org.apache.helix.model.Message) AsyncCallback(org.apache.helix.messaging.AsyncCallback) Criteria(org.apache.helix.Criteria) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 4 with AsyncCallback

use of org.apache.helix.messaging.AsyncCallback in project helix by apache.

the class TestMessagingService method sendSelfMsg.

@Test()
public void sendSelfMsg() {
    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);
    cr.setSelfExcluded(false);
    AsyncCallback callback1 = new MockAsyncCallback();
    int messageSent1 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);
    AssertJUnit.assertTrue(callback1.getMessageReplied().size() == NODE_NR);
    AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord().getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage").equals("TestReplyMessage"));
}
Also used : Message(org.apache.helix.model.Message) AsyncCallback(org.apache.helix.messaging.AsyncCallback) Criteria(org.apache.helix.Criteria) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

UUID (java.util.UUID)4 Criteria (org.apache.helix.Criteria)4 AsyncCallback (org.apache.helix.messaging.AsyncCallback)4 Message (org.apache.helix.model.Message)4 Test (org.testng.annotations.Test)4