Merge closes #110 from willschipp/BATCH-1745

* BATCH-1745:
  BATCH-1745: Added test to verify restart behavior
  additional logic to support if already set by a tasklet - the step value is ignored
  test changes
  trial ignore
  renamed test and corresponding text context
  BATCH-1745 - removed excessive schema, added test and cleaned up schema mappings
  BATCH-1745 - added new spring-batch-2.2.xsd and schema pointers including new attributeGroup for "allow-start-if-complete" flag and appropriate parsers.
This commit is contained in:
Michael Minella
2013-01-22 13:18:04 -06:00
4 changed files with 164 additions and 7 deletions

View File

@@ -52,6 +52,8 @@ public abstract class AbstractStepParser {
private static final String PARENT_ATTR = "parent";
private static final String REF_ATTR = "ref";
private static final String ALLOW_START_ATTR = "allow-start-if-complete";
private static final String TASKLET_ELE = "tasklet";
@@ -176,6 +178,16 @@ public abstract class AbstractStepParser {
bd.setAttribute("jobParserJobFactoryBeanRef", jobFactoryRef);
}
//add the allow parser here
String isAllowStart = stepElement.getAttribute(ALLOW_START_ATTR);
if (StringUtils.hasText(isAllowStart)) {
//check if the value is already set from an inner element
if (!bd.getPropertyValues().contains("allowStartIfComplete")) {
//set the value as a property
bd.getPropertyValues().add("allowStartIfComplete", Boolean.valueOf(isAllowStart));
}//end if
}
stepListenerParser.handleListenersElement(stepElement, bd, parserContext);
return bd;
}

View File

@@ -286,6 +286,7 @@ ref" is not required, and only needs to be specified explicitly
<xsd:extension base="stepType">
<xsd:attribute name="id" type="xsd:ID" use="required" />
<xsd:attributeGroup ref="nextAttribute" />
<xsd:attributeGroup ref="allowStartIfCompleteAttribute" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -623,13 +624,6 @@ ref" is not required, and only needs to be specified explicitly
]]></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="transaction-manager" type="xsd:string">
<xsd:annotation>
<xsd:documentation source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
@@ -665,6 +659,7 @@ ref" is not required, and only needs to be specified explicitly
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attributeGroup ref="allowStartIfCompleteAttribute"/>
</xsd:complexType>
<xsd:complexType name="transaction-attributesType">
@@ -985,6 +980,16 @@ ref" is not required, and only needs to be specified explicitly
</xsd:attribute>
</xsd:attributeGroup>
<xsd:attributeGroup name="allowStartIfCompleteAttribute">
<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:attributeGroup>
<xsd:attributeGroup name="exceptionClassAttribute">
<xsd:attribute name="class" type="xsd:string" use="required">
<xsd:annotation>

View File

@@ -0,0 +1,84 @@
package org.springframework.batch.core.configuration.xml;
<<<<<<< HEAD
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.beans.factory.annotation.Autowired;
=======
import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.step.AbstractStep;
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
<<<<<<< HEAD
=======
//@Ignore
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class TaskletStepAllowStartIfCompleteTest {
<<<<<<< HEAD
@Autowired
Job job;
@Autowired
JobRepository jobRepository;
@Resource
private ApplicationContext context;
@Test
public void test() throws Exception {
//retrieve the step from the context and see that it's allow is set
AbstractStep abstractStep = (AbstractStep) context.getBean("simpleJob.step1");
assertTrue(abstractStep.isAllowStartIfComplete());
}
@Test
public void testRestart() throws Exception {
JobParametersBuilder paramBuilder = new JobParametersBuilder();
paramBuilder.addDate("value", new Date());
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), paramBuilder.toJobParameters());
job.execute(jobExecution);
jobExecution = jobRepository.createJobExecution(job.getName(), paramBuilder.toJobParameters());
job.execute(jobExecution);
int count = jobRepository.getStepExecutionCount(jobExecution.getJobInstance(), "simpleJob.step1");
assertEquals(2, count);
}
=======
@Resource
private ApplicationContext context;
@Test
public void test() throws Exception {
//retrieve the step from the context and see that it's allow is set
AbstractStep abstractStep = context.getBean(AbstractStep.class);
assertTrue(abstractStep.isAllowStartIfComplete());
}
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
}

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"/>
<batch:job id="simpleJob">
<<<<<<< HEAD
<batch:step id="simpleJob.step1" allow-start-if-complete="true" next="simpleJob.step2">
=======
<batch:step id="simpleJob.step1" allow-start-if-complete="true">
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
<batch:tasklet>
<bean class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
<property name="targetObject">
<bean class="java.lang.String">
<constructor-arg value="hello world"/>
</bean>
</property>
<property name="targetMethod" value="length"/>
</bean>
</batch:tasklet>
</batch:step>
<<<<<<< HEAD
<batch:step id="simpleJob.step2">
<batch:tasklet>
<bean class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
<property name="targetObject">
<bean class="java.lang.String" scope="step">
<constructor-arg value="#{jobParameters['value']}"/>
</bean>
</property>
<property name="targetMethod" value="length"/>
</bean>
</batch:tasklet>
</batch:step>
=======
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
</batch:job>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
<<<<<<< HEAD
=======
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
</beans>