Skip to content

Commit

Permalink
finos#504 Fixed Resilience4jRetryWithRecoveryTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
thibauult committed Apr 30, 2021
1 parent 5c5a946 commit 20ebad8
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void testSupplierWithExceptionAndNoRetryShouldFailWithException() throws Throwab
ofMinimalInterval(), supplier,
(t) -> false, Collections.emptyList());

assertThrows(ApiException.class, () -> r.execute());
assertThrows(ApiException.class, r::execute);
verify(supplier, times(1)).get();
}

Expand All @@ -108,7 +108,7 @@ void testMaxAttemptsReachedShouldFailWithException() throws ApiException {
retryConfig, supplier, (t) -> true,
Collections.emptyList());

assertThrows(ApiException.class, () -> r.execute());
assertThrows(ApiException.class, r::execute);
verify(supplier, times(retryConfig.getMaxAttempts())).get();
}

Expand All @@ -122,7 +122,7 @@ void testExceptionNotMatchingRetryPredicateShouldBeForwarded() throws ApiExcepti
(t) -> t instanceof ApiException && ((ApiException) t).isServerError(),
Collections.emptyList());

assertThrows(ApiException.class, () -> r.execute());
assertThrows(ApiException.class, r::execute);
verify(supplier, times(1)).get();
}

Expand Down Expand Up @@ -166,13 +166,13 @@ void testNonMatchingExceptionShouldNotTriggerRecoveryAndRetry() throws Throwable
final String value = "string";

SupplierWithApiException<String> supplier = mock(ConcreteSupplier.class);
when(supplier.get()).thenThrow(new ApiException(500, "error")).thenReturn(value);
when(supplier.get()).thenThrow(new ApiException(400, "error")).thenReturn(value);

ConcreteConsumer consumer = mock(ConcreteConsumer.class);

Resilience4jRetryWithRecovery<String> r = new Resilience4jRetryWithRecovery<>("name", "localhost.symphony.com",
ofMinimalInterval(), supplier, (t) -> true,
Collections.singletonList(new RecoveryStrategy(ApiException.class, e -> e.isClientError(), consumer)));
Collections.singletonList(new RecoveryStrategy(ApiException.class, ApiException::isServerError, consumer)));

assertEquals(value, r.execute());
verify(supplier, times(2)).get();
Expand All @@ -195,7 +195,7 @@ void testThrowableInRecoveryAndNotMatchingRetryPredicateShouldBeForwarded() thro
(t) -> t instanceof ApiException,
Collections.singletonList(new RecoveryStrategy(ApiException.class, ApiException::isClientError, consumer)));

assertThrows(IndexOutOfBoundsException.class, () -> r.execute());
assertThrows(IndexOutOfBoundsException.class, r::execute);

InOrder inOrder = inOrder(supplier, consumer);
inOrder.verify(supplier).get();
Expand Down Expand Up @@ -241,7 +241,7 @@ void testExecuteAndRetrySucceeds() throws Throwable {
@Test
void testExecuteAndRetryShouldConvertApiExceptionIntoApiRuntimeException() throws Throwable {
SupplierWithApiException<String> supplier = mock(ConcreteSupplier.class);
when(supplier.get()).thenThrow(new ApiException(500, ""));
when(supplier.get()).thenThrow(new ApiException(400, ""));

assertThrows(ApiRuntimeException.class,
() -> Resilience4jRetryWithRecovery.executeAndRetry(new RetryWithRecoveryBuilder<String>(), "test", "serviceName", supplier));
Expand Down

0 comments on commit 20ebad8

Please sign in to comment.