mirror of https://github.com/apache/activemq.git
Apply patch from Kevin Richards after adding proper license headers etc
This commit is contained in:
parent
73db4d2bfd
commit
9445e93ae4
|
@ -122,6 +122,7 @@
|
||||||
<groupId>com.thoughtworks.xstream</groupId>
|
<groupId>com.thoughtworks.xstream</groupId>
|
||||||
<artifactId>xstream</artifactId>
|
<artifactId>xstream</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -132,5 +133,10 @@
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -29,16 +29,16 @@ import org.apache.activemq.broker.jmx.BrokerViewMBean;
|
||||||
import org.apache.activemq.broker.jmx.ManagedRegionBroker;
|
import org.apache.activemq.broker.jmx.ManagedRegionBroker;
|
||||||
import org.apache.activemq.broker.jmx.ManagementContext;
|
import org.apache.activemq.broker.jmx.ManagementContext;
|
||||||
import org.apache.activemq.broker.region.Destination;
|
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.Queue;
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of {@link BrokerFacade} which uses a local in JVM broker
|
* An implementation of {@link BrokerFacade} which uses a local in JVM broker
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class LocalBrokerFacade extends BrokerFacadeSupport {
|
public class LocalBrokerFacade extends BrokerFacadeSupport {
|
||||||
private BrokerService brokerService;
|
|
||||||
|
private final BrokerService brokerService;
|
||||||
|
|
||||||
public LocalBrokerFacade(BrokerService brokerService) {
|
public LocalBrokerFacade(BrokerService brokerService) {
|
||||||
this.brokerService = brokerService;
|
this.brokerService = brokerService;
|
||||||
|
@ -47,18 +47,26 @@ public class LocalBrokerFacade extends BrokerFacadeSupport {
|
||||||
public BrokerService getBrokerService() {
|
public BrokerService getBrokerService() {
|
||||||
return brokerService;
|
return brokerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getBrokerName() throws Exception {
|
public String getBrokerName() throws Exception {
|
||||||
return brokerService.getBrokerName();
|
return brokerService.getBrokerName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Broker getBroker() throws Exception {
|
public Broker getBroker() throws Exception {
|
||||||
return brokerService.getBroker();
|
return brokerService.getBroker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ManagementContext getManagementContext() {
|
public ManagementContext getManagementContext() {
|
||||||
return brokerService.getManagementContext();
|
return brokerService.getManagementContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BrokerViewMBean getBrokerAdmin() throws Exception {
|
public BrokerViewMBean getBrokerAdmin() throws Exception {
|
||||||
return brokerService.getAdminView();
|
return brokerService.getAdminView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManagedRegionBroker getManagedBroker() throws Exception {
|
public ManagedRegionBroker getManagedBroker() throws Exception {
|
||||||
BrokerView adminView = brokerService.getAdminView();
|
BrokerView adminView = brokerService.getAdminView();
|
||||||
if (adminView == null) {
|
if (adminView == null) {
|
||||||
|
@ -67,10 +75,11 @@ public class LocalBrokerFacade extends BrokerFacadeSupport {
|
||||||
return adminView.getBroker();
|
return adminView.getBroker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void purgeQueue(ActiveMQDestination destination) throws Exception {
|
public void purgeQueue(ActiveMQDestination destination) throws Exception {
|
||||||
Set destinations = getManagedBroker().getQueueRegion().getDestinations(destination);
|
Set<Destination> destinations = getManagedBroker().getQueueRegion().getDestinations(destination);
|
||||||
for (Iterator i = destinations.iterator(); i.hasNext();) {
|
for (Iterator<Destination> i = destinations.iterator(); i.hasNext();) {
|
||||||
Destination dest = (Destination) i.next();
|
Destination dest = unwrap(i.next());
|
||||||
if (dest instanceof Queue) {
|
if (dest instanceof Queue) {
|
||||||
Queue regionQueue = (Queue) dest;
|
Queue regionQueue = (Queue) dest;
|
||||||
regionQueue.purge();
|
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
|
@Override
|
||||||
public Set queryNames(ObjectName name, QueryExp query) throws Exception {
|
public Set queryNames(ObjectName name, QueryExp query) throws Exception {
|
||||||
return getManagementContext().queryNames(name, query);
|
return getManagementContext().queryNames(name, query);
|
||||||
|
@ -87,5 +103,4 @@ public class LocalBrokerFacade extends BrokerFacadeSupport {
|
||||||
public Object newProxyInstance(ObjectName objectName, Class interfaceClass, boolean notificationBroadcaster) {
|
public Object newProxyInstance(ObjectName objectName, Class interfaceClass, boolean notificationBroadcaster) {
|
||||||
return getManagementContext().newProxyInstance(objectName, interfaceClass, notificationBroadcaster);
|
return getManagementContext().newProxyInstance(objectName, interfaceClass, notificationBroadcaster);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue