diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/pools/DiscoveryPoolTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/pools/DiscoveryPoolTest.java index b637ebe808..d1b331d6e3 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/pools/DiscoveryPoolTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/pools/DiscoveryPoolTest.java @@ -136,7 +136,6 @@ public class DiscoveryPoolTest extends PoolTestBase { Stream.concat(initialNodeIDs.stream(), addedNodeIDs.stream()).forEach(nodeID -> { if (removingNodeIDs.contains(nodeID)) { Assert.assertNull(pool.getTarget(nodeID)); - Assert.assertEquals(0, targetProbe.getTargetExecutions(pool.getTarget(nodeID))); } else { Assert.assertTrue(pool.isTargetReady(pool.getTarget(nodeID))); Assert.assertTrue(targetProbe.getTargetExecutions(pool.getTarget(nodeID)) > 0); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/pools/PoolTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/pools/PoolTestBase.java index c3edd97f33..92af5c0599 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/pools/PoolTestBase.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/pools/PoolTestBase.java @@ -65,24 +65,28 @@ public abstract class PoolTestBase { pool.start(); - Wait.assertEquals(targets, () -> pool.getTargets().size(), CHECK_TIMEOUT); + try { + Wait.assertEquals(targets, () -> pool.getTargets().size(), CHECK_TIMEOUT); - targetFactory.getCreatedTargets().stream().limit(targets - quorumSize + 1) - .forEach(mockTarget -> mockTarget.setReady(false)); + targetFactory.getCreatedTargets().stream().limit(targets - quorumSize + 1) + .forEach(mockTarget -> mockTarget.setReady(false)); - Wait.assertEquals(0, () -> pool.getTargets().size(), CHECK_TIMEOUT); + Wait.assertEquals(0, () -> pool.getTargets().size(), CHECK_TIMEOUT); - targetFactory.getCreatedTargets().get(0).setReady(true); + targetFactory.getCreatedTargets().get(0).setReady(true); - Wait.assertEquals(quorumSize, () -> pool.getTargets().size(), CHECK_TIMEOUT); + Wait.assertEquals(quorumSize, () -> pool.getTargets().size(), CHECK_TIMEOUT); - pool.setQuorumSize(quorumSize + 1); + pool.setQuorumSize(quorumSize + 1); - Wait.assertEquals(0, () -> pool.getTargets().size(), CHECK_TIMEOUT); + Wait.assertEquals(0, () -> pool.getTargets().size(), CHECK_TIMEOUT); - targetFactory.getCreatedTargets().get(1).setReady(true); + targetFactory.getCreatedTargets().get(1).setReady(true); - Wait.assertEquals(quorumSize + 1, () -> pool.getTargets().size(), CHECK_TIMEOUT); + Wait.assertEquals(quorumSize + 1, () -> pool.getTargets().size(), CHECK_TIMEOUT); + } finally { + pool.stop(); + } } @@ -96,10 +100,6 @@ public abstract class PoolTestBase { Assert.assertEquals(0, pool.getTargets().size()); Assert.assertEquals(0, pool.getAllTargets().size()); Assert.assertEquals(0, targetFactory.getCreatedTargets().size()); - targetFactory.getCreatedTargets().forEach(mockTarget -> { - Assert.assertFalse(pool.isTargetReady(mockTarget)); - Assert.assertEquals(0, targetProbe.getTargetExecutions(mockTarget)); - }); pool.start(); @@ -133,6 +133,8 @@ public abstract class PoolTestBase { Wait.assertTrue(() -> targetProbe.getTargetExecutions(mockTarget) > 0, CHECK_TIMEOUT); }); + targetProbe.clearTargetExecutions(); + targetProbe.setChecked(true); Wait.assertEquals(targets, () -> pool.getTargets().size(), CHECK_TIMEOUT); @@ -154,10 +156,6 @@ public abstract class PoolTestBase { Wait.assertEquals(0, () -> pool.getTargets().size(), CHECK_TIMEOUT); Assert.assertEquals(targets, pool.getAllTargets().size()); Assert.assertEquals(targets, targetFactory.getCreatedTargets().size()); - targetFactory.getCreatedTargets().forEach(mockTarget -> { - Assert.assertFalse(pool.isTargetReady(mockTarget)); - Assert.assertTrue(targetProbe.getTargetExecutions(mockTarget) > 0); - }); targetProbe.clearTargetExecutions(); @@ -167,8 +165,8 @@ public abstract class PoolTestBase { Assert.assertEquals(targets, pool.getAllTargets().size()); Assert.assertEquals(targets, targetFactory.getCreatedTargets().size()); targetFactory.getCreatedTargets().forEach(mockTarget -> { - Assert.assertTrue(pool.isTargetReady(mockTarget)); - Assert.assertTrue(targetProbe.getTargetExecutions(mockTarget) > 0); + Wait.assertTrue(() -> pool.isTargetReady(mockTarget), CHECK_TIMEOUT); + Wait.assertTrue(() -> targetProbe.getTargetExecutions(mockTarget) > 0, CHECK_TIMEOUT); }); targetProbe.clearTargetExecutions(); @@ -179,8 +177,8 @@ public abstract class PoolTestBase { Assert.assertEquals(targets, pool.getAllTargets().size()); Assert.assertEquals(targets, targetFactory.getCreatedTargets().size()); targetFactory.getCreatedTargets().forEach(mockTarget -> { - Assert.assertFalse(pool.isTargetReady(mockTarget)); - Assert.assertTrue(targetProbe.getTargetExecutions(mockTarget) > 0); + Wait.assertTrue(() -> !pool.isTargetReady(mockTarget), CHECK_TIMEOUT); + Wait.assertTrue(() -> targetProbe.getTargetExecutions(mockTarget) > 0, CHECK_TIMEOUT); }); } } finally { diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/targets/MockTarget.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/targets/MockTarget.java index 3c31d6f0a4..972c87884c 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/targets/MockTarget.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/targets/MockTarget.java @@ -123,7 +123,7 @@ public class MockTarget extends AbstractTarget { @Override public boolean checkReadiness() { - return ready; + return connected && ready; } @Override diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/targets/MockTargetProbe.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/targets/MockTargetProbe.java index d8c3aa2e48..e4292598f9 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/targets/MockTargetProbe.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/balancing/targets/MockTargetProbe.java @@ -17,13 +17,13 @@ package org.apache.activemq.artemis.core.server.balancing.targets; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class MockTargetProbe extends TargetProbe { - private final Map targetExecutions = new HashMap<>(); + private final Map targetExecutions = new ConcurrentHashMap<>(); - private boolean checked; + private volatile boolean checked; public boolean isChecked() { return checked;