Skip to content

Commit 7acb9a6

Browse files
author
Adrian Cole
committed
Merge pull request OpenFeign#5 from Netflix/customize-retryer
bumped exponential backoff in Retryer.Default and made it possible to adjust
2 parents ef9700b + cc555a0 commit 7acb9a6

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Version 1.1.0
22
* adds Ribbon integration
3+
* exponential backoff customizable via Retryer.Default ctor
34

45
### Version 1.0.0
56

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,27 @@ public interface Retryer {
3737
void continueOrPropagate(RetryableException e);
3838

3939
public static class Default implements Retryer {
40-
private final int maxAttempts = 5;
41-
private final long period = MILLISECONDS.toNanos(50);
42-
private final long maxPeriod = SECONDS.toNanos(1);
4340

44-
// visible for testing;
45-
Ticker ticker = Ticker.systemTicker();
46-
int attempt;
47-
long sleptForNanos;
41+
private final int maxAttempts;
42+
private final long period;
43+
private final long maxPeriod;
4844

4945
public Default() {
46+
this(MILLISECONDS.toNanos(100), SECONDS.toNanos(1), 5);
47+
}
48+
49+
public Default(long period, long maxPeriod, int maxAttempts) {
50+
this.period = period;
51+
this.maxPeriod = maxPeriod;
52+
this.maxAttempts = maxAttempts;
5053
this.attempt = 1;
5154
}
5255

56+
// visible for testing;
57+
Ticker ticker = Ticker.systemTicker();
58+
int attempt;
59+
long sleptForNanos;
60+
5361
public void continueOrPropagate(RetryableException e) {
5462
if (attempt++ >= maxAttempts)
5563
throw e;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ public void only5TriesAllowedAndExponentialBackoff() throws Exception {
3737

3838
retryer.continueOrPropagate(e);
3939
assertEquals(retryer.attempt, 2);
40-
assertEquals(retryer.sleptForNanos, 75000000);
40+
assertEquals(retryer.sleptForNanos, 150000000);
4141

4242
retryer.continueOrPropagate(e);
4343
assertEquals(retryer.attempt, 3);
44-
assertEquals(retryer.sleptForNanos, 187500000);
44+
assertEquals(retryer.sleptForNanos, 375000000);
4545

4646
retryer.continueOrPropagate(e);
4747
assertEquals(retryer.attempt, 4);
48-
assertEquals(retryer.sleptForNanos, 356250000);
48+
assertEquals(retryer.sleptForNanos, 712500000);
4949

5050
retryer.continueOrPropagate(e);
5151
assertEquals(retryer.attempt, 5);
52-
assertEquals(retryer.sleptForNanos, 609375000);
52+
assertEquals(retryer.sleptForNanos, 1218750000);
5353

5454
retryer.continueOrPropagate(e);
5555
// fail

0 commit comments

Comments
 (0)