diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java
index d4e9c201a..9db70a515 100644
--- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java
+++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java
@@ -145,7 +145,6 @@ public class SimpleJobRepository implements JobRepository {
Assert.notNull(job, "Job must not be null.");
Assert.notNull(jobParameters, "JobParameters must not be null.");
- List jobInstances = new ArrayList();
JobInstance jobInstance;
/*
@@ -157,15 +156,14 @@ public class SimpleJobRepository implements JobRepository {
* has finished.
*/
- jobInstances = jobInstanceDao.findJobInstances(job, jobParameters);
-
- if ((jobInstances.size() > 0) && (job.isRestartable() == false)) {
- throw new BatchRestartException("JobInstance already exists and is not restartable");
- }
+ jobInstance = jobInstanceDao.getJobInstance(job, jobParameters);
- if (jobInstances.size() == 1) {
- // One job was found
- jobInstance = (JobInstance) jobInstances.get(0);
+ // existing job instance found
+ if (jobInstance != null) {
+ if (!job.isRestartable()) {
+ throw new BatchRestartException("JobInstance already exists and is not restartable");
+ }
+
jobInstance.setJobExecutionCount(jobExecutionDao.getJobExecutionCount(jobInstance));
if (jobInstance.getJobExecutionCount() > job.getStartLimit()) {
throw new BatchRestartException("Restart Max exceeded for Job: " + jobInstance.toString());
@@ -190,15 +188,10 @@ public class SimpleJobRepository implements JobRepository {
}
jobInstance.setLastExecution(lastExecution);
}
- else if (jobInstances.size() == 0) {
+ else {
// no job found, create one
jobInstance = jobInstanceDao.createJobInstance(job, jobParameters);
}
- else {
- // More than one job found, throw exception
- throw new BatchRestartException("Error restarting job, more than one JobInstance found for: "
- + job.toString());
- }
return generateJobExecution(jobInstance);
diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobInstanceDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobInstanceDao.java
index 4fef13593..dbb11092f 100644
--- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobInstanceDao.java
+++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobInstanceDao.java
@@ -158,7 +158,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
* @throws IllegalArgumentException if any {@link JobIdentifier} fields are
* null.
*/
- public List findJobInstances(final Job job, final JobParameters jobParameters) {
+ public JobInstance getJobInstance(final Job job, final JobParameters jobParameters) {
Assert.notNull(job, "Job must not be null.");
Assert.hasLength(job.getName(), "Job must have a name");
@@ -172,8 +172,15 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
return jobInstance;
}
};
-
- return getJdbcTemplate().query(getQuery(FIND_JOBS), parameters, rowMapper);
+
+ List instances = getJdbcTemplate().query(getQuery(FIND_JOBS), parameters, rowMapper);
+
+ if (instances.isEmpty()) {
+ return null;
+ } else {
+ Assert.state(instances.size() == 1);
+ return (JobInstance) instances.get(0);
+ }
}
/**
diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobInstanceDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobInstanceDao.java
index 9400fe6e4..964419b4a 100644
--- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobInstanceDao.java
+++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobInstanceDao.java
@@ -37,6 +37,6 @@ public interface JobInstanceDao {
* @return List of {@link JobInstance} objects matching
* {@link JobIdentifier}
*/
- List findJobInstances(Job job, JobParameters jobParameters);
+ JobInstance getJobInstance(Job job, JobParameters jobParameters);
}
diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobDao.java
deleted file mode 100644
index 39595ace9..000000000
--- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobDao.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.execution.repository.dao;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.springframework.batch.core.domain.Job;
-import org.springframework.batch.core.domain.JobExecution;
-import org.springframework.batch.core.domain.JobInstance;
-import org.springframework.batch.core.domain.JobParameters;
-import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
-
-public class MapJobDao implements JobInstanceDao, JobExecutionDao {
-
- private static Map jobsById;
- private static Map executionsById;
-
- private long currentId = 0;
-
- static {
- jobsById = TransactionAwareProxyFactory.createTransactionalMap();
- executionsById = TransactionAwareProxyFactory.createTransactionalMap();
- }
-
- public static void clear() {
- jobsById.clear();
- executionsById.clear();
- }
-
- public JobInstance createJobInstance(Job job, JobParameters jobParameters) {
- JobInstance jobInstance = new JobInstance(new Long(currentId++), jobParameters, job);
-
- jobsById.put(jobInstance.getId(), jobInstance);
- return jobInstance;
- }
-
- public List findJobInstances(Job job, JobParameters jobParameters) {
- List list = new ArrayList();
- for (Iterator iter = jobsById.values().iterator(); iter.hasNext();) {
- JobInstance jobInstance = (JobInstance) iter.next();
- if (jobInstance.getJobName().equals(job.getName()) && jobInstance.getJobParameters().equals(jobParameters)) {
- list.add(jobInstance);
- }
- }
- return list;
- }
-
- public int getJobExecutionCount(JobInstance jobInstance) {
- Set executions = (Set) executionsById.get(jobInstance.getId());
- if (executions==null) return 0;
- return executions.size(); }
-
- public void saveJobExecution(JobExecution jobExecution) {
- Set executions = (Set) executionsById.get(jobExecution.getJobId());
- if (executions==null) {
- executions = TransactionAwareProxyFactory.createTransactionalSet();
- executionsById.put(jobExecution.getJobId(), executions);
- }
- executions.add(jobExecution);
- jobExecution.setId(new Long(currentId++));
- }
-
- public List findJobExecutions(JobInstance jobInstance) {
- Set executions = (Set) executionsById.get(jobInstance.getId());
- if( executions == null ){
- return new ArrayList();
- }
- else{
- return new ArrayList(executions);
- }
- }
-
- public void updateJobExecution(JobExecution jobExecution) {
- // no-op
- }
-
- public JobExecution getLastJobExecution(JobInstance jobInstance) {
- // no-op
- return null;
- }
-
-}
diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobExecutionDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobExecutionDao.java
new file mode 100644
index 000000000..6a328d6a8
--- /dev/null
+++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobExecutionDao.java
@@ -0,0 +1,58 @@
+package org.springframework.batch.execution.repository.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.batch.core.domain.JobExecution;
+import org.springframework.batch.core.domain.JobInstance;
+import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
+import org.springframework.util.Assert;
+
+public class MapJobExecutionDao implements JobExecutionDao {
+
+ private static Map executionsByJobInstanceId = TransactionAwareProxyFactory.createTransactionalMap();
+
+ private static long currentId;
+
+ public static void clear() {
+ executionsByJobInstanceId.clear();
+ }
+
+ public int getJobExecutionCount(JobInstance jobInstance) {
+ Set executions = (Set) executionsByJobInstanceId.get(jobInstance.getId());
+ if (executions == null)
+ return 0;
+ return executions.size();
+ }
+
+ public void saveJobExecution(JobExecution jobExecution) {
+ Set executions = (Set) executionsByJobInstanceId.get(jobExecution.getJobId());
+ if (executions == null) {
+ executions = TransactionAwareProxyFactory.createTransactionalSet();
+ executionsByJobInstanceId.put(jobExecution.getJobId(), executions);
+ }
+ executions.add(jobExecution);
+ jobExecution.setId(new Long(currentId++));
+ }
+
+ public List findJobExecutions(JobInstance jobInstance) {
+ Set executions = (Set) executionsByJobInstanceId.get(jobInstance.getId());
+ if (executions == null) {
+ return new ArrayList();
+ }
+ else {
+ return new ArrayList(executions);
+ }
+ }
+
+ public void updateJobExecution(JobExecution jobExecution) {
+ Assert.notNull(jobExecution.getJobId());
+ }
+
+ public JobExecution getLastJobExecution(JobInstance jobInstance) {
+ Assert.notNull(jobInstance.getId());
+ return null;
+ }
+}
diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobInstanceDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobInstanceDao.java
new file mode 100644
index 000000000..c98abc228
--- /dev/null
+++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapJobInstanceDao.java
@@ -0,0 +1,45 @@
+package org.springframework.batch.execution.repository.dao;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.springframework.batch.core.domain.Job;
+import org.springframework.batch.core.domain.JobInstance;
+import org.springframework.batch.core.domain.JobParameters;
+import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
+
+public class MapJobInstanceDao implements JobInstanceDao {
+
+ private static Collection jobInstances = TransactionAwareProxyFactory.createTransactionalList();
+
+ private long currentId = 0;
+
+ public static void clear() {
+ jobInstances.clear();
+ }
+
+ public JobInstance createJobInstance(Job job, JobParameters jobParameters) {
+
+ if (getJobInstance(job, jobParameters) != null) {
+ throw new IllegalArgumentException("JobInstance already exists for given job and parameters");
+ }
+
+ JobInstance jobInstance = new JobInstance(new Long(currentId++), jobParameters, job);
+ jobInstances.add(jobInstance);
+
+ return jobInstance;
+ }
+
+ public JobInstance getJobInstance(Job job, JobParameters jobParameters) {
+
+ for (Iterator iterator = jobInstances.iterator(); iterator.hasNext();) {
+ JobInstance instance = (JobInstance) iterator.next();
+ if (instance.getJobName().equals(job.getName()) && instance.getJobParameters().equals(jobParameters)) {
+ return instance;
+ }
+ }
+ return null;
+
+ }
+
+}
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/SimpleJobTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/SimpleJobTests.java
index 75538a178..c2f1bc724 100644
--- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/SimpleJobTests.java
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/SimpleJobTests.java
@@ -30,11 +30,11 @@ import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier;
-import org.springframework.batch.execution.job.SimpleJob;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.JobExecutionDao;
import org.springframework.batch.execution.repository.dao.JobInstanceDao;
-import org.springframework.batch.execution.repository.dao.MapJobDao;
+import org.springframework.batch.execution.repository.dao.MapJobExecutionDao;
+import org.springframework.batch.execution.repository.dao.MapJobInstanceDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;
import org.springframework.batch.execution.repository.dao.StepExecutionDao;
import org.springframework.batch.execution.step.AbstractStep;
@@ -83,10 +83,11 @@ public class SimpleJobTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
- MapJobDao.clear();
+ MapJobInstanceDao.clear();
+ MapJobExecutionDao.clear();
MapStepDao.clear();
- jobInstanceDao = new MapJobDao();
- jobExecutionDao = new MapJobDao();
+ jobInstanceDao = new MapJobInstanceDao();
+ jobExecutionDao = new MapJobExecutionDao();
stepExecutionDao = new MapStepDao();
jobRepository = new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao);
job = new SimpleJob();
@@ -255,7 +256,7 @@ public class SimpleJobTests extends TestCase {
* Check JobRepository to ensure status is being saved.
*/
private void checkRepository(BatchStatus status, ExitStatus exitStatus) {
- assertEquals(jobInstance, jobInstanceDao.findJobInstances(jobInstance.getJob(), jobParameters).get(0));
+ assertEquals(jobInstance, jobInstanceDao.getJobInstance(jobInstance.getJob(), jobParameters));
// because map dao stores in memory, it can be checked directly
JobExecution jobExecution = (JobExecution) jobExecutionDao.findJobExecutions(jobInstance).get(0);
assertEquals(jobInstance.getId(), jobExecution.getJobId());
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/SimpleJobTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/SimpleJobTests.java
index 06c30e73a..37890e86a 100644
--- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/SimpleJobTests.java
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/SimpleJobTests.java
@@ -30,7 +30,8 @@ import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.execution.job.SimpleJob;
import org.springframework.batch.execution.repository.SimpleJobRepository;
-import org.springframework.batch.execution.repository.dao.MapJobDao;
+import org.springframework.batch.execution.repository.dao.MapJobExecutionDao;
+import org.springframework.batch.execution.repository.dao.MapJobInstanceDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;
import org.springframework.batch.execution.step.AbstractStep;
import org.springframework.batch.execution.step.ItemOrientedStep;
@@ -48,7 +49,7 @@ public class SimpleJobTests extends TestCase {
private List recovered = new ArrayList();
- private SimpleJobRepository repository = new SimpleJobRepository(new MapJobDao(), new MapJobDao(), new MapStepDao());
+ private SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), new MapStepDao());
private List processed = new ArrayList();
@@ -65,7 +66,8 @@ public class SimpleJobTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
job.setJobRepository(repository);
- MapJobDao.clear();
+ MapJobInstanceDao.clear();
+ MapJobExecutionDao.clear();
MapStepDao.clear();
}
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java
index 850da98cf..a2013424a 100644
--- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java
@@ -226,36 +226,12 @@ public class SimpleJobRepositoryTests extends TestCase {
//// assertTrue(step.getStepExecutionCount() == 1);
}
- // Test that a restartable job that has multiple instances throws an
- // exception.
- public void testFindRestartableJobWithMultipleInstances() throws Exception {
-
- List jobs = new ArrayList();
- jobs.add(databaseJob);
- jobs.add(new JobInstance(new Long(127), jobParameters, jobConfiguration));
- jobInstanceDao.findJobInstances(jobConfiguration, jobParameters);
- jobInstanceDaoControl.setReturnValue(jobs);
- jobInstanceDaoControl.replay();
-
- try {
- jobRepository.createJobExecution(jobConfiguration, jobParameters);
- fail("Expected BatchRestartException");
- }
- catch (BatchRestartException e) {
- // expected
- }
-
- jobInstanceDaoControl.verify();
- }
-
public void testRestartJobStartLimitExceeded() throws Exception {
jobConfiguration.setStartLimit(1);
- List jobs = new ArrayList();
- jobInstanceDao.findJobInstances(jobConfiguration, jobParameters);
- jobs.add(databaseJob);
- jobInstanceDaoControl.setReturnValue(jobs);
+ jobInstanceDao.getJobInstance(jobConfiguration, jobParameters);
+ jobInstanceDaoControl.setReturnValue(databaseJob);
jobExecutionDao.getJobExecutionCount(databaseJob);
// return a greater execution count then the start limit, should throw
// exception
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java
index 14483b0b1..bacab526f 100644
--- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java
@@ -99,23 +99,22 @@ public abstract class AbstractJobDaoTests extends AbstractTransactionalDataSourc
public void testFindNonExistentJob() {
// No job should be found since it hasn't been created.
- List jobs = jobInstanceDao.findJobInstances(new JobSupport("nonexistentJob"), jobParameters);
- assertTrue(jobs.size() == 0);
+ JobInstance jobInstance = jobInstanceDao.getJobInstance(new JobSupport("nonexistentJob"), jobParameters);
+ assertNull(jobInstance);
}
public void testFindJob() {
- List jobs = jobInstanceDao.findJobInstances(job, jobParameters);
- assertTrue(jobs.size() == 1);
- JobInstance tempJob = (JobInstance) jobs.get(0);
- assertTrue(jobInstance.equals(tempJob));
- assertEquals(jobParameters, tempJob.getJobParameters());
+ JobInstance instance = jobInstanceDao.getJobInstance(job, jobParameters);
+ assertNotNull(instance);
+ assertTrue(jobInstance.equals(instance));
+ assertEquals(jobParameters, instance.getJobParameters());
}
public void testFindJobWithNullRuntime() {
try {
- jobInstanceDao.findJobInstances(null, null);
+ jobInstanceDao.getJobInstance(null, null);
fail();
}
catch (IllegalArgumentException ex) {
@@ -137,14 +136,13 @@ public abstract class AbstractJobDaoTests extends AbstractTransactionalDataSourc
// JobInstance
JobParameters tempProps = new JobParametersBuilder().addString("job.key", "testKey1").toJobParameters();
- List jobs;
- jobs = jobInstanceDao.findJobInstances(scheduledJob, jobParameters);
- assertEquals(1, jobs.size());
- JobInstance jobInstance = (JobInstance) jobs.get(0);
- assertEquals(jobParameters, jobInstance.getJobParameters());
+ JobInstance instance;
+ instance = jobInstanceDao.getJobInstance(scheduledJob, jobParameters);
+ assertNotNull(instance);
+ assertEquals(jobParameters, instance.getJobParameters());
- jobs = jobInstanceDao.findJobInstances(scheduledJob, tempProps);
- assertEquals(0, jobs.size());
+ instance = jobInstanceDao.getJobInstance(scheduledJob, tempProps);
+ assertNull(instance);
}
@@ -231,10 +229,10 @@ public abstract class AbstractJobDaoTests extends AbstractTransactionalDataSourc
// Create job.
jobInstance = jobInstanceDao.createJobInstance(testDefaultJob, jobParameters);
- List jobs = jobInstanceDao.findJobInstances(testDefaultJob, jobParameters);
+ JobInstance instance = jobInstanceDao.getJobInstance(testDefaultJob, jobParameters);
- assertEquals(1, jobs.size());
- assertEquals(jobParameters.getString("job.key"), ((JobInstance) jobs.get(0)).getJobParameters().getString(
+ assertNotNull(instance);
+ assertEquals(jobParameters.getString("job.key"), instance.getJobParameters().getString(
"job.key"));
}
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobDaoTests.java
deleted file mode 100644
index e241d4f15..000000000
--- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobDaoTests.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.execution.repository.dao;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.springframework.batch.core.domain.Job;
-import org.springframework.batch.core.domain.JobExecution;
-import org.springframework.batch.core.domain.JobInstance;
-import org.springframework.batch.core.domain.JobParameters;
-import org.springframework.batch.execution.job.JobSupport;
-
-public class MapJobDaoTests extends TestCase {
-
- MapJobDao dao = new MapJobDao();
-
- JobParameters jobParameters = new JobParameters();
-
- Job fooJob = new JobSupport("foo");
-
- protected void setUp() throws Exception {
- MapJobDao.clear();
- }
-
- public void testCreateAndRetrieveSingle() throws Exception {
- JobInstance job = dao.createJobInstance(fooJob, jobParameters);
- List result = dao.findJobInstances(fooJob, jobParameters);
- assertTrue(result.contains(job));
- }
-
- public void testCreateAndRetrieveMultiple() throws Exception {
- JobInstance job = dao.createJobInstance(fooJob, jobParameters);
- Job barJob = new JobSupport("bar");
- job = dao.createJobInstance(barJob, jobParameters);
- List result = dao.findJobInstances(barJob, jobParameters);
- assertEquals(1, result.size());
- assertTrue(result.contains(job));
- }
-
- public void testNoExecutionsForNewJob() throws Exception {
- JobInstance job = dao.createJobInstance(fooJob, jobParameters);
- assertEquals(0, dao.getJobExecutionCount(job));
- }
-
- public void testSaveExecutionUpdatesId() throws Exception {
- JobInstance job = dao.createJobInstance(fooJob, jobParameters);
- JobExecution execution = new JobExecution(job);
- assertNull(execution.getId());
- dao.saveJobExecution(execution);
- assertNotNull(execution.getId());
- }
- public void testCorrectExecutionCountForExistingJob() throws Exception {
- JobInstance job = dao.createJobInstance(fooJob, jobParameters);
- dao.saveJobExecution(new JobExecution(job));
- assertEquals(1, dao.getJobExecutionCount(job));
- }
-
- public void testMultipleExecutionsPerExisting() throws Exception {
- JobInstance job = dao.createJobInstance(fooJob, jobParameters);
- dao.saveJobExecution(new JobExecution(job));
- Thread.sleep(50L); // Hack, hack, hackety, hack - job executions are not unique if created too close together!
- dao.saveJobExecution(new JobExecution(job));
- assertEquals(2, dao.getJobExecutionCount(job));
- }
-}
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobExecutionDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobExecutionDaoTests.java
new file mode 100644
index 000000000..a3738a876
--- /dev/null
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobExecutionDaoTests.java
@@ -0,0 +1,57 @@
+package org.springframework.batch.execution.repository.dao;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.springframework.batch.core.domain.JobExecution;
+import org.springframework.batch.core.domain.JobInstance;
+import org.springframework.batch.core.domain.JobParameters;
+import org.springframework.batch.execution.job.JobSupport;
+
+public class MapJobExecutionDaoTests extends TestCase {
+
+ JobExecutionDao dao = new MapJobExecutionDao();
+
+ JobInstance jobInstance = new JobInstance(new Long(1), new JobParameters(), new JobSupport("execTestJob"));
+
+ protected void setUp() throws Exception {
+ MapJobExecutionDao.clear();
+ }
+
+ /**
+ * Save and find a job execution.
+ */
+ public void testSaveAndFind() {
+ JobExecution exec = new JobExecution(jobInstance);
+ dao.saveJobExecution(exec);
+
+ List executions = dao.findJobExecutions(jobInstance);
+ assertTrue(executions.size() == 1);
+ assertEquals(exec, executions.get(0));
+ }
+
+ /**
+ * Saving sets id to the entity.
+ */
+ public void testSaveAddsId() {
+ JobExecution exec = new JobExecution(jobInstance);
+ assertNull(exec.getId());
+ dao.saveJobExecution(exec);
+ assertNotNull(exec.getId());
+ }
+ /**
+ * Execution count increases by one with every save
+ * for the same job instance.
+ */
+ public void testGetExecutionCount() {
+ JobExecution exec1 = new JobExecution(jobInstance);
+ JobExecution exec2 = new JobExecution(jobInstance);
+
+ dao.saveJobExecution(exec1);
+ assertEquals(1, dao.getJobExecutionCount(jobInstance));
+
+ dao.saveJobExecution(exec2);
+ assertEquals(2, dao.getJobExecutionCount(jobInstance));
+ }
+}
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobInstanceDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobInstanceDaoTests.java
new file mode 100644
index 000000000..e4fc224d7
--- /dev/null
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobInstanceDaoTests.java
@@ -0,0 +1,38 @@
+package org.springframework.batch.execution.repository.dao;
+
+import junit.framework.TestCase;
+
+import org.springframework.batch.core.domain.Job;
+import org.springframework.batch.core.domain.JobInstance;
+import org.springframework.batch.core.domain.JobParameters;
+import org.springframework.batch.core.domain.JobParametersBuilder;
+import org.springframework.batch.execution.job.JobSupport;
+
+public class MapJobInstanceDaoTests extends TestCase {
+
+ JobInstanceDao dao = new MapJobInstanceDao();
+
+ protected void setUp() throws Exception {
+ MapJobInstanceDao.clear();
+ }
+
+ protected void tearDown() throws Exception {
+ MapJobInstanceDao.clear();
+ }
+
+ /**
+ * Create and retrieve a job instance.
+ */
+ public void testCreateAndRetrieve() throws Exception {
+ Job fooJob = new JobSupport("foo");
+ JobParameters fooParams = new JobParametersBuilder().addString("fooKey", "fooValue").toJobParameters();
+
+ JobInstance fooInstance = dao.createJobInstance(fooJob, fooParams);
+ assertNotNull(fooInstance.getId());
+ assertEquals(fooJob, fooInstance.getJob());
+ assertEquals(fooParams, fooInstance.getJobParameters());
+
+ JobInstance retrievedInstance = dao.getJobInstance(fooJob, fooParams);
+ assertEquals(fooInstance, retrievedInstance);
+ }
+}
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java
index 145ef794d..491e17c3b 100644
--- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java
@@ -32,7 +32,8 @@ import org.springframework.batch.core.domain.StepContribution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.repository.SimpleJobRepository;
-import org.springframework.batch.execution.repository.dao.MapJobDao;
+import org.springframework.batch.execution.repository.dao.MapJobExecutionDao;
+import org.springframework.batch.execution.repository.dao.MapJobInstanceDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;
import org.springframework.batch.execution.scope.StepSynchronizationManager;
import org.springframework.batch.execution.step.support.JobRepositorySupport;
@@ -195,7 +196,7 @@ public class ItemOrientedStepTests extends TestCase {
public void testRepository() throws Exception {
- SimpleJobRepository repository = new SimpleJobRepository(new MapJobDao(), new MapJobDao(), new MapStepDao());
+ SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), new MapStepDao());
itemOrientedStep.setJobRepository(repository);
Step step = new StepSupport("stepName");
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/StepExecutorInterruptionTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/StepExecutorInterruptionTests.java
index 0ca88f7ba..5c8721a98 100644
--- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/StepExecutorInterruptionTests.java
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/StepExecutorInterruptionTests.java
@@ -29,7 +29,8 @@ import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.JobExecutionDao;
import org.springframework.batch.execution.repository.dao.JobInstanceDao;
-import org.springframework.batch.execution.repository.dao.MapJobDao;
+import org.springframework.batch.execution.repository.dao.MapJobExecutionDao;
+import org.springframework.batch.execution.repository.dao.MapJobInstanceDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;
import org.springframework.batch.execution.repository.dao.StepExecutionDao;
import org.springframework.batch.execution.step.ItemOrientedStep;
@@ -44,16 +45,17 @@ public class StepExecutorInterruptionTests extends TestCase {
private JobRepository jobRepository;
- private JobInstanceDao jobInstanceDao = new MapJobDao();
+ private JobInstanceDao jobInstanceDao = new MapJobInstanceDao();
- private JobExecutionDao jobExecutionDao = new MapJobDao();
+ private JobExecutionDao jobExecutionDao = new MapJobExecutionDao();
private StepExecutionDao stepExecutionDao = new MapStepDao();
private ItemOrientedStep step;
public void setUp() throws Exception {
- MapJobDao.clear();
+ MapJobInstanceDao.clear();
+ MapJobExecutionDao.clear();
MapStepDao.clear();
jobRepository = new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao);
diff --git a/spring-batch-execution/src/test/resources/simple-container-definition.xml b/spring-batch-execution/src/test/resources/simple-container-definition.xml
index b0192e051..bc15e6e2a 100644
--- a/spring-batch-execution/src/test/resources/simple-container-definition.xml
+++ b/spring-batch-execution/src/test/resources/simple-container-definition.xml
@@ -44,13 +44,17 @@
-
-
+
+
-
+
+
+
+
-
+
+
+
-