From c6b85ea4e3fc7e28b932cd30f7aa49da5d468a4e Mon Sep 17 00:00:00 2001 From: gtully Date: Mon, 1 Nov 2021 12:33:50 +0000 Subject: [PATCH] ARTEMIS-1925 - fix test regression - isHighAcceptPriority does not need to check for off_with_redistribution --- .../cluster/impl/RemoteQueueBindingImpl.java | 2 +- .../MessageRedistributionTest.java | 30 +++++++++++++++++++ .../cluster/impl/RemoteQueueBindImplTest.java | 7 ++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/RemoteQueueBindingImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/RemoteQueueBindingImpl.java index 8a2f88cc03..e87ded4825 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/RemoteQueueBindingImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/RemoteQueueBindingImpl.java @@ -154,7 +154,7 @@ public class RemoteQueueBindingImpl implements RemoteQueueBinding { @Override public synchronized boolean isHighAcceptPriority(final Message message) { - if (consumerCount == 0 || messageLoadBalancingType.equals(MessageLoadBalancingType.OFF) || messageLoadBalancingType.equals(MessageLoadBalancingType.OFF_WITH_REDISTRIBUTION)) { + if (consumerCount == 0 || messageLoadBalancingType.equals(MessageLoadBalancingType.OFF)) { return false; } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/MessageRedistributionTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/MessageRedistributionTest.java index 01293dbf9e..01292e9dac 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/MessageRedistributionTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/MessageRedistributionTest.java @@ -764,6 +764,36 @@ public class MessageRedistributionTest extends ClusterTestBase { verifyNotReceive(1); } + @Test + public void testRedistributionOnlyWhenLocalRemovedLbOffWithRedistribution() throws Exception { + setupCluster(MessageLoadBalancingType.OFF_WITH_REDISTRIBUTION); + + startServers(0, 1); + + setupSessionFactory(0, isNetty()); + setupSessionFactory(1, isNetty()); + + createQueue(0, "queues.testaddress", "queue0", null, false); + createQueue(1, "queues.testaddress", "queue0", null, false); + + addConsumer(0, 0, "queue0", null); + addConsumer(1, 1, "queue0", null); + + waitForBindings(0, "queues.testaddress", 1, 1, true); + waitForBindings(1, "queues.testaddress", 1, 1, true); + + waitForBindings(0, "queues.testaddress", 1, 1, false); + waitForBindings(1, "queues.testaddress", 1, 1, false); + + send(0, "queues.testaddress", 2, false, null); + + verifyNotReceive(1); + + removeConsumer(0); + + verifyReceiveAll(2, 1); + } + @Test public void testBackAndForth() throws Exception { for (int i = 0; i < 10; i++) { diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/cluster/impl/RemoteQueueBindImplTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/cluster/impl/RemoteQueueBindImplTest.java index 82f5239cc1..cdeb4e42fd 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/cluster/impl/RemoteQueueBindImplTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/cluster/impl/RemoteQueueBindImplTest.java @@ -93,9 +93,14 @@ public class RemoteQueueBindImplTest extends ActiveMQTestBase { final SimpleString bridgeName = RandomUtil.randomSimpleString(); final int distance = 0; RemoteQueueBindingImpl bindingOff = new RemoteQueueBindingImpl(id, address, uniqueName, routingName, remoteQueueID, filterString, storeAndForwardQueue, bridgeName, distance, MessageLoadBalancingType.OFF); + bindingOff.addConsumer(null); assertFalse(bindingOff.isHighAcceptPriority(null)); RemoteQueueBindingImpl bindingOffWithRedistribution = new RemoteQueueBindingImpl(id, address, uniqueName, routingName, remoteQueueID, filterString, storeAndForwardQueue, bridgeName, distance, MessageLoadBalancingType.OFF_WITH_REDISTRIBUTION); - assertFalse(bindingOffWithRedistribution.isHighAcceptPriority(null)); + bindingOffWithRedistribution.addConsumer(null); + // not really intuitive, but via getNextBinding (initial routing) BindingsImpl.matchBinding() traps remote bindings + // with OFF_WITH_REDISTRIBUTION which makes the need for change in isHighAcceptPriority redundant + // and ensures that redistribution can occur as isHighAcceptPriority is invoked from redistribute + assertTrue(bindingOffWithRedistribution.isHighAcceptPriority(null)); } }