use of cn.taketoday.retry.RetryCallback in project today-infrastructure by TAKETODAY.
the class StatefulRecoveryRetryTests method testExhaustedClearsHistoryAfterLastAttempt.
@Test
public void testExhaustedClearsHistoryAfterLastAttempt() throws Throwable {
RetryPolicy retryPolicy = new SimpleRetryPolicy(1);
this.retryTemplate.setRetryPolicy(retryPolicy);
final String input = "foo";
RetryState state = new DefaultRetryState(input);
RetryCallback<String, Exception> callback = new RetryCallback<String, Exception>() {
@Override
public String doWithRetry(RetryContext context) throws Exception {
throw new RuntimeException("Barf!");
}
};
try {
this.retryTemplate.execute(callback, state);
fail("Expected ExhaustedRetryException");
} catch (RuntimeException e) {
assertEquals("Barf!", e.getMessage());
}
try {
this.retryTemplate.execute(callback, state);
fail("Expected ExhaustedRetryException");
} catch (ExhaustedRetryException e) {
// expected
}
RetryContext context = this.retryTemplate.open(retryPolicy, state);
// True after exhausted - the history is reset...
assertTrue(retryPolicy.canRetry(context));
}
Aggregations