Skip to content

Commit 28e9103

Browse files
committed
GH-1071: Retain stacktrace when broker required
1 parent 958806a commit 28e9103

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/BrokerRunningSupport.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,10 @@ public static class BrokerNotAliveException extends RuntimeException {
617617
super(message);
618618
}
619619

620+
BrokerNotAliveException(String message, Throwable throwable) {
621+
super(message, throwable);
622+
}
623+
620624
}
621625

622626
}

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerRecoveryRepeatIntegrationTests.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,27 @@
2525

2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
28-
import org.junit.jupiter.api.AfterEach;
29-
import org.junit.jupiter.api.BeforeEach;
30-
import org.junit.jupiter.api.RepeatedTest;
31-
import org.junit.jupiter.api.RepetitionInfo;
32-
import org.junit.jupiter.api.Test;
28+
import org.apache.logging.log4j.Level;
29+
import org.junit.After;
30+
import org.junit.Before;
31+
import org.junit.Rule;
32+
import org.junit.Test;
3333

3434
import org.springframework.amqp.core.AcknowledgeMode;
3535
import org.springframework.amqp.core.Message;
3636
import org.springframework.amqp.core.Queue;
3737
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
3838
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
3939
import org.springframework.amqp.rabbit.core.RabbitTemplate;
40+
import org.springframework.amqp.rabbit.junit.BrokerRunning;
4041
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
41-
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
42+
import org.springframework.amqp.rabbit.junit.LogLevelAdjuster;
4243
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
4344
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
4445
import org.springframework.amqp.rabbit.listener.exception.FatalListenerExecutionException;
46+
import org.springframework.amqp.rabbit.test.RepeatProcessor;
4547
import org.springframework.beans.factory.DisposableBean;
48+
import org.springframework.test.annotation.Repeat;
4649

4750
import com.rabbitmq.client.Channel;
4851

@@ -54,7 +57,6 @@
5457
* @author Gary Russell
5558
*
5659
*/
57-
@RabbitAvailable(queues = { "test.queue", "test.send" })
5860
public class MessageListenerRecoveryRepeatIntegrationTests {
5961

6062
private static Log logger = LogFactory.getLog(MessageListenerRecoveryRepeatIntegrationTests.class);
@@ -75,48 +77,48 @@ public class MessageListenerRecoveryRepeatIntegrationTests {
7577

7678
private SimpleMessageListenerContainer container;
7779

78-
// @Rule
79-
// public LogLevelAdjuster logLevels = new LogLevelAdjuster(Level.ERROR, RabbitTemplate.class,
80-
// ConditionalRejectingErrorHandler.class,
81-
// SimpleMessageListenerContainer.class, BlockingQueueConsumer.class, MessageListenerRecoveryRepeatIntegrationTests.class);
82-
//
83-
// @Rule
84-
// public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName(), sendQueue.getName());
85-
//
86-
// @Rule
87-
// public RepeatProcessor repeatProcessor = new RepeatProcessor();
80+
@Rule
81+
public LogLevelAdjuster logLevels = new LogLevelAdjuster(Level.ERROR, RabbitTemplate.class,
82+
ConditionalRejectingErrorHandler.class,
83+
SimpleMessageListenerContainer.class, BlockingQueueConsumer.class, MessageListenerRecoveryRepeatIntegrationTests.class);
84+
85+
@Rule
86+
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName(), sendQueue.getName());
87+
88+
@Rule
89+
public RepeatProcessor repeatProcessor = new RepeatProcessor();
8890

8991
private CloseConnectionListener listener;
9092

9193
private ConnectionFactory connectionFactory;
9294

93-
@BeforeEach
94-
public void init(RepetitionInfo info) {
95-
// if (!repeatProcessor.isInitialized()) {
95+
@Before
96+
public void init() {
97+
if (!repeatProcessor.isInitialized()) {
9698
logger.info("Initializing at start of test");
9799
connectionFactory = createConnectionFactory();
98100
listener = new CloseConnectionListener();
99-
// }
101+
}
100102
}
101103

102-
@AfterEach
104+
@After
103105
public void clear() throws Exception {
104-
// if (repeatProcessor.isFinalizing()) {
106+
if (repeatProcessor.isFinalizing()) {
105107
// Wait for broker communication to finish before trying to stop container
106-
// Thread.sleep(300L);
108+
Thread.sleep(300L);
107109
logger.info("Shutting down at end of test");
108110
if (container != null) {
109111
container.shutdown();
110112
}
111113
if (connectionFactory != null) {
112114
((DisposableBean) connectionFactory).destroy();
113115
}
114-
// this.brokerIsRunning.removeTestQueues();
115-
// }
116+
this.brokerIsRunning.removeTestQueues();
117+
}
116118
}
117119

118120
@Test
119-
@RepeatedTest(1000)
121+
@Repeat(1000)
120122
public void testListenerRecoversFromClosedConnection() throws Exception {
121123
if (this.container == null) {
122124
this.container = createContainer(queue.getName(), listener, connectionFactory);
@@ -161,7 +163,6 @@ private SimpleMessageListenerContainer createContainer(String queueName, Object
161163
container.setChannelTransacted(transactional);
162164
container.setAcknowledgeMode(acknowledgeMode);
163165
container.setTaskExecutor(Executors.newFixedThreadPool(concurrentConsumers));
164-
container.setReceiveTimeout(20L);
165166
container.afterPropertiesSet();
166167
container.start();
167168
return container;

0 commit comments

Comments
 (0)