Search in sources :

Example 6 with ConsumeMQTT

use of org.apache.nifi.processors.mqtt.ConsumeMQTT 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 7 with ConsumeMQTT

use of org.apache.nifi.processors.mqtt.ConsumeMQTT 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)

Example 8 with ConsumeMQTT

use of org.apache.nifi.processors.mqtt.ConsumeMQTT in project nifi by apache.

the class TestConsumeMqttCommon method testResizeBuffer.

@Test
public void testResizeBuffer() throws Exception {
    testRunner.setProperty(ConsumeMQTT.PROP_QOS, "2");
    testRunner.setProperty(ConsumeMQTT.PROP_MAX_QUEUE_SIZE, "2");
    testRunner.assertValid();
    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);
    ConsumeMQTT consumeMQTT = (ConsumeMQTT) testRunner.getProcessor();
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    assertTrue(isConnected(consumeMQTT));
    internalPublish(testMessage);
    internalPublish(testMessage);
    Thread.sleep(PUBLISH_WAIT_MS);
    consumeMQTT.onUnscheduled(testRunner.getProcessContext());
    testRunner.setProperty(ConsumeMQTT.PROP_MAX_QUEUE_SIZE, "1");
    testRunner.assertNotValid();
    testRunner.setProperty(ConsumeMQTT.PROP_MAX_QUEUE_SIZE, "3");
    testRunner.assertValid();
    testRunner.run(1);
    testRunner.assertTransferCount(ConsumeMQTT.REL_MESSAGE, 2);
    assertProvenanceEvents(2);
    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 9 with ConsumeMQTT

use of org.apache.nifi.processors.mqtt.ConsumeMQTT in project nifi by apache.

the class TestConsumeMQTT method testRetainedQoS2.

@Test
public void testRetainedQoS2() throws Exception {
    testRunner.setProperty(ConsumeMQTT.PROP_QOS, "2");
    testRunner.assertValid();
    PublishMessage testMessage = new PublishMessage();
    testMessage.setPayload(ByteBuffer.wrap("testMessage".getBytes()));
    testMessage.setTopicName("testTopic");
    testMessage.setDupFlag(false);
    testMessage.setQos(AbstractMessage.QOSType.EXACTLY_ONCE);
    testMessage.setRetainFlag(true);
    internalPublish(testMessage);
    ConsumeMQTT consumeMQTT = (ConsumeMQTT) testRunner.getProcessor();
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    testRunner.run(1, false, false);
    testRunner.assertTransferCount(ConsumeMQTT.REL_MESSAGE, 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, "true");
}
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 10 with ConsumeMQTT

use of org.apache.nifi.processors.mqtt.ConsumeMQTT in project nifi by apache.

the class TestConsumeMqttSSL method testRetainedQoS2.

@Test
public void testRetainedQoS2() throws Exception {
    testRunner.setProperty(ConsumeMQTT.PROP_QOS, "2");
    testRunner.assertValid();
    PublishMessage testMessage = new PublishMessage();
    testMessage.setPayload(ByteBuffer.wrap("testMessage".getBytes()));
    testMessage.setTopicName("testTopic");
    testMessage.setDupFlag(false);
    testMessage.setQos(AbstractMessage.QOSType.EXACTLY_ONCE);
    testMessage.setRetainFlag(true);
    internalPublish(testMessage);
    ConsumeMQTT consumeMQTT = (ConsumeMQTT) testRunner.getProcessor();
    consumeMQTT.onScheduled(testRunner.getProcessContext());
    reconnect(consumeMQTT);
    Thread.sleep(PUBLISH_WAIT_MS);
    testRunner.run(1, false, false);
    testRunner.assertTransferCount(ConsumeMQTT.REL_MESSAGE, 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, "true");
}
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

ConsumeMQTT (org.apache.nifi.processors.mqtt.ConsumeMQTT)10 MockFlowFile (org.apache.nifi.util.MockFlowFile)9 Test (org.junit.Test)9 PublishMessage (io.moquette.proto.messages.PublishMessage)8 Field (java.lang.reflect.Field)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)1