From 48f23ccfb72b86fc7ecff65eb1d2f02ed0be7b18 Mon Sep 17 00:00:00 2001 From: lucasward Date: Fri, 22 Feb 2008 22:08:20 +0000 Subject: [PATCH] Reorganized the execution.step package to contain all Step implementations --- .../JobBeanDefinitionParser.java | 2 +- .../step/{simple => }/AbstractStep.java | 4 +- .../step/{simple => }/ChunkedStep.java | 46 ++++--- .../step/{simple => }/ItemOrientedStep.java | 25 ++-- .../step/{tasklet => }/TaskletStep.java | 2 +- .../execution/step/simple/ItemChunker.java | 1 - .../step/simple/RepeatOperationsStep.java | 4 +- .../execution/step/simple/SimpleStep.java | 59 -------- .../step/simple/StepInterruptionPolicy.java | 2 +- ...BatchNamespaceHandlerTaskletStepTests.java | 2 +- .../configuration/StubDataSource.java | 8 ++ .../execution/job/simple/SimpleJobTests.java | 4 +- .../execution/launch/SimpleJobTests.java | 2 +- .../step/{simple => }/ChunkedStepTests.java | 5 +- .../{simple => }/ItemOrientedStepTests.java | 24 +++- .../step/{tasklet => }/TaskletStepTests.java | 3 +- .../simple/RepeatOperationsStepTests.java | 2 +- .../simple/SimpleStepConfigurationTests.java | 114 ---------------- .../step/simple/SimpleStepTests.java | 129 ------------------ .../src/test/resources/job-configuration.xml | 2 +- .../batch/execution/bootstrap/support/job.xml | 2 +- .../execution/configuration/test-context.xml | 2 +- .../resources/simple-container-definition.xml | 2 +- 23 files changed, 87 insertions(+), 359 deletions(-) rename spring-batch-execution/src/main/java/org/springframework/batch/execution/step/{simple => }/AbstractStep.java (93%) rename spring-batch-execution/src/main/java/org/springframework/batch/execution/step/{simple => }/ChunkedStep.java (93%) rename spring-batch-execution/src/main/java/org/springframework/batch/execution/step/{simple => }/ItemOrientedStep.java (96%) rename spring-batch-execution/src/main/java/org/springframework/batch/execution/step/{tasklet => }/TaskletStep.java (98%) delete mode 100644 spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStep.java rename spring-batch-execution/src/test/java/org/springframework/batch/execution/step/{simple => }/ChunkedStepTests.java (98%) rename spring-batch-execution/src/test/java/org/springframework/batch/execution/step/{simple => }/ItemOrientedStepTests.java (96%) rename spring-batch-execution/src/test/java/org/springframework/batch/execution/step/{tasklet => }/TaskletStepTests.java (97%) delete mode 100644 spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java delete mode 100644 spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepTests.java diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobBeanDefinitionParser.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobBeanDefinitionParser.java index 78a76e64c..c3fcec497 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobBeanDefinitionParser.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/configuration/JobBeanDefinitionParser.java @@ -16,7 +16,7 @@ package org.springframework.batch.execution.configuration; -import org.springframework.batch.execution.step.tasklet.TaskletStep; +import org.springframework.batch.execution.step.TaskletStep; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.RuntimeBeanReference; diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/AbstractStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/AbstractStep.java similarity index 93% rename from spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/AbstractStep.java rename to spring-batch-execution/src/main/java/org/springframework/batch/execution/step/AbstractStep.java index a00e69317..240877565 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/AbstractStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/AbstractStep.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.execution.step.simple; +package org.springframework.batch.execution.step; import org.springframework.batch.core.domain.ItemFailureHandler; import org.springframework.batch.core.domain.ItemSkipPolicy; @@ -22,6 +22,8 @@ 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.repository.JobRepository; +import org.springframework.batch.execution.step.simple.DefaultItemFailureHandler; +import org.springframework.batch.execution.step.simple.NeverSkipItemSkipPolicy; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ChunkedStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ChunkedStep.java similarity index 93% rename from spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ChunkedStep.java rename to spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ChunkedStep.java index 63c18f7a1..613f4df50 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ChunkedStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ChunkedStep.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.execution.step.simple; +package org.springframework.batch.execution.step; import java.util.Date; import java.util.Iterator; @@ -40,6 +40,12 @@ import org.springframework.batch.execution.scope.SimpleStepContext; import org.springframework.batch.execution.scope.StepContext; import org.springframework.batch.execution.scope.StepScope; import org.springframework.batch.execution.scope.StepSynchronizationManager; +import org.springframework.batch.execution.step.simple.DefaultItemFailureHandler; +import org.springframework.batch.execution.step.simple.ItemChunker; +import org.springframework.batch.execution.step.simple.ItemDechunker; +import org.springframework.batch.execution.step.simple.SimpleExitStatusExceptionClassifier; +import org.springframework.batch.execution.step.simple.StepInterruptionPolicy; +import org.springframework.batch.execution.step.simple.ThreadStepInterruptionPolicy; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.io.exception.WriteFailureException; import org.springframework.batch.item.ExecutionContext; @@ -357,14 +363,29 @@ public class ChunkedStep extends StepSupport implements InitializingBean { // Before starting a new transaction, check for // interruption. interruptionPolicy.checkInterrupted(context); + + final StepContribution contribution = stepExecution + .createStepContribution(); + + ChunkingResult chunkingResult = chunker.chunk(chunkSize, + contribution); + + if (chunkingResult == null) { + return ExitStatus.FINISHED; + } + + final Chunk chunk = chunkingResult.getChunk(); + for(Iterator it = chunkingResult.getExceptions().iterator();it.hasNext();){ + failureLog.handleReadFailure((Exception)it.next()); + } ExitStatus result = (ExitStatus) retryTemplate .execute(new RetryCallback() { public Object doWithRetry(RetryContext context) throws Throwable { - return processChunk(stepExecution, - stepContext); + return processChunk(contribution, stepExecution, + stepContext, chunk); } }); @@ -435,29 +456,14 @@ public class ChunkedStep extends StepSupport implements InitializingBean { * the current step context. * @return true if there is more data to process. */ - ExitStatus processChunk(final StepExecution stepExecution, - StepContext stepContext) { + ExitStatus processChunk(final StepContribution contribution,StepExecution stepExecution, + StepContext stepContext, final Chunk chunk) { TransactionStatus transaction = streamManager .getTransaction(stepExecution); - final StepContribution contribution = stepExecution - .createStepContribution(); - try { - ChunkingResult chunkingResult = chunker.chunk(chunkSize, - contribution); - - if (chunkingResult == null) { - return ExitStatus.FINISHED; - } - - final Chunk chunk = chunkingResult.getChunk(); - for(Iterator it = chunkingResult.getExceptions().iterator();it.hasNext();){ - failureLog.handleReadFailure((Exception)it.next()); - } - DechunkingResult dechunkingResult = dechunker.dechunk(chunk, contribution); for(Iterator it = dechunkingResult.getExceptions().iterator(); it.hasNext();){ diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ItemOrientedStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java similarity index 96% rename from spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ItemOrientedStep.java rename to spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java index 6d0525f06..2b9fbbcf7 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ItemOrientedStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.execution.step.simple; +package org.springframework.batch.execution.step; import java.util.Date; @@ -31,6 +31,9 @@ import org.springframework.batch.execution.scope.SimpleStepContext; import org.springframework.batch.execution.scope.StepContext; import org.springframework.batch.execution.scope.StepScope; import org.springframework.batch.execution.scope.StepSynchronizationManager; +import org.springframework.batch.execution.step.simple.SimpleExitStatusExceptionClassifier; +import org.springframework.batch.execution.step.simple.StepInterruptionPolicy; +import org.springframework.batch.execution.step.simple.ThreadStepInterruptionPolicy; import org.springframework.batch.io.Skippable; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.item.ExecutionContext; @@ -110,14 +113,14 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean { } /** - * The {@link RepeatOperations} to use for the inner loop of the batch - * processing. Should be set up by the caller through a factory. Defaults to - * a plain {@link RepeatTemplate}. + * the {@link repeatoperations} to use for the inner loop of the batch + * processing. should be set up by the caller through a factory. defaults to + * a plain {@link repeattemplate}. * - * @param chunkOperations a {@link RepeatOperations} instance. + * @param chunkoperations a {@link repeatoperations} instance. */ - public void setChunkOperations(RepeatOperations chunkOperations) { - this.chunkOperations = chunkOperations; + public void setChunkOperations(RepeatOperations chunkoperations) { + this.chunkOperations = chunkoperations; } /** @@ -196,14 +199,6 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean { */ void applyConfiguration(AbstractStep step) { - if (step instanceof SimpleStep) { - SimpleStep simple = (SimpleStep) step; - if (this.chunkOperations instanceof RepeatTemplate) { - RepeatTemplate template = (RepeatTemplate) this.chunkOperations; - template.setCompletionPolicy(new SimpleCompletionPolicy(simple.getCommitInterval())); - } - } - ExceptionHandler exceptionHandler = step.getExceptionHandler(); if (step.getSkipLimit() > 0 && exceptionHandler == null) { diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/tasklet/TaskletStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/TaskletStep.java similarity index 98% rename from spring-batch-execution/src/main/java/org/springframework/batch/execution/step/tasklet/TaskletStep.java rename to spring-batch-execution/src/main/java/org/springframework/batch/execution/step/TaskletStep.java index 4734e29ad..1573792c5 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/tasklet/TaskletStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/TaskletStep.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.execution.step.tasklet; +package org.springframework.batch.execution.step; import java.util.Date; diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ItemChunker.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ItemChunker.java index 3b5a31453..2a8cafa44 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ItemChunker.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/ItemChunker.java @@ -23,7 +23,6 @@ import org.springframework.batch.core.domain.Chunker; import org.springframework.batch.core.domain.ChunkingResult; import org.springframework.batch.core.domain.ItemSkipPolicy; import org.springframework.batch.core.domain.StepContribution; -import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.io.exception.ReadFailureException; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/RepeatOperationsStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/RepeatOperationsStep.java index e66988a16..b324216bc 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/RepeatOperationsStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/RepeatOperationsStep.java @@ -16,12 +16,12 @@ package org.springframework.batch.execution.step.simple; +import org.springframework.batch.core.domain.JobInterruptedException; import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; -import org.springframework.batch.core.domain.JobInterruptedException; +import org.springframework.batch.execution.step.ItemOrientedStep; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.repeat.RepeatOperations; -import org.springframework.batch.repeat.support.RepeatTemplate; /** * {@link Step} implementation that allows full step of the diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStep.java deleted file mode 100644 index b77645bee..000000000 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStep.java +++ /dev/null @@ -1,59 +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.step.simple; - -import org.springframework.batch.core.domain.JobInterruptedException; -import org.springframework.batch.core.domain.Step; -import org.springframework.batch.core.domain.StepExecution; -import org.springframework.batch.io.exception.BatchCriticalException; - -/** - * Simple {@link Step} good enough for most purposes and easy to configure simple properties, principally the commit - * interval. - * - * @author Lucas Ward - * @author Dave Syer - * @author Ben Hale - */ -public class SimpleStep extends AbstractStep { - - // default commit interval is one - private int commitInterval = 1; - - public SimpleStep() { - super(); - } - - public SimpleStep(String name) { - super(name); - } - - public void setCommitInterval(int commitInterval) { - this.commitInterval = commitInterval; - } - - public int getCommitInterval() { - return commitInterval; - } - - public void execute(StepExecution stepExecution) - throws JobInterruptedException, BatchCriticalException { - throw new UnsupportedOperationException( - "Cannot process a StepExecution. Use a smarter subclass of StepSupport."); - } - -} diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/StepInterruptionPolicy.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/StepInterruptionPolicy.java index f1a9eabd3..f1142e856 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/StepInterruptionPolicy.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/StepInterruptionPolicy.java @@ -16,8 +16,8 @@ package org.springframework.batch.execution.step.simple; -import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.JobInterruptedException; +import org.springframework.batch.core.domain.Step; import org.springframework.batch.repeat.RepeatContext; /** diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepTests.java index 032e63645..6f8c634cc 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/BatchNamespaceHandlerTaskletStepTests.java @@ -18,7 +18,7 @@ package org.springframework.batch.execution.configuration; import junit.framework.TestCase; -import org.springframework.batch.execution.step.tasklet.TaskletStep; +import org.springframework.batch.execution.step.TaskletStep; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/StubDataSource.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/StubDataSource.java index 26b721a63..f193a2332 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/StubDataSource.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/StubDataSource.java @@ -53,5 +53,13 @@ public class StubDataSource implements DataSource { // TODO Auto-generated method stub throw new UnsupportedOperationException(); } + + public boolean isWrapperFor(Class arg0) throws SQLException { + return false; + } + + public Object unwrap(Class arg0) throws SQLException { + return null; + } } \ No newline at end of file diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/simple/SimpleJobTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/simple/SimpleJobTests.java index c5b66483a..1978bf530 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/simple/SimpleJobTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/simple/SimpleJobTests.java @@ -35,7 +35,7 @@ import org.springframework.batch.execution.repository.dao.JobInstanceDao; import org.springframework.batch.execution.repository.dao.MapJobDao; import org.springframework.batch.execution.repository.dao.MapStepDao; import org.springframework.batch.execution.repository.dao.StepExecutionDao; -import org.springframework.batch.execution.step.simple.SimpleStep; +import org.springframework.batch.execution.step.AbstractStep; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.item.reader.AbstractItemReader; import org.springframework.batch.repeat.ExitStatus; @@ -265,7 +265,7 @@ public class SimpleJobTests extends TestCase { checkRepository(status, null); } - private class StubStep extends SimpleStep { + private class StubStep extends AbstractStep { private Runnable runnable; private Exception exception; 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 29ff87fc0..ea9f6e204 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 @@ -32,7 +32,7 @@ import org.springframework.batch.execution.job.simple.SimpleJob; 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.step.simple.AbstractStep; +import org.springframework.batch.execution.step.AbstractStep; import org.springframework.batch.execution.step.simple.RepeatOperationsStep; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemRecoverer; diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/ChunkedStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ChunkedStepTests.java similarity index 98% rename from spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/ChunkedStepTests.java rename to spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ChunkedStepTests.java index b5a214435..c94b20a91 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/ChunkedStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ChunkedStepTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.batch.execution.step.simple; +package org.springframework.batch.execution.step; import java.util.ArrayList; import java.util.Arrays; @@ -31,6 +31,9 @@ import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.execution.scope.StepScope; import org.springframework.batch.execution.scope.StepSynchronizationManager; +import org.springframework.batch.execution.step.simple.ItemChunker; +import org.springframework.batch.execution.step.simple.ItemDechunker; +import org.springframework.batch.execution.step.simple.JobRepositorySupport; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/ItemOrientedStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java similarity index 96% rename from spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/ItemOrientedStepTests.java rename to spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java index 2fcb8bd3a..acf4ae9fc 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/ItemOrientedStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.batch.execution.step.simple; +package org.springframework.batch.execution.step; import java.util.ArrayList; import java.util.Arrays; @@ -37,6 +37,10 @@ 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.simple.JobRepositorySupport; +import org.springframework.batch.execution.step.simple.StepInterruptionPolicy; +import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; @@ -357,7 +361,7 @@ public class ItemOrientedStepTests extends TestCase { } public void testApplyConfigurationWithExceptionHandler() throws Exception { - AbstractStep stepConfiguration = new SimpleStep("foo"); + AbstractStep stepConfiguration = new StubStep("foo"); final List list = new ArrayList(); itemOrientedStep.setStepOperations(new RepeatTemplate() { public void setExceptionHandler(ExceptionHandler exceptionHandler) { @@ -370,7 +374,7 @@ public class ItemOrientedStepTests extends TestCase { } public void testApplyConfigurationWithZeroSkipLimit() throws Exception { - AbstractStep stepConfiguration = new SimpleStep("foo"); + AbstractStep stepConfiguration = new StubStep("foo"); stepConfiguration.setSkipLimit(0); final List list = new ArrayList(); itemOrientedStep.setStepOperations(new RepeatTemplate() { @@ -383,7 +387,7 @@ public class ItemOrientedStepTests extends TestCase { } public void testApplyConfigurationWithNonZeroSkipLimit() throws Exception { - AbstractStep stepConfiguration = new SimpleStep("foo"); + AbstractStep stepConfiguration = new StubStep("foo"); stepConfiguration.setSkipLimit(1); final List list = new ArrayList(); itemOrientedStep.setStepOperations(new RepeatTemplate() { @@ -554,5 +558,17 @@ public class ItemOrientedStepTests extends TestCase { assertEquals("Foo", ex.getCause().getMessage()); } } + + private class StubStep extends AbstractStep{ + + public StubStep(String name) { + super(name); + } + + public void execute(StepExecution stepExecution) + throws JobInterruptedException, BatchCriticalException { + } + + } } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/tasklet/TaskletStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/TaskletStepTests.java similarity index 97% rename from spring-batch-execution/src/test/java/org/springframework/batch/execution/step/tasklet/TaskletStepTests.java rename to spring-batch-execution/src/test/java/org/springframework/batch/execution/step/TaskletStepTests.java index 7038a375f..20f89f80c 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/tasklet/TaskletStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/TaskletStepTests.java @@ -1,4 +1,4 @@ -package org.springframework.batch.execution.step.tasklet; +package org.springframework.batch.execution.step; import java.util.ArrayList; import java.util.List; @@ -11,6 +11,7 @@ import org.springframework.batch.core.domain.JobInterruptedException; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.tasklet.Tasklet; +import org.springframework.batch.execution.step.TaskletStep; import org.springframework.batch.execution.step.simple.JobRepositorySupport; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.repeat.ExitStatus; diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/RepeatOperationsStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/RepeatOperationsStepTests.java index bc0439ba2..5d96f89ef 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/RepeatOperationsStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/RepeatOperationsStepTests.java @@ -20,11 +20,11 @@ import java.util.List; import junit.framework.TestCase; -import org.springframework.batch.core.domain.ItemFailureHandler; 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.StepExecution; +import org.springframework.batch.execution.step.ItemOrientedStep; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.reader.ItemReaderAdapter; diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java deleted file mode 100644 index 71b727d1c..000000000 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java +++ /dev/null @@ -1,114 +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.step.simple; - -import junit.framework.TestCase; - -import org.springframework.batch.item.reader.AbstractItemReader; -import org.springframework.batch.item.writer.AbstractItemWriter; -import org.springframework.batch.repeat.exception.handler.DefaultExceptionHandler; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; - -/** - * @author Dave Syer - * - */ -public class SimpleStepConfigurationTests extends TestCase { - - SimpleStep configuration = new SimpleStep("foo"); - - /** - * Test method for {@link org.springframework.batch.execution.step.simple.SimpleStep#SimpleStepConfiguration()}. - */ - public void testSimpleStepConfiguration() { - assertNotNull(configuration.getName()); - configuration = new SimpleStep(); - assertNull(configuration.getName()); - } - - /** - * Test method for - * {@link org.springframework.batch.execution.step.simple.SimpleStep#SimpleStepConfiguration(org.springframework.batch.core.tasklet.Tasklet)}. - * - * @throws Exception - */ - public void testSimpleStepConfigurationTasklet() throws Exception { - configuration = new SimpleStep(); - configuration.setItemReader(new AbstractItemReader() { - - public Object read() throws Exception { - // TODO Auto-generated method stub - return null; - } - }); - configuration.setItemWriter(new AbstractItemWriter() { - - public void write(Object item) throws Exception { - // TODO Auto-generated method stub - - } - }); - configuration.setJobRepository(new JobRepositorySupport()); - configuration.setTransactionManager(new ResourcelessTransactionManager()); - configuration.afterPropertiesSet(); - } - - /** - * Test method for {@link org.springframework.batch.execution.step.simple.SimpleStep#getCommitInterval()}. - */ - public void testGetCommitInterval() { - assertEquals(1, configuration.getCommitInterval()); - configuration.setCommitInterval(20); - assertEquals(20, configuration.getCommitInterval()); - } - - /** - * Test method for {@link org.springframework.batch.execution.step.simple.AbstractStep#getExceptionHandler()}. - */ - public void testGetExceptionHandler() { - assertNull(configuration.getExceptionHandler()); - configuration.setExceptionHandler(new DefaultExceptionHandler()); - assertNotNull(configuration.getExceptionHandler()); - } - - /** - * Test method for {@link org.springframework.batch.execution.step.simple.AbstractStep#getExceptionHandler()}. - */ - public void testSkipLimit() { - assertEquals(0, configuration.getSkipLimit()); - configuration.setSkipLimit(2); - assertEquals(2, configuration.getSkipLimit()); - } - - /** - * Test method for {@link org.springframework.batch.execution.step.simple.AbstractStep#getSkipLimit()}. - */ - public void testGetSkipLimit() { - assertEquals(0, configuration.getSkipLimit()); - configuration.setSkipLimit(20); - assertEquals(20, configuration.getSkipLimit()); - } - - /** - * Test method for {@link org.springframework.batch.execution.step.simple.AbstractStep#isSaveExecutionContext()}. - */ - public void testIsSaveExecutionContext() { - assertEquals(false, configuration.isSaveExecutionContext()); - configuration.setSaveExecutionContext(true); - assertEquals(true, configuration.isSaveExecutionContext()); - } - -} diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepTests.java deleted file mode 100644 index 53aff9133..000000000 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepTests.java +++ /dev/null @@ -1,129 +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.step.simple; - -import junit.framework.TestCase; - -import org.springframework.batch.item.stream.SimpleStreamManager; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; - -/** - * Most of the tests have been commented out, since SimpleStep - * will likely be removed soon. - * - * @author Dave Syer - * - */ -public class SimpleStepTests extends TestCase { - -// public void testSuccessfulStepExecutor() throws Exception { -// SimpleStep step = new SimpleStep(); -// step.setJobRepository(new JobRepositorySupport()); -// step.setTransactionManager(new ResourcelessTransactionManager()); -// step.setItemReader(new ItemReaderAdapter()); -// step.setItemWriter(new ItemWriterAdapter()); -// assertNotNull(step.createStepExecutor()); -// } -// -// public void testSuccessfulExceptionHandler() throws Exception { -// SimpleStep step = new SimpleStep("foo"); -// step.setItemReader(new ItemReaderAdapter()); -// step.setItemWriter(new ItemWriterAdapter()); -// step.setJobRepository(new JobRepositorySupport()); -// step.setTransactionManager(new ResourcelessTransactionManager()); -// final List list = new ArrayList(); -// step.setExceptionHandler(new ExceptionHandler() { -// public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException { -// list.add(throwable); -// throw new RuntimeException("Oops"); -// } -// }); -// ItemOrientedStep executor = (ItemOrientedStep) step.createStepExecutor(); -// StepExecution stepExecution = new StepExecution("stepName", new JobExecution( -// new JobInstance(new Long(0L), new JobParameters()), new Long(12))); -// try { -// executor.execute(stepExecution); -// fail("Expected RuntimeException"); -// } -// catch (NullPointerException e) { -// throw e; -// } -// catch (RuntimeException e) { -// assertEquals("Oops", e.getMessage()); -// } -// assertEquals(1, list.size()); -// } - -// public void testUnsuccessfulNoJobRepository() throws Exception { -// try { -// new SimpleStep().createStepExecutor(); -// fail("Expected IllegalArgumentException"); -// } -// catch (IllegalArgumentException e) { -// // expected -// assertTrue("Error message does not contain JobRepository: " + e.getMessage(), e.getMessage().indexOf( -// "JobRepository") >= 0); -// } -// } - - public void testMandatoryProperties() throws Exception { - try { - new SimpleStep().afterPropertiesSet(); - fail("Expected IllegalArgumentException"); - } - catch (IllegalArgumentException e) { - // expected - } - } - - public void testMandatoryPropertiesNoTransactionManagerOrStreamManager() throws Exception { - try { - SimpleStep configuration = new SimpleStep("foo"); - configuration.setJobRepository(new JobRepositorySupport()); - configuration.assertMandatoryProperties(); - fail("Experetscted IllegalStateException"); - } - catch (IllegalStateException e) { - // expected - } - } - - public void testMandatoryPropertiesTransactionManagerAndStreamManager() throws Exception { - try { - SimpleStep configuration = new SimpleStep("foo"); - configuration.setJobRepository(new JobRepositorySupport()); - configuration.setTransactionManager(new ResourcelessTransactionManager()); - configuration.setStreamManager(new SimpleStreamManager()); - configuration.assertMandatoryProperties(); - fail("Expected IllegalStateException"); - } - catch (IllegalStateException e) { - // expected - } - } - -// public void testMandatoryPropertiesAfterExecution() throws Exception { -// SimpleStep step = new SimpleStep(); -// step.setItemReader(new ItemReaderAdapter()); -// step.setItemWriter(new ItemWriterAdapter()); -// step.setJobRepository(new JobRepositorySupport()); -// step.setTransactionManager(new ResourcelessTransactionManager()); -// assertNotNull(step.createStepExecutor()); -// // If we do that again, we don't expect a different result (e.g. -// // mandatory properties test failing). -// assertNotNull(step.createStepExecutor()); -// } -} diff --git a/spring-batch-execution/src/test/resources/job-configuration.xml b/spring-batch-execution/src/test/resources/job-configuration.xml index 3e75ce21f..9b8176c8a 100644 --- a/spring-batch-execution/src/test/resources/job-configuration.xml +++ b/spring-batch-execution/src/test/resources/job-configuration.xml @@ -18,7 +18,7 @@ class="org.springframework.batch.core.domain.JobSupport"> + class="org.springframework.batch.execution.step.ItemOrientedStep"> diff --git a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml index 7c1065a80..2723a12ee 100644 --- a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml +++ b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml @@ -13,7 +13,7 @@ class="org.springframework.batch.core.domain.JobSupport"> + class="org.springframework.batch.execution.step.ItemOrientedStep"> diff --git a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/configuration/test-context.xml b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/configuration/test-context.xml index a5712745d..f7cc96f16 100644 --- a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/configuration/test-context.xml +++ b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/configuration/test-context.xml @@ -20,7 +20,7 @@ - + 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 10d3973bf..9a2b3e180 100644 --- a/spring-batch-execution/src/test/resources/simple-container-definition.xml +++ b/spring-batch-execution/src/test/resources/simple-container-definition.xml @@ -25,7 +25,7 @@