@Test
public void testEarlyCompletionWithSessionAndException() throws Exception {
template.setCompletionPolicy(new SimpleCompletionPolicy(4));
RepeatStatus result = RepeatStatus.FINISHED;
try {
result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
@Override
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
RepeatStatus result = super.doInIteration(context);
if (processor.count >= 2) {
context.setCompleteOnly();
throw new RuntimeException("Barf second try count=" + processor.count);
}
return result;
}
});
fail("Expected exception on last item in batch");
}
catch (RuntimeException e) {
// expected
assertEquals("Barf second try count=2", e.getMessage());
}
// 2 items were processed before completion signalled
assertEquals(2, processor.count);
System.err.println(result);
// An exception was thrown by the template so result is still false
assertFalse(result.isContinuable());
}