BATCH-1774: Updated to catch Throwable so Errors don't cause NPEs when processing results

This commit is contained in:
Michael Minella
2012-11-15 12:57:11 -06:00
parent 84ca7cbc40
commit 0580e33760
2 changed files with 34 additions and 1 deletions

View File

@@ -232,6 +232,39 @@ public class TaskExecutorRepeatTemplateBulkAsynchronousTests {
assertEquals(0, frequency);
}
@Test
public void testErrorThrownByCallback() throws Exception {
callback = new RepeatCallback() {
private volatile AtomicInteger count = new AtomicInteger(0);
public RepeatStatus doInIteration(RepeatContext context)
throws Exception {
int position = count.incrementAndGet();
if(position == 4) {
throw new OutOfMemoryError("Planned");
}
else {
return RepeatStatus.CONTINUABLE;
}
}
};
template.setCompletionPolicy(new SimpleCompletionPolicy(10));
try {
template.iterate(callback);
fail("Expected planned exception");
} catch (OutOfMemoryError oome) {
assertEquals("Planned", oome.getMessage());
} catch (Exception e) {
e.printStackTrace();
fail("Wrong exception was thrown: " + e);
}
}
/**
* Slightly flakey convenience method. If this doesn't do something that

View File

@@ -258,7 +258,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate {
result = callback.doInIteration(context);
}
catch (Exception e) {
catch (Throwable e) {
error = e;
}
finally {