activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-5685
Date Thu, 16 Apr 2015 16:54:02 GMT
Repository: activemq
Updated Branches:
  refs/heads/master 73db4d2bf -> 9445e93ae


https://issues.apache.org/jira/browse/AMQ-5685

Apply patch from Kevin Richards after adding proper license headers etc

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/9445e93a
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/9445e93a
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/9445e93a

Branch: refs/heads/master
Commit: 9445e93ae4ea518ee631a0c8f3a537c478c15b6c
Parents: 73db4d2
Author: Timothy Bish <tabish121@gmail.com>
Authored: Thu Apr 16 12:53:18 2015 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Thu Apr 16 12:53:49 2015 -0400

----------------------------------------------------------------------
 activemq-web/pom.xml                            |   6 +
 .../apache/activemq/web/LocalBrokerFacade.java  |  83 ++++++++------
 .../activemq/web/LocalBrokerFacadeTest.java     | 114 +++++++++++++++++++
 3 files changed, 169 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/9445e93a/activemq-web/pom.xml
----------------------------------------------------------------------
diff --git a/activemq-web/pom.xml b/activemq-web/pom.xml
index 81d5c4e..790b0a5 100755
--- a/activemq-web/pom.xml
+++ b/activemq-web/pom.xml
@@ -122,6 +122,7 @@
       <groupId>com.thoughtworks.xstream</groupId>
       <artifactId>xstream</artifactId>
     </dependency>
+
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
@@ -132,5 +133,10 @@
       <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq/blob/9445e93a/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java
----------------------------------------------------------------------
diff --git a/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java b/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java
index 99e0cd8..50ef17c 100644
--- a/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java
+++ b/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java
@@ -29,48 +29,57 @@ import org.apache.activemq.broker.jmx.BrokerViewMBean;
 import org.apache.activemq.broker.jmx.ManagedRegionBroker;
 import org.apache.activemq.broker.jmx.ManagementContext;
 import org.apache.activemq.broker.region.Destination;
