Ensure job interruption is treated as exception in step and job
This commit is contained in:
@@ -7,6 +7,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobInterruptedException;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
@@ -175,6 +176,43 @@ public class AbstractStepTests extends TestCase {
|
||||
.containsKey("onErrorInStep"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception during business processing.
|
||||
*/
|
||||
public void testStoppedStep() throws Exception {
|
||||
tested = new EventTrackingStep() {
|
||||
protected ExitStatus doExecute(StepExecution stepExecution) throws Exception {
|
||||
stepExecution.setTerminateOnly();
|
||||
return super.doExecute(stepExecution);
|
||||
}
|
||||
};
|
||||
tested.setJobRepository(repository);
|
||||
tested.setStepExecutionListeners(new StepExecutionListener[] { listener1, listener2 });
|
||||
|
||||
try {
|
||||
tested.execute(execution);
|
||||
fail();
|
||||
}
|
||||
catch (JobInterruptedException expected) {
|
||||
assertEquals("JobExecution interrupted.", expected.getMessage());
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
assertEquals("listener1#beforeStep", events.get(i++));
|
||||
assertEquals("listener2#beforeStep", events.get(i++));
|
||||
assertEquals("open", events.get(i++));
|
||||
assertEquals("doExecute", events.get(i++));
|
||||
assertEquals("listener2#onErrorInStep", events.get(i++));
|
||||
assertEquals("listener1#onErrorInStep", events.get(i++));
|
||||
assertEquals("close", events.get(i++));
|
||||
assertEquals(7, events.size());
|
||||
|
||||
assertEquals("JOB_INTERRUPTED", execution.getExitStatus().getExitCode());
|
||||
|
||||
assertTrue("Execution context modifications made by listener should be persisted", repository.saved
|
||||
.containsKey("onErrorInStep"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception during business processing.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user