NO-JIRA skeleton test for MQTT

This commit is contained in:
Justin Bertram 2023-12-05 14:30:30 -06:00
parent c3963b4284
commit afe0e889c5
No known key found for this signature in database
GPG Key ID: F41830B875BB8633
1 changed files with 22 additions and 0 deletions

View File

@ -59,6 +59,28 @@ public class MQTT5Test extends MQTT5TestSupport {
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
*/