@Test public void testMaxRetrySleepTime() { SleepingRetry retry = new ExponentialBackoffRetry(10, 10, 50, TimeUnit.MILLISECONDS); for (int i = 1; i <= 10; i++) { long sleepTimeMs = retry.getSleepTimeMs(i, 0); assertTrue(sleepTimeMs <= 50); } }
@Override protected long getSleepTimeMs(int numAttempts, long elapsedTimeMs) { checkArgument(numAttempts >= 1); long rangeMax = Math.min(_baseSleepTimeMs * (1 << numAttempts), _maxSleepTimeMs); long rangeMin = Math.max(rangeMax / 2, _baseSleepTimeMs); return rangeMin >= rangeMax ? rangeMax : rangeMin + _random.nextInt((int) (rangeMax - rangeMin + 1)); }
ExponentialBackoffRetry extends SleepingRetry { @Override protected long getSleepTimeMs(int numAttempts, long elapsedTimeMs) { checkArgument(numAttempts >= 1); long rangeMax = Math.min(_baseSleepTimeMs * (1 << numAttempts), _maxSleepTimeMs); long rangeMin = Math.max(rangeMax / 2, _baseSleepTimeMs); return rangeMin >= rangeMax ? rangeMax : rangeMin + _random.nextInt((int) (rangeMax - rangeMin + 1)); } }
ExponentialBackoffRetry extends SleepingRetry { @Override protected long getSleepTimeMs(int numAttempts, long elapsedTimeMs) { checkArgument(numAttempts >= 1); long rangeMax = Math.min(_baseSleepTimeMs * (1 << numAttempts), _maxSleepTimeMs); long rangeMin = Math.max(rangeMax / 2, _baseSleepTimeMs); return rangeMin >= rangeMax ? rangeMax : rangeMin + _random.nextInt((int) (rangeMax - rangeMin + 1)); } ExponentialBackoffRetry(int maxNumAttempts, long baseSleepTime, long maxSleepTime, TimeUnit unit); }
ExponentialBackoffRetry extends SleepingRetry { @Override protected long getSleepTimeMs(int numAttempts, long elapsedTimeMs) { checkArgument(numAttempts >= 1); long rangeMax = Math.min(_baseSleepTimeMs * (1 << numAttempts), _maxSleepTimeMs); long rangeMin = Math.max(rangeMax / 2, _baseSleepTimeMs); return rangeMin >= rangeMax ? rangeMax : rangeMin + _random.nextInt((int) (rangeMax - rangeMin + 1)); } ExponentialBackoffRetry(int maxNumAttempts, long baseSleepTime, long maxSleepTime, TimeUnit unit);  }
ExponentialBackoffRetry extends SleepingRetry { @Override protected long getSleepTimeMs(int numAttempts, long elapsedTimeMs) { checkArgument(numAttempts >= 1); long rangeMax = Math.min(_baseSleepTimeMs * (1 << numAttempts), _maxSleepTimeMs); long rangeMin = Math.max(rangeMax / 2, _baseSleepTimeMs); return rangeMin >= rangeMax ? rangeMax : rangeMin + _random.nextInt((int) (rangeMax - rangeMin + 1)); } ExponentialBackoffRetry(int maxNumAttempts, long baseSleepTime, long maxSleepTime, TimeUnit unit);   }