RESOLVED - BATCH-608: JobExecutionListener.onInterrupt() is never called by spring batch framework
This commit is contained in:
@@ -134,6 +134,7 @@ public class SimpleJob extends AbstractJob {
|
|||||||
}
|
}
|
||||||
catch (JobInterruptedException e) {
|
catch (JobInterruptedException e) {
|
||||||
execution.setStatus(BatchStatus.STOPPED);
|
execution.setStatus(BatchStatus.STOPPED);
|
||||||
|
listener.onInterrupt(execution);
|
||||||
rethrow(e);
|
rethrow(e);
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.easymock.MockControl;
|
||||||
import org.springframework.batch.core.BatchStatus;
|
import org.springframework.batch.core.BatchStatus;
|
||||||
import org.springframework.batch.core.JobExecution;
|
import org.springframework.batch.core.JobExecution;
|
||||||
import org.springframework.batch.core.JobExecutionException;
|
import org.springframework.batch.core.JobExecutionException;
|
||||||
|
import org.springframework.batch.core.JobExecutionListener;
|
||||||
import org.springframework.batch.core.JobInstance;
|
import org.springframework.batch.core.JobInstance;
|
||||||
import org.springframework.batch.core.JobInterruptedException;
|
import org.springframework.batch.core.JobInterruptedException;
|
||||||
import org.springframework.batch.core.JobParameters;
|
import org.springframework.batch.core.JobParameters;
|
||||||
@@ -345,6 +347,30 @@ public class SimpleJobTests extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInterruptWithListener() throws Exception {
|
||||||
|
step1.setProcessException(new JobInterruptedException("job interrupted!"));
|
||||||
|
|
||||||
|
MockControl control = MockControl.createStrictControl(JobExecutionListener.class);
|
||||||
|
JobExecutionListener listener = (JobExecutionListener) control.getMock();
|
||||||
|
listener.beforeJob(jobExecution);
|
||||||
|
control.setVoidCallable();
|
||||||
|
listener.onInterrupt(jobExecution);
|
||||||
|
control.setVoidCallable();
|
||||||
|
control.replay();
|
||||||
|
|
||||||
|
job.setJobExecutionListeners(new JobExecutionListener[] { listener });
|
||||||
|
|
||||||
|
try {
|
||||||
|
job.execute(jobExecution);
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch (UnexpectedJobExecutionException e){
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
control.verify();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check JobRepository to ensure status is being saved.
|
* Check JobRepository to ensure status is being saved.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user