diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java index c1929ce417..858fd34522 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java @@ -346,11 +346,10 @@ public class ManagedRegionBroker extends RegionBroker { protected void unregisterDestination(ObjectName key) throws Exception { - DestinationView view = null; - removeAndRemember(topics, key, view); - removeAndRemember(queues, key, view); - removeAndRemember(temporaryQueues, key, view); - removeAndRemember(temporaryTopics, key, view); + DestinationView view = removeAndRemember(topics, key, null); + view = removeAndRemember(queues, key, view); + view = removeAndRemember(temporaryQueues, key, view); + view = removeAndRemember(temporaryTopics, key, view); if (registeredMBeans.remove(key)) { try { managementContext.unregisterMBean(key); @@ -417,11 +416,12 @@ public class ManagedRegionBroker extends RegionBroker { } } - private void removeAndRemember(Map map, ObjectName key, DestinationView view) { + private DestinationView removeAndRemember(Map map, ObjectName key, DestinationView view) { DestinationView candidate = map.remove(key); if (candidate != null && view == null) { view = candidate; } + return candidate != null ? candidate : view; } protected void registerSubscription(ObjectName key, ConsumerInfo info, SubscriptionKey subscriptionKey, SubscriptionView view) throws Exception { diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/policy/AbortSlowConsumerTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/policy/AbortSlowConsumerTest.java index 162e3419be..583fe83d6a 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/policy/AbortSlowConsumerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/policy/AbortSlowConsumerTest.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.broker.policy; +import javax.management.InstanceNotFoundException; import junit.framework.Test; import org.apache.activemq.JmsMultipleClientsTestSupport; import org.apache.activemq.broker.BrokerService; @@ -37,6 +38,7 @@ import javax.jms.Session; import javax.management.ObjectName; import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; +import java.lang.reflect.UndeclaredThrowableException; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; @@ -173,6 +175,17 @@ public class AbortSlowConsumerTest extends JmsMultipleClientsTestSupport impleme slowOnes = abortPolicy.getSlowConsumers(); assertEquals("no slow consumers left", 0, slowOnes.size()); + // verify mbean gone with destination + broker.getAdminView().removeTopic(amqDest.getPhysicalName()); + + try { + abortPolicy.getSlowConsumers(); + fail("expect not found post destination removal"); + } catch(UndeclaredThrowableException expected) { + assertTrue("correct exception: " + expected.getCause(), + expected.getCause() instanceof InstanceNotFoundException); + } + }