@Test public void testExpBackoffWithJitter() throws Exception { Duration initialDelay = ofSeconds(1); RepeatStrategy strategy = new RepeatStrategy(repeatWithExponentialBackoffAndJitter(2, initialDelay, timerExecutor)); LegacyMockedCompletableListenerRule signalListener = strategy.invokeAndListen(); verifyDelayWithJitter(initialDelay.toNanos(), 1); timers.take().verifyListenCalled().onComplete(); signalListener.verifyCompletion(); verifyNoMoreInteractions(timerExecutor); signalListener = strategy.invokeAndListen(); long nextDelay = initialDelay.toNanos() << 1; verifyDelayWithJitter(nextDelay, 2); timers.take().verifyListenCalled().onComplete(); signalListener.verifyCompletion(); verifyNoMoreInteractions(timerExecutor); }
public static IntFunction<Completable> repeatWithExponentialBackoffAndJitter(final int maxRepeats, final Duration initialDelay, final Executor timerExecutor) { requireNonNull(timerExecutor); final long initialDelayNanos = initialDelay.toNanos(); return repeatCount -> { if (repeatCount > maxRepeats) { return terminateRepeat(); } return timerExecutor.timer(ThreadLocalRandom.current().nextLong(0, initialDelayNanos << (repeatCount - 1)), NANOSECONDS); }; }
RepeatStrategies { public static IntFunction<Completable> repeatWithExponentialBackoffAndJitter(final int maxRepeats, final Duration initialDelay, final Executor timerExecutor) { requireNonNull(timerExecutor); final long initialDelayNanos = initialDelay.toNanos(); return repeatCount -> { if (repeatCount > maxRepeats) { return terminateRepeat(); } return timerExecutor.timer(ThreadLocalRandom.current().nextLong(0, initialDelayNanos << (repeatCount - 1)), NANOSECONDS); }; } }
RepeatStrategies { public static IntFunction<Completable> repeatWithExponentialBackoffAndJitter(final int maxRepeats, final Duration initialDelay, final Executor timerExecutor) { requireNonNull(timerExecutor); final long initialDelayNanos = initialDelay.toNanos(); return repeatCount -> { if (repeatCount > maxRepeats) { return terminateRepeat(); } return timerExecutor.timer(ThreadLocalRandom.current().nextLong(0, initialDelayNanos << (repeatCount - 1)), NANOSECONDS); }; } private  RepeatStrategies(); }
RepeatStrategies { public static IntFunction<Completable> repeatWithExponentialBackoffAndJitter(final int maxRepeats, final Duration initialDelay, final Executor timerExecutor) { requireNonNull(timerExecutor); final long initialDelayNanos = initialDelay.toNanos(); return repeatCount -> { if (repeatCount > maxRepeats) { return terminateRepeat(); } return timerExecutor.timer(ThreadLocalRandom.current().nextLong(0, initialDelayNanos << (repeatCount - 1)), NANOSECONDS); }; } private  RepeatStrategies(); static IntFunction<Completable> repeatWithConstantBackoff(final int maxRepeats, final Duration backoff,
                                                                     final Executor timerExecutor); static IntFunction<Completable> repeatWithExponentialBackoff(final int maxRepeats,
                                                                        final Duration initialDelay,
                                                                        final Executor timerExecutor); static IntFunction<Completable> repeatWithExponentialBackoffAndJitter(final int maxRepeats,
                                                                                 final Duration initialDelay,
                                                                                 final Executor timerExecutor); }
RepeatStrategies { public static IntFunction<Completable> repeatWithExponentialBackoffAndJitter(final int maxRepeats, final Duration initialDelay, final Executor timerExecutor) { requireNonNull(timerExecutor); final long initialDelayNanos = initialDelay.toNanos(); return repeatCount -> { if (repeatCount > maxRepeats) { return terminateRepeat(); } return timerExecutor.timer(ThreadLocalRandom.current().nextLong(0, initialDelayNanos << (repeatCount - 1)), NANOSECONDS); }; } private  RepeatStrategies(); static IntFunction<Completable> repeatWithConstantBackoff(final int maxRepeats, final Duration backoff,
                                                                     final Executor timerExecutor); static IntFunction<Completable> repeatWithExponentialBackoff(final int maxRepeats,
                                                                        final Duration initialDelay,
                                                                        final Executor timerExecutor); static IntFunction<Completable> repeatWithExponentialBackoffAndJitter(final int maxRepeats,
                                                                                 final Duration initialDelay,
                                                                                 final Executor timerExecutor);  }