Search in sources :

Example 1 with PublishMessage

use of io.moquette.proto.messages.PublishMessage in project nifi by apache.

the class TestConsumeMqttCommon method testQoS1NotCleanSession.

@Test
public void testQoS1NotCleanSession() throws Exception {
    testRunner.setProperty(ConsumeMQTT.PROP_QOS, "1");
    testRunner.setProperty(ConsumeMQTT.PROP_CLEAN_SESSION, ALLOWABLE_VALUE_CLEAN_SESSION_FALSE);
    testRunner.assertValid();
    ConsumeMQTT consumeMQTT = (ConsumeMQTT) testRunner.getProcessor();
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    assertTrue(isConnected(consumeMQTT));
    consumeMQTT.onUnscheduled(testRunner.getProcessContext());
    PublishMessage testMessage = new PublishMessage();
    testMessage.setPayload(ByteBuffer.wrap("testMessage".getBytes()));
    testMessage.setTopicName("testTopic");
    testMessage.setDupFlag(false);
    testMessage.setQos(AbstractMessage.QOSType.LEAST_ONE);
    testMessage.setRetainFlag(false);
    internalPublish(testMessage);
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    assertTrue(isConnected(consumeMQTT));
    testRunner.run(1, false, false);
    testRunner.assertTransferCount(ConsumeMQTT.REL_MESSAGE, 1);
    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(ConsumeMQTT.REL_MESSAGE);
    assertTrue(flowFiles.size() > 0);
    assertProvenanceEvents(flowFiles.size());
    MockFlowFile flowFile = flowFiles.get(0);
    flowFile.assertContentEquals("testMessage");
    flowFile.assertAttributeEquals(BROKER_ATTRIBUTE_KEY, broker);
    flowFile.assertAttributeEquals(TOPIC_ATTRIBUTE_KEY, "testTopic");
    flowFile.assertAttributeEquals(QOS_ATTRIBUTE_KEY, "1");
    flowFile.assertAttributeEquals(IS_DUPLICATE_ATTRIBUTE_KEY, "false");
    flowFile.assertAttributeEquals(IS_RETAINED_ATTRIBUTE_KEY, "false");
}
Also used : PublishMessage(io.moquette.proto.messages.PublishMessage) MockFlowFile(org.apache.nifi.util.MockFlowFile) ConsumeMQTT(org.apache.nifi.processors.mqtt.ConsumeMQTT) Test(org.junit.Test)

Example 2 with PublishMessage

use of io.moquette.proto.messages.PublishMessage in project nifi by apache.

the class TestConsumeMqttCommon method testQoS2.

@Test
public void testQoS2() throws Exception {
    testRunner.setProperty(ConsumeMQTT.PROP_QOS, "2");
    testRunner.assertValid();
    ConsumeMQTT consumeMQTT = (ConsumeMQTT) testRunner.getProcessor();
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    assertTrue(isConnected(consumeMQTT));
    PublishMessage testMessage = new PublishMessage();
    testMessage.setPayload(ByteBuffer.wrap("testMessage".getBytes()));
    testMessage.setTopicName("testTopic");
    testMessage.setDupFlag(false);
    testMessage.setQos(AbstractMessage.QOSType.EXACTLY_ONCE);
    testMessage.setRetainFlag(false);
    internalPublish(testMessage);
    Thread.sleep(PUBLISH_WAIT_MS);
    testRunner.run(1, false, false);
    testRunner.assertTransferCount(ConsumeMQTT.REL_MESSAGE, 1);
    assertProvenanceEvents(1);
    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(ConsumeMQTT.REL_MESSAGE);
    MockFlowFile flowFile = flowFiles.get(0);
    flowFile.assertContentEquals("testMessage");
    flowFile.assertAttributeEquals(BROKER_ATTRIBUTE_KEY, broker);
    flowFile.assertAttributeEquals(TOPIC_ATTRIBUTE_KEY, "testTopic");
    flowFile.assertAttributeEquals(QOS_ATTRIBUTE_KEY, "2");
    flowFile.assertAttributeEquals(IS_DUPLICATE_ATTRIBUTE_KEY, "false");
    flowFile.assertAttributeEquals(IS_RETAINED_ATTRIBUTE_KEY, "false");
}
Also used : PublishMessage(io.moquette.proto.messages.PublishMessage) MockFlowFile(org.apache.nifi.util.MockFlowFile) ConsumeMQTT(org.apache.nifi.processors.mqtt.ConsumeMQTT) Test(org.junit.Test)

Example 3 with PublishMessage

use of io.moquette.proto.messages.PublishMessage in project nifi by apache.

the class TestConsumeMqttCommon method testQoS1.

@Test
public void testQoS1() throws Exception {
    testRunner.setProperty(ConsumeMQTT.PROP_QOS, "1");
    testRunner.assertValid();
    ConsumeMQTT consumeMQTT = (ConsumeMQTT) testRunner.getProcessor();
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    assertTrue(isConnected(consumeMQTT));
    PublishMessage testMessage = new PublishMessage();
    testMessage.setPayload(ByteBuffer.wrap("testMessage".getBytes()));
    testMessage.setTopicName("testTopic");
    testMessage.setDupFlag(false);
    testMessage.setQos(AbstractMessage.QOSType.LEAST_ONE);
    testMessage.setRetainFlag(false);
    internalPublish(testMessage);
    Thread.sleep(PUBLISH_WAIT_MS);
    testRunner.run(1, false, false);
    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(ConsumeMQTT.REL_MESSAGE);
    assertTrue(flowFiles.size() > 0);
    assertProvenanceEvents(flowFiles.size());
    MockFlowFile flowFile = flowFiles.get(0);
    flowFile.assertContentEquals("testMessage");
    flowFile.assertAttributeEquals(BROKER_ATTRIBUTE_KEY, broker);
    flowFile.assertAttributeEquals(TOPIC_ATTRIBUTE_KEY, "testTopic");
    flowFile.assertAttributeEquals(QOS_ATTRIBUTE_KEY, "1");
    flowFile.assertAttributeEquals(IS_DUPLICATE_ATTRIBUTE_KEY, "false");
    flowFile.assertAttributeEquals(IS_RETAINED_ATTRIBUTE_KEY, "false");
}
Also used : PublishMessage(io.moquette.proto.messages.PublishMessage) MockFlowFile(org.apache.nifi.util.MockFlowFile) ConsumeMQTT(org.apache.nifi.processors.mqtt.ConsumeMQTT) Test(org.junit.Test)

