@Test public void largeRetriesProducePositiveTime() { int max = 1000; MockExponentialBackoffRetry backoff = new MockExponentialBackoffRetry(50, Integer.MAX_VALUE, max); for (int i = 0; i < max; i++) { backoff.setRetryCount(i); long time = backoff.getSleepTime(); assertTrue("Time must always be positive: " + time, time > 0); } }
@Override protected long getSleepTime() { int count = getAttemptCount(); if (count >= 30) { return mMaxSleepMs; } else { int sleepMs = mBaseSleepTimeMs * (ThreadLocalRandom.current().nextInt(1 << count, 1 << (count + 1))); return Math.min(abs(sleepMs, mMaxSleepMs), mMaxSleepMs); } }
ExponentialBackoffRetry extends SleepingRetry { @Override protected long getSleepTime() { int count = getAttemptCount(); if (count >= 30) { return mMaxSleepMs; } else { int sleepMs = mBaseSleepTimeMs * (ThreadLocalRandom.current().nextInt(1 << count, 1 << (count + 1))); return Math.min(abs(sleepMs, mMaxSleepMs), mMaxSleepMs); } } }
ExponentialBackoffRetry extends SleepingRetry { @Override protected long getSleepTime() { int count = getAttemptCount(); if (count >= 30) { return mMaxSleepMs; } else { int sleepMs = mBaseSleepTimeMs * (ThreadLocalRandom.current().nextInt(1 << count, 1 << (count + 1))); return Math.min(abs(sleepMs, mMaxSleepMs), mMaxSleepMs); } } ExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepMs, int maxRetries); }
ExponentialBackoffRetry extends SleepingRetry { @Override protected long getSleepTime() { int count = getAttemptCount(); if (count >= 30) { return mMaxSleepMs; } else { int sleepMs = mBaseSleepTimeMs * (ThreadLocalRandom.current().nextInt(1 << count, 1 << (count + 1))); return Math.min(abs(sleepMs, mMaxSleepMs), mMaxSleepMs); } } ExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepMs, int maxRetries);  }
ExponentialBackoffRetry extends SleepingRetry { @Override protected long getSleepTime() { int count = getAttemptCount(); if (count >= 30) { return mMaxSleepMs; } else { int sleepMs = mBaseSleepTimeMs * (ThreadLocalRandom.current().nextInt(1 << count, 1 << (count + 1))); return Math.min(abs(sleepMs, mMaxSleepMs), mMaxSleepMs); } } ExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepMs, int maxRetries);   }