RESOLVED - issue BATCH-1187: Step shouldn't exit with status=EXECUTING
AbstractStep now sets the ExitStatus (by ANDing with the existing value), so a Tasklet does not have to set it manually.
This commit is contained in:
@@ -48,7 +48,7 @@ public class FailTransitionJobParserTests extends AbstractJobParserTests {
|
||||
assertTrue(stepNamesList.contains("fail"));
|
||||
|
||||
assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
|
||||
assertEquals("FAILED EARLY TERMINATION", jobExecution.getExitStatus()
|
||||
assertEquals("EARLY TERMINATION", jobExecution.getExitStatus()
|
||||
.getExitCode());
|
||||
|
||||
StepExecution stepExecution1 = getStepExecution(jobExecution, "s1");
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
|
||||
@@ -44,7 +43,6 @@ public class NameStoringTasklet extends StepExecutionListenerSupport implements
|
||||
if (stepNamesList != null) {
|
||||
stepNamesList.add(stepName);
|
||||
}
|
||||
contribution.setExitStatus(ExitStatus.COMPLETED);
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
@@ -11,7 +10,6 @@ public class TestTasklet extends AbstractTestComponent implements Tasklet {
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
executed = true;
|
||||
contribution.setExitStatus(ExitStatus.COMPLETED);
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class AbstractStepTests {
|
||||
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
assertSame(execution, stepExecution);
|
||||
events.add(getEvent("afterStep"));
|
||||
events.add(getEvent("afterStep("+stepExecution.getExitStatus().getExitCode()+")"));
|
||||
stepExecution.getExecutionContext().putString("afterStep", "afterStep");
|
||||
return stepExecution.getExitStatus();
|
||||
}
|
||||
@@ -175,8 +175,8 @@ public class AbstractStepTests {
|
||||
assertEquals("listener2#beforeStep", events.get(i++));
|
||||
assertEquals("open", events.get(i++));
|
||||
assertEquals("doExecute", events.get(i++));
|
||||
assertEquals("listener2#afterStep", events.get(i++));
|
||||
assertEquals("listener1#afterStep", events.get(i++));
|
||||
assertEquals("listener2#afterStep(COMPLETED)", events.get(i++));
|
||||
assertEquals("listener1#afterStep(COMPLETED)", events.get(i++));
|
||||
assertEquals("close", events.get(i++));
|
||||
assertEquals(7, events.size());
|
||||
|
||||
@@ -213,8 +213,8 @@ public class AbstractStepTests {
|
||||
assertEquals("listener2#beforeStep", events.get(i++));
|
||||
assertEquals("open", events.get(i++));
|
||||
assertEquals("doExecute", events.get(i++));
|
||||
assertEquals("listener2#afterStep", events.get(i++));
|
||||
assertEquals("listener1#afterStep", events.get(i++));
|
||||
assertEquals("listener2#afterStep(FAILED)", events.get(i++));
|
||||
assertEquals("listener1#afterStep(FAILED)", events.get(i++));
|
||||
assertEquals("close", events.get(i++));
|
||||
assertEquals(7, events.size());
|
||||
|
||||
@@ -251,8 +251,8 @@ public class AbstractStepTests {
|
||||
assertEquals("listener2#beforeStep", events.get(i++));
|
||||
assertEquals("open", events.get(i++));
|
||||
assertEquals("doExecute", events.get(i++));
|
||||
assertEquals("listener2#afterStep", events.get(i++));
|
||||
assertEquals("listener1#afterStep", events.get(i++));
|
||||
assertEquals("listener2#afterStep(STOPPED)", events.get(i++));
|
||||
assertEquals("listener1#afterStep(STOPPED)", events.get(i++));
|
||||
assertEquals("close", events.get(i++));
|
||||
assertEquals(7, events.size());
|
||||
|
||||
|
||||
@@ -100,8 +100,10 @@ public class ChunkOrientedTaskletTests {
|
||||
});
|
||||
StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(new JobInstance(
|
||||
123L, new JobParameters(), "job"))));
|
||||
ExitStatus expected = contribution.getExitStatus();
|
||||
handler.execute(contribution, context);
|
||||
assertEquals(ExitStatus.COMPLETED.getExitCode(), contribution.getExitStatus().getExitCode());
|
||||
// The tasklet does not change the exit code
|
||||
assertEquals(expected, contribution.getExitStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ public class TaskletStepExceptionTests {
|
||||
|
||||
taskletStep.execute(stepExecution);
|
||||
assertEquals(FAILED, stepExecution.getStatus());
|
||||
assertEquals(FAILED.toString(), stepExecution.getExitStatus().getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,6 +82,7 @@ public class TaskletStepExceptionTests {
|
||||
taskletStep.setStepExecutionListeners(new StepExecutionListener[] { new InterruptionListener() });
|
||||
taskletStep.execute(stepExecution);
|
||||
assertEquals(STOPPED, stepExecution.getStatus());
|
||||
assertEquals(STOPPED.toString(), stepExecution.getExitStatus().getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,7 +118,7 @@ public class TaskletStepExceptionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterStepFailure() throws Exception {
|
||||
public void testAfterStepFailureWhenTaskletSucceeds() throws Exception {
|
||||
|
||||
final RuntimeException exception = new RuntimeException();
|
||||
taskletStep.setStepExecutionListeners(new StepExecutionListenerSupport[] { new StepExecutionListenerSupport() {
|
||||
@@ -142,7 +144,7 @@ public class TaskletStepExceptionTests {
|
||||
/*
|
||||
* Exception in afterStep is ignored (only logged).
|
||||
*/
|
||||
public void testAfterStepFAilure() throws Exception {
|
||||
public void testAfterStepFailureWhenTaskletFails() throws Exception {
|
||||
|
||||
final RuntimeException exception = new RuntimeException();
|
||||
taskletStep.setStepExecutionListeners(new StepExecutionListenerSupport[] { new StepExecutionListenerSupport() {
|
||||
|
||||
Reference in New Issue
Block a user