Skip to content

Commit 61737be

Browse files
committed
BATCH-2686: Add tests for overridden setters
1 parent 94bd4d1 commit 61737be

File tree

2 files changed

+65
-37
lines changed

2 files changed

+65
-37
lines changed

spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingMasterStepBuilder.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616
package org.springframework.batch.integration.chunk;
1717

18-
import java.util.function.Function;
19-
2018
import org.springframework.batch.core.ChunkListener;
21-
import org.springframework.batch.core.ItemProcessListener;
2219
import org.springframework.batch.core.ItemReadListener;
2320
import org.springframework.batch.core.ItemWriteListener;
2421
import org.springframework.batch.core.SkipListener;
@@ -29,7 +26,6 @@
2926
import org.springframework.batch.core.step.item.KeyGenerator;
3027
import org.springframework.batch.core.step.skip.SkipPolicy;
3128
import org.springframework.batch.core.step.tasklet.TaskletStep;
32-
import org.springframework.batch.item.ItemProcessor;
3329
import org.springframework.batch.item.ItemReader;
3430
import org.springframework.batch.item.ItemStream;
3531
import org.springframework.batch.item.ItemWriter;
@@ -175,7 +171,7 @@ public TaskletStep build() {
175171
if (this.messagingTemplate == null) {
176172
this.messagingTemplate = new MessagingTemplate();
177173
}
178-
this.messagingTemplate.setDefaultChannel(outputChannel);
174+
this.messagingTemplate.setDefaultChannel(this.outputChannel);
179175

180176
// configure item writer
181177
ChunkMessageChannelItemWriter<O> chunkMessageChannelItemWriter = new ChunkMessageChannelItemWriter<>();
@@ -330,12 +326,6 @@ public RemoteChunkingMasterStepBuilder<I, O> retry(Class<? extends Throwable> ty
330326
return this;
331327
}
332328

333-
@Override
334-
public RemoteChunkingMasterStepBuilder<I, O> processorNonTransactional() {
335-
super.processorNonTransactional();
336-
return this;
337-
}
338-
339329
@Override
340330
public RemoteChunkingMasterStepBuilder<I, O> stream(ItemStream stream) {
341331
super.stream(stream);
@@ -368,18 +358,6 @@ public RemoteChunkingMasterStepBuilder<I, O> writer(ItemWriter<? super O> writer
368358
return this;
369359
}
370360

371-
@Override
372-
public RemoteChunkingMasterStepBuilder<I, O> processor(ItemProcessor<? super I, ? extends O> processor) {
373-
super.processor(processor);
374-
return this;
375-
}
376-
377-
@Override
378-
public RemoteChunkingMasterStepBuilder<I, O> processor(Function<? super I, ? extends O> function) {
379-
super.processor(function);
380-
return this;
381-
}
382-
383361
@Override
384362
public RemoteChunkingMasterStepBuilder<I, O> readerIsTransactionalQueue() {
385363
super.readerIsTransactionalQueue();
@@ -398,12 +376,6 @@ public RemoteChunkingMasterStepBuilder<I, O> listener(ItemWriteListener<? super
398376
return this;
399377
}
400378

401-
@Override
402-
public RemoteChunkingMasterStepBuilder<I, O> listener(ItemProcessListener<? super I, ? super O> listener) {
403-
super.listener(listener);
404-
return this;
405-
}
406-
407379
@Override
408380
public RemoteChunkingMasterStepBuilder<I, O> chunkOperations(RepeatOperations repeatTemplate) {
409381
super.chunkOperations(repeatTemplate);

spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingMasterStepBuilderTest.java

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,30 @@
2424
import org.junit.runner.RunWith;
2525

2626
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
27+
import org.springframework.batch.core.listener.ChunkListenerSupport;
28+
import org.springframework.batch.core.listener.CompositeItemReadListener;
29+
import org.springframework.batch.core.listener.CompositeItemWriteListener;
30+
import org.springframework.batch.core.listener.SkipListenerSupport;
31+
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
2732
import org.springframework.batch.core.repository.JobRepository;
2833
import org.springframework.batch.core.step.tasklet.TaskletStep;
2934
import org.springframework.batch.item.ItemReader;
35+
import org.springframework.batch.item.ItemStreamSupport;
3036
import org.springframework.batch.item.support.ListItemReader;
37+
import org.springframework.batch.repeat.exception.DefaultExceptionHandler;
38+
import org.springframework.batch.repeat.support.RepeatTemplate;
3139
import org.springframework.beans.factory.annotation.Autowired;
3240
import org.springframework.context.annotation.Configuration;
3341
import org.springframework.integration.channel.DirectChannel;
3442
import org.springframework.integration.channel.QueueChannel;
3543
import org.springframework.messaging.PollableChannel;
44+
import org.springframework.retry.backoff.NoBackOffPolicy;
45+
import org.springframework.retry.listener.RetryListenerSupport;
46+
import org.springframework.retry.policy.MapRetryContextCache;
3647
import org.springframework.test.context.ContextConfiguration;
3748
import org.springframework.test.context.junit4.SpringRunner;
3849
import org.springframework.transaction.PlatformTransactionManager;
50+
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
3951

4052
/**
4153
* @author Mahmoud Ben Hassine
@@ -52,6 +64,10 @@ public class RemoteChunkingMasterStepBuilderTest {
5264
@Autowired
5365
private PlatformTransactionManager transactionManager;
5466

67+
private PollableChannel inputChannel = new QueueChannel();
68+
private DirectChannel outputChannel = new DirectChannel();
69+
private ItemReader<String> itemReader = new ListItemReader<>(Arrays.asList("a", "b", "c"));
70+
5571
@Test
5672
public void inputChannelMustNotBeNull() {
5773
// given
@@ -146,7 +162,7 @@ public void testMandatoryInputChannel() {
146162
public void testMandatoryOutputChannel() {
147163
// given
148164
RemoteChunkingMasterStepBuilder<String, String> builder = new RemoteChunkingMasterStepBuilder<String, String>("step")
149-
.inputChannel(new QueueChannel());
165+
.inputChannel(this.inputChannel);
150166

151167
this.expectedException.expect(IllegalArgumentException.class);
152168
this.expectedException.expectMessage("An OutputChannel must be provided");
@@ -160,18 +176,58 @@ public void testMandatoryOutputChannel() {
160176

161177
@Test
162178
public void testMasterStepCreation() {
163-
// given
164-
ItemReader<String> itemReader = new ListItemReader<>(Arrays.asList("a", "b", "c"));
165-
PollableChannel inputChannel = new QueueChannel();
166-
DirectChannel outputChannel = new DirectChannel();
179+
// when
180+
TaskletStep taskletStep = new RemoteChunkingMasterStepBuilder<String, String>("step")
181+
.reader(this.itemReader)
182+
.repository(this.jobRepository)
183+
.transactionManager(this.transactionManager)
184+
.inputChannel(this.inputChannel)
185+
.outputChannel(this.outputChannel)
186+
.build();
187+
188+
// then
189+
Assert.assertNotNull(taskletStep);
190+
}
167191

192+
/*
193+
* The following test is to cover setters that override those from parent builders.
194+
*/
195+
@Test
196+
public void testSetters() {
168197
// when
169198
TaskletStep taskletStep = new RemoteChunkingMasterStepBuilder<String, String>("step")
170-
.reader(itemReader)
199+
.reader(this.itemReader)
200+
.readerIsTransactionalQueue()
201+
.writer(items -> { })
171202
.repository(this.jobRepository)
172203
.transactionManager(this.transactionManager)
173-
.inputChannel(inputChannel)
174-
.outputChannel(outputChannel)
204+
.transactionAttribute(new DefaultTransactionAttribute())
205+
.inputChannel(this.inputChannel)
206+
.outputChannel(this.outputChannel)
207+
.listener(new Object())
208+
.listener(new SkipListenerSupport<>())
209+
.listener(new ChunkListenerSupport())
210+
.listener(new StepExecutionListenerSupport())
211+
.listener(new CompositeItemReadListener<>())
212+
.listener(new CompositeItemWriteListener<>())
213+
.listener(new RetryListenerSupport())
214+
.skip(Exception.class)
215+
.noSkip(RuntimeException.class)
216+
.skipLimit(10)
217+
.retry(Exception.class)
218+
.noRetry(RuntimeException.class)
219+
.retryLimit(10)
220+
.retryContextCache(new MapRetryContextCache())
221+
.noRollback(Exception.class)
222+
.chunk(10)
223+
.startLimit(3)
224+
.allowStartIfComplete(true)
225+
.exceptionHandler(new DefaultExceptionHandler())
226+
.stepOperations(new RepeatTemplate())
227+
.chunkOperations(new RepeatTemplate())
228+
.backOffPolicy(new NoBackOffPolicy())
229+
.stream(new ItemStreamSupport() {})
230+
.keyGenerator(Object::hashCode)
175231
.build();
176232

177233
// then

0 commit comments

Comments
 (0)