use of net.jodah.failsafe.Failsafe in project failsafe by jhalterman.
the class Issue36 method failedAttemptListener_WithExceptions_ShouldBeCalled.
@Test
public void failedAttemptListener_WithExceptions_ShouldBeCalled() throws Exception {
RetryPolicy policy = new RetryPolicy().retryIf((Boolean response) -> response != null && !response).retryOn(Exception.class).withMaxRetries(3);
AtomicInteger listenerCallbacks = new AtomicInteger();
try {
Failsafe.<Boolean>with(policy).onFailedAttempt((failedResponse, exception, context) -> listenerCallbacks.incrementAndGet()).get(() -> {
throw new RuntimeException();
});
} catch (RuntimeException e) {
}
assertEquals(listenerCallbacks.get(), 4);
}
use of net.jodah.failsafe.Failsafe in project failsafe by jhalterman.
the class Issue36 method failedAttemptListener_WithFailedResponses_ShouldBeCalled.
@Test
public void failedAttemptListener_WithFailedResponses_ShouldBeCalled() throws Exception {
RetryPolicy policy = new RetryPolicy().retryIf((Boolean response) -> response != null && !response).retryOn(Exception.class).withMaxRetries(3);
AtomicInteger listenerCallbacks = new AtomicInteger();
Failsafe.<Boolean>with(policy).onFailedAttempt((failedResponse, exception, context) -> listenerCallbacks.incrementAndGet()).get(() -> false);
assertEquals(listenerCallbacks.get(), 4);
}
use of net.jodah.failsafe.Failsafe in project failsafe by jhalterman.
the class Issue36 method retryListener_WithFailedResponses_ShouldBeCalled.
@Test
public void retryListener_WithFailedResponses_ShouldBeCalled() throws Exception {
RetryPolicy policy = new RetryPolicy().retryIf((Boolean response) -> response != null && !response).retryOn(Exception.class).withMaxRetries(3);
AtomicInteger listenerCallbacks = new AtomicInteger();
Failsafe.<Boolean>with(policy).onRetry((failedResponse, exception, context) -> listenerCallbacks.incrementAndGet()).get(() -> false);
assertEquals(listenerCallbacks.get(), 3);
}
use of net.jodah.failsafe.Failsafe in project failsafe by jhalterman.
the class Issue36 method retryListener_WithExceptions_ShouldBeCalled.
@Test
public void retryListener_WithExceptions_ShouldBeCalled() throws Exception {
RetryPolicy policy = new RetryPolicy().retryIf((Boolean response) -> response != null && !response).retryOn(Exception.class).withMaxRetries(3);
AtomicInteger listenerCallbacks = new AtomicInteger();
try {
Failsafe.<Boolean>with(policy).onRetry((failedResponse, exception, context) -> listenerCallbacks.incrementAndGet()).get(() -> {
throw new RuntimeException();
});
} catch (RuntimeException e) {
}
assertEquals(listenerCallbacks.get(), 3);
}
Aggregations