@Test public void immediateRetryRule() throws Exception { try (final Service service = new Failing2TimesServiceImpl()) { final List<RetryRule> retryRules = singletonList(RetryRule.of(RetryPredicate.ofAlwaysTrue(), RetryAction.ofImmediateRetries(3))); try(final AsyncRetrySupervisor supervisor = AsyncRetrySupervisor.of(retryRules)) { final CompletionStage<Integer> bar = supervisor.supervise(service, service::apply, "bar"); assertThat(waitAndGet(bar)).isEqualTo(3); assertThat(service.isClosed()).isFalse(); } } }
@Test public void immediateRetryRuleNonSufficient() throws Exception { try (final Service service = new Failing2TimesServiceImpl()) { final List<RetryRule> retryRules = singletonList(RetryRule.of(RetryPredicate.ofAlwaysTrue(), RetryAction.ofImmediateRetries(1))); try(final AsyncRetrySupervisor supervisor = AsyncRetrySupervisor.of(retryRules)) { final CompletionStage<Integer> bar = supervisor.supervise(service, service::apply, "bar"); final Throwable throwable = catchThrowable(() -> waitAndGet(bar)); assertThat(throwable.getCause()).hasMessage(Failing2TimesServiceImpl.ERROR_MESSAGE); assertThat(service.isClosed()).isFalse(); } } }