IN PROGRESS - BATCH-961: integration tests for JobOperator
added start-stop-resume-stop testcase
This commit is contained in:
@@ -41,6 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class GracefulShutdownFunctionalTests extends AbstractBatchLauncherTests {
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testLaunchJob() throws Exception {
|
||||
|
||||
final JobParameters jobParameters = new JobParametersBuilder().addLong("timestamp", System.currentTimeMillis())
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.springframework.batch.core.BatchStatus.*;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.configuration.ListableJobRegistry;
|
||||
import org.springframework.batch.core.configuration.support.ReferenceJobFactory;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.core.launch.NoSuchJobExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration()
|
||||
public class JobOperatorFunctionalTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(JobOperatorFunctionalTests.class);
|
||||
|
||||
@Autowired
|
||||
JobOperator tested;
|
||||
|
||||
@Autowired
|
||||
JobLauncher launcher;
|
||||
|
||||
@Autowired
|
||||
Job job;
|
||||
|
||||
@Autowired
|
||||
ListableJobRegistry jobRegistry;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
jobRegistry.register(new ReferenceJobFactory(job));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartStopResumeJob() throws Exception {
|
||||
|
||||
String params = new JobParametersBuilder().addLong("jobOperatorTestParam", 7L).toJobParameters().toString();
|
||||
long executionId = tested.start(job.getName(), params);
|
||||
stopAndCheckStatus(executionId);
|
||||
|
||||
long resumedExecutionId = tested.resume(executionId);
|
||||
stopAndCheckStatus(resumedExecutionId);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param executionId id of running job execution
|
||||
*/
|
||||
private void stopAndCheckStatus(long executionId) throws InterruptedException, NoSuchJobExecutionException {
|
||||
Thread.sleep(1000);
|
||||
|
||||
assertTrue(tested.getSummary(executionId).contains(STARTED.toString()));
|
||||
|
||||
tested.stop(executionId);
|
||||
|
||||
int count = 0;
|
||||
while (!tested.getSummary(executionId).contains(STOPPED.toString()) && count <= 10) {
|
||||
logger.info("Checking for end time in JobExecution: count=" + count);
|
||||
Thread.sleep(100);
|
||||
count++;
|
||||
}
|
||||
|
||||
String summary = tested.getSummary(executionId);
|
||||
assertFalse("Timed out waiting for job to end.", summary.contains(STARTED.toString()));
|
||||
assertTrue(summary.contains(STOPPED.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/simple-job-launcher-context.xml" />
|
||||
<import resource="classpath:/jobs/infiniteLoopJob.xml" />
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user