This repository was archived by the owner on Jul 27, 2026. It is now read-only.
Description Not sure if this is a "works as designed" problem, but it seems to be useful to support this use-case.
So far, I was not able to make it work:
I need the retry mechanism to be triggered only for declared exceptions and let others be rethrown.
With this code:
@ Retryable (include = {ToRetryException .class }, recover = "recoverRetrieveFromExternal" )
public String retrieveFromExternal (String arg ) {
return externalService .retrieve (arg );
}
@ Recover
private String recoverRetrieveFromExternal (Throwable t , String arg ) {
return "Recover: " + arg ;
}
When an exception different from ToRetryException is thrown by externalService.retrieve(arg) the recover fallback is used.
With stateful = true, all exceptions including ToRetryException are rethrown.
Basically, I need this test suite to pass:
@ Test
void ok () {
when (externalService .retrieve (anyString ())).thenReturn ("TEST" );
assertThat (client .retrieveFromExternal ("" )).isEqualTo ("TEST" );
}
@ Test
void rethrows_the_exception () {
when (externalService .retrieve (anyString ())).thenThrow (new RuntimeException ());
assertThrows (RuntimeException .class , () -> client .retrieveFromExternal ("" ));
}
@ Test
void retries_and_recovers () {
when (externalService .retrieve (anyString ())).thenThrow (new ToRetryException ());
assertThat (client .retrieveFromExternal ("test" )).isEqualTo ("Recover: test" );
}
Is there a way to do that? Thanks!
Reactions are currently unavailable
Not sure if this is a "works as designed" problem, but it seems to be useful to support this use-case.
So far, I was not able to make it work:
I need the retry mechanism to be triggered only for declared exceptions and let others be rethrown.
With this code:
When an exception different from
ToRetryExceptionis thrown byexternalService.retrieve(arg)the recover fallback is used.With
stateful = true, all exceptions includingToRetryExceptionare rethrown.Basically, I need this test suite to pass:
Is there a way to do that? Thanks!