Skip to content

Commit

Permalink
Fix parsing of the stop element in step XML
Browse files Browse the repository at this point in the history
Previously, users were forced to set the attribute
`exit-code` of the element to `""` as a work-around
to prevent failing restarts.

Resolves #1287
  • Loading branch information
hpoettker authored and fmbenhassine committed Dec 6, 2024
1 parent 09df30f commit bd00cde
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2023 the original author or authors.
* Copyright 2006-2024 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.
Expand Down Expand Up @@ -414,8 +414,7 @@ protected static Collection<BeanDefinition> createTransition(FlowExecutionStatus

endBuilder.addConstructorArgValue(abandon);

String nextOnEnd = exitCodeExists ? null : next;
endState = getStateTransitionReference(parserContext, endBuilder.getBeanDefinition(), null, nextOnEnd);
endState = getStateTransitionReference(parserContext, endBuilder.getBeanDefinition(), null, next);
next = endName;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2024 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.
Expand Down Expand Up @@ -33,8 +33,6 @@
*
*/
@SpringJUnitConfig
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
// https://github.com/spring-projects/spring-batch/issues/1287
class StopAndRestartFailedJobParserTests extends AbstractJobParserTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2024 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.
Expand Down Expand Up @@ -29,8 +29,6 @@
*
*/
@SpringJUnitConfig
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
// https://github.com/spring-projects/spring-batch/issues/1287
class StopAndRestartJobParserTests extends AbstractJobParserTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2024 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
*
* https://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 org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Henning Pöttker
*/
@SpringJUnitConfig
class StopAndRestartWithCustomExitCodeJobParserTests extends AbstractJobParserTests {

@Test
void testStopIncomplete() throws Exception {

//
// First Launch
//
JobExecution jobExecution = createJobExecution();
job.execute(jobExecution);
assertEquals(1, stepNamesList.size());
assertEquals("[s1]", stepNamesList.toString());

assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
assertEquals("CUSTOM", jobExecution.getExitStatus().getExitCode());

StepExecution stepExecution1 = getStepExecution(jobExecution, "s1");
assertEquals(BatchStatus.COMPLETED, stepExecution1.getStatus());
assertEquals(ExitStatus.COMPLETED.getExitCode(), stepExecution1.getExitStatus().getExitCode());

//
// Second Launch
//
stepNamesList.clear();
jobExecution = createJobExecution();
job.execute(jobExecution);
assertEquals(1, stepNamesList.size()); // step1 is not executed
assertEquals("[s2]", stepNamesList.toString());

assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());

StepExecution stepExecution2 = getStepExecution(jobExecution, "s2");
assertEquals(BatchStatus.COMPLETED, stepExecution2.getStatus());
assertEquals(ExitStatus.COMPLETED, stepExecution2.getExitStatus());

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2024 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.
Expand Down Expand Up @@ -29,8 +29,6 @@
*
*/
@SpringJUnitConfig
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
// https://github.com/spring-projects/spring-batch/issues/1287
class StopCustomStatusJobParserTests extends AbstractJobParserTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2024 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.
Expand Down Expand Up @@ -29,8 +29,6 @@
*
*/
@SpringJUnitConfig
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
// https://github.com/spring-projects/spring-batch/issues/1287
class StopIncompleteJobParserTests extends AbstractJobParserTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2024 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.
Expand Down Expand Up @@ -34,8 +34,6 @@
*
*/
@SpringJUnitConfig
// FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0:
// https://github.com/spring-projects/spring-batch/issues/1287
class StopJobParserTests extends AbstractJobParserTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

<import resource="common-context.xml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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 https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

<beans:import resource="common-context.xml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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 https://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

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

<job id="job">
<step id="s1" parent="step1">
<stop on="*" restart="s2" exit-code="CUSTOM"/>
</step>
<step id="s2" parent="step2"/>
</job>

</beans:beans>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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 https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

<beans:import resource="common-context.xml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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 https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

<beans:import resource="common-context.xml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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 https://www.springframework.org/schema/batch/spring-batch-2.2.xsd
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

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

0 comments on commit bd00cde

Please sign in to comment.