2121
2222import javax .sql .DataSource ;
2323
24+ import org .junit .jupiter .api .Disabled ;
2425import org .junit .jupiter .api .Test ;
2526
2627import org .springframework .batch .core .configuration .annotation .EnableBatchProcessing ;
@@ -82,18 +83,20 @@ void basicExecution() {
8283 }
8384
8485 @ Test
86+ @ Disabled
8587 void incrementExistingExecution () {
8688 this .contextRunner .run ((context ) -> {
8789 JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
8890 Job job = jobLauncherContext .configureJob ().incrementer (new RunIdIncrementer ()).build ();
89- jobLauncherContext .runner .execute (job , new JobParameters ());
90- jobLauncherContext .runner .execute (job , new JobParameters ());
91+ JobParameters jobParameters = new JobParametersBuilder ().addString ("name" , "foo" ).toJobParameters ();
92+ jobLauncherContext .runner .execute (job , jobParameters );
93+ jobLauncherContext .runner .execute (job , jobParameters );
9194 assertThat (jobLauncherContext .jobInstances ()).hasSize (2 );
9295 });
9396 }
9497
9598 @ Test
96- void retryFailedExecution () {
99+ void retryFailedExecutionWithIncrementer () {
97100 this .contextRunner .run ((context ) -> {
98101 PlatformTransactionManager transactionManager = context .getBean (PlatformTransactionManager .class );
99102 JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
@@ -102,7 +105,23 @@ void retryFailedExecution() {
102105 .incrementer (new RunIdIncrementer ())
103106 .build ();
104107 jobLauncherContext .runner .execute (job , new JobParameters ());
105- jobLauncherContext .runner .execute (job , new JobParametersBuilder ().addLong ("run.id" , 1L ).toJobParameters ());
108+ jobLauncherContext .runner .execute (job , new JobParameters ());
109+ // with an incrementer, we always create a new job instance
110+ assertThat (jobLauncherContext .jobInstances ()).hasSize (2 );
111+ });
112+ }
113+
114+ @ Test
115+ void retryFailedExecutionWithoutIncrementer () {
116+ this .contextRunner .run ((context ) -> {
117+ PlatformTransactionManager transactionManager = context .getBean (PlatformTransactionManager .class );
118+ JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
119+ Job job = jobLauncherContext .jobBuilder ()
120+ .start (jobLauncherContext .stepBuilder ().tasklet (throwingTasklet (), transactionManager ).build ())
121+ .build ();
122+ JobParameters jobParameters = new JobParametersBuilder ().addLong ("run.id" , 1L ).toJobParameters ();
123+ jobLauncherContext .runner .execute (job , jobParameters );
124+ jobLauncherContext .runner .execute (job , jobParameters );
106125 assertThat (jobLauncherContext .jobInstances ()).hasSize (1 );
107126 });
108127 }
@@ -134,17 +153,13 @@ void retryFailedExecutionOnNonRestartableJob() {
134153 Job job = jobLauncherContext .jobBuilder ()
135154 .preventRestart ()
136155 .start (jobLauncherContext .stepBuilder ().tasklet (throwingTasklet (), transactionManager ).build ())
137- .incrementer (new RunIdIncrementer ())
138156 .build ();
139- jobLauncherContext .runner .execute (job , new JobParameters ());
140- jobLauncherContext .runner .execute (job , new JobParameters ());
141- // A failed job that is not restartable does not re-use the job params of
142- // the last execution, but creates a new job instance when running it again.
143- assertThat (jobLauncherContext .jobInstances ()).hasSize (2 );
157+ JobParameters jobParameters = new JobParametersBuilder ().addString ("name" , "foo" ).toJobParameters ();
158+ jobLauncherContext .runner .execute (job , jobParameters );
159+ assertThat (jobLauncherContext .jobInstances ()).hasSize (1 );
144160 assertThatExceptionOfType (JobRestartException .class ).isThrownBy (() -> {
145161 // try to re-run a failed execution
146- jobLauncherContext .runner .execute (job ,
147- new JobParametersBuilder ().addLong ("run.id" , 1L ).toJobParameters ());
162+ jobLauncherContext .runner .execute (job , jobParameters );
148163 fail ("expected JobRestartException" );
149164 }).withMessageContaining ("JobInstance already exists and is not restartable" );
150165 });
@@ -157,9 +172,8 @@ void retryFailedExecutionWithNonIdentifyingParameters() {
157172 JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
158173 Job job = jobLauncherContext .jobBuilder ()
159174 .start (jobLauncherContext .stepBuilder ().tasklet (throwingTasklet (), transactionManager ).build ())
160- .incrementer (new RunIdIncrementer ())
161175 .build ();
162- JobParameters jobParameters = new JobParametersBuilder ().addLong ("id" , 1L , false )
176+ JobParameters jobParameters = new JobParametersBuilder ().addLong ("run. id" , 1L , true )
163177 .addLong ("foo" , 2L , false )
164178 .toJobParameters ();
165179 jobLauncherContext .runner .execute (job , jobParameters );
@@ -200,7 +214,7 @@ static class JobLauncherApplicationRunnerContext {
200214 this .jobBuilder = new JobBuilder ("job" , jobRepository );
201215 this .job = this .jobBuilder .start (this .step ).build ();
202216 this .jobRepository = context .getBean (JobRepository .class );
203- this .runner = new JobLauncherApplicationRunner (jobOperator , jobRepository );
217+ this .runner = new JobLauncherApplicationRunner (jobOperator );
204218 }
205219
206220 List <JobInstance > jobInstances () {
0 commit comments