JobRepository#saveOrUpdate(StepExecution) now assumes JobExecution is already persisted

(true for real job run, but had to fix few unrealistic tests)
This commit is contained in:
robokaso
2008-03-03 16:00:10 +00:00
parent c7b141d295
commit 2ee372a0b3
4 changed files with 8 additions and 56 deletions

View File

@@ -238,13 +238,9 @@ public class SimpleJobRepository implements JobRepository {
Assert.notNull(stepExecution, "StepExecution cannot be null.");
Assert.notNull(stepExecution.getStepName(), "StepExecution's step name cannot be null.");
Assert.notNull(stepExecution.getJobExecutionId(), "StepExecution must belong to persisted JobExecution");
if (stepExecution.getId() == null) {
// new execution, obtain id and insert
JobExecution jobExecution = stepExecution.getJobExecution();
if (jobExecution.getId() == null) {
jobExecutionDao.saveJobExecution(jobExecution);
}
stepExecutionDao.saveStepExecution(stepExecution);
}
else {

View File

@@ -318,50 +318,6 @@ public class SimpleJobRepositoryTests extends TestCase {
jobRepository.saveOrUpdate(jobExecution);
}
public void testUpdateStepExecution() {
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), null, new Long(1));
stepExecution.setId(new Long(11));
ExecutionContext executionContext = new ExecutionContext();
stepExecution.setExecutionContext(executionContext);
stepExecutionDao.updateStepExecution(stepExecution);
stepExecutionDaoControl.replay();
jobRepository.saveOrUpdate(stepExecution);
stepExecutionDaoControl.verify();
}
public void testUpdateExecutionContext() {
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), null, new Long(1));
stepExecution.setId(new Long(11));
ExecutionContext executionContext = new ExecutionContext();
stepExecution.setExecutionContext(executionContext);
stepExecutionDao.updateStepExecution(stepExecution);
stepExecutionDao.saveOrUpdateExecutionContext(stepExecution);
stepExecutionDaoControl.replay();
jobRepository.saveOrUpdateExecutionContext(stepExecution);
stepExecutionDaoControl.verify();
}
public void testSaveExistingStepExecution() {
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(null), null);
ExecutionContext executionContext = new ExecutionContext();
stepExecution.setExecutionContext(executionContext);
stepExecutionDao.saveStepExecution(stepExecution);
stepExecutionDaoControl.replay();
jobRepository.saveOrUpdate(stepExecution);
stepExecutionDaoControl.verify();
}
public void testSaveExistingExecutionContext() {
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(null), null);
ExecutionContext executionContext = new ExecutionContext();
stepExecution.setExecutionContext(executionContext);
stepExecutionDao.saveStepExecution(stepExecution);
stepExecutionDao.saveOrUpdateExecutionContext(stepExecution);
stepExecutionDaoControl.replay();
jobRepository.saveOrUpdateExecutionContext(stepExecution);
stepExecutionDaoControl.verify();
}
public void testSaveOrUpdateStepExecutionException() {
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), null, null);

View File

@@ -144,8 +144,8 @@ public class ItemOrientedStepTests extends TestCase {
SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), new MapStepExecutionDao());
itemOrientedStep.setJobRepository(repository);
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext);
JobExecution jobExecution = repository.createJobExecution(jobInstance.getJob(), jobInstance.getJobParameters());
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecution);
itemOrientedStep.execute(stepExecution);
assertEquals(1, processed.size());

View File

@@ -20,7 +20,6 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
@@ -52,6 +51,8 @@ public class StepExecutorInterruptionTests extends TestCase {
private StepExecutionDao stepExecutionDao = new MapStepExecutionDao();
private ItemOrientedStep step;
private JobExecution jobExecution;
public void setUp() throws Exception {
MapJobInstanceDao.clear();
@@ -64,7 +65,7 @@ public class StepExecutorInterruptionTests extends TestCase {
step = new ItemOrientedStep("interruptedStep");
jobConfiguration.addStep(step);
jobConfiguration.setBeanName("testJob");
jobRepository.createJobExecution(jobConfiguration, new JobParameters());
jobExecution = jobRepository.createJobExecution(jobConfiguration, new JobParameters());
step.setJobRepository(jobRepository);
step.setTransactionManager(new ResourcelessTransactionManager());
step.setItemReader(new ItemReaderAdapter());
@@ -76,8 +77,7 @@ public class StepExecutorInterruptionTests extends TestCase {
public void testInterruptChunk() throws Exception {
JobExecution jobExecutionContext = new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")));
final StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
final StepExecution stepExecution = new StepExecution(step, jobExecution);
step.setItemReader(new AbstractItemReader() {
public Object read() throws Exception {
// do something non-trivial (and not Thread.sleep())