Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Version 1.1.0
* adds Ribbon integration
* exponential backoff customizable via Retryer.Default ctor

### Version 1.0.0

Expand Down
22 changes: 15 additions & 7 deletions feign-core/src/main/java/feign/Retryer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions feign-core/src/test/java/feign/DefaultRetryerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public void only5TriesAllowedAndExponentialBackoff() throws Exception {

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
Expand Down