OPEN - issue BATCH-773: Refactor and extend ExportedJobLauncher to JobOperator
Add some new methods to the daos to support the JobOperator
This commit is contained in:
@@ -126,8 +126,8 @@ public class SimpleJobTests extends TestCase {
|
||||
jobExecution = jobRepository.createJobExecution(job, jobParameters);
|
||||
jobInstance = jobExecution.getJobInstance();
|
||||
|
||||
stepExecution1 = new StepExecution(step1.getName(), jobExecution, null);
|
||||
stepExecution2 = new StepExecution(step2.getName(), jobExecution, null);
|
||||
stepExecution1 = new StepExecution(step1.getName(), jobExecution);
|
||||
stepExecution2 = new StepExecution(step2.getName(), jobExecution);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,14 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -27,6 +30,13 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
*/
|
||||
protected abstract JobExecutionDao getJobExecutionDao();
|
||||
|
||||
/**
|
||||
* @return tested object ready for use
|
||||
*/
|
||||
protected StepExecutionDao getStepExecutionDao() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void onSetUp() throws Exception {
|
||||
dao = getJobExecutionDao();
|
||||
@@ -35,7 +45,8 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
/**
|
||||
* Save and find a job execution.
|
||||
*/
|
||||
@Transactional @Test
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSaveAndFind() {
|
||||
|
||||
dao.saveJobExecution(execution);
|
||||
@@ -48,7 +59,8 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
/**
|
||||
* Saving sets id to the entity.
|
||||
*/
|
||||
@Transactional @Test
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSaveAddsIdAndVersion() {
|
||||
|
||||
assertNull(execution.getId());
|
||||
@@ -62,7 +74,8 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
* Update and retrieve job execution - check attributes have changed as
|
||||
* expected.
|
||||
*/
|
||||
@Transactional @Test
|
||||
@Transactional
|
||||
@Test
|
||||
public void testUpdateExecution() {
|
||||
execution.setStatus(BatchStatus.STARTED);
|
||||
dao.saveJobExecution(execution);
|
||||
@@ -78,7 +91,8 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
/**
|
||||
* Check the execution with most recent start time is returned
|
||||
*/
|
||||
@Transactional @Test
|
||||
@Transactional
|
||||
@Test
|
||||
public void testGetLastExecution() {
|
||||
JobExecution exec1 = new JobExecution(jobInstance);
|
||||
exec1.setCreateTime(new Date(0));
|
||||
@@ -92,5 +106,47 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
JobExecution last = dao.getLastJobExecution(jobInstance);
|
||||
assertEquals(exec2, last);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check the execution is returned
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testFindRunningExecutions() {
|
||||
JobExecution exec = new JobExecution(jobInstance);
|
||||
exec.setCreateTime(new Date(0));
|
||||
exec.setEndTime(new Date(0));
|
||||
dao.saveJobExecution(exec);
|
||||
exec = new JobExecution(jobInstance);
|
||||
exec.createStepExecution(new StepSupport("foo"));
|
||||
dao.saveJobExecution(exec);
|
||||
StepExecutionDao stepExecutionDao = getStepExecutionDao();
|
||||
if (stepExecutionDao != null) {
|
||||
for (StepExecution stepExecution : exec.getStepExecutions()) {
|
||||
stepExecutionDao.saveStepExecution(stepExecution);
|
||||
}
|
||||
}
|
||||
Set<JobExecution> values = dao.findRunningJobExecutions(exec.getJobInstance().getJobName());
|
||||
|
||||
assertEquals(1, values.size());
|
||||
JobExecution value = values.iterator().next();
|
||||
assertEquals(exec, value);
|
||||
assertEquals(1, value.getStepExecutions().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the execution is returned
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testGetExecution() {
|
||||
JobExecution exec = new JobExecution(jobInstance);
|
||||
exec.setCreateTime(new Date(0));
|
||||
|
||||
dao.saveJobExecution(exec);
|
||||
JobExecution value = dao.getJobExecution(exec.getId());
|
||||
|
||||
assertEquals(exec, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,15 @@
|
||||
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
@@ -93,19 +98,32 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
stepExecution.setRollbackCount(3);
|
||||
dao.saveStepExecution(stepExecution);
|
||||
|
||||
StepExecution retrieved = dao.getStepExecution(jobExecution, step);
|
||||
StepExecution retrieved = dao.getStepExecution(jobExecution, step.getName());
|
||||
assertEquals(stepExecution, retrieved);
|
||||
assertEquals(BatchStatus.STARTED, retrieved.getStatus());
|
||||
assertEquals(stepExecution.getReadSkipCount(), retrieved.getReadSkipCount());
|
||||
assertEquals(stepExecution.getWriteSkipCount(), retrieved.getWriteSkipCount());
|
||||
assertEquals(stepExecution.getRollbackCount(), retrieved.getRollbackCount());
|
||||
|
||||
assertNull(dao.getStepExecution(jobExecution, new StepSupport("not-existing step")));
|
||||
assertNull(dao.getStepExecution(jobExecution, "not-existing step"));
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
public void testSaveAndGetExecution() {
|
||||
|
||||
stepExecution.setStatus(BatchStatus.STARTED);
|
||||
stepExecution.setReadSkipCount(7);
|
||||
stepExecution.setWriteSkipCount(5);
|
||||
stepExecution.setRollbackCount(3);
|
||||
dao.saveStepExecution(stepExecution);
|
||||
|
||||
List<StepExecution> retrieved = dao.getStepExecutions(jobExecution);
|
||||
assertEquals(stepExecution, retrieved.get(0));
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
public void testGetForNotExistingJobExecution() {
|
||||
assertNull(dao.getStepExecution(new JobExecution(jobInstance, (long) 777), step));
|
||||
assertNull(dao.getStepExecution(new JobExecution(jobInstance, (long) 777), step.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +170,7 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
dao.updateStepExecution(stepExecution);
|
||||
assertEquals(versionAfterSave + 1, stepExecution.getVersion().intValue());
|
||||
|
||||
StepExecution retrieved = dao.getStepExecution(jobExecution, step);
|
||||
StepExecution retrieved = dao.getStepExecution(jobExecution, step.getName());
|
||||
assertEquals(stepExecution, retrieved);
|
||||
assertEquals(BatchStatus.STOPPED, retrieved.getStatus());
|
||||
}
|
||||
|
||||
@@ -1,21 +1,36 @@
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"sql-dao-test.xml"})
|
||||
@ContextConfiguration(locations = { "sql-dao-test.xml" })
|
||||
public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
|
||||
|
||||
@Autowired
|
||||
private StepExecutionDao stepExecutionDao;
|
||||
|
||||
@Autowired
|
||||
private JobExecutionDao jobExecutionDao;
|
||||
|
||||
@Override
|
||||
protected JobExecutionDao getJobExecutionDao() {
|
||||
deleteFromTables("BATCH_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION",
|
||||
"BATCH_JOB_PARAMS", "BATCH_JOB_INSTANCE");
|
||||
deleteFromTables("BATCH_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS",
|
||||
"BATCH_JOB_INSTANCE");
|
||||
|
||||
// job instance needs to exist before job execution can be created
|
||||
simpleJdbcTemplate.getJdbcOperations().execute(
|
||||
"insert into BATCH_JOB_INSTANCE (JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (1,'execTestJob', '', 0)");
|
||||
return (JobExecutionDao) applicationContext.getBean("jobExecutionDao");
|
||||
simpleJdbcTemplate
|
||||
.getJdbcOperations()
|
||||
.execute(
|
||||
"insert into BATCH_JOB_INSTANCE (JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (1,'execTestJob', '', 0)");
|
||||
return jobExecutionDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StepExecutionDao getStepExecutionDao() {
|
||||
return stepExecutionDao;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -44,14 +44,14 @@ public class JdbcStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
|
||||
((JdbcStepExecutionDao) dao).setExitMessageLength(250);
|
||||
dao.saveStepExecution(stepExecution);
|
||||
|
||||
StepExecution retrievedAfterSave = dao.getStepExecution(jobExecution, step);
|
||||
StepExecution retrievedAfterSave = dao.getStepExecution(jobExecution, step.getName());
|
||||
|
||||
assertTrue("Exit description should be truncated", retrievedAfterSave.getExitStatus().getExitDescription()
|
||||
.length() < stepExecution.getExitStatus().getExitDescription().length());
|
||||
|
||||
dao.updateStepExecution(stepExecution);
|
||||
|
||||
StepExecution retrievedAfterUpdate = dao.getStepExecution(jobExecution, step);
|
||||
StepExecution retrievedAfterUpdate = dao.getStepExecution(jobExecution, step.getName());
|
||||
|
||||
assertTrue("Exit description should be truncated", retrievedAfterUpdate.getExitStatus().getExitDescription()
|
||||
.length() < stepExecution.getExitStatus().getExitDescription().length());
|
||||
|
||||
@@ -140,9 +140,9 @@ public class JobRepositoryFactoryBeanTests {
|
||||
|
||||
expect(incrementerFactory.isSupportedIncrementerType("foo")).andReturn(true);
|
||||
expect(incrementerFactory.getSupportedIncrementerTypes()).andReturn(new String[0]);
|
||||
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")).andReturn(new StubIncrementer());
|
||||
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")).andReturn(new StubIncrementer()).times(2);
|
||||
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ")).andReturn(new StubIncrementer());
|
||||
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(new StubIncrementer());
|
||||
expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(new StubIncrementer()).times(2);
|
||||
replay(incrementerFactory);
|
||||
|
||||
factory.afterPropertiesSet();
|
||||
|
||||
@@ -1,37 +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.core.repository.support;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.repository.dao.StepExecutionDao;
|
||||
|
||||
public class MockStepDao implements StepExecutionDao {
|
||||
|
||||
|
||||
public void saveStepExecution(StepExecution stepExecution) {
|
||||
}
|
||||
|
||||
public void updateStepExecution(StepExecution stepExecution) {
|
||||
}
|
||||
|
||||
public StepExecution getStepExecution(JobExecution jobExecution, Step step) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public class SimpleJobRepositoryTests extends TestCase {
|
||||
|
||||
public void testSaveOrUpdateStepExecutionException() {
|
||||
|
||||
StepExecution stepExecution = new StepExecution("stepName", null, null);
|
||||
StepExecution stepExecution = new StepExecution("stepName", null);
|
||||
|
||||
// failure scenario -- no step id set.
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user