### Question:
AbstractRetry implements Function<Flux<S>, Publisher<Long>> { Instant calculateTimeout() { return timeout != null ? Instant.now(clock).plus(timeout) : Instant.MAX; } AbstractRetry(long maxIterations,
			Duration timeout,
			Backoff backoff,
			Jitter jitter,
			@Nullable
			Scheduler backoffScheduler,
			T applicationContext);   }### Answer:
@Test void calculateTimeoutUsesScheduler() { VirtualTimeScheduler scheduler = VirtualTimeScheduler.create(); AbstractRetry<String, Integer> abstractRetry = new AbstractRetry<String, Integer>(2, Duration.ofSeconds(1), Backoff.ZERO_BACKOFF, Jitter.NO_JITTER, scheduler, null) { @Override public Publisher<Long> apply(Flux<Integer> integerFlux) { return null; } }; assertEquals(1000L, abstractRetry.calculateTimeout().toEpochMilli()); scheduler.advanceTimeBy(Duration.ofSeconds(3)); assertEquals(4000L, abstractRetry.calculateTimeout().toEpochMilli()); }
@Test void calculateTimeoutUsesDefaultClockWhenNoScheduler() { AbstractRetry<String, Integer> abstractRetry = new AbstractRetry<String, Integer>(2, Duration.ofSeconds(1), Backoff.ZERO_BACKOFF, Jitter.NO_JITTER, null, null) { @Override public Publisher<Long> apply(Flux<Integer> integerFlux) { return null; } }; Instant oneSecondFromNow = Instant.now().plusSeconds(1); Instant timeout = abstractRetry.calculateTimeout(); assertTrue(timeout.toEpochMilli() >= oneSecondFromNow.toEpochMilli(), "timeout " + timeout + " was not >= " + oneSecondFromNow); }
@Test public void calculateTimeoutUsesScheduler() { VirtualTimeScheduler scheduler = VirtualTimeScheduler.create(); AbstractRetry<String, Integer> abstractRetry = new AbstractRetry<String, Integer>(2, Duration.ofSeconds(1), Backoff.ZERO_BACKOFF, Jitter.NO_JITTER, scheduler, null) { @Override public Publisher<Long> apply(Flux<Integer> integerFlux) { return null; } }; assertThat(abstractRetry.calculateTimeout().toEpochMilli()) .as("at clock 0") .isEqualTo(1000L); scheduler.advanceTimeBy(Duration.ofSeconds(3)); assertThat(abstractRetry.calculateTimeout().toEpochMilli()) .as("after clock move") .isEqualTo(4000L); }
@Test public void calculateTimeoutUsesDefaultClockWhenNoScheduler() { AbstractRetry<String, Integer> abstractRetry = new AbstractRetry<String, Integer>(2, Duration.ofSeconds(1), Backoff.ZERO_BACKOFF, Jitter.NO_JITTER, null, null) { @Override public Publisher<Long> apply(Flux<Integer> integerFlux) { return null; } }; assertThat(abstractRetry.calculateTimeout().toEpochMilli()) .isGreaterThanOrEqualTo(1000L + Instant.now().toEpochMilli()); }