From ef4adc559cc4b81a0c681807986c62fc0b9a13e4 Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Fri, 18 Apr 2014 13:37:32 +0000 Subject: QPID-5710 : [Java Broker] Use common creation/recovery mechanism for Queues git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1588468 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java | 14 ++++++++++---- .../org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java | 9 ++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'qpid/java/broker-plugins/management-jmx/src') diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java index e95ed9a383..a9fc160618 100644 --- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java +++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java @@ -24,6 +24,7 @@ package org.apache.qpid.server.jmx.mbeans; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicLong; import javax.management.JMException; @@ -294,14 +295,19 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN { if (exchangeName == null || "".equals(exchangeName)) { - _queue.setAttribute(Queue.ALTERNATE_EXCHANGE, getAlternateExchange(), null); + _queue.setAttributes(Collections.singletonMap(Queue.ALTERNATE_EXCHANGE, null)); } else { - VirtualHost virtualHost = _queue.getParent(VirtualHost.class); - Exchange exchange = MBeanUtils.findExchangeFromExchangeName(virtualHost, exchangeName); + try + { - _queue.setAttribute(Queue.ALTERNATE_EXCHANGE, getAlternateExchange(), exchange); + _queue.setAttributes(Collections.singletonMap(Queue.ALTERNATE_EXCHANGE, exchangeName)); + } + catch (IllegalArgumentException e) + { + throw new OperationsException("No such exchange \""+exchangeName+"\""); + } } } diff --git a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java index a81de49fb9..6a49b7c4ed 100644 --- a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java +++ b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java @@ -19,8 +19,10 @@ package org.apache.qpid.server.jmx.mbeans; import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -320,7 +322,7 @@ public class QueueMBeanTest extends QpidTestCase when(_mockQueue.getParent(VirtualHost.class)).thenReturn(mockVirtualHost); _queueMBean.setAlternateExchange("exchange2"); - verify(_mockQueue).setAttribute(Queue.ALTERNATE_EXCHANGE, null, mockExchange2); + verify(_mockQueue).setAttributes(Collections.singletonMap(Queue.ALTERNATE_EXCHANGE, "exchange2")); } public void testSetAlternateExchangeWithUnknownExchangeName() throws Exception @@ -331,7 +333,8 @@ public class QueueMBeanTest extends QpidTestCase VirtualHost mockVirtualHost = mock(VirtualHost.class); when(mockVirtualHost.getExchanges()).thenReturn(Collections.singletonList(mockExchange)); when(_mockQueue.getParent(VirtualHost.class)).thenReturn(mockVirtualHost); - + doThrow(new IllegalArgumentException()).when(_mockQueue).setAttributes( + eq(Collections.singletonMap(Queue.ALTERNATE_EXCHANGE, "notknown"))); try { _queueMBean.setAlternateExchange("notknown"); @@ -346,7 +349,7 @@ public class QueueMBeanTest extends QpidTestCase public void testRemoveAlternateExchange() throws Exception { _queueMBean.setAlternateExchange(""); - verify(_mockQueue).setAttribute(Queue.ALTERNATE_EXCHANGE, null, null); + verify(_mockQueue).setAttributes(Collections.singletonMap(Queue.ALTERNATE_EXCHANGE, null)); } /********** Operations **********/ -- cgit v1.2.1