OPEN - issue BATCH-324: Step as factory for StepExecutor

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

run/process -> execute
This commit is contained in:
dsyer
2008-01-30 15:17:42 +00:00
parent 0734480dd6
commit 02f1ae5c0c
20 changed files with 56 additions and 49 deletions

View File

@@ -26,7 +26,7 @@ import org.springframework.batch.io.exception.BatchCriticalException;
* step.
*
* @author Dave Syer
*
*
*/
public interface Job {
@@ -38,6 +38,13 @@ public interface Job {
boolean isRestartable();
void run(JobExecution execution) throws BatchCriticalException;
/**
* Run the {@link JobExecution} and update the meta information like status
* and statistics as necessary.
*
* @param execution a {@link JobExecution}
* @throws BatchCriticalException
*/
void execute(JobExecution execution) throws BatchCriticalException;
}

View File

@@ -43,7 +43,7 @@ public class JobExecution extends Entity {
private ExitStatus exitStatus = ExitStatus.UNKNOWN;
// Package private constructor for Hibernate
// Package private constructor for testing
JobExecution() {
}

View File

@@ -133,7 +133,7 @@ public class JobSupport implements BeanNameAware, Job {
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.Job#run(org.springframework.batch.core.domain.JobExecution)
*/
public void run(JobExecution execution) throws BatchCriticalException {
public void execute(JobExecution execution) throws BatchCriticalException {
throw new UnsupportedOperationException("JobSupport does not provide an implementation of run(). Use a smarter subclass.");
}

View File

@@ -67,6 +67,6 @@ public interface Step {
* @throws BatchCriticalException if there is a problem that needs to be
* signalled to the caller
*/
void process(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException;
void execute(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException;
}

View File

@@ -134,9 +134,9 @@ public class StepSupport implements Step, BeanNameAware {
*
* @throws UnsupportedOperationException always
*
* @see org.springframework.batch.core.domain.Step#process(org.springframework.batch.core.domain.StepExecution)
* @see org.springframework.batch.core.domain.Step#execute(org.springframework.batch.core.domain.StepExecution)
*/
public void process(StepExecution stepExecution)
public void execute(StepExecution stepExecution)
throws StepInterruptedException, BatchCriticalException {
throw new UnsupportedOperationException(
"Cannot process a StepExecution. Use a smarter subclass of StepSupport.");

View File

@@ -104,7 +104,7 @@ public class JobSupportTests extends TestCase {
public void testRunNotSupported() throws Exception {
try {
job.run(null);
job.execute(null);
} catch (UnsupportedOperationException e) {
// expected
String message = e.getMessage();

View File

@@ -89,7 +89,7 @@ public class StepSupportTests extends TestCase {
public void testUnsuccessfulWrongConfiguration() throws Exception {
try {
new StepSupport().process(null);
new StepSupport().execute(null);
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
// expected

View File

@@ -53,9 +53,9 @@ public class SimpleJob extends JobSupport {
* Run the specified job by looping through the steps and delegating to the
* {@link Step}.
*
* @see org.springframework.batch.core.domain.Job#run(org.springframework.batch.core.domain.JobExecution)
* @see org.springframework.batch.core.domain.Job#execute(org.springframework.batch.core.domain.JobExecution)
*/
public void run(JobExecution execution) throws BatchCriticalException {
public void execute(JobExecution execution) throws BatchCriticalException {
JobInstance jobInstance = execution.getJobInstance();
updateStatus(execution, BatchStatus.STARTING);
@@ -78,7 +78,7 @@ public class SimpleJob extends JobSupport {
startedCount++;
updateStatus(execution, BatchStatus.STARTED);
StepExecution stepExecution = execution.createStepExecution(stepInstance);
step.process(stepExecution);
step.execute(stepExecution);
status = stepExecution.getExitStatus();
}
}

View File

@@ -82,7 +82,7 @@ public class SimpleJobLauncher implements JobLauncher, InitializingBean {
public void run() {
try {
logger.info("Job: [" + job + "] launched with the following parameters: [" + jobParameters + "]");
job.run(jobExecution);
job.execute(jobExecution);
logger.info("Job: [" + job + "] completed successfully with the following parameters: ["
+ jobParameters + "]");
}

View File

@@ -111,9 +111,9 @@ public abstract class AbstractStep extends StepSupport {
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.StepSupport#process(org.springframework.batch.core.domain.StepExecution)
*/
public void process(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException {
public void execute(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException {
SimpleStepExecutor executor = createStepExecutor();
executor.process(stepExecution);
executor.execute(stepExecution);
}
/**

View File

@@ -77,7 +77,7 @@ public class RepeatOperationsStep extends AbstractStep implements RepeatOperatio
/* (non-Javadoc)
* @see org.springframework.batch.execution.step.simple.AbstractStep#process(org.springframework.batch.core.domain.StepExecution)
*/
public void process(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException {
public void execute(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException {
assertMandatoryProperties();
SimpleStepExecutor executor = (SimpleStepExecutor) super.createStepExecutor();
if (stepOperations != null) {
@@ -86,6 +86,6 @@ public class RepeatOperationsStep extends AbstractStep implements RepeatOperatio
if (chunkOperations != null) {
executor.setChunkOperations(chunkOperations);
}
executor.process(stepExecution);
executor.execute(stepExecution);
}
}

View File

@@ -171,9 +171,9 @@ public class SimpleStepExecutor {
* @throws StepInterruptedException if the step or a chunk is interrupted
* @throws RuntimeException if there is an exception during a chunk
* execution
* @see StepExecutor#process(StepExecution)
* @see StepExecutor#execute(StepExecution)
*/
public void process(final StepExecution stepExecution) throws BatchCriticalException,
public void execute(final StepExecution stepExecution) throws BatchCriticalException,
StepInterruptedException {
final StepInstance stepInstance = stepExecution.getStep();

View File

@@ -126,7 +126,7 @@ public class SimpleJobTests extends TestCase {
public void testRunNormally() throws Exception {
stepConfiguration1.setStartLimit(5);
stepConfiguration2.setStartLimit(5);
job.run(jobExecution);
job.execute(jobExecution);
assertEquals(2, list.size());
checkRepository(BatchStatus.COMPLETED);
}
@@ -149,7 +149,7 @@ public class SimpleJobTests extends TestCase {
return ExitStatus.FINISHED;
}
});
job.run(jobExecution);
job.execute(jobExecution);
assertEquals(2, list.size());
checkRepository(BatchStatus.COMPLETED, ExitStatus.FINISHED);
@@ -169,7 +169,7 @@ public class SimpleJobTests extends TestCase {
final StepInterruptedException exception = new StepInterruptedException("Interrupt!");
stepConfiguration1.setProcessException(exception);
try {
job.run(jobExecution);
job.execute(jobExecution);
}
catch (BatchCriticalException e) {
assertEquals(exception, e.getCause());
@@ -184,7 +184,7 @@ public class SimpleJobTests extends TestCase {
final RuntimeException exception = new RuntimeException("Foo!");
stepConfiguration1.setProcessException(exception);
try {
job.run(jobExecution);
job.execute(jobExecution);
}
catch (RuntimeException e) {
assertEquals(exception, e);
@@ -198,7 +198,7 @@ public class SimpleJobTests extends TestCase {
stepConfiguration1.setStartLimit(0);
try {
job.run(jobExecution);
job.execute(jobExecution);
fail("Expected BatchCriticalException");
}
catch (BatchCriticalException ex) {
@@ -211,7 +211,7 @@ public class SimpleJobTests extends TestCase {
public void testNoSteps() throws Exception {
job.setSteps(new ArrayList());
job.run(jobExecution);
job.execute(jobExecution);
ExitStatus exitStatus = jobExecution.getExitStatus();
assertTrue("Wrong message in execution: " + exitStatus, exitStatus.getExitDescription().indexOf(
"No steps configured") >= 0);
@@ -221,7 +221,7 @@ public class SimpleJobTests extends TestCase {
step1.setStatus(BatchStatus.COMPLETED);
step2.setStatus(BatchStatus.COMPLETED);
job.run(jobExecution);
job.execute(jobExecution);
ExitStatus exitStatus = jobExecution.getExitStatus();
assertTrue("Wrong message in execution: " + exitStatus, exitStatus.getExitDescription().indexOf(
"steps already completed") >= 0);
@@ -272,7 +272,7 @@ public class SimpleJobTests extends TestCase {
this.runnable = runnable;
}
public void process(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException {
public void execute(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException {
if (exception instanceof RuntimeException) {
throw (RuntimeException)exception;
}

View File

@@ -41,7 +41,7 @@ public class SimpleJobLauncherTests extends TestCase {
private MockControl repositoryControl = MockControl.createControl(JobRepository.class);
private Job job = new JobSupport("foo") {
public void run(JobExecution execution) {
public void execute(JobExecution execution) {
execution.setExitStatus(ExitStatus.FINISHED);
return;
}
@@ -89,7 +89,7 @@ public class SimpleJobLauncherTests extends TestCase {
public void testRunWithException() throws Exception {
job = new JobSupport() {
public void run(JobExecution execution) {
public void execute(JobExecution execution) {
execution.setExitStatus(ExitStatus.FAILED);
throw new RuntimeException("foo");
}
@@ -105,7 +105,7 @@ public class SimpleJobLauncherTests extends TestCase {
public void testRunWithError() throws Exception {
job = new JobSupport() {
public void run(JobExecution execution) {
public void execute(JobExecution execution) {
execution.setExitStatus(ExitStatus.FAILED);
throw new Error("foo");
}

View File

@@ -113,7 +113,7 @@ public class SimpleJobTests extends TestCase {
JobExecution jobExecutionContext = new JobExecution(jobInstance);
job.run(jobExecutionContext);
job.execute(jobExecutionContext);
assertEquals(BatchStatus.COMPLETED, jobInstance.getStatus());
assertEquals(3, processed.size());
assertTrue(processed.contains("foo"));
@@ -153,7 +153,7 @@ public class SimpleJobTests extends TestCase {
job.setSteps(Collections.singletonList(step));
JobExecution jobExecution = repository.createJobExecution(job, new JobParameters());
job.run(jobExecution);
job.execute(jobExecution);
assertEquals(BatchStatus.COMPLETED, jobExecution.getJobInstance().getStatus());
assertEquals(0, processed.size());
@@ -178,7 +178,7 @@ public class SimpleJobTests extends TestCase {
JobExecution jobExecution = repository.createJobExecution(job, new JobParameters());
try {
job.run(jobExecution);
job.execute(jobExecution);
fail("Expected RuntimeException");
}
catch (RuntimeException e) {

View File

@@ -80,7 +80,7 @@ public class RepeatOperationsStepTests extends TestCase {
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
try {
configuration.process(stepExecution);
configuration.execute(stepExecution);
fail("Expected RuntimeException");
} catch (NullPointerException e) {
// expected
@@ -118,7 +118,7 @@ public class RepeatOperationsStepTests extends TestCase {
StepExecution stepExecution = new StepExecution(new StepInstance(
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
configuration.process(stepExecution);
configuration.execute(stepExecution);
assertEquals(2, list.size());
assertEquals(1, steps.size());
}

View File

@@ -123,7 +123,7 @@ public class SimpleStepExecutorTests extends TestCase {
StepExecution stepExecution = new StepExecution(step,
jobExecutionContext);
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
assertEquals(1, processed.size());
assertEquals(1, stepExecution.getTaskCount().intValue());
}
@@ -170,7 +170,7 @@ public class SimpleStepExecutorTests extends TestCase {
}
});
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
assertEquals(1, processed.size());
}
@@ -198,7 +198,7 @@ public class SimpleStepExecutorTests extends TestCase {
}
});
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
assertEquals(1, processed.size());
}
@@ -213,7 +213,7 @@ public class SimpleStepExecutorTests extends TestCase {
StepExecution stepExecution = new StepExecution(step,
jobExecutionContext);
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
assertEquals(1, processed.size());
}
@@ -241,7 +241,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
}
catch (Exception ex) {
assertEquals(stepExecution.getRollbackCount(), new Integer(1));
@@ -273,7 +273,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
}
catch (Exception ex) {
ExitStatus status = stepExecution.getExitStatus();
@@ -295,7 +295,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
}
catch (Throwable t) {
fail();
@@ -320,7 +320,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
}
catch (Throwable t) {
fail();
@@ -345,7 +345,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
}
catch (Throwable t) {
fail();
@@ -372,7 +372,7 @@ public class SimpleStepExecutorTests extends TestCase {
StepExecution stepExecution = new StepExecution(step, jobExecution);
try {
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
}
catch (Throwable t) {
fail();
@@ -443,7 +443,7 @@ public class SimpleStepExecutorTests extends TestCase {
});
try {
stepExecutor.process(stepExecution);
stepExecutor.execute(stepExecution);
}
catch (Throwable t) {
fail();

View File

@@ -60,7 +60,7 @@ public class SimpleStepTests extends TestCase {
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
try {
executor.process(stepExecution);
executor.execute(stepExecution);
fail("Expected RuntimeException");
} catch (NullPointerException e) {
throw e;

View File

@@ -86,7 +86,7 @@ public class StepExecutorInterruptionTests extends TestCase {
Thread processingThread = new Thread() {
public void run() {
try {
stepConfiguration.process(stepExecution);
stepConfiguration.execute(stepExecution);
}
catch (StepInterruptedException e) {
// do nothing...

View File

@@ -75,7 +75,7 @@ public class OrderItemReader extends AbstractItemReader {
}
/**
* @see org.springframework.batch.execution.io.FieldSetCallback#process(StepExecution)
* @see org.springframework.batch.execution.io.FieldSetCallback#execute(StepExecution)
*/
private void process(FieldSet fieldSet) {
//finish processing if we hit the end of file