Add failed transition if none exists when next attribute is used.

Fixes TCK test testStartLimitVariation1
This commit is contained in:
Chris Schaefer
2014-01-12 13:45:15 -05:00
parent b0c9af5e8e
commit ea7a704299
4 changed files with 82 additions and 0 deletions

View File

@@ -148,10 +148,13 @@ public class FlowParser extends AbstractFlowParser {
Collection<BeanDefinition> list = new ArrayList<BeanDefinition>();
boolean transitionElementExists = false;
boolean failedTransitionElementExists = false;
List<Element> childElements = DomUtils.getChildElements(element);
for(Element childElement : childElements) {
if(isChildElementTransitionElement(childElement)) {
list.addAll(parseTransitionElement(childElement, stepId, stateDef, parserContext));
failedTransitionElementExists = failedTransitionElementExists || hasFailedTransitionElement(childElement);
transitionElementExists = true;
}
}
@@ -171,6 +174,11 @@ public class FlowParser extends AbstractFlowParser {
}
if (hasNextAttribute) {
if (transitionElementExists && !failedTransitionElementExists) {
list.addAll(createTransition(FlowExecutionStatus.FAILED, FlowExecutionStatus.FAILED.getName(), null, null,
stateDef, parserContext, false));
}
list.add(getStateTransitionReference(parserContext, stateDef, null, shortNextAttribute));
}
@@ -181,6 +189,10 @@ public class FlowParser extends AbstractFlowParser {
return TRANSITION_TYPES.contains(childElement.getLocalName());
}
private static boolean hasFailedTransitionElement(Element childName) {
return FAIL_ELE.equals(childName.getLocalName());
}
protected static Collection<BeanDefinition> parseTransitionElement(Element transitionElement, String stateId,
BeanDefinition stateDef, ParserContext parserContext) {
FlowExecutionStatus status = getBatchStatusFromEndTransitionName(transitionElement.getNodeName());

View File

@@ -64,6 +64,32 @@ public class FlowParserTests {
assertTrue("step1".equals(failedStep.getStepName()));
}
@Test
public void testStepGetsFailedTransitionWhenNextAttributePresent() throws Exception {
JobExecution jobExecution = runJob("FlowParserTestsStepGetsFailedTransitionWhenNextAttributePresent", new Properties(), 10000l);
assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus());
JobOperator jobOperator = BatchRuntime.getJobOperator();
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(jobExecution.getExecutionId());
assertEquals(1, stepExecutions.size());
StepExecution failedStep = stepExecutions.get(0);
assertTrue("failedExitStatusStep".equals(failedStep.getStepName()));
assertTrue("FAILED".equals(failedStep.getExitStatus()));
}
@Test
public void testStepNoOverrideWhenNextAndFailedTransitionElementExists() throws Exception {
JobExecution jobExecution = runJob("FlowParserTestsStepNoOverrideWhenNextAndFailedTransitionElementExists", new Properties(), 10000l);
assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus());
JobOperator jobOperator = BatchRuntime.getJobOperator();
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(jobExecution.getExecutionId());
assertEquals(1, stepExecutions.size());
StepExecution failedStep = stepExecutions.get(0);
assertTrue("failedExitStatusStepDontOverride".equals(failedStep.getStepName()));
assertTrue("CUSTOM_FAIL".equals(failedStep.getExitStatus()));
}
public static class TestBatchlet extends AbstractBatchlet {
private static int CNT;
@@ -79,6 +105,14 @@ public class FlowParserTests {
CNT++;
}
if("failedExitStatusStep".equals(stepContext.getStepName())) {
exitCode = "FAILED";
}
if("failedExitStatusStepDontOverride".equals(stepContext.getStepName())) {
exitCode = "CUSTOM_FAIL";
}
return exitCode;
}
}

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd">
<job id="job" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
<step id="failedExitStatusStep" next="step2">
<batchlet ref="testBatchlet"/>
<stop on="unused"/>
</step>
<step id="step2">
<batchlet ref="testBatchlet"/>
</step>
</job>
<bean id="testBatchlet" class="org.springframework.batch.core.jsr.configuration.xml.FlowParserTests$TestBatchlet"/>
</beans>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd">
<job id="job" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
<step id="failedExitStatusStepDontOverride" next="step2">
<batchlet ref="testBatchlet"/>
<fail on="CUSTOM_FAIL"/>
</step>
<step id="step2">
<batchlet ref="testBatchlet"/>
</step>
</job>
<bean id="testBatchlet" class="org.springframework.batch.core.jsr.configuration.xml.FlowParserTests$TestBatchlet"/>
</beans>