2828import com .rabbitmq .client .test .TestUtils ;
2929import com .rabbitmq .tools .Host ;
3030import org .junit .After ;
31+ import org .junit .Before ;
3132import org .junit .Test ;
3233import java .io .IOException ;
3334import java .util .HashMap ;
4647public 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