IN PROGRESS - issue BATCH-545: RetryTemplate swallows Throwables that are not Exception or Error

unclassified throwables are wrapped into RetryException and rethrown
TODO unwrapping before passing RetryException to listeners
This commit is contained in:
robokaso
2008-04-02 13:55:29 +00:00
parent 27ce423bea
commit 840cb48995
2 changed files with 31 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import junit.framework.TestCase;
import org.springframework.batch.retry.ExhaustedRetryException;
import org.springframework.batch.retry.RetryCallback;
import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.RetryException;
import org.springframework.batch.retry.backoff.BackOffContext;
import org.springframework.batch.retry.backoff.BackOffInterruptedException;
import org.springframework.batch.retry.backoff.BackOffPolicy;
@@ -230,6 +231,29 @@ public class RetryTemplateTests extends TestCase {
}
}
/**
* Throwables that aren't Exception nor Error are wrapped into
* RetryException.
*/
public void testThrowableWrapping() throws Exception {
RetryCallback callback = new RetryCallback() {
public Object doWithRetry(RetryContext context) throws Throwable {
throw new Throwable("throwable in callback");
}
};
RetryTemplate template = new RetryTemplate();
try {
template.execute(callback);
fail();
}
catch (RetryException expected) {
expected.getMessage().equals("Unclassified Throwable encountered");
expected.getCause().getMessage().equals("throwable in callback");
}
}
private static class MockRetryCallback implements RetryCallback {
private int attempts;