diff options
| author | Marnie McCormack <marnie@apache.org> | 2010-07-05 20:00:54 +0000 |
|---|---|---|
| committer | Marnie McCormack <marnie@apache.org> | 2010-07-05 20:00:54 +0000 |
| commit | 3c57e4b18865b717404ea41efbd4b80516a92a33 (patch) | |
| tree | 4ca087388cc0ee54ef99961f48b4340c08d05feb /java/broker/src | |
| parent | 0f7f0aa39aabb79d49f0fb7294fa233d3f8d5981 (diff) | |
| download | qpid-python-3c57e4b18865b717404ea41efbd4b80516a92a33.tar.gz | |
QPID-2700 Patch for ability to remove bindings from exchanges and additional tests for direct and topic exchange add/remove logic from Andrew Kennedy
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@960678 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker/src')
| -rw-r--r-- | java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java | 31 | ||||
| -rw-r--r-- | java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java | 79 |
2 files changed, 110 insertions, 0 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java index 0dca91b7be..c69d499674 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java +++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java @@ -20,6 +20,9 @@ */ package org.apache.qpid.server.exchange; +import java.util.Collections; +import java.util.Map; + import org.apache.qpid.AMQException; import org.apache.qpid.AMQSecurityException; import org.apache.qpid.server.management.AMQManagedObject; @@ -28,6 +31,7 @@ import org.apache.qpid.server.management.ManagedObjectRegistry; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.server.binding.BindingFactory; import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.logging.actors.ManagementActor; import org.apache.qpid.management.common.mbeans.ManagedExchange; @@ -147,4 +151,31 @@ public abstract class AbstractExchangeMBean<T extends AbstractExchange> extends } CurrentActor.remove(); } + + /** + * Removes a queue binding from the exchange. + * + * @see BindingFactory#removeBinding(String, AMQQueue, Exchange, Map) + */ + public void removeBinding(String queueName, String binding) throws JMException + { + VirtualHost vhost = getExchange().getVirtualHost(); + AMQQueue queue = vhost.getQueueRegistry().getQueue(new AMQShortString(queueName)); + if (queue == null) + { + throw new JMException("Queue \"" + queueName + "\" is not registered with the exchange."); + } + + CurrentActor.set(new ManagementActor(_logActor.getRootMessageLogger())); + try + { + vhost.getBindingFactory().removeBinding(binding, queue, _exchange, Collections.<String, Object>emptyMap()); + } + catch (AMQException ex) + { + JMException jme = new JMException(ex.toString()); + throw new MBeanException(jme, "Error removing binding " + binding); + } + CurrentActor.remove(); + } } diff --git a/java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java b/java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java index e3e736509e..b51c88680e 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java +++ b/java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java @@ -36,6 +36,7 @@ import org.apache.qpid.framing.AMQShortString; import javax.management.openmbean.TabularData; import java.util.ArrayList; +import java.util.Collections; /** * Unit test class for testing different Exchange MBean operations @@ -126,6 +127,84 @@ public class ExchangeMBeanTest extends InternalBrokerBaseCase assertTrue(!mbean.isDurable()); assertTrue(mbean.isAutoDelete()); } + + /** + * Test adding bindings and removing them from the topic exchange via JMX. + * <p> + * QPID-2700 + */ + public void testTopicBindings() throws Exception + { + int bindings = _queue.getBindingCount(); + + Exchange exchange = _queue.getVirtualHost().getExchangeRegistry().getExchange(new AMQShortString("amq.topic")); + ManagedExchange mbean = (ManagedExchange) ((AbstractExchange) exchange).getManagedObject(); + + mbean.createNewBinding(_queue.getName(), "robot.#"); + mbean.createNewBinding(_queue.getName(), "#.kitten"); + + assertEquals("Should have added two bindings", bindings + 2, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "robot.#"); + + assertEquals("Should have one extra binding", bindings + 1, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "#.kitten"); + + assertEquals("Should have original number of binding", bindings, _queue.getBindingCount()); + } + + /** + * Test adding bindings and removing them from the default exchange via JMX. + * <p> + * QPID-2700 + */ + public void testDefaultBindings() throws Exception + { + int bindings = _queue.getBindingCount(); + + Exchange exchange = _queue.getVirtualHost().getExchangeRegistry().getDefaultExchange(); + ManagedExchange mbean = (ManagedExchange) ((AbstractExchange) exchange).getManagedObject(); + + mbean.createNewBinding(_queue.getName(), "robot"); + mbean.createNewBinding(_queue.getName(), "kitten"); + + assertEquals("Should have added two bindings", bindings + 2, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "robot"); + + assertEquals("Should have one extra binding", bindings + 1, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "kitten"); + + assertEquals("Should have original number of binding", bindings, _queue.getBindingCount()); + } + + /** + * Test adding bindings and removing them from the topic exchange via JMX. + * <p> + * QPID-2700 + */ + public void testTopicBindings() throws Exception + { + int bindings = _queue.getBindingCount(); + + Exchange exchange = _queue.getVirtualHost().getExchangeRegistry().getExchange(new AMQShortString("amq.topic")); + ManagedExchange mbean = (ManagedExchange) ((AbstractExchange) exchange).getManagedObject(); + + mbean.createNewBinding(_queue.getName(), "robot.#"); + mbean.createNewBinding(_queue.getName(), "#.kitten"); + + assertEquals("Should have added two bindings", bindings + 2, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "robot.#"); + + assertEquals("Should have one extra binding", bindings + 1, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "#.kitten"); + + assertEquals("Should have original number of binding", bindings, _queue.getBindingCount()); + } @Override public void setUp() throws Exception |
