Skip to content

Commit a90389f

Browse files
parikshitduttafmbenhassine
authored andcommitted
Update SimpleStepBuilder to assign ItemProcessor lambda at construction
Issue #3749
1 parent a5595bf commit a90389f

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
*
6565
* @author Dave Syer
6666
* @author Mahmoud Ben Hassine
67+
* @author Parikshit Dutta
6768
*
6869
* @since 2.2
6970
*/
@@ -111,6 +112,7 @@ protected SimpleStepBuilder(SimpleStepBuilder<I, O> parent) {
111112
this.reader = parent.reader;
112113
this.writer = parent.writer;
113114
this.processor = parent.processor;
115+
this.itemProcessorFunction = parent.itemProcessorFunction;
114116
this.itemListeners = parent.itemListeners;
115117
this.readerTransactionalQueue = parent.readerTransactionalQueue;
116118
}

spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,6 +56,7 @@
5656
* @author Dave Syer
5757
* @author Michael Minella
5858
* @author Mahmoud Ben Hassine
59+
* @author Parikshit Dutta
5960
*
6061
*/
6162
@SuppressWarnings("serial")
@@ -214,6 +215,15 @@ public void testItemListeners() throws Exception {
214215

215216
@Test
216217
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 {
217227
JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject();
218228
StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step");
219229
jobRepository.add(execution);
@@ -228,15 +238,19 @@ public void testFunctions() throws Exception {
228238
ItemReader<Long> reader = new ListItemReader<>(items);
229239

230240
ListItemWriter<String> itemWriter = new ListItemWriter<>();
231-
@SuppressWarnings("unchecked")
241+
232242
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+
}
240254
builder.build().execute(execution);
241255

242256
assertEquals(BatchStatus.COMPLETED, execution.getStatus());

0 commit comments

Comments
 (0)