From ef4501292e69b782dd5eafc28e68ed24aaf463fc Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Sat, 22 Apr 2023 20:24:37 +0200 Subject: [PATCH] ARTEMIS-4252 Fix flaky QuorumFailOverTest tests --- .../core/server/cluster/ClusterConnection.java | 2 ++ .../server/cluster/impl/ClusterConnectionImpl.java | 5 +++++ .../artemis/tests/util/ActiveMQTestBase.java | 13 +++++++++++++ .../cluster/failover/QuorumFailOverTest.java | 2 ++ 4 files changed, 22 insertions(+) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/ClusterConnection.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/ClusterConnection.java index 306d4da334..6555382601 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/ClusterConnection.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/ClusterConnection.java @@ -89,6 +89,8 @@ public interface ClusterConnection extends ActiveMQComponent, ClusterTopologyLis long getCallTimeout(); + Bridge[] getBridges(); + /** * The metric for this cluster connection * diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/ClusterConnectionImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/ClusterConnectionImpl.java index 77a718ffee..cde1d5e826 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/ClusterConnectionImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/ClusterConnectionImpl.java @@ -630,6 +630,11 @@ public final class ClusterConnectionImpl implements ClusterConnection, AfterConn return callTimeout; } + @Override + public Bridge[] getBridges() { + return records.values().stream().map(MessageFlowRecord::getBridge).toArray(Bridge[]::new); + } + @Override public Map getNodes() { synchronized (recordsGuard) { diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java index 1cef31179a..3f828a2de7 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java @@ -41,6 +41,7 @@ import java.lang.ref.WeakReference; import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -120,6 +121,7 @@ import org.apache.activemq.artemis.core.server.JournalType; import org.apache.activemq.artemis.core.server.MessageReference; import org.apache.activemq.artemis.core.server.NodeManager; import org.apache.activemq.artemis.core.server.Queue; +import org.apache.activemq.artemis.core.server.cluster.Bridge; import org.apache.activemq.artemis.core.server.cluster.ClusterConnection; import org.apache.activemq.artemis.core.server.cluster.ClusterManager; import org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding; @@ -1328,6 +1330,17 @@ public abstract class ActiveMQTestBase extends Assert { } } + protected static final void waitForBridges(final ActiveMQServer server, int connectedBridges) throws Exception { + waitForBridges(server.getClusterManager().getDefaultConnection(null), connectedBridges); + } + + protected static final void waitForBridges(ClusterConnection clusterConnection, int connectedBridges) throws Exception { + Bridge[] bridges = clusterConnection.getBridges(); + + Wait.assertTrue(() -> Arrays.stream(clusterConnection.getBridges()) + .filter(bridge -> bridge.isConnected()).count() >= connectedBridges); + } + protected static final Map generateParams(final int node, final boolean netty) { Map params = new HashMap<>(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/QuorumFailOverTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/QuorumFailOverTest.java index 4f4253a74b..28f0e71abb 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/QuorumFailOverTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/QuorumFailOverTest.java @@ -66,6 +66,7 @@ public class QuorumFailOverTest extends StaticClusterWithBackupFailoverTest { startServers(3, 4, 5); for (int i : liveServerIDs) { + waitForBridges(servers[i], 2); waitForTopology(servers[i], 3, 3); } @@ -122,6 +123,7 @@ public class QuorumFailOverTest extends StaticClusterWithBackupFailoverTest { } for (int i : liveServerIDs) { + waitForBridges(servers[i], 2); waitForTopology(servers[i], 3, 3); }