Example 4 with PublishMessage

use of io.moquette.proto.messages.PublishMessage in project nifi by apache.

the class TestConsumeMqttCommon method testQoS0.

@Test
public void testQoS0() throws Exception {
    testRunner.setProperty(ConsumeMQTT.PROP_QOS, "0");
    testRunner.assertValid();
    ConsumeMQTT consumeMQTT = (ConsumeMQTT) testRunner.getProcessor();
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    assertTrue(isConnected(consumeMQTT));
    PublishMessage testMessage = new PublishMessage();
    testMessage.setPayload(ByteBuffer.wrap("testMessage".getBytes()));
    testMessage.setTopicName("testTopic");
    testMessage.setDupFlag(false);
    testMessage.setQos(AbstractMessage.QOSType.MOST_ONE);
    testMessage.setRetainFlag(false);
    internalPublish(testMessage);
    Thread.sleep(PUBLISH_WAIT_MS);
    testRunner.run(1, false, false);
    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(ConsumeMQTT.REL_MESSAGE);
    assertTrue(flowFiles.size() < 2);
    assertProvenanceEvents(flowFiles.size());
    if (flowFiles.size() == 1) {
        MockFlowFile flowFile = flowFiles.get(0);
        flowFile.assertContentEquals("testMessage");
        flowFile.assertAttributeEquals(BROKER_ATTRIBUTE_KEY, broker);
        flowFile.assertAttributeEquals(TOPIC_ATTRIBUTE_KEY, "testTopic");
        flowFile.assertAttributeEquals(QOS_ATTRIBUTE_KEY, "0");
        flowFile.assertAttributeEquals(IS_DUPLICATE_ATTRIBUTE_KEY, "false");
        flowFile.assertAttributeEquals(IS_RETAINED_ATTRIBUTE_KEY, "false");
    }
}
Also used : PublishMessage(io.moquette.proto.messages.PublishMessage) MockFlowFile(org.apache.nifi.util.MockFlowFile) ConsumeMQTT(org.apache.nifi.processors.mqtt.ConsumeMQTT) Test(org.junit.Test)

Example 5 with PublishMessage

use of io.moquette.proto.messages.PublishMessage in project nifi by apache.

the class TestConsumeMqttCommon method testQoS2NotCleanSession.

@Test
public void testQoS2NotCleanSession() throws Exception {
    testRunner.setProperty(ConsumeMQTT.PROP_QOS, "2");
    testRunner.setProperty(ConsumeMQTT.PROP_CLEAN_SESSION, ALLOWABLE_VALUE_CLEAN_SESSION_FALSE);
    testRunner.assertValid();
    ConsumeMQTT consumeMQTT = (ConsumeMQTT) testRunner.getProcessor();
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    assertTrue(isConnected(consumeMQTT));
    consumeMQTT.onUnscheduled(testRunner.getProcessContext());
    PublishMessage testMessage = new PublishMessage();
    testMessage.setPayload(ByteBuffer.wrap("testMessage".getBytes()));
    testMessage.setTopicName("testTopic");
    testMessage.setDupFlag(false);
    testMessage.setQos(AbstractMessage.QOSType.EXACTLY_ONCE);
    testMessage.setRetainFlag(false);
    internalPublish(testMessage);
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    assertTrue(isConnected(consumeMQTT));
    testRunner.run(1, false, false);
    testRunner.assertTransferCount(ConsumeMQTT.REL_MESSAGE, 1);
    assertProvenanceEvents(1);
    List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(ConsumeMQTT.REL_MESSAGE);
    MockFlowFile flowFile = flowFiles.get(0);
    flowFile.assertContentEquals("testMessage");
    flowFile.assertAttributeEquals(BROKER_ATTRIBUTE_KEY, broker);
    flowFile.assertAttributeEquals(TOPIC_ATTRIBUTE_KEY, "testTopic");
    flowFile.assertAttributeEquals(QOS_ATTRIBUTE_KEY, "2");
    flowFile.assertAttributeEquals(IS_DUPLICATE_ATTRIBUTE_KEY, "false");
    flowFile.assertAttributeEquals(IS_RETAINED_ATTRIBUTE_KEY, "false");
}
Also used : PublishMessage(io.moquette.proto.messages.PublishMessage) MockFlowFile(org.apache.nifi.util.MockFlowFile) ConsumeMQTT(org.apache.nifi.processors.mqtt.ConsumeMQTT) Test(org.junit.Test)

Aggregations

PublishMessage (io.moquette.proto.messages.PublishMessage)8 ConsumeMQTT (org.apache.nifi.processors.mqtt.ConsumeMQTT)8 MockFlowFile (org.apache.nifi.util.MockFlowFile)8 Test (org.junit.Test)8