@@ -86,14 +86,15 @@ void incrementExistingExecution() {
86
86
this .contextRunner .run ((context ) -> {
87
87
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
88
88
Job job = jobLauncherContext .configureJob ().incrementer (new RunIdIncrementer ()).build ();
89
- jobLauncherContext .runner .execute (job , new JobParameters ());
90
- jobLauncherContext .runner .execute (job , new JobParameters ());
89
+ JobParameters jobParameters = new JobParametersBuilder ().addString ("name" , "foo" ).toJobParameters ();
90
+ jobLauncherContext .runner .execute (job , jobParameters );
91
+ jobLauncherContext .runner .execute (job , jobParameters );
91
92
assertThat (jobLauncherContext .jobInstances ()).hasSize (2 );
92
93
});
93
94
}
94
95
95
96
@ Test
96
- void retryFailedExecution () {
97
+ void retryFailedExecutionWithIncrementer () {
97
98
this .contextRunner .run ((context ) -> {
98
99
PlatformTransactionManager transactionManager = context .getBean (PlatformTransactionManager .class );
99
100
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
@@ -102,7 +103,23 @@ void retryFailedExecution() {
102
103
.incrementer (new RunIdIncrementer ())
103
104
.build ();
104
105
jobLauncherContext .runner .execute (job , new JobParameters ());
105
- jobLauncherContext .runner .execute (job , new JobParametersBuilder ().addLong ("run.id" , 1L ).toJobParameters ());
106
+ jobLauncherContext .runner .execute (job , new JobParameters ());
107
+ // with an incrementer, we always create a new job instance
108
+ assertThat (jobLauncherContext .jobInstances ()).hasSize (2 );
109
+ });
110
+ }
111
+
112
+ @ Test
113
+ void retryFailedExecutionWithoutIncrementer () {
114
+ this .contextRunner .run ((context ) -> {
115
+ PlatformTransactionManager transactionManager = context .getBean (PlatformTransactionManager .class );
116
+ JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
117
+ Job job = jobLauncherContext .jobBuilder ()
118
+ .start (jobLauncherContext .stepBuilder ().tasklet (throwingTasklet (), transactionManager ).build ())
119
+ .build ();
120
+ JobParameters jobParameters = new JobParametersBuilder ().addLong ("run.id" , 1L ).toJobParameters ();
121
+ jobLauncherContext .runner .execute (job , jobParameters );
122
+ jobLauncherContext .runner .execute (job , jobParameters );
106
123
assertThat (jobLauncherContext .jobInstances ()).hasSize (1 );
107
124
});
108
125
}
@@ -134,17 +151,14 @@ void retryFailedExecutionOnNonRestartableJob() {
134
151
Job job = jobLauncherContext .jobBuilder ()
135
152
.preventRestart ()
136
153
.start (jobLauncherContext .stepBuilder ().tasklet (throwingTasklet (), transactionManager ).build ())
137
- .incrementer (new RunIdIncrementer ())
138
154
.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 );
155
+ JobParameters jobParameters = new JobParametersBuilder ()
156
+ .addString ("name" , "foo" ).toJobParameters ();
157
+ jobLauncherContext .runner .execute (job , jobParameters );
158
+ assertThat (jobLauncherContext .jobInstances ()).hasSize (1 );
144
159
assertThatExceptionOfType (JobRestartException .class ).isThrownBy (() -> {
145
160
// try to re-run a failed execution
146
- jobLauncherContext .runner .execute (job ,
147
- new JobParametersBuilder ().addLong ("run.id" , 1L ).toJobParameters ());
161
+ jobLauncherContext .runner .execute (job , jobParameters );
148
162
fail ("expected JobRestartException" );
149
163
}).withMessageContaining ("JobInstance already exists and is not restartable" );
150
164
});
@@ -157,9 +171,8 @@ void retryFailedExecutionWithNonIdentifyingParameters() {
157
171
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
158
172
Job job = jobLauncherContext .jobBuilder ()
159
173
.start (jobLauncherContext .stepBuilder ().tasklet (throwingTasklet (), transactionManager ).build ())
160
- .incrementer (new RunIdIncrementer ())
161
174
.build ();
162
- JobParameters jobParameters = new JobParametersBuilder ().addLong ("id" , 1L , false )
175
+ JobParameters jobParameters = new JobParametersBuilder ().addLong ("run. id" , 1L , true )
163
176
.addLong ("foo" , 2L , false )
164
177
.toJobParameters ();
165
178
jobLauncherContext .runner .execute (job , jobParameters );
@@ -200,7 +213,7 @@ static class JobLauncherApplicationRunnerContext {
200
213
this .jobBuilder = new JobBuilder ("job" , jobRepository );
201
214
this .job = this .jobBuilder .start (this .step ).build ();
202
215
this .jobRepository = context .getBean (JobRepository .class );
203
- this .runner = new JobLauncherApplicationRunner (jobOperator , jobRepository );
216
+ this .runner = new JobLauncherApplicationRunner (jobOperator );
204
217
}
205
218
206
219
List <JobInstance > jobInstances () {
0 commit comments