RESOLVED - issue BATCH-153: skipLimit property of AbstractStepConfiguration seems to be unused

http://opensource.atlassian.com/projects/spring/browse/BATCH-153

Use skip limit to construct a SimpleLimitExceptionHandler.
This commit is contained in:
dsyer
2007-11-30 09:54:34 +00:00
parent 564b096cd2
commit 42a8a78259
3 changed files with 68 additions and 5 deletions

View File

@@ -40,6 +40,7 @@ import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
import org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHandler;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
@@ -157,7 +158,7 @@ public class SimpleStepExecutor implements StepExecutor {
final StepInstance step = stepExecution.getStep();
boolean isRestart = step.getStepExecutionCount() > 0 ? true : false;
Assert.notNull(step);
final Tasklet module = configuration.getTasklet();
ExitStatus status = ExitStatus.FAILED;
@@ -430,7 +431,9 @@ public class SimpleStepExecutor implements StepExecutor {
* <li> If the configuration is a {@link SimpleStepConfiguration} then we
* apply the commit interval at the chunk level and the exception handler at
* the step level, provided the existing repeat operations are instances of
* {@link RepeatTemplate}.</li>
* {@link RepeatTemplate}. In addition if there is a non-zero skip limit
* and no {@link ExceptionHandler} then we inject a
* {@link SimpleLimitExceptionHandler} with that limit.</li>
* </ul>
*
* @param configuration
@@ -447,14 +450,13 @@ public class SimpleStepExecutor implements StepExecutor {
.state(chunkOperations != null,
"Chunk operations obtained from step configuration must be non-null.");
if (chunkOperations != null) {
setChunkOperations(chunkOperations);
}
if (stepOperations != null) {
setStepOperations(stepOperations);
}
} else if (configuration instanceof SimpleStepConfiguration) {
SimpleStepConfiguration simpleConfiguation = (SimpleStepConfiguration) configuration;
@@ -463,9 +465,19 @@ public class SimpleStepExecutor implements StepExecutor {
template.setCompletionPolicy(new SimpleCompletionPolicy(
simpleConfiguation.getCommitInterval()));
}
ExceptionHandler exceptionHandler = simpleConfiguation
.getExceptionHandler();
if (this.stepOperations instanceof RepeatTemplate && exceptionHandler!=null) {
if (simpleConfiguation.getSkipLimit() > 0
&& exceptionHandler == null) {
SimpleLimitExceptionHandler handler = new SimpleLimitExceptionHandler();
handler.setLimit(simpleConfiguation.getSkipLimit());
exceptionHandler = handler;
}
if (this.stepOperations instanceof RepeatTemplate
&& exceptionHandler != null) {
RepeatTemplate template = (RepeatTemplate) this.stepOperations;
template.setExceptionHandler(exceptionHandler);
}

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.execution.step.simple;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
@@ -41,6 +42,8 @@ import org.springframework.batch.item.ItemProvider;
import org.springframework.batch.item.provider.ListItemProvider;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.exception.handler.DefaultExceptionHandler;
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
import org.springframework.batch.repeat.interceptor.RepeatInterceptorAdapter;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
@@ -381,6 +384,45 @@ public class DefaultStepExecutorTests extends TestCase {
fail();
}
}
public void testApplyConfigurationWithExceptionHandler() throws Exception {
SimpleStepConfiguration stepConfiguration = new SimpleStepConfiguration("foo");
final List list = new ArrayList();
stepExecutor.setStepOperations(new RepeatTemplate() {
public void setExceptionHandler(ExceptionHandler exceptionHandler) {
list.add(exceptionHandler);
}
});
stepConfiguration.setExceptionHandler(new DefaultExceptionHandler());
stepExecutor.applyConfiguration(stepConfiguration);
assertEquals(1, list.size());
}
public void testApplyConfigurationWithZeroSkipLimit() throws Exception {
SimpleStepConfiguration stepConfiguration = new SimpleStepConfiguration("foo");
stepConfiguration.setSkipLimit(0);
final List list = new ArrayList();
stepExecutor.setStepOperations(new RepeatTemplate() {
public void setExceptionHandler(ExceptionHandler exceptionHandler) {
list.add(exceptionHandler);
}
});
stepExecutor.applyConfiguration(stepConfiguration);
assertEquals(0, list.size());
}
public void testApplyConfigurationWithNonZeroSkipLimit() throws Exception {
SimpleStepConfiguration stepConfiguration = new SimpleStepConfiguration("foo");
stepConfiguration.setSkipLimit(1);
final List list = new ArrayList();
stepExecutor.setStepOperations(new RepeatTemplate() {
public void setExceptionHandler(ExceptionHandler exceptionHandler) {
list.add(exceptionHandler);
}
});
stepExecutor.applyConfiguration(stepConfiguration);
assertEquals(1, list.size());
}
private class MockRestartableTasklet implements Tasklet, Restartable {

View File

@@ -70,6 +70,15 @@ public class SimpleStepConfigurationTests extends TestCase {
assertNotNull(configuration.getExceptionHandler());
}
/**
* Test method for {@link org.springframework.batch.execution.step.AbstractStepConfiguration#getExceptionHandler()}.
*/
public void testSkipLimit() {
assertEquals(0, configuration.getSkipLimit());
configuration.setSkipLimit(2);
assertEquals(2, configuration.getSkipLimit());
}
/**
* Test method for {@link org.springframework.batch.execution.step.AbstractStepConfiguration#getSkipLimit()}.
*/