Java Code Examples for io.github.resilience4j.retry.Retry#executeEitherSupplier()

The following examples show how to use io.github.resilience4j.retry.Retry#executeEitherSupplier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SupplierRetryTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotRetryDecoratedEither() {
    given(helloWorldService.returnEither()).willReturn(Either.right("Hello world"));
    final RetryConfig tryAgain = RetryConfig.<String>custom()
        .maxAttempts(2).build();
    Retry retry = Retry.of("id", tryAgain);

    Either<HelloWorldException, String> result = retry
        .executeEitherSupplier(helloWorldService::returnEither);

    then(helloWorldService).should().returnEither();
    assertThat(result.get()).isEqualTo("Hello world");
}
 
Example 2
Source File: SupplierRetryTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRetryDecoratedEither() {
    given(helloWorldService.returnEither()).willReturn(Either.right("Hello world"));
    final RetryConfig tryAgain = RetryConfig.<String>custom()
        .retryOnResult(s -> s.contains("Hello world"))
        .maxAttempts(2).build();
    Retry retry = Retry.of("id", tryAgain);

    Either<HelloWorldException, String> result = retry
        .executeEitherSupplier(helloWorldService::returnEither);

    then(helloWorldService).should(times(2)).returnEither();
    assertThat(result.get()).isEqualTo("Hello world");
}
 
Example 3
Source File: SupplierRetryTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFailToRetryDecoratedEither() {
    given(helloWorldService.returnEither()).willReturn(Either.left(new HelloWorldException()));
    final RetryConfig tryAgain = RetryConfig.<String>custom()
        .maxAttempts(2).build();
    Retry retry = Retry.of("id", tryAgain);

    Either<HelloWorldException, String> result = retry
        .executeEitherSupplier(helloWorldService::returnEither);

    then(helloWorldService).should(times(2)).returnEither();
    assertThat(result.isLeft()).isTrue();
    assertThat(result.getLeft()).isInstanceOf(HelloWorldException.class);
}
 
Example 4
Source File: SupplierRetryTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldIgnoreExceptionOfDecoratedEither() {
    given(helloWorldService.returnEither()).willReturn(Either.left(new HelloWorldException()));
    final RetryConfig tryAgain = RetryConfig.<String>custom()
        .ignoreExceptions(HelloWorldException.class)
        .maxAttempts(2).build();
    Retry retry = Retry.of("id", tryAgain);

    Either<HelloWorldException, String> result = retry
        .executeEitherSupplier(helloWorldService::returnEither);

    then(helloWorldService).should().returnEither();
    assertThat(result.isLeft()).isTrue();
    assertThat(result.getLeft()).isInstanceOf(HelloWorldException.class);
}