use of cn.taketoday.retry.RetryException in project today-infrastructure by TAKETODAY.
the class StatefulRecoveryRetryTests method testKeyGeneratorNotConsistentAfterFailure.
@Test
public void testKeyGeneratorNotConsistentAfterFailure() throws Throwable {
RetryPolicy retryPolicy = new SimpleRetryPolicy(3);
this.retryTemplate.setRetryPolicy(retryPolicy);
final StringHolder item = new StringHolder("bar");
RetryState state = new DefaultRetryState(item);
RetryCallback<StringHolder, Exception> callback = new RetryCallback<StringHolder, Exception>() {
@Override
public StringHolder doWithRetry(RetryContext context) throws Exception {
// This simulates what happens if someone uses a primary key
// for hashCode and equals and then relies on default key
// generator
item.string = item.string + (StatefulRecoveryRetryTests.this.count++);
throw new RuntimeException("Barf!");
}
};
try {
this.retryTemplate.execute(callback, state);
fail("Expected RuntimeException");
} catch (RuntimeException ex) {
String message = ex.getMessage();
assertEquals("Barf!", message);
}
// item already...
try {
this.retryTemplate.execute(callback, state);
fail("Expected RetryException");
} catch (RetryException ex) {
String message = ex.getNestedMessage();
assertTrue("Message doesn't contain 'inconsistent': " + message, message.contains("inconsistent"));
}
RetryContext context = this.retryTemplate.open(retryPolicy, state);
// True after exhausted - the history is reset...
assertEquals(0, context.getRetryCount());
}
Aggregations