@Test public void testRetryable() throws Exception { Map<Class<? extends Throwable>, Boolean> retryable = getRetryableExceptionClasses("s1", getContext()); System.err.println(retryable); assertEquals(3, retryable.size()); containsClassified(retryable, PessimisticLockingFailureException.class, true); containsClassified(retryable, CannotSerializeTransactionException.class, false); }
private Map<Class<? extends Throwable>, Boolean> getRetryableExceptionClasses(String stepName, ApplicationContext ctx) throws Exception { return getNestedExceptionMap(stepName, ctx, "tasklet.chunkProcessor.batchRetryTemplate.regular.retryPolicy.exceptionClassifier", "retryableClassifier"); }
private SkipPolicy getSkipPolicy(String stepName, ApplicationContext ctx) throws Exception { return (SkipPolicy) getNestedPathInStep(stepName, ctx, "tasklet.chunkProvider.skipPolicy"); }
@Test public void testInheritSkippable() throws Exception { Map<Class<? extends Throwable>, Boolean> skippable = getSkippableExceptionClasses("s1", getContext()); System.err.println(skippable); assertEquals(5, skippable.size()); containsClassified(skippable, NullPointerException.class, true); containsClassified(skippable, ArithmeticException.class, true); containsClassified(skippable, CannotAcquireLockException.class, false); containsClassified(skippable, DeadlockLoserDataAccessException.class, false); }
@Test public void testInheritRetryListenersWithNoMerge() throws Exception { Collection<RetryListener> retryListeners = getRetryListeners("s2", getContext()); assertEquals(1, retryListeners.size()); boolean h = false; for (RetryListener o : retryListeners) { if (o instanceof DummyRetryListener) { h = true; } } assertTrue(h); }
@Test public void testInheritStreamsWithNoMerge() throws Exception { Collection<ItemStream> streams = getStreams("s2", getContext()); assertEquals(1, streams.size()); boolean c = false; for (ItemStream o : streams) { if (o instanceof CompositeItemStream) { c = true; } } assertTrue(c); }
@Test public void testSkipPolicyElement() throws Exception { @SuppressWarnings("resource") ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/ChunkElementSkipPolicyParserTests-context.xml"); SkipPolicy policy = getSkipPolicy("s2", context); assertFalse(policy.shouldSkip(new NullPointerException(), 0)); assertTrue(policy.shouldSkip(new ArithmeticException(), 0)); }
@SuppressWarnings("unchecked") private Map<Class<? extends Throwable>, Boolean> getNestedExceptionMap(String stepName, ApplicationContext ctx, String componentName, String classifierName) throws Exception { Object policy = getPolicy(stepName, ctx, componentName); Object exceptionClassifier = ReflectionTestUtils.getField(policy, classifierName); return (Map<Class<? extends Throwable>, Boolean>) ReflectionTestUtils.getField(exceptionClassifier, "classified"); }
private Object getNestedPathInStep(String stepName, ApplicationContext ctx, String path) throws Exception { Map<String, Step> beans = ctx.getBeansOfType(Step.class); assertTrue(beans.containsKey(stepName)); Object step = ctx.getBean(stepName); assertTrue(step instanceof TaskletStep); return getNestedPath(step, path); }
@Test public void testInheritSkippableWithNoMerge() throws Exception { Map<Class<? extends Throwable>, Boolean> skippable = getSkippableExceptionClasses("s2", getContext()); assertEquals(3, skippable.size()); containsClassified(skippable, IllegalArgumentException.class, true); assertFalse(skippable.containsKey(ArithmeticException.class)); containsClassified(skippable, ConcurrencyFailureException.class, false); assertFalse(skippable.containsKey(DeadlockLoserDataAccessException.class)); }
@Test public void testInheritRetryListeners() throws Exception { Collection<RetryListener> retryListeners = getRetryListeners("s1", getContext()); assertEquals(2, retryListeners.size()); boolean g = false; boolean h = false; for (RetryListener o : retryListeners) { if (o instanceof RetryListenerSupport) { g = true; } else if (o instanceof DummyRetryListener) { h = true; } } assertTrue(g); assertTrue(h); }
@Test public void testInheritStreams() throws Exception { Collection<ItemStream> streams = getStreams("s1", getContext()); assertEquals(2, streams.size()); boolean c = false; for (ItemStream o : streams) { if (o instanceof CompositeItemStream) { c = true; } } assertTrue(c); }
@Test public void testSkipPolicyAttribute() throws Exception { @SuppressWarnings("resource") ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/ChunkElementSkipPolicyParserTests-context.xml"); SkipPolicy policy = getSkipPolicy("s1", context); assertTrue(policy.shouldSkip(new NullPointerException(), 0)); assertTrue(policy.shouldSkip(new ArithmeticException(), 0)); }
@Test public void testRetryPolicyElement() throws Exception { @SuppressWarnings("resource") ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/ChunkElementRetryPolicyParserTests-context.xml"); SimpleRetryPolicy policy = (SimpleRetryPolicy) getPolicy("s2", context, "tasklet.chunkProcessor.batchRetryTemplate.regular.retryPolicy.exceptionClassifier"); assertEquals(2, policy.getMaxAttempts()); }
@Test public void testRetryableInherited() throws Exception { Map<Class<? extends Throwable>, Boolean> retryable = getRetryableExceptionClasses("s3", getContext()); System.err.println(retryable); assertEquals(2, retryable.size()); containsClassified(retryable, IOException.class, true); }
private Map<Class<? extends Throwable>, Boolean> getSkippableExceptionClasses(String stepName, ApplicationContext ctx) throws Exception { return getNestedExceptionMap(stepName, ctx, "tasklet.chunkProvider.skipPolicy.classifier", "skippableExceptionClassifier"); }
private Object getPolicy(String stepName, ApplicationContext ctx, String componentName) throws Exception { @SuppressWarnings("unchecked") SubclassClassifier<Throwable, Object> classifier = (SubclassClassifier<Throwable, Object>) getNestedPathInStep( stepName, ctx, componentName); Object policy = classifier.classify(new Exception()); return policy; }
@Test public void testRetryableInheritedMerge() throws Exception { Map<Class<? extends Throwable>, Boolean> retryable = getRetryableExceptionClasses("s4", getContext()); System.err.println(retryable); assertEquals(3, retryable.size()); containsClassified(retryable, IOException.class, true); }
@Test public void testRetryPolicyAttribute() throws Exception { @SuppressWarnings("resource") ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/ChunkElementRetryPolicyParserTests-context.xml"); Map<Class<? extends Throwable>, Boolean> retryable = getNestedExceptionMap("s1", context, "tasklet.chunkProcessor.batchRetryTemplate.regular.retryPolicy.exceptionClassifier", "exceptionClassifier"); assertEquals(2, retryable.size()); assertTrue(retryable.containsKey(NullPointerException.class)); assertTrue(retryable.containsKey(ArithmeticException.class)); }