BATCH-873: add skipPolicy to FultTolerantStepFactoryBean
This commit is contained in:
@@ -26,8 +26,10 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.classify.SubclassClassifier;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.step.item.SimpleChunkProcessor;
|
||||
import org.springframework.batch.core.step.skip.SkipPolicy;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.support.CompositeItemStream;
|
||||
@@ -103,7 +105,7 @@ public class ChunkElementParserTests {
|
||||
@Test
|
||||
public void testInheritSkippable() throws Exception {
|
||||
Map<Class<? extends Throwable>, Boolean> skippable = getExceptionClasses("s1", getContext());
|
||||
assertEquals(11, skippable.size());
|
||||
assertEquals(5, skippable.size());
|
||||
containsClassified(skippable, NullPointerException.class, true);
|
||||
containsClassified(skippable, ArithmeticException.class, true);
|
||||
containsClassified(skippable, CannotAcquireLockException.class, false);
|
||||
@@ -113,7 +115,7 @@ public class ChunkElementParserTests {
|
||||
@Test
|
||||
public void testInheritSkippableWithNoMerge() throws Exception {
|
||||
Map<Class<? extends Throwable>, Boolean> skippable = getExceptionClasses("s2", getContext());
|
||||
assertEquals(9, skippable.size());
|
||||
assertEquals(3, skippable.size());
|
||||
containsClassified(skippable, NullPointerException.class, true);
|
||||
assertFalse(skippable.containsKey(ArithmeticException.class));
|
||||
containsClassified(skippable, CannotAcquireLockException.class, false);
|
||||
@@ -194,8 +196,11 @@ public class ChunkElementParserTests {
|
||||
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
|
||||
Object chunkProvider = ReflectionTestUtils.getField(tasklet, "chunkProvider");
|
||||
Object skipPolicy = ReflectionTestUtils.getField(chunkProvider, "skipPolicy");
|
||||
Object classifier = ReflectionTestUtils.getField(skipPolicy, "skippableExceptionClassifier");
|
||||
return (Map<Class<? extends Throwable>, Boolean>) ReflectionTestUtils.getField(classifier, "classified");
|
||||
SubclassClassifier<Throwable, SkipPolicy> classifier = (SubclassClassifier<Throwable, SkipPolicy>) ReflectionTestUtils
|
||||
.getField(skipPolicy, "classifier");
|
||||
Object limitPolicy = classifier.classify(new Exception());
|
||||
Object limitClassifier = ReflectionTestUtils.getField(limitPolicy, "skippableExceptionClassifier");
|
||||
return (Map<Class<? extends Throwable>, Boolean>) ReflectionTestUtils.getField(limitClassifier, "classified");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,6 +33,7 @@ import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.listener.SkipListenerSupport;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
|
||||
import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.SkipPolicy;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
@@ -188,6 +190,18 @@ public class FaultTolerantStepFactoryBeanTests {
|
||||
.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check items causing errors are skipped as expected.
|
||||
*/
|
||||
@Test
|
||||
public void testReadSkipWithPolicy() throws Exception {
|
||||
// Should be ignored
|
||||
factory.setSkipLimit(0);
|
||||
factory.setSkipPolicy(new LimitCheckingItemSkipPolicy(2, Collections
|
||||
.<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
|
||||
testReadSkip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to make sure that ItemStreamException can be skipped. (see
|
||||
* BATCH-915)
|
||||
@@ -426,7 +440,7 @@ public class FaultTolerantStepFactoryBeanTests {
|
||||
step.execute(stepExecution);
|
||||
|
||||
// 1,3 skipped inside a committed chunk. 5 tripped the skip
|
||||
// limit but it was skipped in a chunk that rolled back, so
|
||||
// limit but it was skipped in a chunk that rolled back, so
|
||||
// it will re-appear on a restart and the listener is not called.
|
||||
assertEquals(2, listenerCalls.size());
|
||||
assertEquals(2, stepExecution.getReadSkipCount());
|
||||
|
||||
Reference in New Issue
Block a user