summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2012-06-28 14:27:04 +0000
committerKeith Wall <kwall@apache.org>2012-06-28 14:27:04 +0000
commit5197e829c8a58c3d664b428132ad488e570ddc71 (patch)
tree972ec22d8b7aeb6a1989c80b038bf68659c8f1ac
parent7f71e8ade87c187abd51740122ab113b5ee71970 (diff)
downloadqpid-python-5197e829c8a58c3d664b428132ad488e570ddc71.tar.gz
NO-JIRA: Bolster QueueMBean and VirtualHostManagerMBean system and unit tests.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-config-and-management@1355024 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java57
-rw-r--r--qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java43
-rw-r--r--qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java69
-rw-r--r--qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java5
-rw-r--r--qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java40
-rw-r--r--qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java184
-rw-r--r--qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java90
-rw-r--r--qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java17
8 files changed, 408 insertions, 97 deletions
diff --git a/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java b/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java
new file mode 100644
index 0000000000..97e84d4796
--- /dev/null
+++ b/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.jmx.mbeans;
+
+import javax.management.OperationsException;
+
+import org.apache.qpid.server.model.ConfiguredObjectFinder;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.VirtualHost;
+
+public class MBeanUtils
+{
+ public static Queue findQueueFromQueueName(VirtualHost virtualHost, String queueName) throws OperationsException
+ {
+ Queue queue = ConfiguredObjectFinder.findConfiguredObjectByName(virtualHost.getQueues(), queueName);
+ if (queue == null)
+ {
+ throw new OperationsException("No such queue \""+queueName+"\"");
+ }
+ else
+ {
+ return queue;
+ }
+ }
+
+ public static Exchange findExchangeFromExchangeName(VirtualHost virtualHost, String exchangeName) throws OperationsException
+ {
+ Exchange exchange = ConfiguredObjectFinder.findConfiguredObjectByName(virtualHost.getExchanges(), exchangeName);
+ if (exchange == null)
+ {
+ throw new OperationsException("No such exchange \""+exchangeName+"\"");
+ }
+ else
+ {
+ return exchange;
+ }
+ }
+}
diff --git a/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java b/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
index 76d545a5f7..1416cfdd89 100644
--- a/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
+++ b/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
@@ -48,7 +48,6 @@ import org.apache.qpid.server.jmx.AMQManagedObject;
import org.apache.qpid.server.jmx.ManagedObject;
import org.apache.qpid.server.message.AMQMessageHeader;
import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.model.ConfiguredObjectFinder;
import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.LifetimePolicy;
import org.apache.qpid.server.model.Queue;
@@ -143,18 +142,11 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN
return _queue.getName();
}
-
public Integer getMessageCount()
{
return getStatisticValue(Queue.QUEUE_DEPTH_MESSAGES).intValue();
}
- private Number getStatisticValue(String name)
- {
- final Number statistic = (Number) _queue.getStatistics().getStatistic(name);
- return statistic == null ? Integer.valueOf(0) : statistic;
- }
-
public Integer getMaximumDeliveryCount()
{
return (Integer) _queue.getAttribute(Queue.MAXIMUM_DELIVERY_ATTEMPTS);
@@ -285,7 +277,7 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN
else
{
VirtualHost virtualHost = _queue.getParent(VirtualHost.class);
- Exchange exchange = findExchangeFromExchangeName(virtualHost, exchangeName);
+ Exchange exchange = MBeanUtils.findExchangeFromExchangeName(virtualHost, exchangeName);
_queue.setAttribute(Queue.ALTERNATE_EXCHANGE, getAlternateExchange(), exchange);
}
@@ -409,9 +401,8 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN
GetMessageVisitor visitor = new GetMessageVisitor(messageId);
_queue.visit(visitor);
return visitor.getEntry();
-
}
-
+
public void deleteMessageFromTop() throws IOException, JMException
{
VirtualHost vhost = _queue.getParent(VirtualHost.class);
@@ -477,7 +468,7 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN
}
VirtualHost vhost = _queue.getParent(VirtualHost.class);
- final Queue destinationQueue = findQueueFromQueueName(vhost, toQueue);
+ final Queue destinationQueue = MBeanUtils.findQueueFromQueueName(vhost, toQueue);
vhost.executeTransaction(new VirtualHost.TransactionalOperation()
{
@@ -549,7 +540,7 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN
}
VirtualHost vhost = _queue.getParent(VirtualHost.class);
- final Queue destinationQueue = findQueueFromQueueName(vhost, toQueue);
+ final Queue destinationQueue = MBeanUtils.findQueueFromQueueName(vhost, toQueue);
vhost.executeTransaction(new VirtualHost.TransactionalOperation()
{
@@ -664,29 +655,9 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN
_queue.setAttribute(Queue.DESCRIPTION, getDescription(), description);
}
- private Queue findQueueFromQueueName(VirtualHost virtualHost, String queueName) throws OperationsException
- {
- Queue queue = ConfiguredObjectFinder.findConfiguredObjectByName(virtualHost.getQueues(), queueName);
- if (queue == null)
- {
- throw new OperationsException("No such queue \""+queueName+"\"");
- }
- else
- {
- return queue;
- }
- }
-
- private Exchange findExchangeFromExchangeName(VirtualHost virtualHost, String exchangeName) throws OperationsException
+ private Number getStatisticValue(String name)
{
- Exchange exchange = ConfiguredObjectFinder.findConfiguredObjectByName(virtualHost.getExchanges(), exchangeName);
- if (exchange == null)
- {
- throw new OperationsException("No such exchange \""+exchangeName+"\"");
- }
- else
- {
- return exchange;
- }
+ final Number statistic = (Number) _queue.getStatistics().getStatistic(name);
+ return statistic == null ? Integer.valueOf(0) : statistic;
}
}
diff --git a/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java b/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
index 7ccb706c80..9d12d8a493 100644
--- a/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
+++ b/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
@@ -33,8 +33,11 @@ import javax.management.JMException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import javax.management.OperationsException;
import org.apache.log4j.Logger;
+import org.apache.qpid.AMQInvalidArgumentException;
+import org.apache.qpid.AMQUnknownExchangeType;
import org.apache.qpid.management.common.mbeans.ManagedBroker;
import org.apache.qpid.management.common.mbeans.ManagedQueue;
import org.apache.qpid.management.common.mbeans.annotations.MBeanConstructor;
@@ -66,6 +69,7 @@ public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<Vi
}
+ @Override
public String getObjectInstanceName()
{
return ObjectName.quote(_virtualHostMBean.getName());
@@ -77,17 +81,20 @@ public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<Vi
return _virtualHostMBean;
}
+ @Override
public String[] getExchangeTypes() throws IOException
{
Collection<String> exchangeTypes = _virtualHostMBean.getVirtualHost().getExchangeTypes();
return exchangeTypes.toArray(new String[exchangeTypes.size()]);
}
+ @Override
public List<String> retrieveQueueAttributeNames() throws IOException
{
return ManagedQueue.QUEUE_ATTRIBUTES;
}
+ @Override
public List<List<Object>> retrieveQueueAttributeValues(
@MBeanOperationParameter(name = "attributes", description = "Attributes to retrieve") String[] attributes)
throws IOException
@@ -125,46 +132,52 @@ public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<Vi
}
+ @Override
public void createNewExchange(String name, String type, boolean durable)
throws IOException, JMException, MBeanException
{
- getConfiguredObject().createExchange(name, State.ACTIVE, durable,
- LifetimePolicy.PERMANENT, 0l, type, Collections.EMPTY_MAP);
+ if (!getConfiguredObject().getExchangeTypes().contains(type))
+ {
+ throw new OperationsException("No such exchange type \""+type+"\"");
+ }
+
+ try
+ {
+ getConfiguredObject().createExchange(name, State.ACTIVE, durable,
+ LifetimePolicy.PERMANENT, 0l, type, Collections.EMPTY_MAP);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ JMException jme = new JMException(iae.toString());
+ throw new MBeanException(jme, "Error in creating exchange " + name);
+ }
}
+ @Override
public void unregisterExchange(String exchangeName)
throws IOException, JMException, MBeanException
{
- Exchange theExchange = null;
- for(Exchange exchange : _virtualHostMBean.getVirtualHost().getExchanges())
+ Exchange theExchange = MBeanUtils.findExchangeFromExchangeName(_virtualHostMBean.getVirtualHost(), exchangeName);
+ try
{
- if(exchange.getName().equals(exchangeName))
- {
- theExchange = exchange;
- break;
- }
+ theExchange.delete();
}
- if(theExchange != null)
+ catch (IllegalStateException ex)
{
- try
- {
- theExchange.delete();
- }
- catch (IllegalStateException ex)
- {
- final JMException jme = new JMException(ex.toString());
- throw new MBeanException(jme, "Error in unregistering exchange " + exchangeName);
- }
+ final JMException jme = new JMException(ex.toString());
+ throw new MBeanException(jme, "Error in unregistering exchange " + exchangeName);
}
}
+ @Override
public void createNewQueue(String queueName, String owner, boolean durable)
throws IOException, JMException, MBeanException
{
createNewQueue(queueName, owner, durable, Collections.EMPTY_MAP);
}
+ @Override
public void createNewQueue(String queueName, String owner, boolean durable, Map<String, Object> originalArguments)
throws IOException, JMException
{
@@ -203,33 +216,21 @@ public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<Vi
return argumentsCopy;
}
+ @Override
public void deleteQueue(
@MBeanOperationParameter(name = ManagedQueue.TYPE, description = "Queue Name") String queueName)
throws IOException, JMException, MBeanException
{
- Queue theQueue = null;
- for(Queue queue : _virtualHostMBean.getVirtualHost().getQueues())
- {
- if(queue.getName().equals(queueName))
- {
- theQueue = queue;
- break;
- }
- }
- if(theQueue != null)
- {
- theQueue.delete();
- }
+ Queue theQueue = MBeanUtils.findQueueFromQueueName(_virtualHostMBean.getVirtualHost(), queueName);
+ theQueue.delete();
}
-
@Override
public ObjectName getObjectName() throws MalformedObjectNameException
{
return getObjectNameForSingleInstanceMBean();
}
-
public synchronized boolean isStatisticsEnabled()
{
updateStats();
diff --git a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
index f294c85c99..f97c5a7210 100644
--- a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
+++ b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
@@ -31,7 +31,6 @@ import javax.management.openmbean.TabularData;
import junit.framework.TestCase;
-import org.apache.commons.beanutils.PropertyUtils;
import org.apache.qpid.management.common.mbeans.ManagedConnection;
import org.apache.qpid.server.jmx.ManagedObject;
import org.apache.qpid.server.jmx.ManagedObjectRegistry;
@@ -206,9 +205,7 @@ public class ConnectionMBeanTest extends TestCase
private void assertAttribute(String jmxAttributeName, Object expectedValue, String underlyingAttributeName) throws Exception
{
when(_mockConnection.getAttribute(underlyingAttributeName)).thenReturn(expectedValue);
-
- Object actualValue = PropertyUtils.getSimpleProperty(_connectionMBean, jmxAttributeName);
- assertEquals("Unexpected " + jmxAttributeName, expectedValue, actualValue);
+ MBeanTestUtils.assertMBeanAttribute(_connectionMBean, jmxAttributeName, expectedValue);
}
private void assertChannelRow(final CompositeData row, int channelId, int unacknowledgedMessages, boolean isTransactional, boolean flowBlocked)
diff --git a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
new file mode 100644
index 0000000000..5f913e5f33
--- /dev/null
+++ b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.jmx.mbeans;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.qpid.server.jmx.DefaultManagedObject;
+
+public class MBeanTestUtils
+{
+
+ public static void assertMBeanAttribute(DefaultManagedObject managedObject, String jmxAttributeName, Object expectedValue) throws Exception
+ {
+ Object actualValue = PropertyUtils.getSimpleProperty(managedObject, jmxAttributeName);
+ TestCase.assertEquals("Attribute " + jmxAttributeName + " has unexpected value", expectedValue, actualValue);
+ }
+
+ public static void setMBeanAttribute(DefaultManagedObject managedObject, String jmxAttributeName, Object newValue) throws Exception
+ {
+ PropertyUtils.setSimpleProperty(managedObject, jmxAttributeName, newValue);
+ }
+}
diff --git a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java
index ceaad0d29b..2003c12735 100644
--- a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java
+++ b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java
@@ -34,7 +34,9 @@ import javax.management.OperationsException;
import org.apache.qpid.server.jmx.ManagedObjectRegistry;
import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.LifetimePolicy;
import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.queue.NotificationCheck;
import org.mockito.ArgumentMatcher;
@@ -49,6 +51,7 @@ public class QueueMBeanTest extends TestCase
private static final String QUEUE_ALTERNATE_EXCHANGE = "QUEUE_ALTERNATE_EXCHANGE";
private Queue _mockQueue;
+ private Statistics _mockQueueStatistics;
private VirtualHostMBean _mockVirtualHostMBean;
private ManagedObjectRegistry _mockManagedObjectRegistry;
private QueueMBean _queueMBean;
@@ -57,7 +60,9 @@ public class QueueMBeanTest extends TestCase
protected void setUp() throws Exception
{
_mockQueue = mock(Queue.class);
+ _mockQueueStatistics = mock(Statistics.class);
when(_mockQueue.getName()).thenReturn(QUEUE_NAME);
+ when(_mockQueue.getStatistics()).thenReturn(_mockQueueStatistics);
_mockVirtualHostMBean = mock(VirtualHostMBean.class);
_mockManagedObjectRegistry = mock(ManagedObjectRegistry.class);
@@ -71,26 +76,161 @@ public class QueueMBeanTest extends TestCase
assertEquals(QUEUE_NAME, _queueMBean.getName());
}
- public void testGetQueueDescription()
+ /********** Statistics **********/
+
+ public void testGetMessageCount() throws Exception
+ {
+ assertStatistic("messageCount", 1000, Queue.QUEUE_DEPTH_MESSAGES);
+ }
+
+ public void testGetReceivedMessageCount() throws Exception
+ {
+ assertStatistic("receivedMessageCount", 1000l, Queue.TOTAL_ENQUEUED_MESSAGES);
+ }
+
+ public void testQueueDepth() throws Exception
+ {
+ assertStatistic("queueDepth", 4096l, Queue.QUEUE_DEPTH_BYTES);
+ }
+
+ public void testActiveConsumerCount() throws Exception
+ {
+ assertStatistic("activeConsumerCount", 3, Queue.CONSUMER_COUNT_WITH_CREDIT);
+ }
+
+ public void testConsumerCount() throws Exception
+ {
+ assertStatistic("consumerCount", 3, Queue.CONSUMER_COUNT);
+ }
+
+ /********** Simple Attributes **********/
+
+ public void testGetQueueDescription() throws Exception
+ {
+ assertAttribute("description", QUEUE_DESCRIPTION, Queue.DESCRIPTION);
+ }
+
+ public void testSetQueueDescription() throws Exception
{
- when(_mockQueue.getAttribute(Queue.DESCRIPTION)).thenReturn(QUEUE_DESCRIPTION);
+ testSetAttribute("description", Queue.DESCRIPTION, "descriptionold", "descriptionnew");
+ }
- assertEquals(QUEUE_DESCRIPTION, _queueMBean.getDescription());
+ public void testQueueType() throws Exception
+ {
+ assertAttribute("queueType", QUEUE_TYPE, Queue.TYPE);
}
- public void testSetQueueDescription()
+ public void testMaximumDeliveryCount() throws Exception
{
- _queueMBean.setDescription(QUEUE_DESCRIPTION);
- verify(_mockQueue).setAttribute(Queue.DESCRIPTION, null, QUEUE_DESCRIPTION);
+ assertAttribute("maximumDeliveryCount", 5, Queue.MAXIMUM_DELIVERY_ATTEMPTS);
}
- public void testQueueType()
+ public void testOwner() throws Exception
{
- when(_mockQueue.getAttribute(Queue.TYPE)).thenReturn(QUEUE_TYPE);
+ assertAttribute("owner", "testOwner", Queue.OWNER);
+ }
- assertEquals(QUEUE_TYPE, _queueMBean.getQueueType());
+ public void testIsDurable() throws Exception
+ {
+ when(_mockQueue.isDurable()).thenReturn(true);
+ assertTrue(_queueMBean.isDurable());
}
+ public void testIsNotDurable() throws Exception
+ {
+ when(_mockQueue.isDurable()).thenReturn(false);
+ assertFalse(_queueMBean.isDurable());
+ }
+
+ public void testIsAutoDelete() throws Exception
+ {
+ when(_mockQueue.getLifetimePolicy()).thenReturn(LifetimePolicy.AUTO_DELETE);
+ assertTrue(_queueMBean.isAutoDelete());
+ }
+
+ public void testIsNotAutoDelete() throws Exception
+ {
+ when(_mockQueue.getLifetimePolicy()).thenReturn(LifetimePolicy.PERMANENT);
+ assertFalse(_queueMBean.isAutoDelete());
+ }
+
+ public void testGetMaximumMessageAge() throws Exception
+ {
+ assertAttribute("maximumMessageAge", 10000l, Queue.ALERT_THRESHOLD_MESSAGE_AGE);
+ }
+
+ public void testSetMaximumMessageAge() throws Exception
+ {
+ testSetAttribute("maximumMessageAge", Queue.ALERT_THRESHOLD_MESSAGE_AGE, 1000l, 10000l);
+ }
+
+ public void testGetMaximumMessageSize() throws Exception
+ {
+ assertAttribute("maximumMessageSize", 1024l, Queue.ALERT_THRESHOLD_MESSAGE_SIZE);
+ }
+
+ public void testSetMaximumMessageSize() throws Exception
+ {
+ testSetAttribute("maximumMessageSize", Queue.ALERT_THRESHOLD_MESSAGE_SIZE, 1024l, 2048l);
+ }
+
+ public void testGetMaximumMessageCount() throws Exception
+ {
+ assertAttribute("maximumMessageCount", 5000l, Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES);
+ }
+
+ public void testSetMaximumMessageCount() throws Exception
+ {
+ testSetAttribute("maximumMessageCount", Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, 4000l, 5000l);
+ }
+
+ public void testGetMaximumQueueDepth() throws Exception
+ {
+ assertAttribute("maximumQueueDepth", 1048576l, Queue.ALERT_THRESHOLD_QUEUE_DEPTH_BYTES);
+ }
+
+ public void testSetMaximumQueueDepth() throws Exception
+ {
+ testSetAttribute("maximumQueueDepth", Queue.ALERT_THRESHOLD_QUEUE_DEPTH_BYTES,1048576l , 2097152l);
+ }
+
+ public void testGetCapacity() throws Exception
+ {
+ assertAttribute("capacity", 1048576l, Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES);
+ }
+
+ public void testSetCapacity() throws Exception
+ {
+ testSetAttribute("capacity", Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES,1048576l , 2097152l);
+ }
+
+ public void testGetFlowResumeCapacity() throws Exception
+ {
+ assertAttribute("flowResumeCapacity", 1048576l, Queue.QUEUE_FLOW_RESUME_SIZE_BYTES);
+ }
+
+ public void testSetFlowResumeCapacity() throws Exception
+ {
+ testSetAttribute("flowResumeCapacity", Queue.QUEUE_FLOW_RESUME_SIZE_BYTES,1048576l , 2097152l);
+ }
+
+ public void testIsExclusive() throws Exception
+ {
+ assertAttribute("exclusive", Boolean.TRUE, Queue.EXCLUSIVE);
+ }
+
+ public void testIsNotExclusive() throws Exception
+ {
+ assertAttribute("exclusive", Boolean.FALSE, Queue.EXCLUSIVE);
+ }
+
+ public void testSetExclusive() throws Exception
+ {
+ testSetAttribute("exclusive", Queue.EXCLUSIVE, Boolean.FALSE , Boolean.TRUE);
+ }
+
+ /********** Other attributes **********/
+
public void testGetAlternateExchange()
{
Exchange mockAlternateExchange = mock(Exchange.class);
@@ -153,6 +293,10 @@ public class QueueMBeanTest extends TestCase
verify(_mockQueue).setAttribute(Queue.ALTERNATE_EXCHANGE, null, null);
}
+ /********** Operations **********/
+
+ /********** Notifications **********/
+
public void testNotificationListenerCalled() throws Exception
{
NotificationListener listener = mock(NotificationListener.class);
@@ -199,4 +343,26 @@ public class QueueMBeanTest extends TestCase
}
});
}
+
+ private void assertStatistic(String jmxAttributeName, Object expectedValue, String underlyingAttributeName) throws Exception
+ {
+ when(_mockQueueStatistics.getStatistic(underlyingAttributeName)).thenReturn(expectedValue);
+ MBeanTestUtils.assertMBeanAttribute(_queueMBean, jmxAttributeName, expectedValue);
+ }
+
+ private void assertAttribute(String jmxAttributeName, Object expectedValue, String underlyingAttributeName) throws Exception
+ {
+ when(_mockQueue.getAttribute(underlyingAttributeName)).thenReturn(expectedValue);
+ MBeanTestUtils.assertMBeanAttribute(_queueMBean, jmxAttributeName, expectedValue);
+ }
+
+ private void testSetAttribute(String jmxAttributeName, String underlyingAttributeName, Object originalAttributeValue, Object newAttributeValue) throws Exception
+ {
+ when(_mockQueue.getAttribute(underlyingAttributeName)).thenReturn(originalAttributeValue);
+
+ MBeanTestUtils.setMBeanAttribute(_queueMBean, jmxAttributeName, newAttributeValue);
+
+ verify(_mockQueue).setAttribute(underlyingAttributeName, originalAttributeValue, newAttributeValue);
+ }
+
}
diff --git a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java
index 7f021bdb32..93a80665a9 100644
--- a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java
+++ b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java
@@ -21,23 +21,32 @@ package org.apache.qpid.server.jmx.mbeans;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.Map;
+import javax.management.OperationsException;
+
import junit.framework.TestCase;
import org.apache.qpid.server.jmx.ManagedObjectRegistry;
+import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.mockito.verification.VerificationMode;
public class VirtualHostManagerMBeanTest extends TestCase
{
private static final String TEST_QUEUE_NAME = "QUEUE_NAME";
+ private static final String TEST_EXCHANGE_NAME = "EXCHANGE_NAME";
private static final String TEST_OWNER = "OWNER";
private static final String TEST_DESCRIPTION = "DESCRIPTION";
+ private static final String TEST_EXCHANGE_TYPE = "EXCHANGE_TYPE";
private static final Map<String, Object> EMPTY_ARGUMENT_MAP = Collections.emptyMap();
@@ -49,6 +58,8 @@ public class VirtualHostManagerMBeanTest extends TestCase
protected void setUp() throws Exception
{
_mockVirtualHost = mock(VirtualHost.class);
+ when(_mockVirtualHost.getExchangeTypes()).thenReturn(Collections.singletonList(TEST_EXCHANGE_TYPE));
+
_mockManagedObjectRegistry = mock(ManagedObjectRegistry.class);
_virtualHostManagerMBean = new VirtualHostManagerMBean(new VirtualHostMBean(_mockVirtualHost, _mockManagedObjectRegistry));
@@ -82,4 +93,83 @@ public class VirtualHostManagerMBeanTest extends TestCase
verify(_mockVirtualHost).createQueue(TEST_QUEUE_NAME, State.ACTIVE, true, false, LifetimePolicy.PERMANENT, 0, expectedArguments);
}
+ public void testDeleteQueue() throws Exception
+ {
+ Queue mockQueue = mock(Queue.class);
+ when(mockQueue.getName()).thenReturn("queue1");
+ when(_mockVirtualHost.getQueues()).thenReturn(Collections.singletonList(mockQueue));
+
+ _virtualHostManagerMBean.deleteQueue("queue1");
+ verify(mockQueue).delete();
+ }
+
+ public void testDeleteQueueWhenQueueDoesNotExist() throws Exception
+ {
+ Queue mockQueue = mock(Queue.class);
+ when(mockQueue.getName()).thenReturn("queue1");
+ when(_mockVirtualHost.getQueues()).thenReturn(Collections.singletonList(mockQueue));
+
+ try
+ {
+ _virtualHostManagerMBean.deleteQueue("unknownqueue");
+ fail("Exception not thrown");
+ }
+ catch(OperationsException oe)
+ {
+ // PASS
+ assertEquals("No such queue \"unknownqueue\"", oe.getMessage());
+ }
+ verify(mockQueue, never()).delete();
+ }
+
+ public void testCreateNewDurableExchange() throws Exception
+ {
+ _virtualHostManagerMBean.createNewExchange(TEST_EXCHANGE_NAME, TEST_EXCHANGE_TYPE, true);
+ verify(_mockVirtualHost).createExchange(TEST_EXCHANGE_NAME, State.ACTIVE, true, LifetimePolicy.PERMANENT, 0, TEST_EXCHANGE_TYPE, EMPTY_ARGUMENT_MAP);
+ }
+
+ public void testCreateNewExchangeWithUnknownExchangeType() throws Exception
+ {
+ String exchangeType = "notknown";
+ try
+ {
+ _virtualHostManagerMBean.createNewExchange(TEST_EXCHANGE_NAME, exchangeType, true);
+ fail("Exception not thrown");
+ }
+ catch (OperationsException oe)
+ {
+ // PASS
+ }
+ verify(_mockVirtualHost, never()).createExchange(TEST_EXCHANGE_NAME, State.ACTIVE, true, LifetimePolicy.PERMANENT, 0, exchangeType, EMPTY_ARGUMENT_MAP);
+ }
+
+ public void testUnregisterExchange() throws Exception
+ {
+ Exchange mockExchange = mock(Exchange.class);
+ when(mockExchange.getName()).thenReturn("exchange1");
+ when(_mockVirtualHost.getExchanges()).thenReturn(Collections.singletonList(mockExchange));
+
+ _virtualHostManagerMBean.unregisterExchange("exchange1");
+ verify(mockExchange).delete();
+ }
+
+ public void testUnregisterExchangeWhenExchangeDoesNotExist() throws Exception
+ {
+ Exchange mockExchange = mock(Exchange.class);
+ when(mockExchange.getName()).thenReturn("exchange1");
+ when(_mockVirtualHost.getExchanges()).thenReturn(Collections.singletonList(mockExchange));
+
+ try
+ {
+ _virtualHostManagerMBean.unregisterExchange("unknownexchange");
+ fail("Exception not thrown");
+ }
+ catch(OperationsException oe)
+ {
+ // PASS
+ assertEquals("No such exchange \"unknownexchange\"", oe.getMessage());
+ }
+
+ verify(mockExchange, never()).delete();
+ }
}
diff --git a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
index 5e6c570e8c..2c341b7f2e 100644
--- a/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
+++ b/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
@@ -33,17 +33,9 @@ import javax.management.ObjectName;
*/
public class BrokerManagementTest extends QpidBrokerTestCase
{
- /**
- * Test virtual host
- */
private static final String VIRTUAL_HOST = "test";
/**
- * Test exchange type
- */
- private static final String EXCHANGE_TYPE = "topic";
-
- /**
* JMX helper.
*/
private JMXTestUtils _jmxUtils;
@@ -82,7 +74,7 @@ public class BrokerManagementTest extends QpidBrokerTestCase
_managedBroker.createNewQueue(queueName, "testowner", true);
// Ensure the queue exists
- assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName("test", queueName));
+ assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName));
assertNotNull("Manager queue expected to be available", _jmxUtils.getManagedQueue(queueName));
// Now verify that the default exchange has been bound.
@@ -104,14 +96,11 @@ public class BrokerManagementTest extends QpidBrokerTestCase
{
String exchangeName = getTestName();
_managedBroker.createNewExchange(exchangeName, "topic", true);
- String queryString = "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost="
- + ObjectName.quote(VIRTUAL_HOST) + ",name=" + ObjectName.quote(exchangeName) + ",ExchangeType="
- + EXCHANGE_TYPE;
- ManagedExchange exchange = _jmxUtils.getManagedObject(ManagedExchange.class, queryString);
+
+ ManagedExchange exchange = _jmxUtils.getManagedExchange(exchangeName);
assertNotNull("Exchange should exist", exchange);
_managedBroker.unregisterExchange(exchangeName);
- assertFalse("Exchange should have been removed", _jmxUtils.isManagedObjectExist(queryString));
}
/**