@Override
  protected long getSleepTime() {
    int count = getAttemptCount();
    if (count >= 30) {
      // current logic overflows at 30, so set value to max
      return mMaxSleepMs;
    } else {
      // use randomness to avoid contention between many operations using the same retry policy
      int sleepMs =
          mBaseSleepTimeMs * (ThreadLocalRandom.current().nextInt(1 << count, 1 << (count + 1)));
      return Math.min(Math.abs(sleepMs), mMaxSleepMs);
    }
  }
@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);
    }
  }