Search in sources :

Example 16 with RetryConfig

use of io.github.resilience4j.retry.RetryConfig in project resilience4j by resilience4j.

the class RetryTransformerTest method shouldNotRetryFromPredicateUsingSingle.

@Test
public void shouldNotRetryFromPredicateUsingSingle() {
    // Given
    RetryConfig config = RetryConfig.custom().retryOnException(t -> t instanceof IOException).maxAttempts(3).build();
    Retry retry = Retry.of("testName", config);
    given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!"));
    // When
    Single.fromCallable(helloWorldService::returnHelloWorld).compose(RetryTransformer.of(retry)).test().assertError(WebServiceException.class).assertNotComplete().assertSubscribed();
    // Then
    BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnHelloWorld();
    Retry.Metrics metrics = retry.getMetrics();
    assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(1);
    assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(0);
}
Also used : RetryConfig(io.github.resilience4j.retry.RetryConfig) WebServiceException(javax.xml.ws.WebServiceException) IOException(java.io.IOException) Retry(io.github.resilience4j.retry.Retry) Test(org.junit.Test)

Aggregations

Retry (io.github.resilience4j.retry.Retry)16 RetryConfig (io.github.resilience4j.retry.RetryConfig)16 WebServiceException (javax.xml.ws.WebServiceException)16 Test (org.junit.Test)16 CheckedRunnable (io.vavr.CheckedRunnable)4 IOException (java.io.IOException)4 IntervalFunction (io.github.resilience4j.retry.IntervalFunction)2 HelloWorldService (io.github.resilience4j.test.HelloWorldService)2 API (io.vavr.API)2 Predicates (io.vavr.Predicates)2 Try (io.vavr.control.Try)2 Before (org.junit.Before)2 BDDMockito (org.mockito.BDDMockito)2 Mockito (org.mockito.Mockito)2 API.$ (io.vavr.API.$)1 CheckedFunction0 (io.vavr.CheckedFunction0)1 Duration (java.time.Duration)1 Callable (java.util.concurrent.Callable)1 Supplier (java.util.function.Supplier)1 Assertions (org.assertj.core.api.Assertions)1