File tree Expand file tree Collapse file tree 3 files changed +20
-11
lines changed
Expand file tree Collapse file tree 3 files changed +20
-11
lines changed Original file line number Diff line number Diff line change 11### Version 1.1.0
22* adds Ribbon integration
3+ * exponential backoff customizable via Retryer.Default ctor
34
45### Version 1.0.0
56
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments