RESOLVED - issue BATCH-814: JobRepository should not require Step or Job (only their names)

Moved the check for restartability up into JobLauncher.  There is a corner case where a non-restartable job could be restarted (see comment in SimpleJobLancher), but it should have a pretty small impact.
This commit is contained in:
dsyer
2008-09-05 17:21:24 +00:00
parent db608b91a8
commit 34c2fce32f
26 changed files with 152 additions and 128 deletions

View File

@@ -5,16 +5,16 @@
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<bean id="xmlStaxJob" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<property name="itemReader">
<bean id="xmlStaxJob" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<property name="itemReader">
<bean
class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="fragmentRootElementName"

View File

@@ -27,7 +27,6 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

View File

@@ -25,45 +25,46 @@ import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* Functional test for graceful shutdown. A batch container is started in a new thread,
* then it's stopped using {@link JobExecution#stop()}.
* Functional test for graceful shutdown. A batch container is started in a new
* thread, then it's stopped using {@link JobExecution#stop()}.
*
* @author Lucas Ward
*
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class GracefulShutdownFunctionalTests extends AbstractBatchLauncherTests {
@Transactional @Test
@Test
public void testLaunchJob() throws Exception {
final JobParameters jobParameters = new JobParameters();
final JobParameters jobParameters = new JobParametersBuilder().addLong("timestamp", System.currentTimeMillis())
.toJobParameters();
JobExecution jobExecution = getLauncher().run(getJob(), jobParameters);
Thread.sleep(1000);
assertEquals(BatchStatus.STARTED, jobExecution.getStatus());
assertTrue(jobExecution.isRunning());
jobExecution.stop();
int count = 0;
while(jobExecution.isRunning() && count <= 10){
logger.info("Checking for end time in JobExecution: count="+count);
while (jobExecution.isRunning() && count <= 10) {
logger.info("Checking for end time in JobExecution: count=" + count);
Thread.sleep(100);
count++;
}
assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
}
}

View File

@@ -55,7 +55,7 @@ public class JdbcJobRepositoryTests {
private JobRepository repository;
private JobSupport jobConfiguration;
private JobSupport job;
private Set<Long> jobExecutionIds = new HashSet<Long>();
@@ -87,8 +87,8 @@ public class JdbcJobRepositoryTests {
@Before
public void onSetUpInTransaction() throws Exception {
jobConfiguration = new JobSupport("test-job");
jobConfiguration.setRestartable(true);
job = new JobSupport("test-job");
job.setRestartable(true);
simpleJdbcTemplate.update("DELETE FROM BATCH_EXECUTION_CONTEXT");
simpleJdbcTemplate.update("DELETE FROM BATCH_STEP_EXECUTION");
simpleJdbcTemplate.update("DELETE FROM BATCH_JOB_EXECUTION");
@@ -112,9 +112,9 @@ public class JdbcJobRepositoryTests {
@Transactional @Test
public void testFindOrCreateJob() throws Exception {
jobConfiguration.setName("foo");
job.setName("foo");
int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
assertEquals(before + 1, after);
assertNotNull(execution.getId());
@@ -123,7 +123,7 @@ public class JdbcJobRepositoryTests {
@Transactional @Test
public void testFindOrCreateJobConcurrently() throws Exception {
jobConfiguration.setName("bar");
job.setName("bar");
int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
assertEquals(0, before);
@@ -153,9 +153,9 @@ public class JdbcJobRepositoryTests {
@Transactional @Test
public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception {
jobConfiguration.setName("spam");
job.setName("spam");
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
cacheJobIds(execution);
execution.setEndTime(new Timestamp(System.currentTimeMillis()));
repository.update(execution);
@@ -196,7 +196,7 @@ public class JdbcJobRepositoryTests {
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
public Object doInTransaction(org.springframework.transaction.TransactionStatus status) {
try {
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
cacheJobIds(execution);
list.add(execution);
Thread.sleep(1000);
@@ -216,7 +216,7 @@ public class JdbcJobRepositoryTests {
}).start();
Thread.sleep(400);
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobParameters());
JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
cacheJobIds(execution);
int count = 0;