From 486896d99ef18d50245414658147d2d838190445 Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Thu, 6 Aug 2020 00:12:02 +0100 Subject: [PATCH] ARTEMIS-2873 Config-managed queues are auto-deleted auto-delete-queues and auto-delete-created-queues should only apply to NON configuration managed queues. --- .../server/impl/QueueConfigurationUtils.java | 2 +- .../client/AutoDeleteCreatedQueueTest.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueConfigurationUtils.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueConfigurationUtils.java index ed90282678..0b3b1ce254 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueConfigurationUtils.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueConfigurationUtils.java @@ -39,7 +39,7 @@ public class QueueConfigurationUtils { config.setPurgeOnNoConsumers(config.isPurgeOnNoConsumers() == null ? as.isDefaultPurgeOnNoConsumers() : config.isPurgeOnNoConsumers()); config.setAutoCreateAddress(config.isAutoCreateAddress() == null ? as.isAutoCreateAddresses() : config.isAutoCreateAddress()); // set the default auto-delete - config.setAutoDelete(config.isAutoDelete() == null ? (config.isAutoCreated() && as.isAutoDeleteQueues()) || (!config.isAutoCreated() && as.isAutoDeleteCreatedQueues()) : config.isAutoDelete()); + config.setAutoDelete(config.isAutoDelete() == null ? !config.isConfigurationManaged() && ((config.isAutoCreated() && as.isAutoDeleteQueues()) || (!config.isAutoCreated() && as.isAutoDeleteCreatedQueues())) : config.isAutoDelete()); config.setAutoDeleteDelay(config.getAutoDeleteDelay() == null ? as.getAutoDeleteQueuesDelay() : config.getAutoDeleteDelay()); config.setAutoDeleteMessageCount(config.getAutoDeleteMessageCount() == null ? as.getAutoDeleteQueuesMessageCount() : config.getAutoDeleteMessageCount()); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteCreatedQueueTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteCreatedQueueTest.java index 8898f6d996..f73b4bfe6e 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteCreatedQueueTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteCreatedQueueTest.java @@ -32,6 +32,7 @@ public class AutoDeleteCreatedQueueTest extends ActiveMQTestBase { public final SimpleString addressA = new SimpleString("addressA"); public final SimpleString queueA = new SimpleString("queueA"); + public final SimpleString queueConfigurationManaged = new SimpleString("queueConfigurationManaged"); private ServerLocator locator; private ActiveMQServer server; @@ -59,4 +60,23 @@ public class AutoDeleteCreatedQueueTest extends ActiveMQTestBase { cf.createSession().createConsumer(queueA).close(); Wait.assertTrue(() -> server.locateQueue(queueA) == null); } + + + @Test + public void testAutoDeleteCreatedQueueDoesNOTDeleteConfigurationManagedQueuesOnLastConsumerClose() throws Exception { + server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoDeleteCreatedQueues(true)); + + server.createQueue(new QueueConfiguration(queueA).setAddress(addressA).setRoutingType(RoutingType.MULTICAST).setAutoCreated(false)); + server.createQueue(new QueueConfiguration(queueConfigurationManaged).setAddress(addressA).setRoutingType(RoutingType.MULTICAST).setAutoCreated(false).setConfigurationManaged(true)); + assertNotNull(server.locateQueue(queueA)); + assertNotNull(server.locateQueue(queueConfigurationManaged)); + assertTrue(server.locateQueue(queueA).isAutoDelete()); + assertFalse(server.locateQueue(queueConfigurationManaged).isAutoDelete()); + cf.createSession().createConsumer(queueA).close(); + cf.createSession().createConsumer(queueConfigurationManaged).close(); + //Make sure the reaper has run by checking the queueA should be removed. + Wait.assertTrue(() -> server.locateQueue(queueA) == null); + //Check that our configuration managed queue is not removed. + assertNotNull(server.locateQueue(queueConfigurationManaged)); + } }