Search in sources :

Example 1 with Match

use of io.vavr.API.Match in project resilience4j by resilience4j.

the class AsyncRetryEventPublisherTest method shouldConsumeIgnoredErrorEvent.

@Test
public void shouldConsumeIgnoredErrorEvent() {
    given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!"));
    RetryConfig retryConfig = RetryConfig.custom().retryOnException(throwable -> Match(throwable).of(Case($(instanceOf(WebServiceException.class)), false), Case($(), true))).build();
    retry = AsyncRetry.of("testName", retryConfig);
    retry.getEventPublisher().onIgnoredError(event -> logger.info(event.getEventType().toString()));
    Try.of(() -> awaitResult(retry.executeCompletionStage(scheduler, () -> helloWorldService.returnHelloWorld())));
    then(logger).should(times(1)).info("IGNORED_ERROR");
    then(helloWorldService).should(times(1)).returnHelloWorld();
}
Also used : Match(io.vavr.API.Match) Logger(org.slf4j.Logger) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BDDMockito.then(org.mockito.BDDMockito.then) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) Case(io.vavr.API.Case) Mockito.times(org.mockito.Mockito.times) AsyncHelloWorldService(io.github.resilience4j.test.AsyncHelloWorldService) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncUtils.awaitResult(io.github.resilience4j.retry.utils.AsyncUtils.awaitResult) Try(io.vavr.control.Try) WebServiceException(javax.xml.ws.WebServiceException) Predicates.instanceOf(io.vavr.Predicates.instanceOf) BDDMockito.given(org.mockito.BDDMockito.given) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Before(org.junit.Before) API.$(io.vavr.API.$) Mockito.mock(org.mockito.Mockito.mock) WebServiceException(javax.xml.ws.WebServiceException) Test(org.junit.Test)

Aggregations

AsyncUtils.awaitResult (io.github.resilience4j.retry.utils.AsyncUtils.awaitResult)1 AsyncHelloWorldService (io.github.resilience4j.test.AsyncHelloWorldService)1 API.$ (io.vavr.API.$)1 Case (io.vavr.API.Case)1 Match (io.vavr.API.Match)1 Predicates.instanceOf (io.vavr.Predicates.instanceOf)1 Try (io.vavr.control.Try)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 WebServiceException (javax.xml.ws.WebServiceException)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1 Test (org.junit.Test)1 BDDMockito.given (org.mockito.BDDMockito.given)1 BDDMockito.then (org.mockito.BDDMockito.then)1 Mockito.mock (org.mockito.Mockito.mock)1