Skip to content

Commit bd00cde

Browse files
hpoettkerfmbenhassine
authored andcommitted
Fix parsing of the stop element in step XML
Previously, users were forced to set the attribute `exit-code` of the element to `""` as a work-around to prevent failing restarts. Resolves #1287
1 parent 09df30f commit bd00cde

13 files changed

+97
-23
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -414,8 +414,7 @@ protected static Collection<BeanDefinition> createTransition(FlowExecutionStatus
414414

415415
endBuilder.addConstructorArgValue(abandon);
416416

417-
String nextOnEnd = exitCodeExists ? null : next;
418-
endState = getStateTransitionReference(parserContext, endBuilder.getBeanDefinition(), null, nextOnEnd);
417+
endState = getStateTransitionReference(parserContext, endBuilder.getBeanDefinition(), null, next);
419418
next = endName;
420419

421420
}

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StopAndRestartFailedJobParserTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,8 +33,6 @@
3333
*
3434
*/
3535
@SpringJUnitConfig
36-
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
37-
// https://github.com/spring-projects/spring-batch/issues/1287
3836
class StopAndRestartFailedJobParserTests extends AbstractJobParserTests {
3937

4038
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StopAndRestartJobParserTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,6 @@
2929
*
3030
*/
3131
@SpringJUnitConfig
32-
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
33-
// https://github.com/spring-projects/spring-batch/issues/1287
3432
class StopAndRestartJobParserTests extends AbstractJobParserTests {
3533

3634
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.batch.core.configuration.xml;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.springframework.batch.core.BatchStatus;
20+
import org.springframework.batch.core.ExitStatus;
21+
import org.springframework.batch.core.JobExecution;
22+
import org.springframework.batch.core.StepExecution;
23+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
24+
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
27+
/**
28+
* @author Henning Pöttker
29+
*/
30+
@SpringJUnitConfig
31+
class StopAndRestartWithCustomExitCodeJobParserTests extends AbstractJobParserTests {
32+
33+
@Test
34+
void testStopIncomplete() throws Exception {
35+
36+
//
37+
// First Launch
38+
//
39+
JobExecution jobExecution = createJobExecution();
40+
job.execute(jobExecution);
41+
assertEquals(1, stepNamesList.size());
42+
assertEquals("[s1]", stepNamesList.toString());
43+
44+
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
45+
assertEquals("CUSTOM", jobExecution.getExitStatus().getExitCode());
46+
47+
StepExecution stepExecution1 = getStepExecution(jobExecution, "s1");
48+
assertEquals(BatchStatus.COMPLETED, stepExecution1.getStatus());
49+
assertEquals(ExitStatus.COMPLETED.getExitCode(), stepExecution1.getExitStatus().getExitCode());
50+
51+
//
52+
// Second Launch
53+
//
54+
stepNamesList.clear();
55+
jobExecution = createJobExecution();
56+
job.execute(jobExecution);
57+
assertEquals(1, stepNamesList.size()); // step1 is not executed
58+
assertEquals("[s2]", stepNamesList.toString());
59+
60+
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
61+
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
62+
63+
StepExecution stepExecution2 = getStepExecution(jobExecution, "s2");
64+
assertEquals(BatchStatus.COMPLETED, stepExecution2.getStatus());
65+
assertEquals(ExitStatus.COMPLETED, stepExecution2.getExitStatus());
66+
67+
}
68+
69+
}

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StopCustomStatusJobParserTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,6 @@
2929
*
3030
*/
3131
@SpringJUnitConfig
32-
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
33-
// https://github.com/spring-projects/spring-batch/issues/1287
3432
class StopCustomStatusJobParserTests extends AbstractJobParserTests {
3533

3634
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StopIncompleteJobParserTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,6 @@
2929
*
3030
*/
3131
@SpringJUnitConfig
32-
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
33-
// https://github.com/spring-projects/spring-batch/issues/1287
3432
class StopIncompleteJobParserTests extends AbstractJobParserTests {
3533

3634
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StopJobParserTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,8 +34,6 @@
3434
*
3535
*/
3636
@SpringJUnitConfig
37-
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
38-
// https://github.com/spring-projects/spring-batch/issues/1287
3937
class StopJobParserTests extends AbstractJobParserTests {
4038

4139
@Test

spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StopAndRestartFailedJobParserTests-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:p="http://www.springframework.org/schema/p"
5-
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
5+
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
66
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
77

88
<import resource="common-context.xml" />

spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StopAndRestartJobParserTests-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
4+
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
55
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
66

77
<beans:import resource="common-context.xml" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
5+
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
6+
7+
<beans:import resource="common-context.xml" />
8+
9+
<job id="job">
10+
<step id="s1" parent="step1">
11+
<stop on="*" restart="s2" exit-code="CUSTOM"/>
12+
</step>
13+
<step id="s2" parent="step2"/>
14+
</job>
15+
16+
</beans:beans>

spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StopCustomStatusJobParserTests-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans:beans xmlns="http://www.springframework.org/schema/batch"
33
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
4+
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
55
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
66

77
<beans:import resource="common-context.xml" />

spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StopIncompleteJobParserTests-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
4+
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
55
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
66

77
<beans:import resource="common-context.xml" />

spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StopJobParserTests-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
4+
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
55
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
66

77
<beans:import resource="common-context.xml" />

0 commit comments

Comments
 (0)