From 99f3d4c5054bbf401c6460d99574873b604e4b49 Mon Sep 17 00:00:00 2001 From: gtully Date: Thu, 15 Jun 2017 10:46:23 +0100 Subject: [PATCH] [AMQ-6703] have jmx purge clear the audit such that messages can be copied back, fix and test --- .../apache/activemq/broker/region/Queue.java | 2 + .../apache/activemq/broker/jmx/MBeanTest.java | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java index 6bd24de98d..1bdfe70e26 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -1280,6 +1280,8 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index // store } while (!list.isEmpty() && this.destinationStatistics.getMessages().getCount() > 0); + getMessages().getMessageAudit().clear(); + if (this.destinationStatistics.getMessages().getCount() > 0) { LOG.warn("{} after purge of {} messages, message count stats report: {}", getActiveMQDestination().getQualifiedName(), originalMessageCount, this.destinationStatistics.getMessages().getCount()); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java index 1345ec0047..d72d709286 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java @@ -438,6 +438,45 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { assertEquals("dest has no memory usage", 0, queue.getMemoryPercentUsage()); } + + public void testCopyPurgeCopyBack() throws Exception { + connection = connectionFactory.createConnection(); + final int numMessages = 100; + useConnection(connection, numMessages); + + ObjectName queueViewMBeanName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + getDestinationString()); + + QueueViewMBean queueT = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, queueViewMBeanName, QueueViewMBean.class, true); + + String newDestination = getSecondDestinationString(); + long queueSize = queueT.getQueueSize(); + assertTrue(queueSize > 0); + + int c = queueT.copyMatchingMessagesTo(null, newDestination); + LOG.info("Copied: " + c); + + queueViewMBeanName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + newDestination); + + QueueViewMBean queueD = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, queueViewMBeanName, QueueViewMBean.class, true); + + LOG.info("Queue: " + queueD.getName() + " now has: " + queueD.getQueueSize() + " message(s)"); + assertEquals("Expected messages in a queue: " + queueD.getQueueSize(), numMessages, queueD.getQueueSize()); + + LOG.info("Queue: " + queueT.getName() + " now has: " + queueT.getQueueSize() + " message(s)"); + assertEquals("Expected messages in a queue: " + queueT.getQueueSize(), numMessages, queueT.getQueueSize()); + + queueT.purge(); + queueD.copyMatchingMessagesTo(null, getDestinationString()); + + LOG.info("Queue: " + queueD.getName() + " now has: " + queueD.getQueueSize() + " message(s)"); + assertEquals("Expected messages in a queue: " + queueD.getQueueSize(), numMessages, queueD.getQueueSize()); + + LOG.info("Queue: " + queueT.getName() + " now has: " + queueT.getQueueSize() + " message(s)"); + assertEquals("Expected messages in a queue: " + queueT.getQueueSize(), numMessages, queueT.getQueueSize()); + + assertNotRegisteredObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME ); + } + public void testCreateDestinationWithSpacesAtEnds() throws Exception { ObjectName brokerName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost"); BrokerViewMBean broker = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, brokerName, BrokerViewMBean.class, true);