Browse Source

bumped exponential backoff in Retryer.Default and made it possible to adjust.

pull/5/head
adriancole 11 years ago
parent
commit
cc555a0fc2
  1. 1
      CHANGES.md
  2. 22
      feign-core/src/main/java/feign/Retryer.java
  3. 8
      feign-core/src/test/java/feign/DefaultRetryerTest.java

1
CHANGES.md

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
### Version 1.1.0
* adds Ribbon integration
* exponential backoff customizable via Retryer.Default ctor
### Version 1.0.0

22
feign-core/src/main/java/feign/Retryer.java

@ -37,19 +37,27 @@ public interface Retryer { @@ -37,19 +37,27 @@ public interface Retryer {
void continueOrPropagate(RetryableException e);
public static class Default implements Retryer {
private final int maxAttempts = 5;
private final long period = MILLISECONDS.toNanos(50);
private final long maxPeriod = SECONDS.toNanos(1);
// visible for testing;
Ticker ticker = Ticker.systemTicker();
int attempt;
long sleptForNanos;
private final int maxAttempts;
private final long period;
private final long maxPeriod;
public Default() {
this(MILLISECONDS.toNanos(100), SECONDS.toNanos(1), 5);
}
public Default(long period, long maxPeriod, int maxAttempts) {
this.period = period;
this.maxPeriod = maxPeriod;
this.maxAttempts = maxAttempts;
this.attempt = 1;
}
// visible for testing;
Ticker ticker = Ticker.systemTicker();
int attempt;
long sleptForNanos;
public void continueOrPropagate(RetryableException e) {
if (attempt++ >= maxAttempts)
throw e;

8
feign-core/src/test/java/feign/DefaultRetryerTest.java

@ -37,19 +37,19 @@ public class DefaultRetryerTest { @@ -37,19 +37,19 @@ public class DefaultRetryerTest {
retryer.continueOrPropagate(e);
assertEquals(retryer.attempt, 2);
assertEquals(retryer.sleptForNanos, 75000000);
assertEquals(retryer.sleptForNanos, 150000000);
retryer.continueOrPropagate(e);
assertEquals(retryer.attempt, 3);
assertEquals(retryer.sleptForNanos, 187500000);
assertEquals(retryer.sleptForNanos, 375000000);
retryer.continueOrPropagate(e);
assertEquals(retryer.attempt, 4);
assertEquals(retryer.sleptForNanos, 356250000);
assertEquals(retryer.sleptForNanos, 712500000);
retryer.continueOrPropagate(e);
assertEquals(retryer.attempt, 5);
assertEquals(retryer.sleptForNanos, 609375000);
assertEquals(retryer.sleptForNanos, 1218750000);
retryer.continueOrPropagate(e);
// fail

Loading…
Cancel
Save