mirror of https://github.com/apache/activemq.git
Merging in new JUnit Rule for ActiveMQ unit testing Patch applied with thanks to Quinn Stevenson This closes #163
This commit is contained in:
commit
8317208a1b
|
@ -0,0 +1,70 @@
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.apache.activemq.tooling</groupId>
|
||||||
|
<artifactId>activemq-tooling</artifactId>
|
||||||
|
<version>5.14-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>activemq-junit</artifactId>
|
||||||
|
<name>ActiveMQ :: JUnit Rule</name>
|
||||||
|
|
||||||
|
<description>JUnit Rule for Embedded ActiveMQ Brokers</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.activemq</groupId>
|
||||||
|
<artifactId>activemq-broker</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.activemq</groupId>
|
||||||
|
<artifactId>activemq-spring</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.activemq</groupId>
|
||||||
|
<artifactId>activemq-pool</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>${slf4j-version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,404 @@
|
||||||
|
/*
|
||||||
|
* 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.junit;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
|
import org.apache.activemq.broker.BrokerFactory;
|
||||||
|
import org.apache.activemq.broker.BrokerPlugin;
|
||||||
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
import org.apache.activemq.broker.region.Destination;
|
||||||
|
import org.apache.activemq.broker.region.Queue;
|
||||||
|
import org.apache.activemq.broker.region.Topic;
|
||||||
|
import org.apache.activemq.broker.region.policy.PolicyEntry;
|
||||||
|
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||||
|
import org.apache.activemq.plugin.StatisticsBrokerPlugin;
|
||||||
|
import org.apache.activemq.pool.PooledConnectionFactory;
|
||||||
|
import org.junit.rules.ExternalResource;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JUnit Rule that embeds an ActiveMQ broker into a test.
|
||||||
|
*/
|
||||||
|
public class EmbeddedActiveMQBroker extends ExternalResource {
|
||||||
|
Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
BrokerService brokerService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an embedded ActiveMQ broker using defaults
|
||||||
|
*
|
||||||
|
* The defaults are:
|
||||||
|
* - the broker name is 'embedded-broker'
|
||||||
|
* - JMX is disabled
|
||||||
|
* - Persistence is disabled
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public EmbeddedActiveMQBroker() {
|
||||||
|
brokerService = new BrokerService();
|
||||||
|
brokerService.setUseJmx(false);
|
||||||
|
brokerService.setUseShutdownHook(false);
|
||||||
|
brokerService.setPersistent(false);
|
||||||
|
brokerService.setBrokerName("embedded-broker");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an embedded ActiveMQ broker using a configuration URI
|
||||||
|
*/
|
||||||
|
public EmbeddedActiveMQBroker(String configurationURI ) {
|
||||||
|
try {
|
||||||
|
brokerService = BrokerFactory.createBroker(configurationURI);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException("Exception encountered creating embedded ActiveMQ broker from configuration URI: " + configurationURI, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an embedded ActiveMQ broker using a configuration URI
|
||||||
|
*/
|
||||||
|
public EmbeddedActiveMQBroker(URI configurationURI ) {
|
||||||
|
try {
|
||||||
|
brokerService = BrokerFactory.createBroker(configurationURI);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException("Exception encountered creating embedded ActiveMQ broker from configuration URI: " + configurationURI, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customize the configuration of the embedded ActiveMQ broker
|
||||||
|
*
|
||||||
|
* This method is called before the embedded ActiveMQ broker is started, and can
|
||||||
|
* be overridden to this method to customize the broker configuration.
|
||||||
|
*/
|
||||||
|
protected void configure() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the embedded ActiveMQ broker, blocking until the broker has successfully started.
|
||||||
|
* <p/>
|
||||||
|
* The broker will normally be started by JUnit using the before() method. This method allows the broker to
|
||||||
|
* be started manually to support advanced testing scenarios.
|
||||||
|
*/
|
||||||
|
public void start() {
|
||||||
|
try {
|
||||||
|
this.configure();
|
||||||
|
brokerService.start();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException("Exception encountered starting embedded ActiveMQ broker: {}" + this.getBrokerName(), ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
brokerService.waitUntilStarted();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the embedded ActiveMQ broker, blocking until the broker has stopped.
|
||||||
|
* <p/>
|
||||||
|
* The broker will normally be stopped by JUnit using the after() method. This method allows the broker to
|
||||||
|
* be stopped manually to support advanced testing scenarios.
|
||||||
|
*/
|
||||||
|
public void stop() {
|
||||||
|
if (!brokerService.isStopped()) {
|
||||||
|
try {
|
||||||
|
brokerService.stop();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.warn("Exception encountered stopping embedded ActiveMQ broker: {}" + this.getBrokerName(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
brokerService.waitUntilStopped();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the embedded ActiveMQ Broker
|
||||||
|
* <p/>
|
||||||
|
* Invoked by JUnit to setup the resource
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void before() throws Throwable {
|
||||||
|
log.info("Starting embedded ActiveMQ broker: {}", this.getBrokerName());
|
||||||
|
|
||||||
|
this.start();
|
||||||
|
|
||||||
|
super.before();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the embedded ActiveMQ Broker
|
||||||
|
* <p/>
|
||||||
|
* Invoked by JUnit to tear down the resource
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void after() {
|
||||||
|
log.info("Stopping Embedded ActiveMQ Broker: {}", this.getBrokerName());
|
||||||
|
|
||||||
|
super.after();
|
||||||
|
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an ActiveMQConnectionFactory for the embedded ActiveMQ Broker
|
||||||
|
*
|
||||||
|
* @return a new ActiveMQConnectionFactory
|
||||||
|
*/
|
||||||
|
public ActiveMQConnectionFactory createConnectionFactory() {
|
||||||
|
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
|
||||||
|
connectionFactory.setBrokerURL(brokerService.getVmConnectorURI().toString());
|
||||||
|
return connectionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an PooledConnectionFactory for the embedded ActiveMQ Broker
|
||||||
|
*
|
||||||
|
* @return a new PooledConnectionFactory
|
||||||
|
*/
|
||||||
|
public PooledConnectionFactory createPooledConnectionFactory() {
|
||||||
|
ActiveMQConnectionFactory connectionFactory = createConnectionFactory();
|
||||||
|
|
||||||
|
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
|
||||||
|
|
||||||
|
return pooledConnectionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the BrokerService for the embedded ActiveMQ broker.
|
||||||
|
* <p/>
|
||||||
|
* This may be required for advanced configuration of the BrokerService.
|
||||||
|
*
|
||||||
|
* @return the embedded ActiveMQ broker
|
||||||
|
*/
|
||||||
|
public BrokerService getBrokerService() {
|
||||||
|
return brokerService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the VM URL for the embedded ActiveMQ Broker
|
||||||
|
* <p/>
|
||||||
|
* NOTE: The option is precreate=false option is appended to the URL to avoid the automatic creation of brokers
|
||||||
|
* and the resulting duplicate broker errors
|
||||||
|
*
|
||||||
|
* @return the VM URL for the embedded broker
|
||||||
|
*/
|
||||||
|
public String getVmURL() {
|
||||||
|
return String.format("failover:(%s?create=false)", brokerService.getVmConnectorURI().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the embedded ActiveMQ Broker
|
||||||
|
*
|
||||||
|
* @return name of the embedded broker
|
||||||
|
*/
|
||||||
|
public String getBrokerName() {
|
||||||
|
return brokerService.getBrokerName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBrokerName(String brokerName) {
|
||||||
|
brokerService.setBrokerName(brokerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStatisticsPluginEnabled() {
|
||||||
|
BrokerPlugin[] plugins = brokerService.getPlugins();
|
||||||
|
|
||||||
|
if (null != plugins) {
|
||||||
|
for (BrokerPlugin plugin : plugins) {
|
||||||
|
if (plugin instanceof StatisticsBrokerPlugin) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableStatisticsPlugin() {
|
||||||
|
if (!isStatisticsPluginEnabled()) {
|
||||||
|
BrokerPlugin[] newPlugins;
|
||||||
|
BrokerPlugin[] currentPlugins = brokerService.getPlugins();
|
||||||
|
if (null != currentPlugins && 0 < currentPlugins.length) {
|
||||||
|
newPlugins = new BrokerPlugin[currentPlugins.length + 1];
|
||||||
|
|
||||||
|
System.arraycopy(currentPlugins, 0, newPlugins, 0, currentPlugins.length);
|
||||||
|
} else {
|
||||||
|
newPlugins = new BrokerPlugin[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
newPlugins[newPlugins.length - 1] = new StatisticsBrokerPlugin();
|
||||||
|
|
||||||
|
brokerService.setPlugins(newPlugins);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableStatisticsPlugin() {
|
||||||
|
if (isStatisticsPluginEnabled()) {
|
||||||
|
BrokerPlugin[] currentPlugins = brokerService.getPlugins();
|
||||||
|
if (1 < currentPlugins.length) {
|
||||||
|
BrokerPlugin[] newPlugins = new BrokerPlugin[currentPlugins.length - 1];
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (BrokerPlugin plugin : currentPlugins) {
|
||||||
|
if (!(plugin instanceof StatisticsBrokerPlugin)) {
|
||||||
|
newPlugins[i++] = plugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
brokerService.setPlugins(newPlugins);
|
||||||
|
} else {
|
||||||
|
brokerService.setPlugins(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdvisoryForDeliveryEnabled() {
|
||||||
|
return getDefaultPolicyEntry().isAdvisoryForDelivery();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableAdvisoryForDelivery() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForDelivery(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAdvisoryForDelivery() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForDelivery(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdvisoryForConsumedEnabled() {
|
||||||
|
return getDefaultPolicyEntry().isAdvisoryForConsumed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableAdvisoryForConsumed() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForConsumed(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAdvisoryForConsumed() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForConsumed(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdvisoryForDiscardingMessagesEnabled() {
|
||||||
|
return getDefaultPolicyEntry().isAdvisoryForDiscardingMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableAdvisoryForDiscardingMessages() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForDiscardingMessages(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAdvisoryForDiscardingMessages() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForDiscardingMessages(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdvisoryForFastProducersEnabled() {
|
||||||
|
return getDefaultPolicyEntry().isAdvisoryForFastProducers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableAdvisoryForFastProducers() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForFastProducers(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAdvisoryForFastProducers() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForFastProducers(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdvisoryForSlowConsumersEnabled() {
|
||||||
|
return getDefaultPolicyEntry().isAdvisoryForSlowConsumers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableAdvisoryForSlowConsumers() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForSlowConsumers(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAdvisoryForSlowConsumers() {
|
||||||
|
getDefaultPolicyEntry().setAdvisoryForSlowConsumers(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of messages in a specific JMS Destination.
|
||||||
|
* <p/>
|
||||||
|
* The full name of the JMS destination including the prefix should be provided - i.e. queue:myQueue
|
||||||
|
* or topic:myTopic. If the destination type prefix is not included in the destination name, a prefix
|
||||||
|
* of "queue:" is assumed.
|
||||||
|
*
|
||||||
|
* @param fullDestinationName the full name of the JMS Destination
|
||||||
|
* @return the number of messages in the JMS Destination
|
||||||
|
*/
|
||||||
|
public int getMessageCount(String fullDestinationName) throws Exception {
|
||||||
|
final int QUEUE_TYPE = 1;
|
||||||
|
final int TOPIC_TYPE = 2;
|
||||||
|
|
||||||
|
if (null == brokerService) {
|
||||||
|
throw new IllegalStateException("BrokerService has not yet been created - was before() called?");
|
||||||
|
}
|
||||||
|
|
||||||
|
int destinationType = QUEUE_TYPE;
|
||||||
|
String destinationName = fullDestinationName;
|
||||||
|
|
||||||
|
if (fullDestinationName.startsWith("queue:")) {
|
||||||
|
destinationName = fullDestinationName.substring(fullDestinationName.indexOf(':') + 1);
|
||||||
|
} else if (fullDestinationName.startsWith("topic:")) {
|
||||||
|
destinationType = TOPIC_TYPE;
|
||||||
|
destinationName = fullDestinationName.substring(fullDestinationName.indexOf(':') + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int messageCount = -1;
|
||||||
|
boolean foundDestination = false;
|
||||||
|
for (Destination destination : brokerService.getBroker().getDestinationMap().values()) {
|
||||||
|
String tmpName = destination.getName();
|
||||||
|
if (tmpName.equalsIgnoreCase(destinationName)) {
|
||||||
|
switch (destinationType) {
|
||||||
|
case QUEUE_TYPE:
|
||||||
|
if (destination instanceof Queue) {
|
||||||
|
messageCount = destination.getMessageStore().getMessageCount();
|
||||||
|
foundDestination = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TOPIC_TYPE:
|
||||||
|
if (destination instanceof Topic) {
|
||||||
|
messageCount = destination.getMessageStore().getMessageCount();
|
||||||
|
foundDestination = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Should never see this
|
||||||
|
log.error("Type didn't match: {}", destination.getClass().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (foundDestination) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundDestination) {
|
||||||
|
log.warn("Didn't find destination {} in broker {}", fullDestinationName, getBrokerName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return messageCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PolicyEntry getDefaultPolicyEntry() {
|
||||||
|
PolicyMap destinationPolicy = brokerService.getDestinationPolicy();
|
||||||
|
if (null == destinationPolicy) {
|
||||||
|
destinationPolicy = new PolicyMap();
|
||||||
|
brokerService.setDestinationPolicy(destinationPolicy);
|
||||||
|
}
|
||||||
|
|
||||||
|
PolicyEntry defaultEntry = destinationPolicy.getDefaultEntry();
|
||||||
|
if (null == defaultEntry) {
|
||||||
|
defaultEntry = new PolicyEntry();
|
||||||
|
destinationPolicy.setDefaultEntry(defaultEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultEntry;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* 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.junit;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the get/set operations are working properly
|
||||||
|
*/
|
||||||
|
public class EmbeddedActiveMQBrokerConfigTest {
|
||||||
|
|
||||||
|
// Don't use @Rule in this case - just testing getters/setters
|
||||||
|
EmbeddedActiveMQBroker instance;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
instance = new EmbeddedActiveMQBroker();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetVmURL() throws Exception {
|
||||||
|
assertEquals( "Default VM URL in incorrect", "failover:(vm://embedded-broker?create=false)", instance.getVmURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetBrokerName() throws Exception {
|
||||||
|
assertEquals( "Default Broker Name in incorrect", "embedded-broker", instance.getBrokerName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBrokerNameConfig() throws Exception {
|
||||||
|
String dummyName = "test-broker-name";
|
||||||
|
|
||||||
|
instance.setBrokerName( dummyName);
|
||||||
|
|
||||||
|
assertEquals( "Broker Name not set correctly", dummyName, instance.getBrokerName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStatisticsPluginConfig() throws Exception {
|
||||||
|
assertFalse( "Statistics plugin should not be enabled by default", instance.isStatisticsPluginEnabled());
|
||||||
|
instance.enableStatisticsPlugin();
|
||||||
|
assertTrue( "Statistics plugin not enabled", instance.isStatisticsPluginEnabled());
|
||||||
|
instance.disableStatisticsPlugin();
|
||||||
|
assertFalse( "Statistics plugin not disabled", instance.isStatisticsPluginEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForDeliveryConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for delivery should not be enabled by default", instance.isAdvisoryForDeliveryEnabled());
|
||||||
|
instance.enableAdvisoryForDelivery();
|
||||||
|
assertTrue( "Advisory messages for delivery not enabled", instance.isAdvisoryForDeliveryEnabled());
|
||||||
|
instance.disableAdvisoryForDelivery();
|
||||||
|
assertFalse( "Advisory messages for delivery not disabled", instance.isAdvisoryForDeliveryEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForConsumedConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for consumed should not be enabled by default", instance.isAdvisoryForConsumedEnabled());
|
||||||
|
instance.enableAdvisoryForConsumed();
|
||||||
|
assertTrue( "Advisory messages for consumed not enabled", instance.isAdvisoryForConsumedEnabled());
|
||||||
|
instance.disableAdvisoryForConsumed();
|
||||||
|
assertFalse( "Advisory messages for consumed not disabled", instance.isAdvisoryForConsumedEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForDiscardingMessagesConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for discarding messages should not be enabled by default", instance.isAdvisoryForDiscardingMessagesEnabled());
|
||||||
|
instance.enableAdvisoryForDiscardingMessages();
|
||||||
|
assertTrue( "Advisory messages for discarding messages not enabled", instance.isAdvisoryForDiscardingMessagesEnabled());
|
||||||
|
instance.disableAdvisoryForDiscardingMessages();
|
||||||
|
assertFalse( "Advisory messages for discarding messages not disabled", instance.isAdvisoryForDiscardingMessagesEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForFastProducersConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for fast producers should not be enabled by default", instance.isAdvisoryForFastProducersEnabled());
|
||||||
|
instance.enableAdvisoryForFastProducers();
|
||||||
|
assertTrue( "Advisory messages for fast producers not enabled", instance.isAdvisoryForFastProducersEnabled());
|
||||||
|
instance.disableAdvisoryForFastProducers();
|
||||||
|
assertFalse( "Advisory messages for fast producers not disabled", instance.isAdvisoryForFastProducersEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForSlowConsumersConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for slow consumers should not be enabled by default", instance.isAdvisoryForSlowConsumersEnabled());
|
||||||
|
instance.enableAdvisoryForSlowConsumers();
|
||||||
|
assertTrue( "Advisory messages for slow consumers not enabled", instance.isAdvisoryForSlowConsumersEnabled());
|
||||||
|
instance.disableAdvisoryForSlowConsumers();
|
||||||
|
assertFalse( "Advisory messages for slow consumers not disabled", instance.isAdvisoryForSlowConsumersEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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.junit;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class EmbeddedActiveMQBrokerRuleTest {
|
||||||
|
@Rule
|
||||||
|
public EmbeddedActiveMQBroker broker = new EmbeddedActiveMQBroker();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
assertTrue( "Broker should be started", broker.brokerService.isStarted());
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
assertTrue( "Broker should still be running", broker.brokerService.isStarted());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStart() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
* 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.junit;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the xbean configuration URI is working properly
|
||||||
|
*/
|
||||||
|
public class EmbeddedActiveMQBrokerXbeanUriConfigTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public EmbeddedActiveMQBroker instance = new EmbeddedActiveMQBroker( "xbean:activemq-simple.xml");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetVmURL() throws Exception {
|
||||||
|
assertEquals( "Default VM URL in incorrect", "failover:(vm://embedded-broker?create=false)", instance.getVmURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetBrokerName() throws Exception {
|
||||||
|
assertEquals( "Default Broker Name in incorrect", "embedded-broker", instance.getBrokerName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBrokerNameConfig() throws Exception {
|
||||||
|
String dummyName = "test-broker-name";
|
||||||
|
|
||||||
|
instance.setBrokerName( dummyName);
|
||||||
|
|
||||||
|
assertEquals( "Broker Name not set correctly", dummyName, instance.getBrokerName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStatisticsPluginConfig() throws Exception {
|
||||||
|
assertFalse( "Statistics plugin should not be enabled by default", instance.isStatisticsPluginEnabled());
|
||||||
|
instance.enableStatisticsPlugin();
|
||||||
|
assertTrue( "Statistics plugin not enabled", instance.isStatisticsPluginEnabled());
|
||||||
|
instance.disableStatisticsPlugin();
|
||||||
|
assertFalse( "Statistics plugin not disabled", instance.isStatisticsPluginEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForDeliveryConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for delivery should not be enabled by default", instance.isAdvisoryForDeliveryEnabled());
|
||||||
|
instance.enableAdvisoryForDelivery();
|
||||||
|
assertTrue( "Advisory messages for delivery not enabled", instance.isAdvisoryForDeliveryEnabled());
|
||||||
|
instance.disableAdvisoryForDelivery();
|
||||||
|
assertFalse( "Advisory messages for delivery not disabled", instance.isAdvisoryForDeliveryEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForConsumedConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for consumed should not be enabled by default", instance.isAdvisoryForConsumedEnabled());
|
||||||
|
instance.enableAdvisoryForConsumed();
|
||||||
|
assertTrue( "Advisory messages for consumed not enabled", instance.isAdvisoryForConsumedEnabled());
|
||||||
|
instance.disableAdvisoryForConsumed();
|
||||||
|
assertFalse( "Advisory messages for consumed not disabled", instance.isAdvisoryForConsumedEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForDiscardingMessagesConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for discarding messages should not be enabled by default", instance.isAdvisoryForDiscardingMessagesEnabled());
|
||||||
|
instance.enableAdvisoryForDiscardingMessages();
|
||||||
|
assertTrue( "Advisory messages for discarding messages not enabled", instance.isAdvisoryForDiscardingMessagesEnabled());
|
||||||
|
instance.disableAdvisoryForDiscardingMessages();
|
||||||
|
assertFalse( "Advisory messages for discarding messages not disabled", instance.isAdvisoryForDiscardingMessagesEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForFastProducersConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for fast producers should not be enabled by default", instance.isAdvisoryForFastProducersEnabled());
|
||||||
|
instance.enableAdvisoryForFastProducers();
|
||||||
|
assertTrue( "Advisory messages for fast producers not enabled", instance.isAdvisoryForFastProducersEnabled());
|
||||||
|
instance.disableAdvisoryForFastProducers();
|
||||||
|
assertFalse( "Advisory messages for fast producers not disabled", instance.isAdvisoryForFastProducersEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvisoryForSlowConsumersConfig() throws Exception {
|
||||||
|
assertFalse( "Advisory messages for slow consumers should not be enabled by default", instance.isAdvisoryForSlowConsumersEnabled());
|
||||||
|
instance.enableAdvisoryForSlowConsumers();
|
||||||
|
assertTrue( "Advisory messages for slow consumers not enabled", instance.isAdvisoryForSlowConsumersEnabled());
|
||||||
|
instance.disableAdvisoryForSlowConsumers();
|
||||||
|
assertFalse( "Advisory messages for slow consumers not disabled", instance.isAdvisoryForSlowConsumersEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* 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.junit;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class MultipleEmbeddedActiveMQBrokerRuleTest {
|
||||||
|
final String brokerOneName = "broker-one";
|
||||||
|
final String brokerTwoName = "broker-two";
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public EmbeddedActiveMQBroker brokerOne = new EmbeddedActiveMQBroker();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public EmbeddedActiveMQBroker brokerTwo = new EmbeddedActiveMQBroker();
|
||||||
|
|
||||||
|
public MultipleEmbeddedActiveMQBrokerRuleTest() {
|
||||||
|
// Perform and broker configuation here before JUnit starts the brokers
|
||||||
|
brokerOne.setBrokerName( brokerOneName);
|
||||||
|
brokerTwo.setBrokerName( brokerTwoName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
assertTrue( "Broker One should be started", brokerOne.brokerService.isStarted());
|
||||||
|
assertTrue( "Broker Two should be started", brokerTwo.brokerService.isStarted());
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
assertTrue( "Broker One should still be running", brokerOne.brokerService.isStarted());
|
||||||
|
assertTrue( "Broker Two should still be running", brokerTwo.brokerService.isStarted());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStart() throws Exception {
|
||||||
|
assertEquals( "Broker One name is incorrect", brokerOneName, brokerOne.getBrokerName());
|
||||||
|
assertEquals( "Broker Two name is incorrect", brokerTwoName, brokerTwo.getBrokerName());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<beans
|
||||||
|
xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||||
|
|
||||||
|
<broker xmlns="http://activemq.apache.org/schema/core"
|
||||||
|
brokerName="embedded-broker" persistent="false" useJmx="false" useShutdownHook="false" >
|
||||||
|
|
||||||
|
</broker>
|
||||||
|
|
||||||
|
</beans>
|
|
@ -34,5 +34,6 @@
|
||||||
<module>activemq-memtest-maven-plugin</module>
|
<module>activemq-memtest-maven-plugin</module>
|
||||||
<module>activemq-perf-maven-plugin</module>
|
<module>activemq-perf-maven-plugin</module>
|
||||||
<module>activemq-maven-plugin</module>
|
<module>activemq-maven-plugin</module>
|
||||||
|
<module>activemq-junit</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
||||||
|
|
Loading…
Reference in New Issue