@Test void jitterOffsetCappedForSuperLargeMaxDuration() { double factor = 0.5; Duration min = Duration.ofMillis(100); Duration max = Duration.ofMillis(100); Duration delay = Duration.ofSeconds(Long.MAX_VALUE); BackoffDelay bd = new BackoffDelay(min, max, delay); RandomJitter jitter = new RandomJitter(factor); assertThat(jitter.jitterOffsetCapped(bd)) .isEqualTo(Math.round(Long.MAX_VALUE * factor)); }
long jitterOffsetCapped(BackoffDelay backoff) { try { return backoff.delay.multipliedBy((long) (100 * randomFactor)) .dividedBy(100) .toMillis(); } catch (ArithmeticException ae) { return Math.round(Long.MAX_VALUE * randomFactor); } }
RandomJitter implements Jitter { long jitterOffsetCapped(BackoffDelay backoff) { try { return backoff.delay.multipliedBy((long) (100 * randomFactor)) .dividedBy(100) .toMillis(); } catch (ArithmeticException ae) { return Math.round(Long.MAX_VALUE * randomFactor); } } }
RandomJitter implements Jitter { long jitterOffsetCapped(BackoffDelay backoff) { try { return backoff.delay.multipliedBy((long) (100 * randomFactor)) .dividedBy(100) .toMillis(); } catch (ArithmeticException ae) { return Math.round(Long.MAX_VALUE * randomFactor); } } RandomJitter(double randomFactor); }
RandomJitter implements Jitter { long jitterOffsetCapped(BackoffDelay backoff) { try { return backoff.delay.multipliedBy((long) (100 * randomFactor)) .dividedBy(100) .toMillis(); } catch (ArithmeticException ae) { return Math.round(Long.MAX_VALUE * randomFactor); } } RandomJitter(double randomFactor); @Override Duration apply(BackoffDelay backoff); @Override String toString(); }
RandomJitter implements Jitter { long jitterOffsetCapped(BackoffDelay backoff) { try { return backoff.delay.multipliedBy((long) (100 * randomFactor)) .dividedBy(100) .toMillis(); } catch (ArithmeticException ae) { return Math.round(Long.MAX_VALUE * randomFactor); } } RandomJitter(double randomFactor); @Override Duration apply(BackoffDelay backoff); @Override String toString();  }