Skip to content

Commit 7559d50

Browse files
committed
Add integration test for ExponentialBackoffDelayHandler
References #308
1 parent e3a6039 commit 7559d50

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

src/main/java/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,15 +1069,21 @@ public long getNetworkRecoveryInterval() {
10691069

10701070
/**
10711071
* Sets connection recovery interval. Default is 5000.
1072+
* Uses {@link com.rabbitmq.client.RecoveryDelayHandler.DefaultRecoveryDelayHandler} by default.
1073+
* Use another {@link RecoveryDelayHandler} implementation for more flexibility.
10721074
* @param networkRecoveryInterval how long will automatic recovery wait before attempting to reconnect, in ms
1075+
* @see RecoveryDelayHandler
10731076
*/
10741077
public void setNetworkRecoveryInterval(int networkRecoveryInterval) {
10751078
this.networkRecoveryInterval = networkRecoveryInterval;
10761079
}
10771080

10781081
/**
10791082
* Sets connection recovery interval. Default is 5000.
1083+
* Uses {@link com.rabbitmq.client.RecoveryDelayHandler.DefaultRecoveryDelayHandler} by default.
1084+
* Use another {@link RecoveryDelayHandler} implementation for more flexibility.
10801085
* @param networkRecoveryInterval how long will automatic recovery wait before attempting to reconnect, in ms
1086+
* @see RecoveryDelayHandler
10811087
*/
10821088
public void setNetworkRecoveryInterval(long networkRecoveryInterval) {
10831089
this.networkRecoveryInterval = networkRecoveryInterval;
@@ -1086,6 +1092,7 @@ public void setNetworkRecoveryInterval(long networkRecoveryInterval) {
10861092
/**
10871093
* Returns automatic connection recovery delay handler.
10881094
* @return recovery delay handler. May be null if not set.
1095+
* @since 4.3.0
10891096
*/
10901097
public RecoveryDelayHandler getRecoveryDelayHandler() {
10911098
return recoveryDelayHandler;
@@ -1094,6 +1101,7 @@ public RecoveryDelayHandler getRecoveryDelayHandler() {
10941101
/**
10951102
* Sets the automatic connection recovery delay handler.
10961103
* @param recoveryDelayHandler the recovery delay handler
1104+
* @since 4.3.0
10971105
*/
10981106
public void setRecoveryDelayHandler(final RecoveryDelayHandler recoveryDelayHandler) {
10991107
this.recoveryDelayHandler = recoveryDelayHandler;

src/main/java/com/rabbitmq/client/RecoveryDelayHandler.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright (c) 2007-Present Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
// info@rabbitmq.com.
15+
116
package com.rabbitmq.client;
217

318
import java.util.Arrays;
@@ -24,7 +39,7 @@ public interface RecoveryDelayHandler {
2439
/**
2540
* Basic implementation of {@link RecoveryDelayHandler} that returns the {@link ConnectionFactory#getNetworkRecoveryInterval() network recovery interval} each time.
2641
*/
27-
public static class DefaultRecoveryDelayHandler implements RecoveryDelayHandler {
42+
class DefaultRecoveryDelayHandler implements RecoveryDelayHandler {
2843

2944
private final long networkRecoveryInterval;
3045

@@ -47,7 +62,7 @@ public long getDelay(int recoveryAttempts) {
4762
* Backoff implementation of {@link RecoveryDelayHandler} that uses the Fibonacci sequence (by default) to increase the recovery delay time after each failed attempt.
4863
* You can optionally use your own backoff sequence.
4964
*/
50-
public static class ExponentialBackoffDelayHandler implements RecoveryDelayHandler {
65+
class ExponentialBackoffDelayHandler implements RecoveryDelayHandler {
5166

5267
private final List<Long> sequence;
5368

src/test/java/com/rabbitmq/client/test/ClientTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
JavaNioTest.class,
4949
ConnectionFactoryTest.class,
5050
RecoveryAwareAMQConnectionFactoryTest.class,
51-
RpcTest.class
51+
RpcTest.class,
52+
RecoveryDelayHandlerTest.class
5253
})
5354
public class ClientTests {
5455

src/test/java/com/rabbitmq/client/test/RecoveryDelayHandlerTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright (c) 2007-Present Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
// info@rabbitmq.com.
15+
116
package com.rabbitmq.client.test;
217

318
import static org.junit.Assert.assertEquals;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,19 @@ public void handleDelivery(String consumerTag,
720720
}
721721
}
722722

723+
@Test public void recoveryWithExponentialBackoffDelayHandler() throws Exception {
724+
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
725+
connectionFactory.setRecoveryDelayHandler(new RecoveryDelayHandler.ExponentialBackoffDelayHandler());
726+
Connection testConnection = connectionFactory.newConnection();
727+
try {
728+
assertTrue(testConnection.isOpen());
729+
closeAndWaitForRecovery((RecoverableConnection) testConnection);
730+
assertTrue(testConnection.isOpen());
731+
} finally {
732+
connection.close();
733+
}
734+
}
735+
723736
private void assertConsumerCount(int exp, String q) throws IOException {
724737
assertEquals(exp, channel.queueDeclarePassive(q).getConsumerCount());
725738
}

0 commit comments

Comments
 (0)