+import org.apache.activemq.broker.region.DestinationFilter;
 import org.apache.activemq.broker.region.Queue;
 import org.apache.activemq.command.ActiveMQDestination;
 
 /**
  * An implementation of {@link BrokerFacade} which uses a local in JVM broker
- * 
- * 
  */
 public class LocalBrokerFacade extends BrokerFacadeSupport {
-	private BrokerService brokerService;
-
-	public LocalBrokerFacade(BrokerService brokerService) {
-		this.brokerService = brokerService;
-	}
-
-	public BrokerService getBrokerService() {
-		return brokerService;
-	}
-	public String getBrokerName() throws Exception {
-		return brokerService.getBrokerName();
-	}
-	public Broker getBroker() throws Exception {
-		return brokerService.getBroker();
-	}
-	public ManagementContext getManagementContext() {
-		return brokerService.getManagementContext();
-	}
-	public BrokerViewMBean getBrokerAdmin() throws Exception {
-		return brokerService.getAdminView();
-	}
-	public ManagedRegionBroker getManagedBroker() throws Exception {
-		BrokerView adminView = brokerService.getAdminView();
-		if (adminView == null) {
-			return null;
-		}
-		return adminView.getBroker();
-	}
 
+    private final BrokerService brokerService;
+
+    public LocalBrokerFacade(BrokerService brokerService) {
+        this.brokerService = brokerService;
+    }
+
+    public BrokerService getBrokerService() {
+        return brokerService;
+    }
+
+    @Override
+    public String getBrokerName() throws Exception {
+        return brokerService.getBrokerName();
+    }
+
+    public Broker getBroker() throws Exception {
+        return brokerService.getBroker();
+    }
+
+    @Override
+    public ManagementContext getManagementContext() {
+        return brokerService.getManagementContext();
+    }
+
+    @Override
+    public BrokerViewMBean getBrokerAdmin() throws Exception {
+        return brokerService.getAdminView();
+    }
+
+    public ManagedRegionBroker getManagedBroker() throws Exception {
+        BrokerView adminView = brokerService.getAdminView();
+        if (adminView == null) {
+            return null;
+        }
+        return adminView.getBroker();
+    }
+
+    @Override
     public void purgeQueue(ActiveMQDestination destination) throws Exception {
-        Set destinations = getManagedBroker().getQueueRegion().getDestinations(destination);
-        for (Iterator i = destinations.iterator(); i.hasNext();) {
-            Destination dest = (Destination) i.next();
+        Set<Destination> destinations = getManagedBroker().getQueueRegion().getDestinations(destination);
+        for (Iterator<Destination> i = destinations.iterator(); i.hasNext();) {
+            Destination dest = unwrap(i.next());
             if (dest instanceof Queue) {
                 Queue regionQueue = (Queue) dest;
                 regionQueue.purge();
@@ -78,6 +87,13 @@ public class LocalBrokerFacade extends BrokerFacadeSupport {
         }
     }
 
+    private Destination unwrap(Destination dest) {
+        if (dest instanceof DestinationFilter) {
+            return unwrap(((DestinationFilter) dest).getNext());
+        }
+        return dest;
+    }
+
     @Override
     public Set queryNames(ObjectName name, QueryExp query) throws Exception {
         return getManagementContext().queryNames(name, query);
@@ -87,5 +103,4 @@ public class LocalBrokerFacade extends BrokerFacadeSupport {
     public Object newProxyInstance(ObjectName objectName, Class interfaceClass, boolean notificationBroadcaster)
{
         return getManagementContext().newProxyInstance(objectName, interfaceClass, notificationBroadcaster);
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/9445e93a/activemq-web/src/test/java/org/apache/activemq/web/LocalBrokerFacadeTest.java
----------------------------------------------------------------------
diff --git a/activemq-web/src/test/java/org/apache/activemq/web/LocalBrokerFacadeTest.java
b/activemq-web/src/test/java/org/apache/activemq/web/LocalBrokerFacadeTest.java
new file mode 100644
index 0000000..37961e9
--- /dev/null
+++ b/activemq-web/src/test/java/org/apache/activemq/web/LocalBrokerFacadeTest.java
@@ -0,0 +1,114 @@
+/**
+ * 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.activemq.web;
+
+import static com.google.common.collect.Sets.newHashSet;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.BrokerView;
+import org.apache.activemq.broker.jmx.ManagedRegionBroker;
+import org.apache.activemq.broker.region.Destination;
+import org.apache.activemq.broker.region.DestinationFilter;
+import org.apache.activemq.broker.region.Queue;
+import org.apache.activemq.broker.region.Region;
+import org.apache.activemq.command.ActiveMQDestination;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class LocalBrokerFacadeTest {
+
+    @Mock
+    private BrokerService brokerService;
+    @Mock
+    private BrokerView brokerView;
+    @Mock
+    private Queue queue;
+    @Mock
+    private Queue otherQueue;
+    @Mock
+    private ManagedRegionBroker managedRegionBroker;
+    @Mock
+    private Region region;
+    @Mock
+    private ActiveMQDestination destination;
+
+    @Test
+    public void testPurgeQueueWorksForSimpleQueue() throws Exception {
+        LocalBrokerFacade facade = new LocalBrokerFacade(brokerService);
+        when(brokerService.getAdminView()).thenReturn(brokerView);
+        when(brokerView.getBroker()).thenReturn(managedRegionBroker);
+        when(managedRegionBroker.getQueueRegion()).thenReturn(region);
+        when(region.getDestinations(destination)).thenReturn(newHashSet((Destination) queue));
+
+        facade.purgeQueue(destination);
+
+        verify(queue).purge();
+    }
+
+    @Test
+    public void testPurgeQueueWorksForMultipleDestinations() throws Exception {
+        Queue queue1 = mock(Queue.class);
+        Queue queue2 = mock(Queue.class);
+
+        LocalBrokerFacade facade = new LocalBrokerFacade(brokerService);
+        when(brokerService.getAdminView()).thenReturn(brokerView);
+        when(brokerView.getBroker()).thenReturn(managedRegionBroker);
+        when(managedRegionBroker.getQueueRegion()).thenReturn(region);
+        when(region.getDestinations(destination)).thenReturn(newHashSet((Destination) queue1,
queue2));
+
+        facade.purgeQueue(destination);
+
+        verify(queue1).purge();
+        verify(queue2).purge();
+    }
+
+    @Test
+    public void testPurgeQueueWorksForFilterWrappedQueue() throws Exception {
+
+        LocalBrokerFacade facade = new LocalBrokerFacade(brokerService);
+        when(brokerService.getAdminView()).thenReturn(brokerView);
+        when(brokerView.getBroker()).thenReturn(managedRegionBroker);
+        when(managedRegionBroker.getQueueRegion()).thenReturn(region);
+
+        when(region.getDestinations(destination)).thenReturn(newHashSet((Destination) new
DestinationFilter(queue)));
+
+        facade.purgeQueue(destination);
+
+        verify(queue).purge();
+    }
+
+    @Test
+    public void testPurgeQueueWorksForMultipleFiltersWrappingAQueue() throws Exception {
+
+        LocalBrokerFacade facade = new LocalBrokerFacade(brokerService);
+        when(brokerService.getAdminView()).thenReturn(brokerView);
+        when(brokerView.getBroker()).thenReturn(managedRegionBroker);
+        when(managedRegionBroker.getQueueRegion()).thenReturn(region);
+
+        when(region.getDestinations(destination)).thenReturn(newHashSet((Destination) new
DestinationFilter(new DestinationFilter(queue))));
+
+        facade.purgeQueue(destination);
+
+        verify(queue).purge();
+    }
+}


Mime
View raw message