This commit is contained in:
Robbie Gemmell 2021-09-07 10:14:06 +01:00
commit 27c1df6687
4 changed files with 24 additions and 27 deletions

View File

@ -136,7 +136,6 @@ public class DiscoveryPoolTest extends PoolTestBase {
Stream.concat(initialNodeIDs.stream(), addedNodeIDs.stream()).forEach(nodeID -> { Stream.concat(initialNodeIDs.stream(), addedNodeIDs.stream()).forEach(nodeID -> {
if (removingNodeIDs.contains(nodeID)) { if (removingNodeIDs.contains(nodeID)) {
Assert.assertNull(pool.getTarget(nodeID)); Assert.assertNull(pool.getTarget(nodeID));
Assert.assertEquals(0, targetProbe.getTargetExecutions(pool.getTarget(nodeID)));
} else { } else {
Assert.assertTrue(pool.isTargetReady(pool.getTarget(nodeID))); Assert.assertTrue(pool.isTargetReady(pool.getTarget(nodeID)));
Assert.assertTrue(targetProbe.getTargetExecutions(pool.getTarget(nodeID)) > 0); Assert.assertTrue(targetProbe.getTargetExecutions(pool.getTarget(nodeID)) > 0);

View File

@ -65,24 +65,28 @@ public abstract class PoolTestBase {
pool.start(); 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) targetFactory.getCreatedTargets().stream().limit(targets - quorumSize + 1)
.forEach(mockTarget -> mockTarget.setReady(false)); .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.getTargets().size());
Assert.assertEquals(0, pool.getAllTargets().size()); Assert.assertEquals(0, pool.getAllTargets().size());
Assert.assertEquals(0, targetFactory.getCreatedTargets().size()); Assert.assertEquals(0, targetFactory.getCreatedTargets().size());
targetFactory.getCreatedTargets().forEach(mockTarget -> {
Assert.assertFalse(pool.isTargetReady(mockTarget));
Assert.assertEquals(0, targetProbe.getTargetExecutions(mockTarget));
});
pool.start(); pool.start();
@ -133,6 +133,8 @@ public abstract class PoolTestBase {
Wait.assertTrue(() -> targetProbe.getTargetExecutions(mockTarget) > 0, CHECK_TIMEOUT); Wait.assertTrue(() -> targetProbe.getTargetExecutions(mockTarget) > 0, CHECK_TIMEOUT);
}); });
targetProbe.clearTargetExecutions();
targetProbe.setChecked(true); targetProbe.setChecked(true);
Wait.assertEquals(targets, () -> pool.getTargets().size(), CHECK_TIMEOUT); Wait.assertEquals(targets, () -> pool.getTargets().size(), CHECK_TIMEOUT);
@ -154,10 +156,6 @@ public abstract class PoolTestBase {
Wait.assertEquals(0, () -> pool.getTargets().size(), CHECK_TIMEOUT); Wait.assertEquals(0, () -> pool.getTargets().size(), CHECK_TIMEOUT);
Assert.assertEquals(targets, pool.getAllTargets().size()); Assert.assertEquals(targets, pool.getAllTargets().size());
Assert.assertEquals(targets, targetFactory.getCreatedTargets().size()); Assert.assertEquals(targets, targetFactory.getCreatedTargets().size());
targetFactory.getCreatedTargets().forEach(mockTarget -> {
Assert.assertFalse(pool.isTargetReady(mockTarget));
Assert.assertTrue(targetProbe.getTargetExecutions(mockTarget) > 0);
});
targetProbe.clearTargetExecutions(); targetProbe.clearTargetExecutions();
@ -167,8 +165,8 @@ public abstract class PoolTestBase {
Assert.assertEquals(targets, pool.getAllTargets().size()); Assert.assertEquals(targets, pool.getAllTargets().size());
Assert.assertEquals(targets, targetFactory.getCreatedTargets().size()); Assert.assertEquals(targets, targetFactory.getCreatedTargets().size());
targetFactory.getCreatedTargets().forEach(mockTarget -> { targetFactory.getCreatedTargets().forEach(mockTarget -> {
Assert.assertTrue(pool.isTargetReady(mockTarget)); Wait.assertTrue(() -> pool.isTargetReady(mockTarget), CHECK_TIMEOUT);
Assert.assertTrue(targetProbe.getTargetExecutions(mockTarget) > 0); Wait.assertTrue(() -> targetProbe.getTargetExecutions(mockTarget) > 0, CHECK_TIMEOUT);
}); });
targetProbe.clearTargetExecutions(); targetProbe.clearTargetExecutions();
@ -179,8 +177,8 @@ public abstract class PoolTestBase {
Assert.assertEquals(targets, pool.getAllTargets().size()); Assert.assertEquals(targets, pool.getAllTargets().size());
Assert.assertEquals(targets, targetFactory.getCreatedTargets().size()); Assert.assertEquals(targets, targetFactory.getCreatedTargets().size());
targetFactory.getCreatedTargets().forEach(mockTarget -> { targetFactory.getCreatedTargets().forEach(mockTarget -> {
Assert.assertFalse(pool.isTargetReady(mockTarget)); Wait.assertTrue(() -> !pool.isTargetReady(mockTarget), CHECK_TIMEOUT);
Assert.assertTrue(targetProbe.getTargetExecutions(mockTarget) > 0); Wait.assertTrue(() -> targetProbe.getTargetExecutions(mockTarget) > 0, CHECK_TIMEOUT);
}); });
} }
} finally { } finally {

View File

@ -123,7 +123,7 @@ public class MockTarget extends AbstractTarget {
@Override @Override
public boolean checkReadiness() { public boolean checkReadiness() {
return ready; return connected && ready;
} }
@Override @Override

View File

@ -17,13 +17,13 @@
package org.apache.activemq.artemis.core.server.balancing.targets; package org.apache.activemq.artemis.core.server.balancing.targets;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class MockTargetProbe extends TargetProbe { public class MockTargetProbe extends TargetProbe {
private final Map<Target, Integer> targetExecutions = new HashMap<>(); private final Map<Target, Integer> targetExecutions = new ConcurrentHashMap<>();
private boolean checked; private volatile boolean checked;
public boolean isChecked() { public boolean isChecked() {
return checked; return checked;