RESOLVED - issue BATCH-1363: Job stopped in split state does not finish with status = STOPPED
Add some more test cases
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
|
||||
/**
|
||||
* This tasklet will call
|
||||
* {@link NameStoringTasklet#execute(StepContribution, ChunkContext)} and then
|
||||
* return CONTINUABLE, so it needs to be interrupted for it to stop.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*/
|
||||
public class InterruptibleTasklet extends NameStoringTasklet {
|
||||
|
||||
private volatile boolean started = false;
|
||||
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
if (!started) {
|
||||
super.execute(contribution, chunkContext);
|
||||
started = true;
|
||||
}
|
||||
Thread.sleep(50L);
|
||||
return RepeatStatus.CONTINUABLE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SplitInterruptedJobParserTests extends AbstractJobParserTests {
|
||||
|
||||
@Test
|
||||
public void testSplitInterrupted() throws Exception {
|
||||
|
||||
final JobExecution jobExecution = createJobExecution();
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
job.execute(jobExecution);
|
||||
}
|
||||
}).start();
|
||||
|
||||
Thread.sleep(100L);
|
||||
jobExecution.setStatus(BatchStatus.STOPPING);
|
||||
Thread.sleep(200L);
|
||||
|
||||
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
|
||||
assertEquals(ExitStatus.STOPPED, jobExecution.getExitStatus());
|
||||
|
||||
assertTrue(stepNamesList.contains("stop"));
|
||||
|
||||
StepExecution stepExecution = getStepExecution(jobExecution, "stop");
|
||||
assertEquals(BatchStatus.STOPPED, stepExecution.getStatus());
|
||||
assertEquals(ExitStatus.STOPPED.getExitCode(), stepExecution.getExitStatus().getExitCode());
|
||||
|
||||
assertEquals(1, stepNamesList.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -252,6 +252,62 @@ public class FlowJobTests {
|
||||
assertEquals(JobInterruptedException.class, jobExecution.getFailureExceptions().get(0).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterruptedException() throws Exception {
|
||||
SimpleFlow flow = new SimpleFlow("job");
|
||||
List<StateTransition> transitions = new ArrayList<StateTransition>();
|
||||
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1") {
|
||||
@Override
|
||||
public void execute(StepExecution stepExecution) throws JobInterruptedException {
|
||||
throw new JobInterruptedException("Stopped");
|
||||
}
|
||||
}), "end0"));
|
||||
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
|
||||
flow.setStateTransitions(transitions);
|
||||
flow.afterPropertiesSet();
|
||||
job.setFlow(flow);
|
||||
job.afterPropertiesSet();
|
||||
job.execute(jobExecution);
|
||||
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
|
||||
checkRepository(BatchStatus.STOPPED, ExitStatus.STOPPED);
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
assertEquals(JobInterruptedException.class, jobExecution.getFailureExceptions().get(0).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterruptedSplitException() throws Exception {
|
||||
SimpleFlow flow = new SimpleFlow("job");
|
||||
SimpleFlow flow1 = new SimpleFlow("flow1");
|
||||
SimpleFlow flow2 = new SimpleFlow("flow2");
|
||||
|
||||
List<StateTransition> transitions = new ArrayList<StateTransition>();
|
||||
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1") {
|
||||
@Override
|
||||
public void execute(StepExecution stepExecution) throws JobInterruptedException {
|
||||
throw new JobInterruptedException("Stopped");
|
||||
}
|
||||
}), "end0"));
|
||||
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
|
||||
flow1.setStateTransitions(new ArrayList<StateTransition>(transitions));
|
||||
flow1.afterPropertiesSet();
|
||||
flow2.setStateTransitions(new ArrayList<StateTransition>(transitions));
|
||||
flow2.afterPropertiesSet();
|
||||
|
||||
transitions = new ArrayList<StateTransition>();
|
||||
transitions.add(StateTransition.createStateTransition(new SplitState(Arrays.<Flow>asList(flow1, flow2), "split"), "end0"));
|
||||
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
|
||||
flow.setStateTransitions(transitions);
|
||||
flow.afterPropertiesSet();
|
||||
|
||||
job.setFlow(flow);
|
||||
job.afterPropertiesSet();
|
||||
job.execute(jobExecution);
|
||||
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
|
||||
checkRepository(BatchStatus.STOPPED, ExitStatus.STOPPED);
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
assertEquals(JobInterruptedException.class, jobExecution.getFailureExceptions().get(0).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndStateStopped() throws Exception {
|
||||
SimpleFlow flow = new SimpleFlow("job");
|
||||
|
||||
Reference in New Issue
Block a user