[ 
https://issues.apache.org/jira/browse/ARTEMIS-4365?focusedWorklogId=871538&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-871538
 ]

ASF GitHub Bot logged work on ARTEMIS-4365:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/Jul/23 12:31
            Start Date: 18/Jul/23 12:31
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on code in PR #4556:
URL: https://github.com/apache/activemq-artemis/pull/4556#discussion_r1266701120


##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/MQTTTest.java:
##########
@@ -2219,4 +2223,71 @@ public void testAutoDeleteRetainedQueue() throws 
Exception {
       Wait.assertTrue(() -> 
server.locateQueue(RETAINED_QUEUE).getMessageCount() == 0, 3000, 50);
       Wait.assertTrue(() -> server.locateQueue(RETAINED_QUEUE) == null, 3000, 
50);
    }
+
+   /*
+    * [MQTT-3.3.1-9] When sending a PUBLISH Packet to a Client the 
Server...MUST set the RETAIN flag to 0 when a PUBLISH
+    * Packet is sent to a Client because it matches an *established* 
subscription regardless of how the flag was set in
+    * the message it received.
+    */
+   @Test(timeout = 60 * 1000)
+   public void testRetainFlagOnEstablishedSubscription() throws Exception {
+      CountDownLatch latch = new CountDownLatch(1);
+      final String topic = RandomUtil.randomString();
+
+      MqttClient subscriber = createPaho3_1_1Client("subscriber");
+      subscriber.connect();
+      subscriber.subscribe(topic, 1);
+      subscriber.setCallback(new DefaultMqtt3Callback() {
+         @Override
+         public void messageArrived(String topic, MqttMessage message) throws 
Exception {
+            if (!message.isRetained()) {
+               latch.countDown();
+            }
+         }
+      });
+
+      MqttClient publisher = createPaho3_1_1Client("publisher");
+      publisher.connect();
+      publisher.publish(topic, "retained".getBytes(StandardCharsets.UTF_8), 1, 
true);
+      publisher.disconnect();
+      publisher.close();
+
+      assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
+
+      subscriber.disconnect();
+      subscriber.close();
+   }
+
+   /*
+    * [MQTT-3.3.1-8] When sending a PUBLISH Packet to a Client the Server MUST 
set the RETAIN flag to 1 if a message is
+    * sent as a result of a new subscription being made by a Client.
+    */
+   @Test(timeout = 60 * 1000)
+   public void testRetainFlagOnNewSubscription() throws Exception {
+      CountDownLatch latch = new CountDownLatch(1);
+      final String topic = RandomUtil.randomString();
+
+      MqttClient publisher = createPaho3_1_1Client("publisher");
+      publisher.connect();
+      publisher.publish(topic, "retained".getBytes(StandardCharsets.UTF_8), 1, 
true);
+      publisher.disconnect();
+      publisher.close();
+
+      MqttClient subscriber = createPaho3_1_1Client("subscriber");
+      subscriber.connect();
+      subscriber.subscribe(topic, 1);
+      subscriber.setCallback(new DefaultMqtt3Callback() {
+         @Override
+         public void messageArrived(String topic, MqttMessage message) throws 
Exception {
+            if (message.isRetained()) {
+               latch.countDown();
+            }
+         }
+      });
+
+      assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));

Review Comment:
   I saw this test fail here on a CI run.
   
   Adding a failure message would be good. Its annoying having to go and match 
up line numbers in remote repositories to see what the failure actually meant.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 871538)
    Time Spent: 0.5h  (was: 20m)

> MQTT retain flag not set correctly
> ----------------------------------
>
>                 Key: ARTEMIS-4365
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4365
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The {{retain}} flag set on MQTT messages dispatched to clients is incorrect 
> in certain circumstances. This is demonstrated by using the {{test}} command 
> from the [MQTT CLI tool|https://hivemq.github.io/mqtt-cli/docs/test/], e.g.:
> {noformat}
> $ mqtt test --all
> MQTT 3: OK
>     - Maximum topic length: 65535 bytes
>     - QoS 0: Received 100000/100000 publishes in 4847.01ms
>     - QoS 1: Received 100000/100000 publishes in 27413.45ms
>     - QoS 2: Received 100000/100000 publishes in 49551.40ms
>     - Retain: OK
>     - Wildcard subscriptions: OK
>     - Shared subscriptions: OK
>     - Payload size: >= 100000 bytes
>     - Maximum client id length: 65535 bytes
>     - Unsupported Ascii Chars: ALL SUPPORTED
> MQTT 5: OK
>     - Connect restrictions: 
>         > Retain: OK
>         > Wildcard subscriptions: OK
>         > Shared subscriptions: OK
>         > Subscription identifiers: OK
>         > Maximum QoS: 2
>         > Receive maximum: 65535
>         > Maximum packet size: 268435455 bytes
>         > Topic alias maximum: 65535
>         > Session expiry interval: Client-based
>         > Server keep alive: Client-based
>     - Maximum topic length: 65535 bytes
>     - QoS 0: Received 100000/100000 publishes in 706.21ms
>     - QoS 1: Received 100000/100000 publishes in 805.38ms
>     - QoS 2: Received 100000/100000 publishes in 972.98ms
>     - Retain: TIME_OUT
>     - Wildcard subscriptions: OK
>     - Shared subscriptions: OK
>     - Payload size: >= 100000 bytes
>     - Maximum client id length: 65535 bytes
>     - Unsupported Ascii Chars: ALL SUPPORTED{noformat}
> Notice the result of {{TIME_OUT}} when testing retain functionality for MQTT 
> 5.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to