https://issues.apache.org/jira/browse/AMQ-3737 - Possible leak in ManangedRegionBroker unregisterDestination. relates to: https://issues.apache.org/activemq/browse/AMQ-2741 - a leak indeed, or more than a mbean

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1292858 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2012-02-23 17:13:37 +00:00
parent 14350af90c
commit 2290502bc9
2 changed files with 19 additions and 6 deletions

View File

@ -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<ObjectName, DestinationView> map, ObjectName key, DestinationView view) {
private DestinationView removeAndRemember(Map<ObjectName, DestinationView> 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 {

View File

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