RetryBoundedBackOff implements BackOff { @Override public long nextBackOffMillis() throws IOException { if (retriesAttempted >= maxRetries) { return BackOff.STOP; } long next = backoff.nextBackOffMillis(); if (next == BackOff.STOP) { return BackOff.STOP; } retriesAttempted++; return next; } RetryBoundedBackOff(int maxRetries, BackOff backoff); @Override void reset(); @Override long nextBackOffMillis();  }
@Test public void stopsAfterAttempts() throws Exception { BackOff backoff = new RetryBoundedBackOff(5, new BackOffTester()); for (int i = 0; i < 5; i++) { assertThat(i + 1).isEqualTo(backoff.nextBackOffMillis()); } assertThat(backoff.nextBackOffMillis()).isEqualTo(BackOff.STOP); assertThat(backoff.nextBackOffMillis()).isEqualTo(BackOff.STOP); }