@Test public void testInvalidCumulativeBackoff() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("maxCumulativeBackoff PT-0.002S must be at least 1 millisecond"); defaultBackoff.withMaxCumulativeBackoff(Duration.millis(-2)); }
@Setup public void setup() throws Exception { solrClient = spec.getConnectionConfiguration().createClient(); retryBackoff = FluentBackoff.DEFAULT .withMaxRetries(0) // default to no retrying .withInitialBackoff(RETRY_INITIAL_BACKOFF); if (spec.getRetryConfiguration() != null) { // FluentBackoff counts retries excluding the original while we count attempts // to remove ambiguity (hence the -1) retryBackoff = retryBackoff .withMaxRetries(spec.getRetryConfiguration().getMaxAttempts() - 1) .withMaxCumulativeBackoff(spec.getRetryConfiguration().getMaxDuration()); } }
/** Tests with bounded interval, custom exponent, limited cumulative time, and a reset. */ @Test public void testBoundedIntervalAndCumTimeWithReset() throws Exception { BackOff backOff = FluentBackoff.DEFAULT .withInitialBackoff(Duration.millis(500)) .withMaxBackoff(Duration.standardSeconds(1)) .withMaxCumulativeBackoff(Duration.standardMinutes(1)) .backoff(); assertThat(countMaximumBackoff(backOff), equalTo(Duration.standardMinutes(1).getMillis())); backOff.reset(); assertThat(countMaximumBackoff(backOff), equalTo(Duration.standardMinutes(1).getMillis())); // sanity check: should get 0 if we don't reset assertThat(countMaximumBackoff(backOff), equalTo(0L)); backOff.reset(); assertThat(countMaximumBackoff(backOff), equalTo(Duration.standardMinutes(1).getMillis())); }
@Setup public void setup() throws IOException { ConnectionConfiguration connectionConfiguration = spec.getConnectionConfiguration(); backendVersion = getBackendVersion(connectionConfiguration); restClient = connectionConfiguration.createClient(); retryBackoff = FluentBackoff.DEFAULT.withMaxRetries(0).withInitialBackoff(RETRY_INITIAL_BACKOFF); if (spec.getRetryConfiguration() != null) { retryBackoff = FluentBackoff.DEFAULT .withInitialBackoff(RETRY_INITIAL_BACKOFF) .withMaxRetries(spec.getRetryConfiguration().getMaxAttempts() - 1) .withMaxCumulativeBackoff(spec.getRetryConfiguration().getMaxDuration()); } }
/** Tests with bounded interval, custom exponent, limited cumulative time and retries. */ @Test public void testBoundedIntervalAndCumTimeAndRetriesWithReset() throws Exception { BackOff backOff = FluentBackoff.DEFAULT .withInitialBackoff(Duration.millis(500)) .withMaxBackoff(Duration.standardSeconds(1)) .withMaxCumulativeBackoff(Duration.standardMinutes(1)) .backoff(); long cumulativeBackoffMillis = 0; long currentBackoffMillis = backOff.nextBackOffMillis(); while (currentBackoffMillis != BackOff.STOP) { cumulativeBackoffMillis += currentBackoffMillis; currentBackoffMillis = backOff.nextBackOffMillis(); } assertThat(cumulativeBackoffMillis, equalTo(Duration.standardMinutes(1).getMillis())); }
@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). } }
backoff = BackOffAdapter.toGcpBackOff( MESSAGES_BACKOFF_FACTORY.withMaxCumulativeBackoff(duration).backoff()); backoff = BackOffAdapter.toGcpBackOff( MESSAGES_BACKOFF_FACTORY.withMaxCumulativeBackoff(remaining).backoff()); } else {
@Setup public void setup() throws Exception { //Initialize SnsPublisher producer = spec.getAWSClientsProvider().createSnsPublisher(); checkArgument( topicExists(producer, spec.getTopicName()), "Topic %s does not exist", spec.getTopicName()); retryBackoff = FluentBackoff.DEFAULT .withMaxRetries(0) // default to no retrying .withInitialBackoff(RETRY_INITIAL_BACKOFF); if (spec.getRetryConfiguration() != null) { retryBackoff = retryBackoff .withMaxRetries(spec.getRetryConfiguration().getMaxAttempts() - 1) .withMaxCumulativeBackoff(spec.getRetryConfiguration().getMaxDuration()); } }
@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()); }