From be87103d94d38d7dcd86cd2157a80ec49c4c14da Mon Sep 17 00:00:00 2001 From: dsyer Date: Thu, 31 Dec 2009 12:46:15 +0000 Subject: [PATCH] RESOLVED BATCH-1441: Added remaining preoperties from FaultTolerant- to StepParserStepFactoryBean --- .../xml/StepParserStepFactoryBean.java | 72 ++++++++++++++++++- .../xml/ParentStepFactoryBeanParserTests.java | 45 ++++++++++++ ...rentStepFactoryBeanParserTests-context.xml | 33 +++++++++ 3 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests.java create mode 100644 spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java index 46d5158b2..40ea73b1b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java @@ -37,6 +37,7 @@ import org.springframework.batch.core.partition.support.TaskExecutorPartitionHan import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.AbstractStep; import org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean; +import org.springframework.batch.core.step.item.KeyGenerator; import org.springframework.batch.core.step.item.SimpleStepFactoryBean; import org.springframework.batch.core.step.job.JobParametersExtractor; import org.springframework.batch.core.step.job.JobStep; @@ -51,7 +52,10 @@ import org.springframework.batch.repeat.CompletionPolicy; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate; import org.springframework.batch.retry.RetryListener; +import org.springframework.batch.retry.RetryPolicy; +import org.springframework.batch.retry.backoff.BackOffPolicy; import org.springframework.batch.retry.policy.MapRetryContextCache; +import org.springframework.batch.retry.policy.RetryContextCache; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.core.task.SyncTaskExecutor; @@ -150,6 +154,14 @@ class StepParserStepFactoryBean implements FactoryBean, BeanNameAware { private Integer retryLimit; + private BackOffPolicy backOffPolicy; + + private RetryPolicy retryPolicy; + + private RetryContextCache retryContextCache; + + private KeyGenerator keyGenerator; + private Integer skipLimit; private SkipPolicy skipPolicy; @@ -348,6 +360,18 @@ class StepParserStepFactoryBean implements FactoryBean, BeanNameAware { if (skipPolicy != null) { fb.setSkipPolicy(skipPolicy); } + if (backOffPolicy != null) { + fb.setBackOffPolicy(backOffPolicy); + } + if (retryPolicy != null) { + fb.setRetryPolicy(retryPolicy); + } + if (retryContextCache != null) { + fb.setRetryContextCache(retryContextCache); + } + if (keyGenerator != null) { + fb.setKeyGenerator(keyGenerator); + } if (retryListeners != null) { fb.setRetryListeners(retryListeners); @@ -441,7 +465,8 @@ class StepParserStepFactoryBean implements FactoryBean, BeanNameAware { * * @param dependantName the name of the first field * @param dependantValue the value of the first field - * @param names the names of the other fields (used to construct an exception message) + * @param names the names of the other fields (used to construct an + * exception message) * @param values the other field values (one of which must be set if the * first field is) */ @@ -500,8 +525,8 @@ class StepParserStepFactoryBean implements FactoryBean, BeanNameAware { } private boolean isFaultTolerant() { - return skipPolicy != null || isPositive(skipLimit) || isPositive(retryLimit) || isPositive(cacheCapacity) - || isTrue(readerTransactionalQueue); + return backOffPolicy != null || skipPolicy != null || isPositive(skipLimit) || isPositive(retryLimit) + || isPositive(cacheCapacity) || isTrue(readerTransactionalQueue); } private boolean isTrue(Boolean b) { @@ -707,6 +732,47 @@ class StepParserStepFactoryBean implements FactoryBean, BeanNameAware { this.propagation = propagation; } + // ========================================================= + // Parent Attributes - can be provided in parent bean but not namespace + // ========================================================= + + /** + * A backoff policy to be applied to retry process. + * + * @param backOffPolicy the {@link BackOffPolicy} to set + */ + public void setBackOffPolicy(BackOffPolicy backOffPolicy) { + this.backOffPolicy = backOffPolicy; + } + + /** + * A retry policy to apply when exceptions occur. If this is specified then + * the retry limit and retryable exceptions will be ignored. + * + * @param retryPolicy the {@link RetryPolicy} to set + */ + public void setRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + } + + /** + * @param retryContextCache the {@link RetryContextCache} to set + */ + public void setRetryContextCache(RetryContextCache retryContextCache) { + this.retryContextCache = retryContextCache; + } + + /** + * A key generator that can be used to compare items with previously + * recorded items in a retry. Only used if the reader is a transactional + * queue. + * + * @param keyGenerator the {@link KeyGenerator} to set + */ + public void setKeyGenerator(KeyGenerator keyGenerator) { + this.keyGenerator = keyGenerator; + } + // ========================================================= // Chunk Attributes // ========================================================= diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests.java new file mode 100644 index 000000000..333aa6395 --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests.java @@ -0,0 +1,45 @@ +/* + * 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.core.configuration.xml; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.step.item.FaultTolerantChunkProcessor; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.test.util.ReflectionTestUtils; + +/** + * @author Dave Syer + * + */ +public class ParentStepFactoryBeanParserTests { + + @Test + public void testSimpleAttributes() throws Exception { + ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( + "org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-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); + } + +} diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml new file mode 100644 index 000000000..fef559552 --- /dev/null +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file