RESOLVED - BATCH-751: ensure StepExecution is saved before trying to save ExecutionContext
EC is now saved immediately after AbstractStep updates the status to 'STARTED'
This commit is contained in:
@@ -155,6 +155,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
UnexpectedJobExecutionException {
|
||||
stepExecution.setStartTime(new Date());
|
||||
stepExecution.setStatus(BatchStatus.STARTED);
|
||||
|
||||
getJobRepository().saveOrUpdate(stepExecution);
|
||||
|
||||
ExitStatus exitStatus = ExitStatus.FAILED;
|
||||
Exception commitException = null;
|
||||
|
||||
@@ -222,7 +222,6 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
*/
|
||||
protected ExitStatus doExecute(final StepExecution stepExecution) throws Exception {
|
||||
stream.update(stepExecution.getExecutionContext());
|
||||
getJobRepository().saveOrUpdate(stepExecution);
|
||||
getJobRepository().saveOrUpdateExecutionContext(stepExecution);
|
||||
itemHandler.mark();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractStep}.
|
||||
@@ -101,13 +102,25 @@ public class AbstractStepTests extends TestCase {
|
||||
* Remembers the last saved values of execution context.
|
||||
*/
|
||||
private static class JobRepositoryStub extends JobRepositorySupport {
|
||||
|
||||
static long counter = 0;
|
||||
|
||||
ExecutionContext saved = new ExecutionContext();
|
||||
|
||||
public void saveOrUpdateExecutionContext(StepExecution stepExecution) {
|
||||
Assert.state(stepExecution.getId() != null, "StepExecution must be already saved");
|
||||
saved = stepExecution.getExecutionContext();
|
||||
}
|
||||
|
||||
public void saveOrUpdate(StepExecution stepExecution) {
|
||||
if (stepExecution.getId() == null) {
|
||||
stepExecution.setId(new Long(counter));
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user