diff --git a/CHANGES.md b/CHANGES.md index 0541be17..8456fa5d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ### Version 1.1.0 * adds Ribbon integration +* exponential backoff customizable via Retryer.Default ctor ### Version 1.0.0 diff --git a/feign-core/src/main/java/feign/Retryer.java b/feign-core/src/main/java/feign/Retryer.java index 832f4137..a18cd421 100644 --- a/feign-core/src/main/java/feign/Retryer.java +++ b/feign-core/src/main/java/feign/Retryer.java @@ -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; diff --git a/feign-core/src/test/java/feign/DefaultRetryerTest.java b/feign-core/src/test/java/feign/DefaultRetryerTest.java index 57cd1b73..c36cca6d 100644 --- a/feign-core/src/test/java/feign/DefaultRetryerTest.java +++ b/feign-core/src/test/java/feign/DefaultRetryerTest.java @@ -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