Skip to content

Commit

Permalink
NO-JIRA skeleton test for MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram committed Dec 5, 2023
1 parent c3963b4 commit afe0e88
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ public MQTT5Test(String protocol) {
super(protocol);
}

@Test(timeout = DEFAULT_TIMEOUT)
public void testSimpleSendReceive() throws Exception {
String topic = RandomUtil.randomString();

CountDownLatch latch = new CountDownLatch(1);
MqttClient subscriber = createPahoClient("subscriber");
subscriber.connect();
subscriber.setCallback(new DefaultMqttCallback() {
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
log.info("Message received from {}", topic);
latch.countDown();
}
});
subscriber.subscribe(topic, AT_LEAST_ONCE);

MqttClient producer = createPahoClient("producer");
producer.connect();
producer.publish(topic, "myMessage".getBytes(StandardCharsets.UTF_8), 1, false);
assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
}

/*
* Ensure that the broker adds a timestamp on the message when sending via MQTT
*/
Expand Down

0 comments on commit afe0e88

Please sign in to comment.