Search in sources :

Example 21 with Criteria

use of org.apache.helix.Criteria 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 22 with Criteria

use of org.apache.helix.Criteria 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

Criteria (org.apache.helix.Criteria)22 Message (org.apache.helix.model.Message)21 Test (org.testng.annotations.Test)15 HelixDataAccessor (org.apache.helix.HelixDataAccessor)8 HelixManager (org.apache.helix.HelixManager)8 PropertyKey (org.apache.helix.PropertyKey)8 StringWriter (java.io.StringWriter)7 ZNRecord (org.apache.helix.ZNRecord)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)7 SerializationConfig (org.codehaus.jackson.map.SerializationConfig)7 UUID (java.util.UUID)6 Builder (org.apache.helix.PropertyKey.Builder)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)4 AsyncCallback (org.apache.helix.messaging.AsyncCallback)4 TreeMap (java.util.TreeMap)2 ConstraintItem (org.apache.helix.model.ConstraintItem)2 SegmentRefreshMessage (com.linkedin.pinot.common.messages.SegmentRefreshMessage)1 ArrayList (java.util.ArrayList)1 GobblinHelixMessagingService (org.apache.gobblin.cluster.GobblinHelixMessagingService)1