1
1
/*
2
- * Copyright 2012-2019 the original author or authors.
2
+ * Copyright 2012-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
56
56
* @author Dave Syer
57
57
* @author Michael Minella
58
58
* @author Mahmoud Ben Hassine
59
+ * @author Parikshit Dutta
59
60
*
60
61
*/
61
62
@ SuppressWarnings ("serial" )
@@ -214,6 +215,15 @@ public void testItemListeners() throws Exception {
214
215
215
216
@ Test
216
217
public void testFunctions () throws Exception {
218
+ assertStepFunctions (false );
219
+ }
220
+
221
+ @ Test
222
+ public void testFunctionsWithFaultTolerantStep () throws Exception {
223
+ assertStepFunctions (true );
224
+ }
225
+
226
+ private void assertStepFunctions (boolean faultTolerantStep ) throws Exception {
217
227
JobRepository jobRepository = new MapJobRepositoryFactoryBean ().getObject ();
218
228
StepExecution execution = jobRepository .createJobExecution ("foo" , new JobParameters ()).createStepExecution ("step" );
219
229
jobRepository .add (execution );
@@ -228,15 +238,19 @@ public void testFunctions() throws Exception {
228
238
ItemReader <Long > reader = new ListItemReader <>(items );
229
239
230
240
ListItemWriter <String > itemWriter = new ListItemWriter <>();
231
- @ SuppressWarnings ( "unchecked" )
241
+
232
242
SimpleStepBuilder <Object , String > builder = new StepBuilder ("step" )
233
- .repository (jobRepository )
234
- .transactionManager (transactionManager )
235
- .<Object , String >chunk (3 )
236
- .reader (reader )
237
- .processor ((Function <Object , String >) s -> s .toString ())
238
- .writer (itemWriter )
239
- .listener (new AnnotationBasedStepExecutionListener ());
243
+ .repository (jobRepository )
244
+ .transactionManager (transactionManager )
245
+ .<Object , String >chunk (3 )
246
+ .reader (reader )
247
+ .processor ((Function <Object , String >) s -> s .toString ())
248
+ .writer (itemWriter )
249
+ .listener (new AnnotationBasedStepExecutionListener ());
250
+
251
+ if (faultTolerantStep ) {
252
+ builder = builder .faultTolerant ();
253
+ }
240
254
builder .build ().execute (execution );
241
255
242
256
assertEquals (BatchStatus .COMPLETED , execution .getStatus ());
0 commit comments