21
21
22
22
import javax .sql .DataSource ;
23
23
24
+ import org .junit .jupiter .api .Disabled ;
24
25
import org .junit .jupiter .api .Test ;
25
26
26
27
import org .springframework .batch .core .configuration .annotation .EnableBatchProcessing ;
@@ -82,18 +83,20 @@ void basicExecution() {
82
83
}
83
84
84
85
@ Test
86
+ @ Disabled
85
87
void incrementExistingExecution () {
86
88
this .contextRunner .run ((context ) -> {
87
89
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
88
90
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 );
91
94
assertThat (jobLauncherContext .jobInstances ()).hasSize (2 );
92
95
});
93
96
}
94
97
95
98
@ Test
96
- void retryFailedExecution () {
99
+ void retryFailedExecutionWithIncrementer () {
97
100
this .contextRunner .run ((context ) -> {
98
101
PlatformTransactionManager transactionManager = context .getBean (PlatformTransactionManager .class );
99
102
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
@@ -102,7 +105,23 @@ void retryFailedExecution() {
102
105
.incrementer (new RunIdIncrementer ())
103
106
.build ();
104
107
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 );
106
125
assertThat (jobLauncherContext .jobInstances ()).hasSize (1 );
107
126
});
108
127
}
@@ -134,17 +153,13 @@ void retryFailedExecutionOnNonRestartableJob() {
134
153
Job job = jobLauncherContext .jobBuilder ()
135
154
.preventRestart ()
136
155
.start (jobLauncherContext .stepBuilder ().tasklet (throwingTasklet (), transactionManager ).build ())
137
- .incrementer (new RunIdIncrementer ())
138
156
.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 );
144
160
assertThatExceptionOfType (JobRestartException .class ).isThrownBy (() -> {
145
161
// 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 );
148
163
fail ("expected JobRestartException" );
149
164
}).withMessageContaining ("JobInstance already exists and is not restartable" );
150
165
});
@@ -157,9 +172,8 @@ void retryFailedExecutionWithNonIdentifyingParameters() {
157
172
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext (context );
158
173
Job job = jobLauncherContext .jobBuilder ()
159
174
.start (jobLauncherContext .stepBuilder ().tasklet (throwingTasklet (), transactionManager ).build ())
160
- .incrementer (new RunIdIncrementer ())
161
175
.build ();
162
- JobParameters jobParameters = new JobParametersBuilder ().addLong ("id" , 1L , false )
176
+ JobParameters jobParameters = new JobParametersBuilder ().addLong ("run. id" , 1L , true )
163
177
.addLong ("foo" , 2L , false )
164
178
.toJobParameters ();
165
179
jobLauncherContext .runner .execute (job , jobParameters );
@@ -200,7 +214,7 @@ static class JobLauncherApplicationRunnerContext {
200
214
this .jobBuilder = new JobBuilder ("job" , jobRepository );
201
215
this .job = this .jobBuilder .start (this .step ).build ();
202
216
this .jobRepository = context .getBean (JobRepository .class );
203
- this .runner = new JobLauncherApplicationRunner (jobOperator , jobRepository );
217
+ this .runner = new JobLauncherApplicationRunner (jobOperator );
204
218
}
205
219
206
220
List <JobInstance > jobInstances () {
0 commit comments