You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@artemis.apache.org by jb...@apache.org on 2026/06/24 13:36:46 UTC

(artemis) branch main updated: ARTEMIS-6008 Prevent CriticalAnalyzer from killing the broker while failing over

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 6d91acda3c ARTEMIS-6008 Prevent CriticalAnalyzer from killing the broker while failing over
6d91acda3c is described below

commit 6d91acda3c72639abd08567e1b470c4ef4ab7004
Author: Simas Joneliunas <ba...@gmail.com>
AuthorDate: Wed Jun 24 21:36:41 2026 +0800

    ARTEMIS-6008 Prevent CriticalAnalyzer from killing the broker while failing over
---
 .../core/server/impl/ActiveMQServerImpl.java       |  6 ++--
 .../server/impl/ActiveMQServerStartupTest.java     | 33 ++++++++++++++++++----
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
index e0d8055f95..3f73c63d06 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
@@ -884,7 +884,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
       final CriticalAnalyzerPolicy criticalAnalyzerPolicy = configuration.getCriticalAnalyzerPolicy();
       CriticalAction criticalAction = switch (criticalAnalyzerPolicy) {
          case HALT -> criticalComponent -> {
-            if (ActiveMQServerImpl.this.state == SERVER_STATE.STARTING) {
+            if (!isActive()) {
                takingLongToStart(criticalComponent);
             } else {
                checkCriticalAnalyzerLogging();
@@ -897,7 +897,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
             }
          };
          case SHUTDOWN -> criticalComponent -> {
-            if (ActiveMQServerImpl.this.state == SERVER_STATE.STARTING) {
+            if (!isActive()) {
                takingLongToStart(criticalComponent);
             } else {
                checkCriticalAnalyzerLogging();
@@ -922,7 +922,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
             }
          };
          case LOG -> criticalComponent -> {
-            if (ActiveMQServerImpl.this.state == SERVER_STATE.STARTING) {
+            if (!isActive()) {
                takingLongToStart(criticalComponent);
             } else {
                checkCriticalAnalyzerLogging();
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerStartupTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerStartupTest.java
index 1960242ce0..c77642c406 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerStartupTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerStartupTest.java
@@ -16,18 +16,22 @@
  */
 package org.apache.activemq.artemis.core.server.impl;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
-import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.ActivateCallback;
 import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
 import org.apache.activemq.artemis.tests.util.ServerTestBase;
+import org.apache.activemq.artemis.utils.Wait;
 import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerAccessor;
 import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy;
 import org.apache.activemq.artemis.utils.critical.CriticalComponentImpl;
 import org.junit.jupiter.api.Test;
 
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+
 public class ActiveMQServerStartupTest extends ServerTestBase {
 
    @Test
@@ -55,12 +59,29 @@ public class ActiveMQServerStartupTest extends ServerTestBase {
          configuration.setPersistenceEnabled(false);
          ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);
          addServer(server);
-         server.start();
-         // this will be faking a condition
-         server.setState(ActiveMQServer.SERVER_STATE.STARTING);
+         CountDownLatch latch = new CountDownLatch(1);
+         server.registerActivateCallback(new ActivateCallback() {
+            @Override
+            public void preActivate() {
+               try {
+                  latch.await();
+               } catch (InterruptedException e) {
+                  throw new RuntimeException(e);
+               }
+            }
+         });
+         CompletableFuture.runAsync(() -> {
+            try {
+               server.start();
+            } catch (Exception e) {
+               e.printStackTrace();
+            }
+         });
+         Wait.waitFor(() -> server.getCriticalAnalyzer() != null);
          CriticalAnalyzerAccessor.fireActions(server.getCriticalAnalyzer(), new CriticalComponentImpl(server.getCriticalAnalyzer(), 2));
          assertTrue(loggerHandler.findText("AMQ224116"));
-         assertEquals(ActiveMQServer.SERVER_STATE.STARTING, server.getState()); // should not be changed
+         assertFalse(server.isActive()); // should not be changed
+         latch.countDown();
          server.stop();
       }
    }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@artemis.apache.org
For additional commands, e-mail: commits-help@artemis.apache.org