RESOLVED - BATCH-765: StepExecution should be saved on every commit
This commit is contained in:
@@ -318,6 +318,8 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
logger.error("Fatal error detected during commit.");
|
||||
throw new FatalException("Fatal error detected during commit", e);
|
||||
}
|
||||
|
||||
getJobRepository().saveOrUpdate(stepExecution);
|
||||
|
||||
}
|
||||
catch (Error e) {
|
||||
|
||||
@@ -684,8 +684,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
String msg = stepExecution.getExitStatus().getExitDescription();
|
||||
assertEquals("", msg);
|
||||
msg = ex.getMessage();
|
||||
assertTrue("Message does not contain 'closing step': " + msg, contains(msg,
|
||||
"closing step"));
|
||||
assertTrue("Message does not contain 'closing step': " + msg, contains(msg, "closing step"));
|
||||
// The original rollback was caused by this one:
|
||||
assertEquals("Bar", ex.getCause().getMessage());
|
||||
}
|
||||
@@ -795,6 +794,36 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testStepExecutionUpdates() throws Exception {
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecution);
|
||||
|
||||
itemOrientedStep.setStepOperations(new RepeatTemplate());
|
||||
|
||||
JobRepositoryStub jobRepository = new JobRepositoryStub();
|
||||
itemOrientedStep.setJobRepository(jobRepository);
|
||||
|
||||
itemOrientedStep.execute(stepExecution);
|
||||
|
||||
assertEquals(3, processed.size());
|
||||
assertEquals(3, stepExecution.getItemCount().intValue());
|
||||
assertTrue(3 <= jobRepository.updateCount);
|
||||
}
|
||||
|
||||
private static class JobRepositoryStub extends JobRepositorySupport {
|
||||
|
||||
private int updateCount = -1;
|
||||
|
||||
public void saveOrUpdate(StepExecution stepExecution) {
|
||||
updateCount++;
|
||||
if (updateCount <= 3) {
|
||||
assertEquals(Integer.valueOf(updateCount), stepExecution.getItemCount());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean contains(String str, String searchStr) {
|
||||
return str.indexOf(searchStr) != -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user