Skip to content

Commit c05e794

Browse files
authored
AMQ-9854 Add wait for broker to process disconnect before publishing … (#1646)
* AMQ-9854 Add wait for broker to process disconnect before publishing messages in MQTTTest * AMQ-9854 Fix MQTTTest to check for no active durable subscribers before publishing messages after disconnect
1 parent 7b502c6 commit c05e794

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt

activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,12 @@ public void testReceiveMessageSentWhileOffline() throws Exception {
16711671
}
16721672
connectionSub.disconnect();
16731673

1674+
// Wait for broker to process disconnect before publishing messages for offline delivery.
1675+
// Check for no active durable subscribers (works for both regular and virtual topic strategies)
1676+
assertTrue("Subscription should become inactive",
1677+
Wait.waitFor(() -> brokerService.getAdminView().getDurableTopicSubscribers().length == 0,
1678+
5000, 100));
1679+
16741680
try {
16751681
for (int j = 0; j < numberOfRuns; j++) {
16761682

@@ -1690,6 +1696,11 @@ public void testReceiveMessageSentWhileOffline() throws Exception {
16901696
message.ack();
16911697
}
16921698
connectionSub.disconnect();
1699+
1700+
// Wait for broker to process disconnect before next iteration publishes
1701+
assertTrue("Subscription should become inactive",
1702+
Wait.waitFor(() -> brokerService.getAdminView().getDurableTopicSubscribers().length == 0,
1703+
5000, 100));
16931704
}
16941705
} catch (Exception exception) {
16951706
LOG.error("unexpected exception", exception);
@@ -1722,6 +1733,12 @@ public void testReceiveMessageSentWhileOfflineAndBrokerRestart() throws Exceptio
17221733
connectionSub.disconnect();
17231734
}
17241735

1736+
// Wait for broker to process disconnect before publishing messages for offline delivery.
1737+
// Check for no active durable subscribers (works for both regular and virtual topic strategies)
1738+
assertTrue("Subscription should become inactive",
1739+
Wait.waitFor(() -> brokerService.getAdminView().getDurableTopicSubscribers().length == 0,
1740+
5000, 100));
1741+
17251742
MQTT mqttPubLoop = createMQTTConnection("MQTT-Pub-Client", true);
17261743
BlockingConnection connectionPub = mqttPubLoop.blockingConnection();
17271744
connectionPub.connect();

0 commit comments

Comments
 (0)