Skip to content

Commit 21555c0

Browse files
Robert McNeesfmbenhassine
Robert McNees
authored andcommitted
Updated documentation and added unit tests for flow builder priority
Fixes #4456
1 parent 0d1d89c commit 21555c0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/DefaultStateTransitionComparator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.Comparator;
2121

2222
/**
23-
* Sorts by decreasing specificity of pattern, based on just counting wildcards (with *
23+
* Sorts by ascending specificity of pattern, based on just counting wildcards (with *
2424
* taking precedence over ?). If wildcard counts are equal then falls back to alphabetic
2525
* comparison. Hence * > foo* > ??? > fo? > foo.
2626
*

spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java

+30
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,36 @@ public FlowExecutionStatus decide(JobExecution jobExecution, @Nullable StepExecu
262262
assertEquals(1, execution.getStepExecutions().size());
263263
}
264264

265+
@Test
266+
void testBuildWithDeciderPriority() {
267+
JobExecutionDecider decider = (jobExecution, stepExecution) -> new FlowExecutionStatus("COMPLETED_PARTIALLY");
268+
JobFlowBuilder builder = new JobBuilder("flow_priority", jobRepository).start(decider);
269+
builder.on("COMPLETED_PARTIALLY").end();
270+
builder.on("COMPLETED*").fail();
271+
builder.build().preventRestart().build().execute(execution);
272+
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
273+
}
274+
275+
@Test
276+
void testBuildWithWildcardDeciderPriority() {
277+
JobExecutionDecider decider = (jobExecution, stepExecution) -> new FlowExecutionStatus("COMPLETED_PARTIALLY");
278+
JobFlowBuilder builder = new JobBuilder("flow_priority", jobRepository).start(decider);
279+
builder.on("COMPLETED_?ARTIALLY").end();
280+
builder.on("COMPLETED_*ARTIALLY").fail();
281+
builder.build().preventRestart().build().execute(execution);
282+
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
283+
}
284+
285+
@Test
286+
void testBuildWithDeciderPrioritySubstringAndWildcard() {
287+
JobExecutionDecider decider = (jobExecution, stepExecution) -> new FlowExecutionStatus("CONTINUABLE");
288+
JobFlowBuilder builder = new JobBuilder("flow_priority", jobRepository).start(decider);
289+
builder.on("CONTINUABLE").end();
290+
builder.on("CONTIN*").fail();
291+
builder.build().preventRestart().build().execute(execution);
292+
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
293+
}
294+
265295
@Test
266296
void testBuildWithIntermediateSimpleJob() {
267297
SimpleJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1);

0 commit comments

Comments
 (0)