Search in sources :

Example 6 with Criteria

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

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

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

Example 9 with Criteria

use of org.apache.helix.Criteria 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"));
}
Also used : ExternalView(org.apache.helix.model.ExternalView) Message(org.apache.helix.model.Message) Builder(org.apache.helix.PropertyKey.Builder) Criteria(org.apache.helix.Criteria) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Test(org.testng.annotations.Test)

Example 10 with Criteria

use of org.apache.helix.Criteria in project helix by apache.

the class TestSchedulerMessage method testSchedulerZeroMsg.

@Test
public void testSchedulerZeroMsg() throws Exception {
    _factory._results.clear();
    HelixManager manager = null;
    for (int i = 0; i < NODE_NR; i++) {
        _participants[i].getMessagingService().registerMessageHandlerFactory(_factory.getMessageTypes(), _factory);
        // _startCMResultMap.get(hostDest)._manager;
        manager = _participants[i];
    }
    Message schedulerMessage = new Message(MessageType.SCHEDULER_MSG + "", UUID.randomUUID().toString());
    schedulerMessage.setTgtSessionId("*");
    schedulerMessage.setTgtName("CONTROLLER");
    // TODO: change it to "ADMIN" ?
    schedulerMessage.setSrcName("CONTROLLER");
    // Template for the individual message sent to each participant
    Message msg = new Message(_factory.getMessageTypes().get(0), "Template");
    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    // Criteria to send individual messages
    Criteria cr = new Criteria();
    cr.setInstanceName("localhost_DOESNOTEXIST");
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setResource("%");
    cr.setPartition("%");
    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, cr);
    String crString = sw.toString();
    schedulerMessage.getRecord().setSimpleField("Criteria", crString);
    schedulerMessage.getRecord().setMapField("MessageTemplate", msg.getRecord().getSimpleFields());
    schedulerMessage.getRecord().setSimpleField("TIMEOUT", "-1");
    HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
    Builder keyBuilder = helixDataAccessor.keyBuilder();
    PropertyKey controllerMessageKey = keyBuilder.controllerMessage(schedulerMessage.getMsgId());
    helixDataAccessor.setProperty(controllerMessageKey, schedulerMessage);
    Thread.sleep(3000);
    Assert.assertEquals(0, _factory._results.size());
    PropertyKey controllerTaskStatus = keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.name(), schedulerMessage.getMsgId());
    for (int i = 0; i < 10; i++) {
        StatusUpdate update = helixDataAccessor.getProperty(controllerTaskStatus);
        if (update == null || update.getRecord().getMapField("SentMessageCount") == null) {
            Thread.sleep(1000);
        }
    }
    ZNRecord statusUpdate = helixDataAccessor.getProperty(controllerTaskStatus).getRecord();
    Assert.assertTrue(statusUpdate.getMapField("SentMessageCount").get("MessageCount").equals("0"));
    int count = 0;
    for (Set<String> val : _factory._results.values()) {
        count += val.size();
    }
    Assert.assertEquals(count, 0);
}
Also used : HelixManager(org.apache.helix.HelixManager) Message(org.apache.helix.model.Message) SerializationConfig(org.codehaus.jackson.map.SerializationConfig) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) Criteria(org.apache.helix.Criteria) StatusUpdate(org.apache.helix.model.StatusUpdate) HelixDataAccessor(org.apache.helix.HelixDataAccessor) StringWriter(java.io.StringWriter) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) PropertyKey(org.apache.helix.PropertyKey) ZNRecord(org.apache.helix.ZNRecord) 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