Created a JSR-352 specific StepState to maintain in the Job's
ExecutionContext what the last step executed was. This is needed for restarts when the step to restart at is a DecisionStep.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.springframework.batch.core.jsr.step;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.batch.core.jsr.JsrTestUtils.restartJob;
|
||||
import static org.springframework.batch.core.jsr.JsrTestUtils.runJob;
|
||||
|
||||
import java.util.List;
|
||||
@@ -20,6 +21,7 @@ import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class DecisionStepTests {
|
||||
|
||||
@@ -101,6 +103,45 @@ public class DecisionStepTests {
|
||||
assertEquals(2, StepExecutionCountingDecider.previousStepCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecisionRestart() throws Exception {
|
||||
JobExecution execution = runJob("DecisionStepTests-restart-context", new Properties(), 10000l);
|
||||
assertEquals(BatchStatus.STOPPED, execution.getBatchStatus());
|
||||
|
||||
List<StepExecution> stepExecutions = BatchRuntime.getJobOperator().getStepExecutions(execution.getExecutionId());
|
||||
assertEquals(2, stepExecutions.size());
|
||||
|
||||
assertEquals("step1", stepExecutions.get(0).getStepName());
|
||||
assertEquals("decision1", stepExecutions.get(1).getStepName());
|
||||
|
||||
JobExecution execution2 = restartJob(execution.getExecutionId(), new Properties(), 10000l);
|
||||
assertEquals(BatchStatus.COMPLETED, execution2.getBatchStatus());
|
||||
|
||||
List<StepExecution> stepExecutions2 = BatchRuntime.getJobOperator().getStepExecutions(execution2.getExecutionId());
|
||||
assertEquals(2, stepExecutions2.size());
|
||||
|
||||
assertEquals("decision1", stepExecutions2.get(0).getStepName());
|
||||
assertEquals("step2", stepExecutions2.get(1).getStepName());
|
||||
}
|
||||
|
||||
public static class RestartDecider implements Decider {
|
||||
|
||||
private static int runs = 0;
|
||||
|
||||
@Override
|
||||
public String decide(StepExecution[] executions) throws Exception {
|
||||
Assert.isTrue(executions.length == 1);
|
||||
Assert.isTrue(executions[0].getStepName().equals("step1"));
|
||||
|
||||
if(runs == 0) {
|
||||
runs++;
|
||||
return "STOP_HERE";
|
||||
} else {
|
||||
return "CONTINUE";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class StepExecutionCountingDecider implements Decider {
|
||||
|
||||
static int previousStepCount = 0;
|
||||
|
||||
Reference in New Issue
Block a user