Search in sources :

Example 6 with PublishMessage

use of io.moquette.proto.messages.PublishMessage 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 7 with PublishMessage

use of io.moquette.proto.messages.PublishMessage 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 8 with PublishMessage

use of io.moquette.proto.messages.PublishMessage 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

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