BATCH-1739: fix all retry/skip inconsistencies *except* with late binding of limits

This commit is contained in:
Dave Syer
2011-05-04 11:16:37 +01:00
parent 6dfc3a4a61
commit 422974800d
12 changed files with 180 additions and 39 deletions

View File

@@ -38,7 +38,6 @@ import org.springframework.batch.retry.listener.RetryListenerSupport;
import org.springframework.batch.retry.policy.SimpleRetryPolicy;
import org.springframework.beans.PropertyAccessorUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -91,8 +90,8 @@ public class ChunkElementParserTests {
"org/springframework/batch/core/configuration/xml/ChunkElementIllegalSkipAndRetryAttributeParserTests-context.xml");
Step step = (Step) context.getBean("s1", Step.class);
assertNotNull("Step not parsed", step);
fail("Expected BeanDefinitionParsingException");
} catch (BeanDefinitionParsingException e) {
fail("Expected BeanCreationException");
} catch (BeanCreationException e) {
// expected
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.configuration.xml;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.step.item.FaultTolerantChunkProcessor;
@@ -53,4 +54,39 @@ public class ParentStepFactoryBeanParserTests {
assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor<?,?>);
}
@Test
public void testRetryableAttributes() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ParentRetryableStepFactoryBeanParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
assertNotNull("Step not parsed", step);
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor<?,?>);
}
@Test
@Ignore // Fix this BATCH-1739
public void testRetryableLateBindingAttributes() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ParentRetryableLateBindingStepFactoryBeanParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
assertNotNull("Step not parsed", step);
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor<?,?>);
}
@Test
@Ignore // Fix this BATCH-1739
public void testSkippableLateBindingAttributes() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ParentSkippableLateBindingStepFactoryBeanParserTests-context.xml");
Object step = context.getBean("s1", Step.class);
assertNotNull("Step not parsed", step);
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
Object chunkProcessor = ReflectionTestUtils.getField(tasklet, "chunkProcessor");
assertTrue("Wrong processor type", chunkProcessor instanceof FaultTolerantChunkProcessor<?,?>);
}
}

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
@@ -226,8 +227,10 @@ public class StepParserStepFactoryBeanTests {
fb.setSkipLimit(100);
fb.setThrottleLimit(10);
fb.setRetryListeners(new RetryListenerSupport());
fb.setSkippableExceptionClasses(new HashMap<Class<? extends Throwable>, Boolean>());
fb.setRetryableExceptionClasses(new HashMap<Class<? extends Throwable>, Boolean>());
@SuppressWarnings("unchecked")
Map<Class<? extends Throwable>, Boolean> exceptionMap = getExceptionMap(Exception.class);
fb.setSkippableExceptionClasses(exceptionMap);
fb.setRetryableExceptionClasses(exceptionMap);
Object step = fb.getObject();
assertTrue(step instanceof TaskletStep);
@@ -297,4 +300,12 @@ public class StepParserStepFactoryBeanTests {
assertTrue(handler instanceof SimpleFlow);
}
private Map<Class<? extends Throwable>, Boolean> getExceptionMap(Class<? extends Throwable>... args) {
Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>();
for (Class<? extends Throwable> arg : args) {
map.put(arg, true);
}
return map;
}
}

View File

@@ -149,7 +149,7 @@ public class FaultTolerantStepFactoryBeanRollbackTests {
reader.setExceptionType(SkippableException.class);
// No skips by default
factory.setSkippableExceptionClasses(getExceptionMap());
factory.setSkippableExceptionClasses(getExceptionMap(RuntimeException.class));
// But this one is explicit in the tx-attrs so it should be skipped
factory.setNoRollbackExceptionClasses(getExceptionList(SkippableException.class));

View File

@@ -127,7 +127,7 @@ public class FaultTolerantStepFactoryBeanTests {
reader.setFailures("2");
// nothing is skippable
factory.setSkippableExceptionClasses(getExceptionMap());
factory.setSkippableExceptionClasses(getExceptionMap(NonExistentException.class));
Step step = (Step) factory.getObject();
@@ -144,7 +144,7 @@ public class FaultTolerantStepFactoryBeanTests {
@Test
public void testNonSkippableException() throws Exception {
// nothing is skippable
factory.setSkippableExceptionClasses(getExceptionMap());
factory.setSkippableExceptionClasses(getExceptionMap(NonExistentException.class));
factory.setCommitInterval(1);
// no failures on read
@@ -1066,5 +1066,9 @@ public class FaultTolerantStepFactoryBeanTests {
}
return map;
}
public static class NonExistentException extends Exception {
}
}