@Test public void testInvalidExponent() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("exponent -2.0 must be greater than 0"); defaultBackoff.withExponent(-2.0); }
@Test public void testBackoffImplToString() throws IOException { FluentBackoff config = FluentBackoff.DEFAULT .withExponent(3.4) .withMaxRetries(4) .withInitialBackoff(Duration.standardSeconds(3)) .withMaxBackoff(Duration.standardHours(1)) .withMaxCumulativeBackoff(Duration.standardDays(1)); BackOff backOff = config.backoff(); assertEquals( "BackoffImpl{backoffConfig=" + config.toString() + "," + " currentRetry=0, currentCumulativeBackoff=PT0S}", backOff.toString()); // backoff once, ignoring result backOff.nextBackOffMillis(); // currentRetry is exact, we can test it. assertThat(backOff.toString(), containsString("currentRetry=1")); // currentCumulativeBackoff is not exact; we cannot even check that it's non-zero (randomness). } }
.withInitialBackoff(MESSAGES_POLLING_INTERVAL) .withMaxRetries(MESSAGES_POLLING_RETRIES) .withExponent(DEFAULT_BACKOFF_EXPONENT); protected static final FluentBackoff STATUS_BACKOFF_FACTORY = FluentBackoff.DEFAULT .withInitialBackoff(STATUS_POLLING_INTERVAL) .withMaxRetries(STATUS_POLLING_RETRIES) .withExponent(DEFAULT_BACKOFF_EXPONENT);
@Test public void testFluentBackoffToString() throws IOException { FluentBackoff config = FluentBackoff.DEFAULT .withExponent(3.4) .withMaxRetries(4) .withInitialBackoff(Duration.standardSeconds(3)) .withMaxBackoff(Duration.standardHours(1)) .withMaxCumulativeBackoff(Duration.standardDays(1)); assertEquals( "FluentBackoff{exponent=3.4, initialBackoff=PT3S, maxBackoff=PT3600S," + " maxRetries=4, maxCumulativeBackoff=PT86400S}", config.toString()); }