@Test public void testNextBackoffWithJitterMultipleCalls() { BoundedExponentialBackoff backoff = new BoundedExponentialBackoff(INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, MAX_JITTER_MS); long expectedMin = INITIAL_BACKOFF_MS; for (int i = 0; i < ITERATIONS_TO_MAX; i++) { long result = backoff.nextBackoff(); assertThat(result).isAtLeast(expectedMin); assertThat(result).isAtMost(expectedMin + (long) MAX_JITTER_MS); expectedMin <<= 1; } }
long nextBackoff() { int jitter = mJitterMillis == 0 ? 0 : mRandom.nextInt(mJitterMillis); long backoff = mCurrentBackoffDurationMillis + (long) jitter; mCurrentBackoffDurationMillis <<= 1; if (mCurrentBackoffDurationMillis > mMaxBackoffMillis) { mCurrentBackoffDurationMillis = mMaxBackoffMillis; } return backoff; }
BoundedExponentialBackoff { long nextBackoff() { int jitter = mJitterMillis == 0 ? 0 : mRandom.nextInt(mJitterMillis); long backoff = mCurrentBackoffDurationMillis + (long) jitter; mCurrentBackoffDurationMillis <<= 1; if (mCurrentBackoffDurationMillis > mMaxBackoffMillis) { mCurrentBackoffDurationMillis = mMaxBackoffMillis; } return backoff; } }
BoundedExponentialBackoff { long nextBackoff() { int jitter = mJitterMillis == 0 ? 0 : mRandom.nextInt(mJitterMillis); long backoff = mCurrentBackoffDurationMillis + (long) jitter; mCurrentBackoffDurationMillis <<= 1; if (mCurrentBackoffDurationMillis > mMaxBackoffMillis) { mCurrentBackoffDurationMillis = mMaxBackoffMillis; } return backoff; } BoundedExponentialBackoff(long initialBackoffMillis, long maxBackoffMillis, int jitterMillis); }
BoundedExponentialBackoff { long nextBackoff() { int jitter = mJitterMillis == 0 ? 0 : mRandom.nextInt(mJitterMillis); long backoff = mCurrentBackoffDurationMillis + (long) jitter; mCurrentBackoffDurationMillis <<= 1; if (mCurrentBackoffDurationMillis > mMaxBackoffMillis) { mCurrentBackoffDurationMillis = mMaxBackoffMillis; } return backoff; } BoundedExponentialBackoff(long initialBackoffMillis, long maxBackoffMillis, int jitterMillis);  }
BoundedExponentialBackoff { long nextBackoff() { int jitter = mJitterMillis == 0 ? 0 : mRandom.nextInt(mJitterMillis); long backoff = mCurrentBackoffDurationMillis + (long) jitter; mCurrentBackoffDurationMillis <<= 1; if (mCurrentBackoffDurationMillis > mMaxBackoffMillis) { mCurrentBackoffDurationMillis = mMaxBackoffMillis; } return backoff; } BoundedExponentialBackoff(long initialBackoffMillis, long maxBackoffMillis, int jitterMillis);   }