This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 9fe47de302 ARTEMIS-5254 pass failure properly when stopping MQTT 
session
9fe47de302 is described below

commit 9fe47de3021b729e01fafd377a751b8196fe1cf7
Author: Justin Bertram <[email protected]>
AuthorDate: Thu Mar 13 10:01:20 2025 -0500

    ARTEMIS-5254 pass failure properly when stopping MQTT session
---
 .../artemis/core/protocol/mqtt/MQTTSession.java    |  4 +-
 .../core/protocol/mqtt/MQTTSessionAccessor.java    | 23 +++++++++++
 .../artemis/tests/integration/mqtt5/MQTT5Test.java | 44 ++++++++++++++++++++++
 3 files changed, 69 insertions(+), 2 deletions(-)

diff --git 
a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSession.java
 
b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSession.java
index e91cadeec8..be40225d5d 100644
--- 
a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSession.java
+++ 
b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSession.java
@@ -122,12 +122,12 @@ public class MQTTSession {
 
          if (serverSession != null) {
             serverSession.stop();
-            serverSession.close(false);
+            serverSession.close(failure);
          }
 
          if (internalServerSession != null) {
             internalServerSession.stop();
-            internalServerSession.close(false);
+            internalServerSession.close(failure);
          }
 
          state.setAttached(false);
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionAccessor.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionAccessor.java
new file mode 100644
index 0000000000..68e7f08c71
--- /dev/null
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionAccessor.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.core.protocol.mqtt;
+
+public class MQTTSessionAccessor {
+   public static void disconnectSession(MQTTSession session, boolean failure) {
+      session.getConnectionManager().disconnect(failure);
+   }
+}
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt5/MQTT5Test.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt5/MQTT5Test.java
index 1a8fd251f1..48fdc3a1f2 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt5/MQTT5Test.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt5/MQTT5Test.java
@@ -32,8 +32,10 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.activemq.artemis.api.core.ActiveMQException;
 import org.apache.activemq.artemis.api.core.QueueConfiguration;
 import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
@@ -41,9 +43,13 @@ import 
org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl;
 import org.apache.activemq.artemis.core.paging.impl.PagingManagerImplAccessor;
 import org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl;
 import org.apache.activemq.artemis.core.postoffice.impl.PostOfficeTestAccessor;
+import org.apache.activemq.artemis.core.protocol.mqtt.MQTTProtocolManager;
 import org.apache.activemq.artemis.core.protocol.mqtt.MQTTReasonCodes;
+import org.apache.activemq.artemis.core.protocol.mqtt.MQTTSessionAccessor;
 import org.apache.activemq.artemis.core.protocol.mqtt.MQTTUtil;
 import org.apache.activemq.artemis.core.server.Queue;
+import org.apache.activemq.artemis.core.server.ServerSession;
+import 
org.apache.activemq.artemis.core.server.plugin.ActiveMQServerSessionPlugin;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
 import org.apache.activemq.artemis.utils.RandomUtil;
@@ -743,4 +749,42 @@ public class MQTT5Test extends MQTT5TestSupport {
       client.disconnect();
       client.close();
    }
+
+   @Test
+   @Timeout(DEFAULT_TIMEOUT_SEC)
+   public void testSessionDisconnectWithFailure() throws Exception {
+      testSessionDisconnect(true);
+   }
+
+   @Test
+   @Timeout(DEFAULT_TIMEOUT_SEC)
+   public void testSessionDisconnectWithoutFailure() throws Exception {
+      testSessionDisconnect(false);
+   }
+
+   private void testSessionDisconnect(boolean failure) throws Exception {
+      AtomicBoolean beforeCloseFailed = new AtomicBoolean(!failure);
+      AtomicBoolean afterCloseFailed = new AtomicBoolean(!failure);
+      server.registerBrokerPlugin(new ActiveMQServerSessionPlugin() {
+         @Override
+         public void beforeCloseSession(ServerSession session, boolean failed) 
throws ActiveMQException {
+            beforeCloseFailed.set(failed);
+         }
+
+         @Override
+         public void afterCloseSession(ServerSession session, boolean failed) 
throws ActiveMQException {
+            afterCloseFailed.set(failed);
+         }
+      });
+      MqttClient client = createPahoClient(getName());
+      client.connect();
+      MQTTProtocolManager protocolManager = getProtocolManager();
+      
MQTTSessionAccessor.disconnectSession(protocolManager.getStateManager().getSessionState(getName()).getSession(),
 failure);
+      Wait.assertEquals(failure, () -> beforeCloseFailed.get(), 2000, 50);
+      Wait.assertEquals(failure, () -> afterCloseFailed.get(), 2000, 50);
+      if (client.isConnected()) {
+         client.disconnect();
+      }
+      client.close();
+   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to