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

This commit is contained in:
gtully 2017-05-31 11:26:46 +01:00
parent 44b5d0be65
commit 8023b9ee44
2 changed files with 37 additions and 0 deletions

View File

@ -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 {

View File

@ -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);