BATCH-1822: JobExecution should be UNKNOWN if Step finishes that way
This commit is contained in:
@@ -29,8 +29,24 @@ package org.springframework.batch.core;
|
||||
*
|
||||
*/
|
||||
public class JobInterruptedException extends JobExecutionException {
|
||||
|
||||
private BatchStatus status = BatchStatus.STOPPED;
|
||||
|
||||
public JobInterruptedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public JobInterruptedException(String msg, BatchStatus status) {
|
||||
super(msg);
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* The desired status of the surrounding execution after the interruption.
|
||||
*
|
||||
* @return the status of the interruption (default STOPPED)
|
||||
*/
|
||||
public BatchStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ public abstract class AbstractJob implements Job, StepLocator, BeanNameAware,
|
||||
logger.debug("Full exception", e);
|
||||
}
|
||||
execution.setExitStatus(getDefaultExitStatusForFailure(e));
|
||||
execution.setStatus(BatchStatus.STOPPED);
|
||||
execution.setStatus(BatchStatus.max(BatchStatus.STOPPED, e.getStatus()));
|
||||
execution.addFailureException(e);
|
||||
} catch (Throwable t) {
|
||||
logger.error("Encountered fatal error executing job", t);
|
||||
|
||||
@@ -64,7 +64,7 @@ public class JobFlowExecutor implements FlowExecutor {
|
||||
return ExitStatus.COMPLETED.getExitCode();
|
||||
}
|
||||
if (stepExecution.isTerminateOnly()) {
|
||||
throw new JobInterruptedException("Step requested termination: "+stepExecution);
|
||||
throw new JobInterruptedException("Step requested termination: "+stepExecution, stepExecution.getStatus());
|
||||
}
|
||||
return stepExecution.getExitStatus().getExitCode();
|
||||
}
|
||||
|
||||
@@ -260,6 +260,19 @@ public class SimpleJobTests {
|
||||
checkRepository(BatchStatus.STOPPED, ExitStatus.STOPPED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterruptedAfterUnknownStatus() throws Exception {
|
||||
step1.setStartLimit(5);
|
||||
step2.setStartLimit(5);
|
||||
final JobInterruptedException exception = new JobInterruptedException("Interrupt!", BatchStatus.UNKNOWN);
|
||||
step1.setProcessException(exception);
|
||||
job.execute(jobExecution);
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
assertEquals(exception, jobExecution.getStepExecutions().iterator().next().getFailureExceptions().get(0));
|
||||
assertEquals(0, list.size());
|
||||
checkRepository(BatchStatus.UNKNOWN, ExitStatus.STOPPED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailed() throws Exception {
|
||||
step1.setStartLimit(5);
|
||||
@@ -573,7 +586,7 @@ public class SimpleJobTests {
|
||||
|
||||
if (exception instanceof JobInterruptedException) {
|
||||
stepExecution.setExitStatus(ExitStatus.FAILED);
|
||||
stepExecution.setStatus(BatchStatus.FAILED);
|
||||
stepExecution.setStatus(((JobInterruptedException) exception).getStatus());
|
||||
stepExecution.addFailureException(exception);
|
||||
throw (JobInterruptedException) exception;
|
||||
}
|
||||
|
||||
@@ -227,8 +227,8 @@ public class FlowJobTests {
|
||||
job.setFlow(flow);
|
||||
job.afterPropertiesSet();
|
||||
job.execute(jobExecution);
|
||||
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
|
||||
checkRepository(BatchStatus.STOPPED, ExitStatus.STOPPED);
|
||||
assertEquals(BatchStatus.UNKNOWN, jobExecution.getStatus());
|
||||
checkRepository(BatchStatus.UNKNOWN, ExitStatus.STOPPED);
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
assertEquals(JobInterruptedException.class, jobExecution.getFailureExceptions().get(0).getClass());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user