Skip to content

Commit 92a4257

Browse files
committed
Polish test
References #667 (cherry picked from commit a759d59)
1 parent 4cd1e64 commit 92a4257

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/test/java/com/rabbitmq/client/test/functional/TopologyRecoveryRetry.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.rabbitmq.client.test.TestUtils;
2929
import com.rabbitmq.tools.Host;
3030
import org.junit.After;
31+
import org.junit.Before;
3132
import org.junit.Test;
3233
import java.io.IOException;
3334
import java.util.HashMap;
@@ -46,12 +47,12 @@
4647
public class TopologyRecoveryRetry extends BrokerTestCase {
4748

4849
private volatile Consumer<Integer> backoffConsumer;
49-
50-
@After
51-
public void cleanup() {
52-
backoffConsumer = null;
50+
51+
@Before
52+
public void init() {
53+
this.backoffConsumer = attempt -> { };
5354
}
54-
55+
5556
@Test
5657
public void topologyRecoveryRetry() throws Exception {
5758
int nbQueues = 200;
@@ -78,8 +79,7 @@ public void topologyRecoveryBindingFailure() throws Exception {
7879
final CountDownLatch messagesReceivedLatch = new CountDownLatch(2);
7980
channel.basicConsume(queue, true, new DefaultConsumer(channel) {
8081
@Override
81-
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {
82-
System.out.println("Got message=" + new String(body));
82+
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) {
8383
messagesReceivedLatch.countDown();
8484
}
8585
});
@@ -141,8 +141,7 @@ public void topologyRecoveryConsumerFailure() throws Exception {
141141
final CountDownLatch messagesReceivedLatch = new CountDownLatch(2);
142142
channel.basicConsume(queue, true, new DefaultConsumer(channel) {
143143
@Override
144-
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {
145-
System.out.println("Got message=" + new String(body));
144+
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) {
146145
messagesReceivedLatch.countDown();
147146
}
148147
});
@@ -198,11 +197,8 @@ public void handleRecovery(Recoverable recoverable) {
198197
@Override
199198
protected ConnectionFactory newConnectionFactory() {
200199
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
201-
connectionFactory.setTopologyRecoveryRetryHandler(RETRY_ON_QUEUE_NOT_FOUND_RETRY_HANDLER.backoffPolicy(attempt -> {
202-
if (backoffConsumer != null) {
203-
backoffConsumer.accept(attempt);
204-
}
205-
}).build());
200+
connectionFactory.setTopologyRecoveryRetryHandler(RETRY_ON_QUEUE_NOT_FOUND_RETRY_HANDLER
201+
.backoffPolicy(attempt -> backoffConsumer.accept(attempt)).build());
206202
connectionFactory.setNetworkRecoveryInterval(1000);
207203
return connectionFactory;
208204
}

0 commit comments

Comments
 (0)