28
28
import com .rabbitmq .client .test .TestUtils ;
29
29
import com .rabbitmq .tools .Host ;
30
30
import org .junit .After ;
31
+ import org .junit .Before ;
31
32
import org .junit .Test ;
32
33
import java .io .IOException ;
33
34
import java .util .HashMap ;
46
47
public class TopologyRecoveryRetry extends BrokerTestCase {
47
48
48
49
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 -> { } ;
53
54
}
54
-
55
+
55
56
@ Test
56
57
public void topologyRecoveryRetry () throws Exception {
57
58
int nbQueues = 200 ;
@@ -78,8 +79,7 @@ public void topologyRecoveryBindingFailure() throws Exception {
78
79
final CountDownLatch messagesReceivedLatch = new CountDownLatch (2 );
79
80
channel .basicConsume (queue , true , new DefaultConsumer (channel ) {
80
81
@ 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 ) {
83
83
messagesReceivedLatch .countDown ();
84
84
}
85
85
});
@@ -141,8 +141,7 @@ public void topologyRecoveryConsumerFailure() throws Exception {
141
141
final CountDownLatch messagesReceivedLatch = new CountDownLatch (2 );
142
142
channel .basicConsume (queue , true , new DefaultConsumer (channel ) {
143
143
@ 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 ) {
146
145
messagesReceivedLatch .countDown ();
147
146
}
148
147
});
@@ -198,11 +197,8 @@ public void handleRecovery(Recoverable recoverable) {
198
197
@ Override
199
198
protected ConnectionFactory newConnectionFactory () {
200
199
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 ());
206
202
connectionFactory .setNetworkRecoveryInterval (1000 );
207
203
return connectionFactory ;
208
204
}
0 commit comments