jbertram commented on code in PR #4563:
URL: https://github.com/apache/activemq-artemis/pull/4563#discussion_r1272357028


##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt5/spec/controlpackets/PublishTests.java:
##########
@@ -1020,6 +1020,74 @@ public void messageArrived(String topic, MqttMessage 
message) throws Exception {
       consumer.disconnect();
    }
 
+   /*
+    * From section 3.3.2.3.4 of the MQTT 5 specification:
+    *
+    * A sender can modify the Topic Alias mapping by sending another PUBLISH 
in the same Network Connection with the
+    * same Topic Alias value and a different non-zero length Topic Name.
+    */
+   @Test(timeout = DEFAULT_TIMEOUT)
+   public void testModifiedTopicAlias() throws Exception {
+      final String TOPIC_1 = this.getTopicName() + "1";
+      final String TOPIC_2 = this.getTopicName() + "2";
+
+      MqttClient consumer1 = createPahoClient("consumer1");
+      CountDownLatch latch1 = new CountDownLatch(2);
+      consumer1.setCallback(new DefaultMqttCallback() {
+         @Override
+         public void messageArrived(String topic, MqttMessage message) throws 
Exception {
+            String payload = new String(message.getPayload());
+            if (payload.equals("first") || payload.equals("second")) {
+               latch1.countDown();
+            }
+         }
+      });
+      consumer1.connect();
+      consumer1.subscribe(TOPIC_1, 1);
+
+      MqttClient consumer2 = createPahoClient("consumer2");
+      CountDownLatch latch2 = new CountDownLatch(2);
+      consumer2.setCallback(new DefaultMqttCallback() {
+         @Override
+         public void messageArrived(String topic, MqttMessage message) throws 
Exception {
+            String payload = new String(message.getPayload());
+            if (payload.equals("third") || payload.equals("fourth")) {
+               latch2.countDown();
+            }
+         }
+      });
+      consumer2.connect();
+      consumer2.subscribe(TOPIC_2, 1);
+
+      MqttClient producer = createPahoClient("producer");
+      producer.connect();
+
+      MqttProperties properties = new MqttProperties();
+      properties.setTopicAlias(1);
+      MqttMessage m = new MqttMessage();
+      m.setProperties(properties);
+      m.setQos(1);
+      m.setRetained(false);
+      m.setPayload("first".getBytes(StandardCharsets.UTF_8));
+      producer.publish(TOPIC_1, m);
+      m.setPayload("second".getBytes(StandardCharsets.UTF_8));
+      producer.publish("", m);

Review Comment:
   I forgot that I had modified my local version of the Paho MQTT 5 client to 
disable topic validation. I fixed the test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to