public void testExternalRetryWithSuccessOnRetry() throws Throwable {
MockRetryCallback callback = new MockRetryCallback();
RetryState retryState = new DefaultRetryState("foo");
RetryTemplate retryTemplate = new RetryTemplate();
MapRetryContextCache cache = new MapRetryContextCache();
retryTemplate.setRetryContextCache(cache);
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2, Collections
.<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
assertFalse(cache.containsKey("foo"));
Object result = "start_foo";
try {
result = retryTemplate.execute(callback, retryState);
// The first failed attempt we expect to retry...
fail("Expected RuntimeException");
}
catch (RuntimeException e) {
assertNull(e.getMessage());
}
assertTrue(cache.containsKey("foo"));
result = retryTemplate.execute(callback, retryState);
assertFalse(cache.containsKey("foo"));
assertEquals(2, callback.attempts);
assertEquals("bar", result);