IN PROGRESS - issue BATCH-340: Refactor JobRepository for greater clarity and consistency.

http://jira.springframework.org/browse/BATCH-340

more StepInstance heritage cleaned up - StepExecution refers to Step rather than stepName string
This commit is contained in:
robokaso
2008-02-25 17:21:46 +00:00
parent 59f884b832
commit 7368aa3541
25 changed files with 162 additions and 139 deletions

View File

@@ -81,7 +81,7 @@ public class SimpleJob extends JobSupport {
if (shouldStart(jobInstance, step)) {
startedCount++;
updateStatus(execution, BatchStatus.STARTED);
StepExecution stepExecution = execution.createStepExecution(step.getName());
StepExecution stepExecution = execution.createStepExecution(step);
step.execute(stepExecution);
status = stepExecution.getExitStatus();
}

View File

@@ -16,6 +16,7 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
@@ -367,14 +368,17 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
private class StepExecutionRowMapper implements RowMapper {
private final JobExecution jobExecution;
private final Step step;
public StepExecutionRowMapper(JobExecution jobExecution) {
public StepExecutionRowMapper(JobExecution jobExecution, Step step) {
this.jobExecution = jobExecution;
this.step = step;
}
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
StepExecution stepExecution = new StepExecution(rs.getString(2), jobExecution, new Long(rs.getLong(1)));
StepExecution stepExecution = new StepExecution(step, jobExecution, new Long(rs.getLong(1)));
stepExecution.setStartTime(rs.getTimestamp(3));
stepExecution.setEndTime(rs.getTimestamp(4));
stepExecution.setStatus(BatchStatus.getStatus(rs.getString(5)));
@@ -437,7 +441,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
public StepExecution getStepExecution(JobExecution jobExecution, Step step) {
List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION),
new Object[] { step.getName(), jobExecution.getId() }, new StepExecutionRowMapper(jobExecution));
new Object[] { step.getName(), jobExecution.getId() }, new StepExecutionRowMapper(jobExecution, step));
Assert.state(executions.size() <= 1,
"There can be at most one step execution with given name for single job execution");

View File

@@ -27,6 +27,7 @@ import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.runtime.JobParametersFactory;
import org.springframework.batch.execution.configuration.MapJobRegistry;
@@ -51,7 +52,7 @@ public class SimpleExportedJobLauncherTests extends TestCase {
launcher.setLauncher(new JobLauncher() {
public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException {
JobExecution result = new JobExecution(null);
StepExecution stepExecution = result.createStepExecution("stepName");
StepExecution stepExecution = result.createStepExecution(new StepSupport("stepName"));
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
list.add(jobParameters);
return result;

View File

@@ -75,9 +75,9 @@ public class SimpleJobTests extends TestCase {
private SimpleJob job;
private String step1;
private Step step1;
private String step2;
private Step step2;
protected void setUp() throws Exception {
super.setUp();
@@ -116,8 +116,8 @@ public class SimpleJobTests extends TestCase {
jobInstance = jobExecution.getJobInstance();
List steps = jobInstance.getJob().getSteps();
step1 = ((Step) steps.get(0)).getName();
step2 = ((Step) steps.get(1)).getName();
step1 = (Step) steps.get(0);
step2 = (Step) steps.get(1);
stepExecution1 = new StepExecution(step1, jobExecution, null);
stepExecution2 = new StepExecution(step2, jobExecution, null);
@@ -163,8 +163,8 @@ public class SimpleJobTests extends TestCase {
testRunNormally();
assertEquals(jobInstance, jobExecution.getJobInstance());
assertEquals(2, jobExecution.getStepExecutions().size());
assertEquals(step1, stepExecution1.getStepName());
assertEquals(step2, stepExecution2.getStepName());
assertEquals(step1.getName(), stepExecution1.getStepName());
assertEquals(step2.getName(), stepExecution2.getStepName());
}
public void testInterrupted() throws Exception {

View File

@@ -17,13 +17,10 @@
package org.springframework.batch.execution.repository;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
import org.easymock.ArgumentsMatcher;
import org.easymock.MockControl;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
@@ -346,7 +343,7 @@ public class SimpleJobRepositoryTests extends TestCase {
}
public void testUpdateStepExecution() {
StepExecution stepExecution = new StepExecution("stepName", null, new Long(1));
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), null, new Long(1));
stepExecution.setId(new Long(11));
ExecutionContext executionContext = new ExecutionContext();
stepExecution.setExecutionContext(executionContext);
@@ -358,7 +355,7 @@ public class SimpleJobRepositoryTests extends TestCase {
}
public void testSaveExistingStepExecution() {
StepExecution stepExecution = new StepExecution("stepName", new JobExecution(null), null);
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(null), null);
ExecutionContext executionContext = new ExecutionContext();
stepExecution.setExecutionContext(executionContext);
stepExecutionDao.saveStepExecution(stepExecution);
@@ -370,7 +367,7 @@ public class SimpleJobRepositoryTests extends TestCase {
public void testSaveOrUpdateStepExecutionException() {
StepExecution stepExecution = new StepExecution(null, null, null);
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), null, null);
// failure scenario -- no step id set.
try {

View File

@@ -24,6 +24,7 @@ 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.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier;
@@ -52,9 +53,9 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
protected JobInstance jobInstance;
protected String step1;
protected Step step1;
protected String step2;
protected Step step2;
protected StepExecution stepExecution;
@@ -91,8 +92,8 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
protected void onSetUpInTransaction() throws Exception {
Job job = new JobSupport("TestJob");
jobInstance = jobInstanceDao.createJobInstance(job, jobParameters);
step1 = "TestStep1";
step2 = "TestStep2";
step1 = new StepSupport("TestStep1");
step2 = new StepSupport("TestStep2");
jobExecution = new JobExecution(jobInstance);
jobExecutionDao.saveJobExecution(jobExecution);
@@ -132,7 +133,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
execution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION,
"java.lang.Exception"));
stepExecutionDao.saveStepExecution(execution);
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, new StepSupport(step2));
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step2);
assertNotNull(retrievedExecution);
assertEquals(execution, retrievedExecution);
assertEquals(execution.getExecutionContext().getString("key1"), retrievedExecution.getExecutionContext().getString("key1"));
@@ -149,14 +150,14 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
stepExecution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION,
"java.lang.Exception"));
stepExecutionDao.updateStepExecution(stepExecution);
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, new StepSupport(step1));
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step1);
assertNotNull(retrievedExecution);
assertEquals(stepExecution, retrievedExecution);
assertEquals(stepExecution.getExitStatus(), retrievedExecution.getExitStatus());
}
public void testUpdateStepExecutionWithNullId() {
StepExecution stepExecution = new StepExecution(null, null, null);
StepExecution stepExecution = new StepExecution(new StepSupport("testStep"), null, null);
try {
stepExecutionDao.updateStepExecution(stepExecution);
fail("Expected IllegalArgumentException");
@@ -201,7 +202,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
}
public void testGetStepExecution() {
assertEquals(stepExecution, stepExecutionDao.getStepExecution(jobExecution, new StepSupport(step1)));
assertEquals(stepExecution, stepExecutionDao.getStepExecution(jobExecution, step1));
}
}

View File

@@ -9,7 +9,9 @@ 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.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
@@ -31,7 +33,7 @@ public class JdbcStepDaoPrefixTests extends TestCase {
MockJdbcTemplate jdbcTemplate = new MockJdbcTemplate();
JobInstance job = new JobInstance(new Long(1), new JobParameters(), new JobSupport("testJob"));
String step = "foo";
Step step = new StepSupport("foo");
StepExecution stepExecution = new StepExecution(step, new JobExecution(job), null);
MockControl stepExecutionIncrementerControl = MockControl.createControl(DataFieldMaxValueIncrementer.class);

View File

@@ -32,7 +32,7 @@ public class JdbcStepDaoTests extends AbstractStepDaoTests {
List executions = jdbcTemplate.queryForList(
"SELECT * FROM BATCH_STEP_EXECUTION where STEP_NAME=?",
new Object[] { step1 });
new Object[] { step1.getName() });
assertEquals(1, executions.size());
assertEquals(LONG_STRING.substring(0, 250), ((Map) executions.get(0))
.get("EXIT_MESSAGE"));

View File

@@ -16,51 +16,56 @@
package org.springframework.batch.execution.repository.dao;
import java.util.Properties;
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.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.core.domain.StepSupport;
public class MapStepDaoTests extends TestCase {
MapStepDao dao = new MapStepDao();
private JobInstance job;
private String step;
private Step step;
// Make sure we get a new job for each test...
static long jobId=100;
static long jobId = 100;
protected void setUp() throws Exception {
MapStepDao.clear();
job = new JobInstance(new Long(jobId++), new JobParameters(), new JobSupport("testJob"));
step = "foo";
step = new StepSupport("foo");
}
public void testSaveExecutionUpdatesId() throws Exception {
StepExecution execution = new StepExecution(step, null, null);
StepExecution execution = new StepExecution(step, new JobExecution(new JobInstance(new Long(1),
new JobParameters(), new JobSupport("jobName"))));
assertNull(execution.getId());
dao.saveStepExecution(execution);
assertNotNull(execution.getId());
}
public void testSaveExecutionContext() throws Exception {
// JobExecution jobExecution = new JobExecution(null);
// StepExecution stepExecution = new StepExecution(step, jobExecution, null);
// assertEquals(null, dao.findExecutionContext(stepExecution));
// Properties data = new Properties();
// data.setProperty("restart.key1", "restartData");
// ExecutionContext executionContext = new ExecutionContext(data);
// stepExecution.setExecutionContext(executionContext);
// dao.saveStepExecution(stepExecution);
// StepExecution tempExecution = dao.getStepExecution(jobExecution, step);
// assertEquals(tempExecution, stepExecution);
// assertEquals(stepExecution.getExecutionContext(), tempExecution.getExecutionContext());
// JobExecution jobExecution = new JobExecution(null);
// StepExecution stepExecution = new StepExecution(step, jobExecution,
// null);
// assertEquals(null, dao.findExecutionContext(stepExecution));
// Properties data = new Properties();
// data.setProperty("restart.key1", "restartData");
// ExecutionContext executionContext = new ExecutionContext(data);
// stepExecution.setExecutionContext(executionContext);
// dao.saveStepExecution(stepExecution);
// StepExecution tempExecution = dao.getStepExecution(jobExecution,
// step);
// assertEquals(tempExecution, stepExecution);
// assertEquals(stepExecution.getExecutionContext(),
// tempExecution.getExecutionContext());
}
}

View File

@@ -26,6 +26,8 @@ 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.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.scope.SimpleStepContext;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.DefaultResourceLoader;
@@ -51,7 +53,7 @@ public class BatchResourceFactoryBeanTests extends TestCase {
private JobInstance jobInstance;
private String stepInstance;
private Step step;
/**
* mock step context
@@ -61,8 +63,8 @@ public class BatchResourceFactoryBeanTests extends TestCase {
jobInstance = new JobInstance(new Long(0), new JobParameters(), new JobSupport("testJob"));
JobExecution jobExecution = jobInstance.createJobExecution();
stepInstance = "bar";
resourceFactory.setStepContext(new SimpleStepContext(jobExecution.createStepExecution(stepInstance)));
step = new StepSupport("bar");
resourceFactory.setStepContext(new SimpleStepContext(jobExecution.createStepExecution(step)));
resourceFactory.afterPropertiesSet();
@@ -100,8 +102,8 @@ public class BatchResourceFactoryBeanTests extends TestCase {
jobInstance = new JobInstance(new Long(0), new JobParametersBuilder().addString("job.key", "spam")
.toJobParameters(), new JobSupport("testJob"));
JobExecution jobExecution = jobInstance.createJobExecution();
stepInstance = "bar";
resourceFactory.setStepContext(new SimpleStepContext(jobExecution.createStepExecution(stepInstance)));
step = new StepSupport("bar");
resourceFactory.setStepContext(new SimpleStepContext(jobExecution.createStepExecution(step)));
resourceFactory.setFilePattern("foo/data/%JOB_NAME%/%job.key%-foo");
doTestPathName("spam-foo", "foo" + pathsep + "data" + pathsep);
}

View File

@@ -21,6 +21,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
/**
* @author Dave Syer
@@ -52,7 +53,7 @@ public class SimpleStepContextTests extends TestCase {
*/
public void testGetStepExecution() {
assertNull(context.getStepExecution());
context = new SimpleStepContext(new StepExecution(null, null, null));
context = new SimpleStepContext(new StepExecution(new StepSupport("stepName"), null, null));
assertNotNull(context.getStepExecution());
}

View File

@@ -28,6 +28,7 @@ import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.execution.scope.StepScope;
import org.springframework.batch.execution.scope.StepSynchronizationManager;
@@ -102,7 +103,7 @@ public class ChunkedStepTests extends TestCase {
chunkedStep.setJobRepository(new JobRepositorySupport());
jobExecutionContext = new JobExecution(jobInstance);
stepExecution = new StepExecution("testStep", jobExecutionContext);
stepExecution = new StepExecution(new StepSupport("testStep"), jobExecutionContext);
}
public void testStepExecutor() throws Exception {
@@ -115,7 +116,7 @@ public class ChunkedStepTests extends TestCase {
public void testStepContextInitialized() throws Exception {
final JobExecution jobExecution = new JobExecution(jobInstance);
final StepExecution stepExecution = new StepExecution("testStep", jobExecution);
final StepExecution stepExecution = new StepExecution(new StepSupport("testStep"), jobExecution);
chunkedStep.setChunker(new ItemChunker(new AbstractItemReader() {
int counter = 0;
@@ -144,7 +145,7 @@ public class ChunkedStepTests extends TestCase {
final JobExecution jobExecution = new JobExecution(jobInstance);
jobExecution.setId(new Long(1));
final StepExecution stepExecution = new StepExecution("testStep", jobExecution);
final StepExecution stepExecution = new StepExecution(new StepSupport("testStep"), jobExecution);
template.setListener(new RepeatListenerSupport() {
public void open(RepeatContext context) {
@@ -171,7 +172,7 @@ public class ChunkedStepTests extends TestCase {
// StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
repository.getLastStepExecution(jobInstance, chunkedStep);
repoControl.setReturnValue(new StepExecution(null,null));
repoControl.setReturnValue(stepExecution);
repository.getStepExecutionCount(jobInstance, chunkedStep);
repoControl.setReturnValue(0);
repository.saveOrUpdate(stepExecution);
@@ -508,7 +509,7 @@ public class ChunkedStepTests extends TestCase {
// }
// }
//
// private class MockRestartableItemReader extends ItemStreamAdapter implements ItemReader {
// private class MockRestartableItemReader extends ItemStreamSupport implements ItemReader {
//
// private boolean getExecutionAttributesCalled = false;
//

View File

@@ -30,14 +30,15 @@ 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.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepContribution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.MapJobDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;
import org.springframework.batch.execution.scope.StepScope;
import org.springframework.batch.execution.scope.StepSynchronizationManager;
import org.springframework.batch.execution.step.ItemOrientedStep;
import org.springframework.batch.execution.step.support.JobRepositorySupport;
import org.springframework.batch.execution.step.support.StepInterruptionPolicy;
import org.springframework.batch.io.exception.BatchCriticalException;
@@ -118,7 +119,7 @@ public class ItemOrientedStepTests extends TestCase {
public void testStepExecutor() throws Exception {
String step = "stepName";
Step step = new StepSupport("stepName");
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
@@ -135,7 +136,7 @@ public class ItemOrientedStepTests extends TestCase {
template.setCompletionPolicy(new SimpleCompletionPolicy(1));
itemOrientedStep.setChunkOperations(template);
String step = "stepName";
Step step = new StepSupport("stepName");
JobExecution jobExecution = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecution);
@@ -155,13 +156,13 @@ public class ItemOrientedStepTests extends TestCase {
template.setCompletionPolicy(new SimpleCompletionPolicy(1));
itemOrientedStep.setChunkOperations(template);
final String step = "stepName";
final Step step = new StepSupport("stepName");
final JobExecution jobExecution = new JobExecution(jobInstance);
final StepExecution stepExecution = new StepExecution(step, jobExecution);
itemOrientedStep.setItemReader(new AbstractItemReader() {
public Object read() throws Exception {
assertEquals(step, stepExecution.getStepName());
assertEquals(step.getName(), stepExecution.getStepName());
assertNotNull(StepSynchronizationManager.getContext().getStepExecution());
return "foo";
}
@@ -180,7 +181,7 @@ public class ItemOrientedStepTests extends TestCase {
template.setCompletionPolicy(new SimpleCompletionPolicy(1));
itemOrientedStep.setStepOperations(template);
final String step = "stepName";
final Step step = new StepSupport("stepName");
final JobExecution jobExecution = new JobExecution(jobInstance);
jobExecution.setId(new Long(1));
final StepExecution stepExecution = new StepExecution(step, jobExecution);
@@ -204,7 +205,7 @@ public class ItemOrientedStepTests extends TestCase {
SimpleJobRepository repository = new SimpleJobRepository(new MapJobDao(), new MapJobDao(), new MapStepDao());
itemOrientedStep.setJobRepository(repository);
String step = "stepName";
Step step = new StepSupport("stepName");
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
@@ -229,7 +230,7 @@ public class ItemOrientedStepTests extends TestCase {
};
String step = "stepName";
Step step = new StepSupport("stepName");
itemOrientedStep.setItemReader(itemReader);
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
@@ -260,7 +261,7 @@ public class ItemOrientedStepTests extends TestCase {
};
String step = "stepName";
Step step = new StepSupport("stepName");
itemOrientedStep.setItemReader(itemReader);
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
@@ -279,7 +280,7 @@ public class ItemOrientedStepTests extends TestCase {
* saveExecutionAttributes = true, doesn't have restoreFrom called on it.
*/
public void testNonRestartedJob() throws Exception {
String step = "stepName";
Step step = new StepSupport("stepName");
MockRestartableItemReader tasklet = new MockRestartableItemReader();
itemOrientedStep.setItemReader(tasklet);
itemOrientedStep.setSaveExecutionContext(true);
@@ -321,8 +322,7 @@ public class ItemOrientedStepTests extends TestCase {
* it.
*/
public void testNoSaveExecutionAttributesRestartableJob() {
String step = "stepName";
// step.setStepExecutionCount(1);
Step step = new StepSupport("stepName");
MockRestartableItemReader tasklet = new MockRestartableItemReader();
itemOrientedStep.setItemReader(tasklet);
itemOrientedStep.setSaveExecutionContext(false);
@@ -346,8 +346,7 @@ public class ItemOrientedStepTests extends TestCase {
* Restartable.
*/
public void testRestartJobOnNonRestartableTasklet() throws Exception {
String step = "stepName";
// step.setStepExecutionCount(1);
Step step = new StepSupport("stepName");
itemOrientedStep.setItemReader(new AbstractItemReader() {
public Object read() throws Exception {
return "foo";
@@ -400,8 +399,7 @@ public class ItemOrientedStepTests extends TestCase {
}
public void testStreamManager() throws Exception {
String step = "stepName";
// step.setStepExecutionCount(1);
Step step = new StepSupport("stepName");
itemOrientedStep.setItemReader(new AbstractItemReader() {
public Object read() throws Exception {
return "foo";
@@ -501,7 +499,7 @@ public class ItemOrientedStepTests extends TestCase {
itemOrientedStep.setItemReader(itemReader);
String step = "stepName";
Step step = new StepSupport("stepName");
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
@@ -538,7 +536,7 @@ public class ItemOrientedStepTests extends TestCase {
}
});
String step = "stepName";
Step step = new StepSupport("stepName");
JobExecution jobExecutionContext = jobInstance.createJobExecution();
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);

View File

@@ -11,8 +11,8 @@ import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.step.TaskletStep;
import org.springframework.batch.execution.step.support.JobRepositorySupport;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
@@ -26,7 +26,7 @@ public class TaskletStepTests extends TestCase {
private List list = new ArrayList();
protected void setUp() throws Exception {
stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(
stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(
new Long(0L), new JobParameters(), new JobSupport("testJob")), new Long(12)));
}

View File

@@ -19,8 +19,13 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.ChunkingResult;
import org.springframework.batch.core.domain.ItemSkipPolicy;
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.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepContribution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.step.support.ItemChunker;
public class ItemChunkerTests extends TestCase {
@@ -29,18 +34,19 @@ public class ItemChunkerTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
StepExecution execution = new StepExecution(null,null);
JobExecution jobExecution = new JobExecution(new JobInstance(new Long(1), new JobParameters(), new JobSupport("jobName")));
StepExecution execution = new StepExecution(new StepSupport("stepName"), jobExecution);
stepContribution = execution.createStepContribution();
}
public void testSizeNegative() {
try {
MockItemReader itemReader = new MockItemReader(10);
ItemChunker chunkReader = new ItemChunker(itemReader);
chunkReader.chunk(-1, stepContribution);
fail();
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {
}
}
@@ -50,7 +56,8 @@ public class ItemChunkerTests extends TestCase {
ItemChunker chunkReader = new ItemChunker(itemReader);
chunkReader.chunk(0, stepContribution);
fail();
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {
}
}
@@ -76,7 +83,8 @@ public class ItemChunkerTests extends TestCase {
try {
chunkReader.chunk(10, stepContribution);
fail();
} catch (RuntimeException e) {
}
catch (RuntimeException e) {
}
}
@@ -86,7 +94,7 @@ public class ItemChunkerTests extends TestCase {
ItemChunker chunkReader = new ItemChunker(itemReader);
chunkReader.setItemSkipPolicy(new StubReadFailurePolicy(false));
ChunkingResult chunkingResult = chunkReader.chunk(1, stepContribution);
assertEquals(1,chunkingResult.getChunk().getItems().size());
assertEquals(1, chunkingResult.getChunk().getItems().size());
}
private class StubReadFailurePolicy implements ItemSkipPolicy {

View File

@@ -23,6 +23,7 @@ import org.springframework.batch.core.domain.Chunk;
import org.springframework.batch.core.domain.DechunkingResult;
import org.springframework.batch.core.domain.StepContribution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.step.support.AlwaysSkipItemSkipPolicy;
import org.springframework.batch.execution.step.support.ItemDechunker;
import org.springframework.batch.io.exception.WriteFailureException;
@@ -50,7 +51,7 @@ public class ItemDechunkerTests extends TestCase {
super.setUp();
itemWriter = (ItemWriter)writerControl.getMock();
StepExecution execution = new StepExecution(null,null);
StepExecution execution = new StepExecution(new StepSupport("stepName"),null);
stepContribution = execution.createStepContribution();
dechunker = new ItemDechunker(itemWriter);
List items = new ArrayList();

View File

@@ -25,6 +25,7 @@ import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.step.ItemOrientedStep;
import org.springframework.batch.item.reader.AbstractItemReader;
import org.springframework.batch.item.reader.ItemReaderAdapter;
@@ -93,7 +94,7 @@ public class RepeatOperationsStepTests extends TestCase {
configuration.setChunkOperations(repeatTemplate);
configuration.setJobRepository(new JobRepositorySupport());
configuration.setTransactionManager(new ResourcelessTransactionManager());
StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")),
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")),
new Long(12)));
configuration.afterPropertiesSet();
try {
@@ -134,7 +135,7 @@ public class RepeatOperationsStepTests extends TestCase {
configuration.setStepOperations(stepTemplate);
configuration.setJobRepository(new JobRepositorySupport());
configuration.setTransactionManager(new ResourcelessTransactionManager());
StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")),
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")),
new Long(12)));
configuration.afterPropertiesSet();
configuration.execute(stepExecution);

View File

@@ -21,6 +21,7 @@ import java.util.List;
import org.springframework.batch.core.domain.StepContribution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.step.support.LimitCheckingItemSkipPolicy;
import org.springframework.batch.execution.step.support.SkipLimitExceededException;
import org.springframework.batch.io.exception.FlatFileParsingException;
@@ -44,7 +45,7 @@ public class SkipLimitReadFailurePolicyTests extends TestCase {
skippableExceptions.add(FlatFileParsingException.class);
failurePolicy = new LimitCheckingItemSkipPolicy(1, skippableExceptions);
stepExecution = new StepExecution(null, null);
stepExecution = new StepExecution(new StepSupport("stepName"), null);
stepExecution.setSkipCount(2);
stepContribution = stepExecution.createStepContribution();
}

View File

@@ -16,8 +16,6 @@
package org.springframework.batch.execution.step.support;
import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.BatchStatus;
@@ -26,7 +24,6 @@ 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.JobSupport;
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.execution.repository.SimpleJobRepository;
@@ -52,8 +49,6 @@ public class StepExecutorInterruptionTests extends TestCase {
private StepExecutionDao stepExecutionDao = new MapStepDao();
private JobInstance jobInstance;
private RepeatOperationsStep step;
public void setUp() throws Exception {
@@ -65,7 +60,7 @@ public class StepExecutorInterruptionTests extends TestCase {
step.setName("stepName");
jobConfiguration.addStep(step);
jobConfiguration.setBeanName("testJob");
jobInstance = jobRepository.createJobExecution(jobConfiguration, new JobParameters()).getJobInstance();
jobRepository.createJobExecution(jobConfiguration, new JobParameters());
step.setJobRepository(jobRepository);
step.setTransactionManager(new ResourcelessTransactionManager());
step.setItemReader(new ItemReaderAdapter());
@@ -77,10 +72,8 @@ public class StepExecutorInterruptionTests extends TestCase {
public void testInterruptChunk() throws Exception {
List steps = jobInstance.getJob().getSteps();
final String stepName = ((Step)steps.get(0)).getName();
JobExecution jobExecutionContext = new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")));
final StepExecution stepExecution = new StepExecution(stepName, jobExecutionContext);
final StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
step.setItemReader(new AbstractItemReader() {
public Object read() throws Exception {
// do something non-trivial (and not Thread.sleep())