RESOLVED - BATCH-435 Tasklet step now propagates JobInterruptedException up to job
This commit is contained in:
@@ -163,6 +163,9 @@ public class TaskletStep extends AbstractStep implements Step, InitializingBean,
|
||||
catch (Exception ex) {
|
||||
logger.error("Encountered an error on listener close.", ex);
|
||||
}
|
||||
if (e instanceof JobInterruptedException) {
|
||||
throw (JobInterruptedException) e;
|
||||
}
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,27 @@ public class TaskletStepTests extends TestCase {
|
||||
assertNotNull(stepExecution.getEndTime());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When job is interrupted the {@link JobInterruptedException} should be propagated up.
|
||||
*/
|
||||
public void testJobInterrupted() throws Exception {
|
||||
TaskletStep step = new TaskletStep(
|
||||
new Tasklet(){
|
||||
public ExitStatus execute() throws Exception {
|
||||
throw new JobInterruptedException("Interrupted while executing tasklet");
|
||||
}
|
||||
},
|
||||
new JobRepositorySupport());
|
||||
|
||||
try {
|
||||
step.execute(stepExecution);
|
||||
fail();
|
||||
}
|
||||
catch (JobInterruptedException expected) {
|
||||
assertEquals("Interrupted while executing tasklet", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private class StubTasklet extends StepListenerSupport implements Tasklet {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user