|
15 | 15 | */ |
16 | 16 | package org.springframework.batch.core.job.builder; |
17 | 17 |
|
18 | | -import java.util.Arrays; |
19 | | - |
20 | | -import javax.sql.DataSource; |
21 | | - |
22 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
23 | | - |
24 | 18 | import org.junit.jupiter.api.BeforeEach; |
25 | 19 | import org.junit.jupiter.api.Test; |
26 | | -import org.springframework.batch.core.BatchStatus; |
27 | | -import org.springframework.batch.core.ExitStatus; |
28 | | -import org.springframework.batch.core.Job; |
29 | | -import org.springframework.batch.core.JobExecution; |
30 | | -import org.springframework.batch.core.JobInterruptedException; |
31 | | -import org.springframework.batch.core.JobParameters; |
32 | | -import org.springframework.batch.core.JobParametersBuilder; |
33 | | -import org.springframework.batch.core.Step; |
34 | | -import org.springframework.batch.core.StepExecution; |
35 | | -import org.springframework.batch.core.UnexpectedJobExecutionException; |
| 20 | +import org.springframework.batch.core.*; |
36 | 21 | import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; |
37 | 22 | import org.springframework.batch.core.configuration.annotation.JobScope; |
38 | 23 | import org.springframework.batch.core.job.flow.Flow; |
|
51 | 36 | import org.springframework.context.annotation.Bean; |
52 | 37 | import org.springframework.context.annotation.Configuration; |
53 | 38 | import org.springframework.core.task.SimpleAsyncTaskExecutor; |
54 | | -import org.springframework.jdbc.support.JdbcTransactionManager; |
55 | 39 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; |
56 | 40 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
| 41 | +import org.springframework.jdbc.support.JdbcTransactionManager; |
57 | 42 | import org.springframework.lang.Nullable; |
58 | 43 | import org.springframework.transaction.PlatformTransactionManager; |
59 | 44 |
|
| 45 | +import javax.sql.DataSource; |
| 46 | +import java.util.Arrays; |
| 47 | + |
| 48 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 49 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 50 | + |
60 | 51 | /** |
61 | 52 | * @author Dave Syer |
62 | 53 | * @author Mahmoud Ben Hassine |
@@ -262,26 +253,6 @@ public FlowExecutionStatus decide(JobExecution jobExecution, @Nullable StepExecu |
262 | 253 | assertEquals(1, execution.getStepExecutions().size()); |
263 | 254 | } |
264 | 255 |
|
265 | | - @Test |
266 | | - void testBuildWithDeciderPriorityOnWildcardCount() { |
267 | | - JobExecutionDecider decider = (jobExecution, stepExecution) -> new FlowExecutionStatus("COMPLETED_PARTIALLY"); |
268 | | - JobFlowBuilder builder = new JobBuilder("flow_priority", jobRepository).start(decider); |
269 | | - builder.on("**").end(); |
270 | | - builder.on("*").fail(); |
271 | | - builder.build().preventRestart().build().execute(execution); |
272 | | - assertEquals(BatchStatus.COMPLETED, execution.getStatus()); |
273 | | - } |
274 | | - |
275 | | - @Test |
276 | | - void testBuildWithDeciderPriorityWithEqualWildcard() { |
277 | | - JobExecutionDecider decider = (jobExecution, stepExecution) -> new FlowExecutionStatus("COMPLETED_PARTIALLY"); |
278 | | - JobFlowBuilder builder = new JobBuilder("flow_priority", jobRepository).start(decider); |
279 | | - builder.on("COMPLETED*").end(); |
280 | | - builder.on("*").fail(); |
281 | | - builder.build().preventRestart().build().execute(execution); |
282 | | - assertEquals(BatchStatus.COMPLETED, execution.getStatus()); |
283 | | - } |
284 | | - |
285 | 256 | @Test |
286 | 257 | void testBuildWithDeciderPriority() { |
287 | 258 | JobExecutionDecider decider = (jobExecution, stepExecution) -> new FlowExecutionStatus("COMPLETED_PARTIALLY"); |
@@ -383,6 +354,41 @@ void testBuildWithJobScopedStep() throws Exception { |
383 | 354 | assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); |
384 | 355 | } |
385 | 356 |
|
| 357 | + //https://github.com/spring-projects/spring-batch/issues/3757#issuecomment-1821593539 |
| 358 | + @Test |
| 359 | + void testStepNamesMustBeUniqueWithinFlowDefinition() { |
| 360 | + Step conditionalStep = new StepSupport("conditionalStep") { |
| 361 | + @Override |
| 362 | + public void execute(StepExecution stepExecution) { |
| 363 | + stepExecution.upgradeStatus(BatchStatus.COMPLETED); |
| 364 | + stepExecution.setExitStatus(ExitStatus.COMPLETED); |
| 365 | + String exitStatus = (System.currentTimeMillis() % 2 == 0) ? "EVEN" : "ODD"; |
| 366 | + stepExecution.setExitStatus(new ExitStatus(exitStatus)); |
| 367 | + jobRepository.update(stepExecution); |
| 368 | + } |
| 369 | + }; |
| 370 | + |
| 371 | + StepSupport misnamedStep = new StepSupport(step3Name) { |
| 372 | + @Override |
| 373 | + public void execute(StepExecution stepExecution) |
| 374 | + throws UnexpectedJobExecutionException { |
| 375 | + |
| 376 | + stepExecution.upgradeStatus(BatchStatus.COMPLETED); |
| 377 | + stepExecution.setExitStatus(ExitStatus.COMPLETED); |
| 378 | + jobRepository.update(stepExecution); |
| 379 | + } |
| 380 | + }; |
| 381 | + |
| 382 | + JobBuilder jobBuilder = new JobBuilder("flow", jobRepository); |
| 383 | + FlowBuilder<FlowJobBuilder> flowBuilder = jobBuilder.start(conditionalStep) |
| 384 | + .on("ODD").to(step2) |
| 385 | + .from(conditionalStep).on("EVEN").to(step3) |
| 386 | + .from(step3); |
| 387 | + assertThrows(AlreadyUsedStepNameException.class, () -> flowBuilder.next(misnamedStep)); |
| 388 | + flowBuilder.end().build(); |
| 389 | + } |
| 390 | + |
| 391 | + |
386 | 392 | @EnableBatchProcessing |
387 | 393 | @Configuration |
388 | 394 | static class JobConfiguration { |
|
0 commit comments