2121
2222import javax .sql .DataSource ;
2323
24- import org .junit .jupiter .api .Disabled ;
2524import org .junit .jupiter .api .Test ;
2625
2726import org .springframework .batch .core .configuration .annotation .EnableBatchProcessing ;
2827import org .springframework .batch .core .configuration .annotation .EnableJdbcJobRepository ;
2928import org .springframework .batch .core .job .Job ;
3029import org .springframework .batch .core .job .JobExecutionException ;
3130import org .springframework .batch .core .job .JobInstance ;
32- import org .springframework .batch .core .job .UnexpectedJobExecutionException ;
3331import org .springframework .batch .core .job .builder .JobBuilder ;
3432import org .springframework .batch .core .job .builder .SimpleJobBuilder ;
3533import org .springframework .batch .core .job .parameters .JobParameters ;
5553import org .springframework .transaction .PlatformTransactionManager ;
5654
5755import static org .assertj .core .api .Assertions .assertThat ;
58- import static org .assertj .core .api .Assertions . assertThatThrownBy ;
56+ import static org .assertj .core .api .AssertionsForClassTypes . assertThatExceptionOfType ;
5957
6058/**
6159 * @author Glenn Renfro
@@ -78,7 +76,6 @@ void basicExecution() {
7876 });
7977 }
8078
81- @ Disabled ("Disabled until Spring Batch allows a incrementer to set identifyable to true." )
8279 @ Test
8380 void incrementExistingExecution () {
8481 this .contextRunner .run ((context ) -> {
@@ -122,10 +119,18 @@ void retryFailedExecutionOnNonRestartableJob() {
122119 .incrementer (new RunIdIncrementer ())
123120 .build ();
124121 runFailedJob (jobLauncherContext , job , new JobParameters ());
125- assertThatThrownBy (() -> runFailedJob (jobLauncherContext , job , new JobParameters ()))
126- .isInstanceOf (UnexpectedJobExecutionException .class )
127- .hasMessageContaining (
128- "Illegal state (only happens on a race condition): job not restartable with name=job and parameters=" );
122+
123+ // A failed job that is not restartable does not re-use the job params of
124+ // the last execution, but creates a new job instance when running it again.
125+ assertThat (jobLauncherContext .jobInstances ()).hasSize (1 );
126+ assertThatExceptionOfType (TaskException .class ).isThrownBy (() -> {
127+ // try to re-run a failed execution
128+ // In this case the change from the previous behavior is that a new job
129+ // instance is created
130+ // https://github.com/spring-projects/spring-batch/issues/4910
131+ jobLauncherContext .runner .execute (job ,
132+ new JobParametersBuilder ().addLong ("run.id" , 1L ).toJobParameters ());
133+ }).withMessageContaining ("Job job failed during execution for job instance id 2 with jobExecutionId of 2 " );
129134 });
130135 }
131136
@@ -148,7 +153,7 @@ void retryFailedExecutionWithNonIdentifyingParameters() {
148153 // https://github.com/spring-projects/spring-batch/issues/4910
149154 runFailedJob (jobLauncherContext , job ,
150155 new JobParametersBuilder (jobParameters ).addLong ("run.id" , 1L ).toJobParameters ());
151- assertThat (jobLauncherContext .jobInstances ()).hasSize (1 );
156+ assertThat (jobLauncherContext .jobInstances ()).hasSize (2 );
152157 });
153158 }
154159
0 commit comments