AMQP-678: Move BrokerRunning @Rule to junit Jar
JIRA: https://jira.spring.io/browse/AMQP-678 Convert `BrokerRunning` to use the amqp-client directly to avoid circular reference. Also `LongRunningIntegrationTest`. Polishing - PR Comments
This commit is contained in:
committed by
Artem Bilan
parent
e656c1250a
commit
4fded3dde1
20
build.gradle
20
build.gradle
@@ -95,9 +95,9 @@ subprojects { subproject ->
|
||||
rabbitmqVersion = project.hasProperty('rabbitmqVersion') ? project.rabbitmqVersion : '4.0.0'
|
||||
rabbitmqHttpClientVersion = '1.1.0.RELEASE'
|
||||
|
||||
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.0.0.M3'
|
||||
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.0.0.BUILD-SNAPSHOT'
|
||||
|
||||
springRetryVersion = '1.2.0.RC1'
|
||||
springRetryVersion = '1.2.0.BUILD-SNAPSHOT'
|
||||
}
|
||||
|
||||
eclipse {
|
||||
@@ -230,12 +230,27 @@ project('spring-rabbit') {
|
||||
|
||||
compile ("org.apache.logging.log4j:log4j-core:$log4jVersion", optional)
|
||||
|
||||
testCompile project(":spring-rabbit-junit")
|
||||
testCompile "commons-cli:commons-cli:$commonsCliVersion"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
project('spring-rabbit-junit') {
|
||||
description = 'Spring Rabbit JUnit Support'
|
||||
|
||||
dependencies {
|
||||
|
||||
compile "org.springframework:spring-core:$springVersion"
|
||||
compile "junit:junit:$junitVersion"
|
||||
compile "com.rabbitmq:amqp-client:$rabbitmqVersion"
|
||||
compile "com.rabbitmq:http-client:$rabbitmqHttpClientVersion"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
project('spring-rabbit-test') {
|
||||
description = 'Spring Rabbit Test Support'
|
||||
|
||||
@@ -250,6 +265,7 @@ project('spring-rabbit-test') {
|
||||
exclude group: 'org.hamcrest', module: 'hamcrest-core'
|
||||
}
|
||||
testCompile project(":spring-rabbit").sourceSets.test.output
|
||||
testCompile project(":spring-rabbit-junit")
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,4 +2,5 @@ rootProject.name = 'spring-amqp-dist'
|
||||
|
||||
include 'spring-amqp'
|
||||
include 'spring-rabbit'
|
||||
include 'spring-rabbit-junit'
|
||||
include 'spring-rabbit-test'
|
||||
|
||||
3
spring-rabbit-junit/README.adoc
Normal file
3
spring-rabbit-junit/README.adoc
Normal file
@@ -0,0 +1,3 @@
|
||||
= spring-rabbit-test
|
||||
|
||||
This project provides testing support classes to help with testing `spring-rabbit` applications.
|
||||
@@ -14,13 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.amqp.rabbit.test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
package org.springframework.amqp.rabbit.junit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -30,12 +34,12 @@ import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.springframework.amqp.AmqpTimeoutException;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.util.Base64Utils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
import com.rabbitmq.http.client.Client;
|
||||
|
||||
/**
|
||||
@@ -65,9 +69,13 @@ import com.rabbitmq.http.client.Client;
|
||||
* @author Dave Syer
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
*/
|
||||
public final class BrokerRunning extends TestWatcher {
|
||||
|
||||
public static final String BROKER_REQUIRED = "RABBITMQ_SERVER_REQUIRED";
|
||||
|
||||
private static final String DEFAULT_QUEUE_NAME = BrokerRunning.class.getName();
|
||||
|
||||
private static Log logger = LogFactory.getLog(BrokerRunning.class);
|
||||
@@ -84,36 +92,24 @@ public final class BrokerRunning extends TestWatcher {
|
||||
|
||||
private final boolean management;
|
||||
|
||||
private final Queue[] queues;
|
||||
private final String[] queues;
|
||||
|
||||
private final int DEFAULT_PORT = BrokerTestUtils.getPort();
|
||||
private final int defaultPort = BrokerTestUtils.getPort();
|
||||
|
||||
private int port;
|
||||
|
||||
private String hostName = null;
|
||||
|
||||
private RabbitAdmin admin;
|
||||
private ConnectionFactory connectionFactory;
|
||||
|
||||
/**
|
||||
* Ensure the broker is running and has an empty queue with the specified name in the default exchange.
|
||||
*
|
||||
* @param names the queues to declare for the test.
|
||||
* @return a new rule that assumes an existing running broker
|
||||
*/
|
||||
public static BrokerRunning isRunningWithEmptyQueues(String... names) {
|
||||
Queue[] queues = new Queue[names.length];
|
||||
for (int i = 0; i < queues.length; i++) {
|
||||
queues[i] = new Queue(names[i]);
|
||||
}
|
||||
return new BrokerRunning(true, true, queues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the broker is running and has an empty queue (which can be addressed via the default exchange).
|
||||
*
|
||||
* @return a new rule that assumes an existing running broker
|
||||
*/
|
||||
public static BrokerRunning isRunningWithEmptyQueues(Queue... queues) {
|
||||
return new BrokerRunning(true, true, queues);
|
||||
return new BrokerRunning(true, true, names);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,34 +128,33 @@ public final class BrokerRunning extends TestWatcher {
|
||||
|
||||
/**
|
||||
* @return a new rule that assumes an existing broker with the management plugin
|
||||
* @since 1.5
|
||||
*/
|
||||
public static BrokerRunning isBrokerAndManagementRunning() {
|
||||
return new BrokerRunning(true, false, true);
|
||||
}
|
||||
|
||||
private BrokerRunning(boolean assumeOnline, boolean purge, Queue... queues) {
|
||||
private BrokerRunning(boolean assumeOnline, boolean purge, String... queues) {
|
||||
this(assumeOnline, purge, false, queues);
|
||||
}
|
||||
|
||||
private BrokerRunning(boolean assumeOnline, boolean purge, boolean management, Queue... queues) {
|
||||
private BrokerRunning(boolean assumeOnline, boolean purge, boolean management, String... queues) {
|
||||
this.assumeOnline = assumeOnline;
|
||||
this.queues = queues;
|
||||
this.purge = purge;
|
||||
this.management = management;
|
||||
setPort(DEFAULT_PORT);
|
||||
setPort(this.defaultPort);
|
||||
}
|
||||
|
||||
private BrokerRunning(boolean assumeOnline, Queue... queues) {
|
||||
private BrokerRunning(boolean assumeOnline, String... queues) {
|
||||
this(assumeOnline, false, queues);
|
||||
}
|
||||
|
||||
private BrokerRunning(boolean assumeOnline) {
|
||||
this(assumeOnline, new Queue(DEFAULT_QUEUE_NAME));
|
||||
this(assumeOnline, DEFAULT_QUEUE_NAME);
|
||||
}
|
||||
|
||||
private BrokerRunning(boolean assumeOnline, boolean purge, boolean management) {
|
||||
this(assumeOnline, purge, management, new Queue(DEFAULT_QUEUE_NAME));
|
||||
this(assumeOnline, purge, management, DEFAULT_QUEUE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,45 +181,42 @@ public final class BrokerRunning extends TestWatcher {
|
||||
public Statement apply(Statement base, Description description) {
|
||||
|
||||
// Check at the beginning, so this can be used as a static field
|
||||
if (assumeOnline) {
|
||||
Assume.assumeTrue(brokerOnline.get(port));
|
||||
if (this.assumeOnline) {
|
||||
Assume.assumeTrue(brokerOnline.get(this.port));
|
||||
}
|
||||
else {
|
||||
Assume.assumeTrue(brokerOffline.get(port));
|
||||
Assume.assumeTrue(brokerOffline.get(this.port));
|
||||
}
|
||||
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
||||
connectionFactory.setHost("localhost");
|
||||
ConnectionFactory connectionFactory = getConnectionFactory();
|
||||
|
||||
Connection connection = null;
|
||||
Channel channel = null;
|
||||
|
||||
try {
|
||||
connection = connectionFactory.newConnection();
|
||||
connection.setId(generateId());
|
||||
channel = connection.createChannel();
|
||||
|
||||
connectionFactory.setPort(port);
|
||||
if (StringUtils.hasText(hostName)) {
|
||||
connectionFactory.setHost(hostName);
|
||||
}
|
||||
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
|
||||
this.admin = admin;
|
||||
for (String queueName : this.queues) {
|
||||
|
||||
for (Queue queue : queues) {
|
||||
String queueName = queue.getName();
|
||||
|
||||
if (purge) {
|
||||
if (this.purge) {
|
||||
logger.debug("Deleting queue: " + queueName);
|
||||
// Delete completely - gets rid of consumers and bindings as well
|
||||
admin.deleteQueue(queueName);
|
||||
channel.queueDelete(queueName);
|
||||
}
|
||||
|
||||
if (isDefaultQueue(queueName)) {
|
||||
// Just for test probe.
|
||||
admin.deleteQueue(queueName);
|
||||
channel.queueDelete(queueName);
|
||||
}
|
||||
else {
|
||||
admin.declareQueue(queue);
|
||||
channel.queueDeclare(queueName, true, false, false, null);
|
||||
}
|
||||
}
|
||||
brokerOffline.put(port, false);
|
||||
if (!assumeOnline) {
|
||||
Assume.assumeTrue(brokerOffline.get(port));
|
||||
brokerOffline.put(this.port, false);
|
||||
if (!this.assumeOnline) {
|
||||
Assume.assumeTrue(brokerOffline.get(this.port));
|
||||
}
|
||||
|
||||
if (this.management) {
|
||||
@@ -235,45 +227,146 @@ public final class BrokerRunning extends TestWatcher {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (AmqpTimeoutException e) {
|
||||
fail("Timed out getting connection");
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("Not executing tests because basic connectivity test failed", e);
|
||||
brokerOnline.put(port, false);
|
||||
if (assumeOnline) {
|
||||
brokerOnline.put(this.port, false);
|
||||
if (this.assumeOnline && !fatal()) {
|
||||
Assume.assumeNoException(e);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
connectionFactory.destroy();
|
||||
closeResources(connection, channel);
|
||||
}
|
||||
|
||||
return super.apply(base, description);
|
||||
}
|
||||
|
||||
private boolean fatal() {
|
||||
String serversRequired = System.getenv(BROKER_REQUIRED);
|
||||
if (Boolean.parseBoolean(serversRequired)) {
|
||||
logger.error("RABBITMQ IS REQUIRED BUT NOT AVAILABLE");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String generateId() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
|
||||
bb.putLong(uuid.getMostSignificantBits())
|
||||
.putLong(uuid.getLeastSignificantBits());
|
||||
return "SpringBrokerRunning." + Base64Utils.encodeToUrlSafeString(bb.array()).replaceAll("=", "");
|
||||
}
|
||||
|
||||
private boolean isDefaultQueue(String queue) {
|
||||
return DEFAULT_QUEUE_NAME.equals(queue);
|
||||
}
|
||||
|
||||
public RabbitAdmin getAdmin() {
|
||||
return this.admin;
|
||||
}
|
||||
|
||||
public void removeTestQueues(String... additionalQueues) {
|
||||
logger.debug("deleting test queues: " + Arrays.toString(additionalQueues));
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
||||
connectionFactory.setHost("localhost");
|
||||
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
|
||||
for (Queue queue : this.queues) {
|
||||
admin.deleteQueue(queue.getName());
|
||||
}
|
||||
List<String> queuesToRemove = Arrays.asList(this.queues);
|
||||
if (additionalQueues != null) {
|
||||
for (String queueName : additionalQueues) {
|
||||
admin.deleteQueue(queueName);
|
||||
queuesToRemove = new ArrayList<>(queuesToRemove);
|
||||
queuesToRemove.addAll(Arrays.asList(additionalQueues));
|
||||
}
|
||||
logger.debug("deleting test queues: " + queuesToRemove);
|
||||
ConnectionFactory connectionFactory = getConnectionFactory();
|
||||
Connection connection = null;
|
||||
Channel channel = null;
|
||||
|
||||
try {
|
||||
connection = connectionFactory.newConnection();
|
||||
connection.setId(generateId() + ".queueDelete");
|
||||
channel = connection.createChannel();
|
||||
|
||||
for (String queue : queuesToRemove) {
|
||||
channel.queueDelete(queue);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("Failed to delete queues", e);
|
||||
}
|
||||
finally {
|
||||
closeResources(connection, channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteQueues(String... queues) {
|
||||
ConnectionFactory connectionFactory = getConnectionFactory();
|
||||
Connection connection = null;
|
||||
Channel channel = null;
|
||||
|
||||
try {
|
||||
connection = connectionFactory.newConnection();
|
||||
connection.setId(generateId() + ".queueDelete");
|
||||
channel = connection.createChannel();
|
||||
|
||||
for (String queue : queues) {
|
||||
channel.queueDelete(queue);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("Failed to delete queues", e);
|
||||
}
|
||||
finally {
|
||||
closeResources(connection, channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteExchanges(String... exchanges) {
|
||||
ConnectionFactory connectionFactory = getConnectionFactory();
|
||||
Connection connection = null;
|
||||
Channel channel = null;
|
||||
|
||||
try {
|
||||
connection = connectionFactory.newConnection();
|
||||
connection.setId(generateId() + ".exchangeDelete");
|
||||
channel = connection.createChannel();
|
||||
|
||||
for (String exchange : exchanges) {
|
||||
channel.exchangeDelete(exchange);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("Failed to delete queues", e);
|
||||
}
|
||||
finally {
|
||||
closeResources(connection, channel);
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionFactory getConnectionFactory() {
|
||||
if (this.connectionFactory == null) {
|
||||
this.connectionFactory = new ConnectionFactory();
|
||||
if (StringUtils.hasText(this.hostName)) {
|
||||
this.connectionFactory.setHost(this.hostName);
|
||||
}
|
||||
else {
|
||||
this.connectionFactory.setHost("localhost");
|
||||
}
|
||||
this.connectionFactory.setPort(this.port);
|
||||
}
|
||||
return this.connectionFactory;
|
||||
}
|
||||
|
||||
private void closeResources(Connection connection, Channel channel) {
|
||||
if (channel != null) {
|
||||
try {
|
||||
channel.close();
|
||||
}
|
||||
catch (IOException | TimeoutException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,9 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.amqp.rabbit.test;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
package org.springframework.amqp.rabbit.junit;
|
||||
|
||||
/**
|
||||
* Global convenience class for all integration tests, carrying constants and other utilities for broker set up.
|
||||
@@ -34,7 +32,8 @@ public final class BrokerTestUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* The port that the broker is listening on (e.g. as input for a {@link ConnectionFactory}).
|
||||
* The port that the broker is listening on (e.g. as input for a
|
||||
* {@link com.rabbitmq.client.ConnectionFactory}).
|
||||
*
|
||||
* @return a port number
|
||||
*/
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.amqp.rabbit.test;
|
||||
package org.springframework.amqp.rabbit.junit;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -41,8 +41,8 @@ public class LongRunningIntegrationTest extends TestWatcher {
|
||||
private boolean shouldRun = false;
|
||||
|
||||
public LongRunningIntegrationTest() {
|
||||
for (String value: new String[]{System.getenv(RUN_LONG_PROP), System.getProperty(RUN_LONG_PROP)}) {
|
||||
if ("true".equalsIgnoreCase(value)) {
|
||||
for (String value: new String[] { System.getenv(RUN_LONG_PROP), System.getProperty(RUN_LONG_PROP) }) {
|
||||
if (Boolean.parseBoolean(value)) {
|
||||
this.shouldRun = true;
|
||||
break;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Provides support classes (Rules etc) for JUnit tests.
|
||||
*/
|
||||
package org.springframework.amqp.rabbit.junit;
|
||||
@@ -36,6 +36,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.RabbitListenerTestHarness.InvocationData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.RabbitListenerTestHarness.InvocationData;
|
||||
import org.springframework.amqp.rabbit.test.mockito.LatchCountDownAndCallRealMethodAnswer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.mockito.LatchCountDownAndCallRealMethodAnswer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -50,10 +50,10 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.ReplyingMessageListener;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -36,10 +36,10 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.ListenerContainerIdleEvent;
|
||||
import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -71,13 +71,13 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitManagementTemplate;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler;
|
||||
import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.MessageTestUtils;
|
||||
import org.springframework.amqp.support.AmqpHeaders;
|
||||
import org.springframework.amqp.support.ConsumerTagStrategy;
|
||||
|
||||
@@ -28,9 +28,8 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.amqp.core.Exchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -73,12 +72,7 @@ public final class ExchangeParserIntegrationTests {
|
||||
@BeforeClass
|
||||
@AfterClass
|
||||
public static void clean() {
|
||||
RabbitAdmin admin = brokerIsRunning.getAdmin();
|
||||
admin.deleteExchange("fanoutTest");
|
||||
admin.deleteExchange("directTest");
|
||||
admin.deleteExchange("topicTest");
|
||||
admin.deleteExchange("headersTest");
|
||||
admin.deleteExchange("headersTestMulti");
|
||||
brokerIsRunning.deleteExchanges("fanoutTest", "directTest", "topicTest", "headersTest", "headersTestMulti");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.junit.Test;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -74,7 +74,7 @@ public final class QueueParserIntegrationTests {
|
||||
assertEquals(null, result);
|
||||
|
||||
connectionFactory.destroy();
|
||||
brokerIsRunning.getAdmin().deleteQueue("arguments");
|
||||
brokerIsRunning.deleteQueues("arguments");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -61,8 +61,8 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
@@ -114,7 +114,7 @@ public class CachingConnectionFactoryIntegrationTests {
|
||||
@After
|
||||
public void close() {
|
||||
if (!this.connectionFactory.getVirtualHost().equals("non-existent")) {
|
||||
this.brokerIsRunning.getAdmin().deleteQueue(CF_INTEGRATION_TEST_QUEUE);
|
||||
this.brokerIsRunning.removeTestQueues();
|
||||
}
|
||||
assertEquals("bar", connectionFactory.getRabbitConnectionFactory().getClientProperties().get("foo"));
|
||||
connectionFactory.destroy();
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.junit.Test;
|
||||
import org.springframework.amqp.core.AnonymousQueue;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.Test;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,10 +54,10 @@ import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.support.BatchingStrategy;
|
||||
import org.springframework.amqp.rabbit.core.support.SimpleBatchingStrategy;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.support.postprocessor.AbstractCompressingPostProcessor;
|
||||
import org.springframework.amqp.support.postprocessor.DelegatingDecompressingPostProcessor;
|
||||
import org.springframework.amqp.support.postprocessor.GUnzipPostProcessor;
|
||||
|
||||
@@ -34,9 +34,9 @@ import org.springframework.amqp.core.QueueBuilder;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.FixedReplyQueueDeadLetterTests.FixedReplyQueueDeadLetterConfig;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -47,8 +47,8 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.AutoRecoverConnectionNotCurrentlyOpenException;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.RabbitUtils;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
import com.rabbitmq.client.AMQP.Queue.DeclareOk;
|
||||
|
||||
@@ -67,7 +67,7 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
||||
@@ -32,11 +32,11 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.core.TopicExchange;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.RabbitAccessor;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.ActiveObjectCounter;
|
||||
import org.springframework.amqp.rabbit.listener.BlockingQueueConsumer;
|
||||
import org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ public class RabbitBindingIntegrationTests {
|
||||
private RabbitTemplate template;
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName());
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.amqp.core.Exchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.core.QueueBuilder;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.DefaultConsumer;
|
||||
|
||||
@@ -86,14 +86,14 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionListener;
|
||||
import org.springframework.amqp.rabbit.connection.RabbitResourceHolder;
|
||||
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.support.ConsumerCancelledException;
|
||||
import org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter;
|
||||
import org.springframework.amqp.rabbit.support.MessagePropertiesConverter;
|
||||
import org.springframework.amqp.rabbit.support.PublisherCallbackChannelImpl;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.amqp.support.postprocessor.GUnzipPostProcessor;
|
||||
|
||||
@@ -25,10 +25,10 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.rabbit.test.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.rabbit.test.RepeatProcessor;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
|
||||
@@ -63,6 +63,8 @@ import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ChannelProxy;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.ReplyingMessageListener;
|
||||
@@ -70,8 +72,6 @@ import org.springframework.amqp.rabbit.support.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.support.PendingConfirm;
|
||||
import org.springframework.amqp.rabbit.support.PublisherCallbackChannel.Listener;
|
||||
import org.springframework.amqp.rabbit.support.PublisherCallbackChannelImpl;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
|
||||
@@ -29,8 +29,8 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
|
||||
import com.rabbitmq.client.AMQP.BasicProperties;
|
||||
import com.rabbitmq.client.DefaultConsumer;
|
||||
|
||||
@@ -34,10 +34,10 @@ import org.springframework.amqp.core.AcknowledgeMode;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.exception.FatalListenerStartupException;
|
||||
import org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BlockingQueueConsumerIntegrationTests {
|
||||
private static Queue queue2 = new Queue("test.queue2");
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue1, queue2);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue1.getName(), queue2.getName());
|
||||
|
||||
@Rule
|
||||
public LogLevelAdjuster logLevels = new LogLevelAdjuster(Level.INFO, RabbitTemplate.class,
|
||||
|
||||
@@ -31,9 +31,9 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.listener.exception.FatalListenerStartupException;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -57,11 +57,11 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer.ChannelHolder;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.ReplyingMessageListener;
|
||||
import org.springframework.amqp.rabbit.support.ArgumentBuilder;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.support.ConsumerTagStrategy;
|
||||
import org.springframework.amqp.support.converter.MessageConversionException;
|
||||
@@ -279,8 +279,7 @@ public class DirectMessageListenerContainerTests {
|
||||
container.start();
|
||||
assertTrue(latch1.await(10, TimeUnit.SECONDS));
|
||||
assertThat(times.get(1) - times.get(0), greaterThanOrEqualTo(50L));
|
||||
brokerRunning.getAdmin().deleteQueue(EQ1);
|
||||
brokerRunning.getAdmin().deleteQueue(EQ2);
|
||||
brokerRunning.deleteQueues(EQ1, EQ2);
|
||||
assertTrue(latch2.await(10, TimeUnit.SECONDS));
|
||||
assertNotNull(failEvent.get());
|
||||
assertThat(failEvent.get(), instanceOf(ListenerContainerConsumerTerminatedEvent.class));
|
||||
@@ -290,13 +289,14 @@ public class DirectMessageListenerContainerTests {
|
||||
|
||||
@Test
|
||||
public void testErrorHandler() throws Exception {
|
||||
brokerRunning.getAdmin().deleteQueue(Q1);
|
||||
brokerRunning.deleteQueues(Q1);
|
||||
Queue q1 = new Queue(Q1, true, false, false, new ArgumentBuilder()
|
||||
.put("x-dead-letter-exchange", "")
|
||||
.put("x-dead-letter-routing-key", DLQ1)
|
||||
.get());
|
||||
brokerRunning.getAdmin().declareQueue(q1);
|
||||
CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
|
||||
RabbitAdmin admin = new RabbitAdmin(cf);
|
||||
admin.declareQueue(q1);
|
||||
DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
|
||||
container.setQueueNames(Q1);
|
||||
container.setConsumersPerQueue(2);
|
||||
@@ -451,13 +451,14 @@ public class DirectMessageListenerContainerTests {
|
||||
assertTrue(consumersOnQueue(Q1, 2));
|
||||
assertTrue(consumersOnQueue(Q2, 2));
|
||||
assertTrue(activeConsumerCount(container, 4));
|
||||
brokerRunning.getAdmin().deleteQueue(Q1);
|
||||
brokerRunning.deleteQueues(Q1);
|
||||
assertTrue(consumersOnQueue(Q2, 2));
|
||||
assertTrue(activeConsumerCount(container, 2));
|
||||
assertTrue(restartConsumerCount(container, 2));
|
||||
RabbitAdmin admin = new RabbitAdmin(cf);
|
||||
if (!autoDeclare) {
|
||||
Thread.sleep(2000);
|
||||
brokerRunning.getAdmin().declareQueue(new Queue(Q1));
|
||||
admin.declareQueue(new Queue(Q1));
|
||||
}
|
||||
assertTrue(consumersOnQueue(Q1, 2));
|
||||
assertTrue(consumersOnQueue(Q2, 2));
|
||||
@@ -504,7 +505,8 @@ public class DirectMessageListenerContainerTests {
|
||||
|
||||
private boolean consumersOnQueue(String queue, int expected) throws Exception {
|
||||
int n = 0;
|
||||
RabbitAdmin admin = brokerRunning.getAdmin();
|
||||
CachingConnectionFactory cf = new CachingConnectionFactory(brokerRunning.getConnectionFactory());
|
||||
RabbitAdmin admin = new RabbitAdmin(cf);
|
||||
Properties queueProperties = admin.getQueueProperties(queue);
|
||||
LogFactory.getLog(getClass()).debug(queue + " waiting for " + expected + " : " + queueProperties);
|
||||
while (n++ < 600
|
||||
@@ -513,6 +515,7 @@ public class DirectMessageListenerContainerTests {
|
||||
queueProperties = admin.getQueueProperties(queue);
|
||||
LogFactory.getLog(getClass()).debug(queue + " waiting for " + expected + " : " + queueProperties);
|
||||
}
|
||||
cf.destroy();
|
||||
return queueProperties.get(RabbitAdmin.QUEUE_CONSUMER_COUNT).equals(expected);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ import org.junit.Test;
|
||||
import org.springframework.amqp.core.Address;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer.ChannelHolder;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
|
||||
import com.rabbitmq.client.AMQP.BasicProperties;
|
||||
|
||||
@@ -41,9 +41,9 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.JavaConfigFixedReplyQueueTests.FixedReplyQueueConfig;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.amqp.core.MessageListener;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
@@ -57,10 +57,10 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.support.converter.MessageConversionException;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
@@ -88,7 +88,7 @@ public class MessageListenerContainerErrorHandlerIntegrationTests {
|
||||
private volatile CountDownLatch errorsHandled;
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName());
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -47,12 +47,12 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.listener.exception.FatalListenerStartupException;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.rabbit.test.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
@@ -124,7 +124,7 @@ public class MessageListenerContainerLifecycleIntegrationTests {
|
||||
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName());
|
||||
|
||||
@Rule
|
||||
public LogLevelAdjuster logLevels = new LogLevelAdjuster(Level.INFO, RabbitTemplate.class,
|
||||
|
||||
@@ -36,9 +36,9 @@ import org.springframework.amqp.core.AcknowledgeMode;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MessageListenerContainerMultipleQueueIntegrationTests {
|
||||
private static Queue queue2 = new Queue("test.queue.2");
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue1, queue2);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue1.getName(), queue2.getName());
|
||||
|
||||
@Rule
|
||||
public LogLevelAdjuster logLevels = new LogLevelAdjuster(Level.INFO, RabbitTemplate.class,
|
||||
|
||||
@@ -40,9 +40,9 @@ import org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptor
|
||||
import org.springframework.amqp.rabbit.config.StatelessRetryOperationsInterceptorFactoryBean;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.rabbit.test.RepeatProcessor;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
@@ -69,7 +69,7 @@ public class MessageListenerContainerRetryIntegrationTests {
|
||||
private static Queue queue = new Queue("test.queue");
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName());
|
||||
|
||||
@Rule
|
||||
public LogLevelAdjuster logLevels = new LogLevelAdjuster(Level.ERROR, RabbitTemplate.class,
|
||||
@@ -285,6 +285,7 @@ public class MessageListenerContainerRetryIntegrationTests {
|
||||
this.failFrequency = failFrequency;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void handleMessage(int value) throws Exception {
|
||||
logger.debug("Handling: [" + value + "], fails:" + count);
|
||||
if (value % failFrequency == 0) {
|
||||
|
||||
@@ -36,9 +36,9 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
|
||||
@@ -75,7 +75,7 @@ public class MessageListenerManualAckIntegrationTests {
|
||||
SimpleMessageListenerContainer.class, BlockingQueueConsumer.class);
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName());
|
||||
|
||||
@Before
|
||||
public void createConnectionFactory() {
|
||||
|
||||
@@ -49,11 +49,11 @@ import org.springframework.amqp.rabbit.connection.ConnectionProxy;
|
||||
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.rabbit.test.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
@@ -93,7 +93,7 @@ public class MessageListenerRecoveryCachingConnectionIntegrationTests {
|
||||
SimpleMessageListenerContainer.class, BlockingQueueConsumer.class, CachingConnectionFactory.class);
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue, sendQueue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName(), sendQueue.getName());
|
||||
|
||||
protected CachingConnectionFactory createConnectionFactory() {
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
||||
|
||||
@@ -39,10 +39,10 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.listener.exception.FatalListenerExecutionException;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.rabbit.test.RepeatProcessor;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
@@ -84,7 +84,7 @@ public class MessageListenerRecoveryRepeatIntegrationTests {
|
||||
SimpleMessageListenerContainer.class, BlockingQueueConsumer.class, MessageListenerRecoveryRepeatIntegrationTests.class);
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue, sendQueue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName(), sendQueue.getName());
|
||||
|
||||
@Rule
|
||||
public RepeatProcessor repeatProcessor = new RepeatProcessor();
|
||||
|
||||
@@ -36,9 +36,9 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
|
||||
@@ -75,7 +75,7 @@ public class MessageListenerTxSizeIntegrationTests {
|
||||
SimpleMessageListenerContainer.class, BlockingQueueConsumer.class);
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName());
|
||||
|
||||
@Before
|
||||
public void createConnectionFactory() {
|
||||
|
||||
@@ -67,13 +67,13 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.ReplyingMessageListener;
|
||||
import org.springframework.amqp.rabbit.support.ConsumerCancelledException;
|
||||
import org.springframework.amqp.rabbit.support.PublisherCallbackChannelImpl;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
@@ -105,7 +105,7 @@ public class SimpleMessageListenerContainerIntegration2Tests {
|
||||
private RabbitAdmin admin;
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue, queue1);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName(), queue1.getName());
|
||||
|
||||
@Rule
|
||||
public LongRunningIntegrationTest longRunningIntegrationTest = new LongRunningIntegrationTest();
|
||||
|
||||
@@ -45,11 +45,11 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.junit.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.amqp.rabbit.test.LongRunningIntegrationTest;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
@@ -91,7 +91,7 @@ public class SimpleMessageListenerContainerIntegrationTests {
|
||||
SimpleMessageListenerContainerIntegrationTests.class);
|
||||
|
||||
@Rule
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue);
|
||||
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName());
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@@ -32,9 +32,9 @@ import org.springframework.amqp.core.MessageListener;
|
||||
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.LongRunningIntegrationTest;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.amqp.core.MessageListener;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.support.Delivery;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
|
||||
import com.rabbitmq.client.AMQP.BasicProperties;
|
||||
import com.rabbitmq.client.Channel;
|
||||
|
||||
@@ -49,7 +49,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.utils.test.TestUtils;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@@ -80,9 +80,8 @@ public class AmqpAppenderTests {
|
||||
public static void teardown() {
|
||||
LOGGER_CONTEXT.setConfigLocation(ORIGINAL_LOGGER_CONFIG);
|
||||
LOGGER_CONTEXT.reconfigure();
|
||||
brokerRunning.getAdmin().deleteQueue("log4jTest");
|
||||
brokerRunning.getAdmin().deleteQueue("log4j2Test");
|
||||
brokerRunning.getAdmin().deleteExchange("log4j2Test");
|
||||
brokerRunning.deleteQueues("log4jTest", "log4j2Test");
|
||||
brokerRunning.deleteExchanges("log4j2Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,6 +143,7 @@ public class AmqpAppenderTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultConfiguration() {
|
||||
@SuppressWarnings("resource")
|
||||
AmqpAppender.AmqpManager manager = new AmqpAppender.AmqpManager(LOGGER_CONTEXT, "test");
|
||||
|
||||
RabbitConnectionFactoryBean bean = mock(RabbitConnectionFactoryBean.class);
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.slf4j.MDC;
|
||||
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.remoting.RemoteProxyFailureException;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
@@ -47,12 +47,11 @@ import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.listener.BlockingQueueConsumer;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.LogLevelAdjuster;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -85,9 +84,8 @@ public class MissingIdRetryTests {
|
||||
@BeforeClass
|
||||
@AfterClass
|
||||
public static void setupAndCleanUp() {
|
||||
RabbitAdmin admin = brokerIsRunning.getAdmin();
|
||||
admin.deleteQueue("retry.test.queue");
|
||||
admin.deleteExchange("retry.test.exchange");
|
||||
brokerIsRunning.deleteQueues("retry.test.queue");
|
||||
brokerIsRunning.deleteExchanges("retry.test.exchange");
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -190,7 +188,7 @@ public class MissingIdRetryTests {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SuppressWarnings({ "rawtypes", "resource" })
|
||||
@Test
|
||||
public void testWithIdAndSuccess() throws Exception {
|
||||
// 2 messages; each retried twice by retry interceptor
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
|
||||
/**
|
||||
* A JUnit method @Rule that changes the logger level for a set of classes
|
||||
* while a test method is running. Useful for performance or scalability tests
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunning;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
|
||||
@@ -260,3 +260,43 @@ for the result.
|
||||
to suspend the test thread.
|
||||
|
||||
<5> When the listener throws an exception, it is available in the `throwable` property of the invocation data.
|
||||
|
||||
[[junit-rules]]
|
||||
==== JUnit @Rules
|
||||
|
||||
Spring AMQP _version 1.7_ provides an additional jar `spring-rabbit-junit`; this jar contains a couple of utility `@Rule` s for use when running JUnit tests.
|
||||
|
||||
`BrokerRunning` provides a mechanism to allow tests to succeed when a broker is not running on `localhost`.
|
||||
|
||||
It also has utility methods to delete queues and exchanges.
|
||||
|
||||
Usage:
|
||||
|
||||
[source, java]
|
||||
----
|
||||
|
||||
@ClassRule
|
||||
public static BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues("foo", "bar");
|
||||
|
||||
@AfterClass
|
||||
public void tearDown() {
|
||||
brokerRunning.removeTestQueues("some.other.queue.too") // removes foo, bar as well
|
||||
}
|
||||
----
|
||||
|
||||
Of course, there are times when you want tests to fail if there is no broker, such as a nightly CI build.
|
||||
To disable the rule at runtime, set an environment variable `RABBITMQ_SERVER_REQUIRED` to `true`.
|
||||
|
||||
There are several `isRunning...` static methods such as `isBrokerAndManagementRunning()` which verifies the broker has the management plugin enabled.
|
||||
|
||||
`LongRunningIntegrationTest` is a rule that disables long running tests; you might want to use this on a developer system but ensure that the rule is disabled on, for example, nightly CI builds.
|
||||
|
||||
Usage:
|
||||
|
||||
[source, java]
|
||||
----
|
||||
@Rule
|
||||
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
|
||||
----
|
||||
|
||||
To disable the rule at runtime, set an environment variable `RUN_LONG_INTEGRATION_TESTS` to `true`.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[whats-new]]
|
||||
=== What's New
|
||||
|
||||
==== Changes in 2.0 Since 1.6
|
||||
==== Changes in 2.0 Since 1.7
|
||||
|
||||
===== AMQP Client library
|
||||
|
||||
|
||||
Reference in New Issue
Block a user