Skip to content

Commit

Permalink
[Fix] separated topic in integration test that generated interference
Browse files Browse the repository at this point in the history
  • Loading branch information
andsel committed Feb 4, 2024
1 parent d4fde68 commit ada1602
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ private String createMessage(int qosPub, int qosSub) {
return "Hello world MQTT " + qosPub + " " + qosSub;
}

private String createTopic(int qosPub, int qosSub) {
return "/topic" + qosPub + qosSub;
private String createTopic(String testName, int qosPub, int qosSub) {
return "/topic/" + testName + "/" + qosPub + qosSub;
}

private void sendRetainedAndSubscribe(int qosPub, int qosSub) throws MqttException {
String topic = createTopic(qosPub, qosSub);
private void sendRetainedAndSubscribe(String testName, int qosPub, int qosSub) throws MqttException {
String topic = createTopic(testName, qosPub, qosSub);
String messageString = createMessage(qosPub, qosSub);
clientPublisher.subscribe(topic);
callbackPublisher.reinit();
Expand All @@ -140,13 +140,13 @@ private void sendRetainedAndSubscribe(int qosPub, int qosSub) throws MqttExcepti
}
}

private void unsubscribeSubscriber(int qosPub, int qosSub) throws MqttException {
String topic = createTopic(qosPub, qosSub);
private void unsubscribeSubscriber(String testName, int qosPub, int qosSub) throws MqttException {
String topic = createTopic(testName, qosPub, qosSub);
clientSubscriber.unsubscribe(topic);
}

private void sendEmptyRetainedAndSubscribe(int qosPub, int qosSub) throws MqttException {
String topic = createTopic(qosPub, qosSub);
private void sendEmptyRetainedAndSubscribe(String testName, int qosPub, int qosSub) throws MqttException {
String topic = createTopic(testName, qosPub, qosSub);
callbackPublisher.reinit();
clientPublisher.publish(topic, new byte[0], qosPub, true);
// Wait for the publish to finish
Expand Down Expand Up @@ -204,30 +204,30 @@ static Stream<Arguments> retainedProvider() {
@MethodSource("notRetainedProvider")
public void checkShouldNotRetain(int qosPub, int qosSub) throws MqttException {
LOG.info("*** checkShouldNotRetain: qosPub {}, qosSub {} ***", qosPub, qosSub);
sendRetainedAndSubscribe(qosPub, qosSub);
sendRetainedAndSubscribe("should_not_retain", qosPub, qosSub);
validateMustNotReceive(qosPub);
}

@ParameterizedTest
@MethodSource("retainedProvider")
public void checkShouldRetain(int qosPub, int qosSub) throws MqttException {
LOG.info("*** checkShouldRetain: qosPub {}, qosSub {} ***", qosPub, qosSub);
sendRetainedAndSubscribe(qosPub, qosSub);
sendRetainedAndSubscribe("should_retain", qosPub, qosSub);
validateMustReceive(qosPub, qosSub);
unsubscribeSubscriber(qosPub, qosSub);
sendEmptyRetainedAndSubscribe(qosPub, qosSub);
unsubscribeSubscriber("should_retain", qosPub, qosSub);
sendEmptyRetainedAndSubscribe("should_retain", qosPub, qosSub);
validateMustNotReceive(qosPub);
}

@Test
public void checkQos0CancelsRetain() throws MqttException {
LOG.info("*** checkQos0CancelsRetain ***");
// First send a QoS 2 retain, and check it arrives.
sendRetainedAndSubscribe(2, 2);
sendRetainedAndSubscribe("qos0_cancel_retain", 2, 2);
validateMustReceive(2, 2);
unsubscribeSubscriber(2, 2);
unsubscribeSubscriber("qos0_cancel_retain", 2, 2);
// Then send a QoS 0 retain, and check it cancels the previous retain.
sendRetainedAndSubscribe(0, 2);
sendRetainedAndSubscribe("qos0_cancel_retain", 0, 2);
validateMustNotReceive(0);
}
}

0 comments on commit ada1602

Please sign in to comment.