You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2017/05/31 10:27:04 UTC

activemq git commit: [AMQ-6690] do nothing for move/copy jmx ops that try to modify self

Repository: activemq
Updated Branches:
  refs/heads/master 44b5d0be6 -> 8023b9ee4


[AMQ-6690] do nothing for move/copy jmx ops that try to modify self


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/8023b9ee
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/8023b9ee
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/8023b9ee

Branch: refs/heads/master
Commit: 8023b9ee448d2ed52c8a5c84b40dd92aae8bfc88
Parents: 44b5d0b
Author: gtully <ga...@gmail.com>
Authored: Wed May 31 11:26:46 2017 +0100
Committer: gtully <ga...@gmail.com>
Committed: Wed May 31 11:26:46 2017 +0100

----------------------------------------------------------------------
 .../apache/activemq/broker/region/Queue.java    | 10 ++++++++
 .../apache/activemq/broker/jmx/MBeanTest.java   | 27 ++++++++++++++++++++
 2 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/8023b9ee/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java
----------------------------------------------------------------------
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 62c8c7a..6bd24de 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
@@ -1402,6 +1402,11 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index
      */
     public int copyMatchingMessages(ConnectionContext context, MessageReferenceFilter filter, ActiveMQDestination dest,
             int maximumMessages) throws Exception {
+
+        if (destination.equals(dest)) {
+            return 0;
+        }
+
         int movedCounter = 0;
         int count = 0;
         Set<MessageReference> set = new LinkedHashSet<MessageReference>();
@@ -1498,6 +1503,11 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index
      */
     public int moveMatchingMessagesTo(ConnectionContext context, MessageReferenceFilter filter,
             ActiveMQDestination dest, int maximumMessages) throws Exception {
+
+        if (destination.equals(dest)) {
+            return 0;
+        }
+
         int movedCounter = 0;
         Set<MessageReference> set = new LinkedHashSet<MessageReference>();
         do {

http://git-wip-us.apache.org/repos/asf/activemq/blob/8023b9ee/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
----------------------------------------------------------------------
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 5304424..1345ec0 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
@@ -225,6 +225,33 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
         assertEquals("no change", initialQueueSize, actualCount);
     }
 
+    public void testMoveCopyToSameDestFails() throws Exception {
+        connection = connectionFactory.createConnection();
+        useConnection(connection);
+
+        ObjectName queueViewMBeanName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + getDestinationString());
+
+        QueueViewMBean queue = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, queueViewMBeanName, QueueViewMBean.class, true);
+
+        CompositeData[] compdatalist = queue.browse();
+        int initialQueueSize = compdatalist.length;
+        CompositeData cdata = compdatalist[0];
+        String messageID = (String) cdata.get("JMSMessageID");
+
+        assertFalse("fail to copy to self", queue.copyMessageTo(messageID, getDestinationString()));
+        assertEquals("fail to copy to self", 0, queue.copyMatchingMessagesTo("", getDestinationString()));
+        assertEquals("fail to copy x to self", 0, queue.copyMatchingMessagesTo("", getDestinationString(), initialQueueSize));
+
+        assertFalse("fail to move to self", queue.moveMessageTo(messageID, getDestinationString()));
+        assertEquals("fail to move to self", 0, queue.moveMatchingMessagesTo("", getDestinationString()));
+        assertEquals("fail to move x to self", 0, queue.moveMatchingMessagesTo("", getDestinationString(), initialQueueSize));
+
+        compdatalist = queue.browse();
+        int actualCount = compdatalist.length;
+        echo("Current queue size: " + actualCount);
+        assertEquals("no change", initialQueueSize, actualCount);
+    }
+
     public void testRemoveMessages() throws Exception {
         ObjectName brokerName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost");
         BrokerViewMBean broker = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, brokerName, BrokerViewMBean.class, true);