use of io.github.resilience4j.retry.RetryConfig in project resilience4j by resilience4j.
the class RetryTransformerTest method shouldNotRetryFromPredicateUsingObservable.
@Test
public void shouldNotRetryFromPredicateUsingObservable() {
// 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
Observable.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);
}
use of io.github.resilience4j.retry.RetryConfig in project resilience4j by resilience4j.
the class RetryTransformerTest method shouldReturnOnErrorUsingFlowable.
@Test
public void shouldReturnOnErrorUsingFlowable() {
// Given
RetryConfig config = RetryConfig.ofDefaults();
Retry retry = Retry.of("testName", config);
RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry);
given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!"));
// When
Flowable.fromCallable(helloWorldService::returnHelloWorld).compose(retryTransformer).test().assertError(WebServiceException.class).assertNotComplete().assertSubscribed();
Flowable.fromCallable(helloWorldService::returnHelloWorld).compose(retryTransformer).test().assertError(WebServiceException.class).assertNotComplete().assertSubscribed();
// Then
BDDMockito.then(helloWorldService).should(Mockito.times(6)).returnHelloWorld();
Retry.Metrics metrics = retry.getMetrics();
assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(2);
assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0);
}
use of io.github.resilience4j.retry.RetryConfig in project resilience4j by resilience4j.
the class RetryTransformerTest method shouldReturnOnCompleteUsingSingle.
@Test
public void shouldReturnOnCompleteUsingSingle() {
// Given
RetryConfig config = RetryConfig.ofDefaults();
Retry retry = Retry.of("testName", config);
RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry);
given(helloWorldService.returnHelloWorld()).willReturn("Hello world").willThrow(new WebServiceException("BAM!")).willThrow(new WebServiceException("BAM!")).willReturn("Hello world");
// When
Single.fromCallable(helloWorldService::returnHelloWorld).compose(retryTransformer).test().assertValueCount(1).assertValues("Hello world").assertComplete();
Single.fromCallable(helloWorldService::returnHelloWorld).compose(retryTransformer).test().assertValueCount(1).assertValues("Hello world").assertComplete();
// Then
BDDMockito.then(helloWorldService).should(Mockito.times(4)).returnHelloWorld();
Retry.Metrics metrics = retry.getMetrics();
assertThat(metrics.getNumberOfSuccessfulCallsWithoutRetryAttempt()).isEqualTo(1);
assertThat(metrics.getNumberOfSuccessfulCallsWithRetryAttempt()).isEqualTo(1);
assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(0);
assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0);
}
use of io.github.resilience4j.retry.RetryConfig in project resilience4j by resilience4j.
the class RetryTransformerTest method shouldNotRetryFromPredicateUsingFlowable.
@Test
public void shouldNotRetryFromPredicateUsingFlowable() {
// 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
Flowable.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);
}
use of io.github.resilience4j.retry.RetryConfig in project resilience4j by resilience4j.
the class RetryTransformerTest method shouldReturnOnCompleteUsingObservable.
@Test
public void shouldReturnOnCompleteUsingObservable() {
// Given
RetryConfig config = RetryConfig.ofDefaults();
Retry retry = Retry.of("testName", config);
RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry);
given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!"));
// When
Observable.fromCallable(helloWorldService::returnHelloWorld).compose(retryTransformer).test().assertError(WebServiceException.class).assertNotComplete().assertSubscribed();
Observable.fromCallable(helloWorldService::returnHelloWorld).compose(retryTransformer).test().assertError(WebServiceException.class).assertNotComplete().assertSubscribed();
// Then
BDDMockito.then(helloWorldService).should(Mockito.times(6)).returnHelloWorld();
Retry.Metrics metrics = retry.getMetrics();
assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(2);
assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0);
}
Aggregations