BATCH-1005: added start-limit and allow-start-if-complete attributes to <tasklet>
This commit is contained in:
@@ -70,12 +70,12 @@ public class StepParser {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Element> processTaskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "tasklet");
|
||||
if (StringUtils.hasText(taskletRef)) {
|
||||
Object task = handleTaskletStep(element, taskletRef, parserContext);
|
||||
Object task = handleTaskletRef(element, taskletRef, parserContext);
|
||||
stateBuilder.addConstructorArgValue(stepRef);
|
||||
stateBuilder.addConstructorArgValue(task);
|
||||
}
|
||||
else if (processTaskElements.size() > 0) {
|
||||
Object task = handleChunkOrientedTaskletStep(element, processTaskElements.get(0), parserContext);
|
||||
Object task = handleTaskletElement(element, processTaskElements.get(0), parserContext);
|
||||
stateBuilder.addConstructorArgValue(stepRef);
|
||||
stateBuilder.addConstructorArgValue(task);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ public class StepParser {
|
||||
* @param parserContext
|
||||
* @return the TaskletStep bean
|
||||
*/
|
||||
protected RootBeanDefinition handleTaskletStep(Element stepElement, String taskletRef, ParserContext parserContext) {
|
||||
protected RootBeanDefinition handleTaskletRef(Element stepElement, String taskletRef, ParserContext parserContext) {
|
||||
|
||||
RootBeanDefinition bd = new RootBeanDefinition("org.springframework.batch.core.step.tasklet.TaskletStep", null, null);
|
||||
|
||||
@@ -229,7 +229,7 @@ public class StepParser {
|
||||
* @param parserContext
|
||||
* @return the TaskletStep bean
|
||||
*/
|
||||
protected RootBeanDefinition handleChunkOrientedTaskletStep(Element stepElement, Element element, ParserContext parserContext) {
|
||||
protected RootBeanDefinition handleTaskletElement(Element stepElement, Element element, ParserContext parserContext) {
|
||||
|
||||
RootBeanDefinition bd;
|
||||
|
||||
@@ -265,6 +265,15 @@ public class StepParser {
|
||||
}
|
||||
|
||||
// now, set the properties on the new bean
|
||||
String startLimit = element.getAttribute("start-limit");
|
||||
if (StringUtils.hasText(startLimit)) {
|
||||
bd.getPropertyValues().addPropertyValue("startLimit", startLimit);
|
||||
}
|
||||
String allowStartIfComplete = element.getAttribute("allow-start-if-complete");
|
||||
if (StringUtils.hasText(allowStartIfComplete)) {
|
||||
bd.getPropertyValues().addPropertyValue("allowStartIfComplete", allowStartIfComplete);
|
||||
}
|
||||
|
||||
String readerBeanId = element.getAttribute("reader");
|
||||
if (StringUtils.hasText(readerBeanId)) {
|
||||
RuntimeBeanReference readerRef = new RuntimeBeanReference(readerBeanId);
|
||||
|
||||
@@ -335,6 +335,20 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="start-limit" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The maximum number of times a Step may be started.†
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="allow-start-if-complete" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Set to true to allow a step to be started even if it is already complete.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="skip-limit" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
||||
@@ -16,10 +16,16 @@
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
|
||||
@@ -28,6 +34,18 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
*/
|
||||
public class StepParserTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testTaskletStepAttributes() throws Exception {
|
||||
ConfigurableApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext("org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml");
|
||||
Map<String, Object> beans = ctx.getBeansOfType(FaultTolerantStepFactoryBean.class);
|
||||
String factoryName = (String) beans.keySet().toArray()[0];
|
||||
FaultTolerantStepFactoryBean<Object, Object> factory = (FaultTolerantStepFactoryBean<Object, Object>) beans.get(factoryName);
|
||||
TaskletStep bean = (TaskletStep) factory.getObject();
|
||||
assertEquals("wrong start-limit:", 25, bean.getStartLimit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskletStepWithBadStepListener() throws Exception {
|
||||
loadContextWithBadListener("org/springframework/batch/core/configuration/xml/StepParserBadStepListenerTests-context.xml");
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<job id="job">
|
||||
<step name="step">
|
||||
<tasklet reader="reader" processor="processor" writer="writer"
|
||||
start-limit="25" allow-start-if-complete="true"
|
||||
commit-interval="10" skip-limit="20"
|
||||
retry-limit="3" cache-capacity="100"
|
||||
transaction-attribute="PROPAGATION_REQUIRED,ISOLATION_DEFAULT,timeout_10,-org.springframework.dao.DataIntegrityViolationException"
|
||||
is-reader-transactional-queue="true"
|
||||
task-executor="taskExecutor">
|
||||
<retry-listeners>
|
||||
<listener class="org.springframework.batch.core.configuration.xml.TestRetryListener"/>
|
||||
</retry-listeners>
|
||||
<streams>
|
||||
<stream ref="reader"/>
|
||||
</streams>
|
||||
<fatal-exception-classes>
|
||||
org.springframework.jdbc.BadSqlGrammarException
|
||||
</fatal-exception-classes>
|
||||
<skippable-exception-classes>
|
||||
org.springframework.dao.DataIntegrityViolationException
|
||||
</skippable-exception-classes>
|
||||
</tasklet>
|
||||
<listeners>
|
||||
<listener ref="listener"/>
|
||||
</listeners>
|
||||
</step>
|
||||
</job>
|
||||
|
||||
<beans:bean id="reader" class="org.springframework.batch.core.configuration.xml.TestReader"/>
|
||||
|
||||
<beans:bean id="processor" class="org.springframework.batch.core.configuration.xml.TestProcessor"/>
|
||||
|
||||
<beans:bean id="writer" class="org.springframework.batch.core.configuration.xml.TestWriter"/>
|
||||
|
||||
<beans:bean id="listener" class="org.springframework.batch.core.configuration.xml.TestListener"/>
|
||||
|
||||
<beans:bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ConcurrentTaskExecutor"/>
|
||||
|
||||
<beans:bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
|
||||
|
||||
<beans:bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
|
||||
<beans:property name="transactionManager" ref="transactionManager" />
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user