LoggingRetryListener implements RetryListener { @Override public void onRetry(final RequestArguments arguments, final ExecutionAttemptedEvent<ClientHttpResponse> event) { if (event.getLastFailure() != null) { logger.warn("Retrying failure", event.getLastFailure()); } } LoggingRetryListener(); @Override void onRetry(final RequestArguments arguments,
            final ExecutionAttemptedEvent<ClientHttpResponse> event);  }
@Test void shouldLogFailure() { final AtomicBoolean success = new AtomicBoolean(false); final RequestArguments arguments = RequestArguments.create(); final IllegalStateException exception = new IllegalStateException(); Failsafe.with(new RetryPolicy<ClientHttpResponse>() .withMaxRetries(3) .onRetry(new RetryListenerAdapter(unit, arguments))) .run(() -> { if (!success.getAndSet(true)) { throw exception; } }); verify(logger).warn(any(), eq(exception)); }
@Test void shouldNotLogResults() { final AtomicBoolean success = new AtomicBoolean(false); final RequestArguments arguments = RequestArguments.create(); Failsafe.with(new RetryPolicy<ClientHttpResponse>() .withMaxRetries(3) .handleResultIf(Objects::isNull) .onRetry(new RetryListenerAdapter(unit, arguments))) .get(() -> { if (!success.getAndSet(true)) { return null; } return mock(ClientHttpResponse.class); }); verifyNoMoreInteractions(logger); }