assertEquals(input, list.get(0));
}
@Test
public void testExhaustedClearsHistoryAfterLastAttempt() throws Throwable {
RetryPolicy retryPolicy = new SimpleRetryPolicy(1, Collections
.<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true));
retryTemplate.setRetryPolicy(retryPolicy);
final String input = "foo";
RetryState state = new DefaultRetryState(input);
RetryCallback<String, Exception> callback = new RetryCallback<String, Exception>() {
public String doWithRetry(RetryContext context) throws Exception {
throw new RuntimeException("Barf!");
}
};
try {
retryTemplate.execute(callback, state);
fail("Expected ExhaustedRetryException");
}
catch (RuntimeException e) {
assertEquals("Barf!", e.getMessage());
}
try {
retryTemplate.execute(callback, state);
fail("Expected ExhaustedRetryException");
}
catch (ExhaustedRetryException e) {
// expected
}
RetryContext context = retryTemplate.open(retryPolicy, state);
// True after exhausted - the history is reset...
assertTrue(retryPolicy.canRetry(context));
}