Skip to content

Instantly share code, notes, and snippets.

Last active Dec 4, 2018
What would you like to do?
// Given the HelloWorldService returns Hello world
.willReturn(completedFuture("Hello world"));
final AsyncRetry retryContext = AsyncRetry.of("retryConfig",
// we set the response type to String
// max retry attempts
// what are the ignore exception to no retry on
// what are the exceptions to try on
// retry if the response contains world
.retryOnResult(s -> s.contains("world"))
// retry backoff strategy, IntervalFunction has many built in interface functions you can check it out
// Decorate the invocation of the HelloWorldService
Supplier<CompletionStage<String>> supplier = AsyncRetry.decorateCompletionStage(
() -> helloWorldService.returnHelloWorld());
// When
String result = awaitResult(supplier);
// Then the helloWorldService should be invoked 1 time
Assertions.assertEquals(result, "Hello world");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment