Improve Step/Job builder APIs to guide users to set mandatory properties
Before this commit, the user had to manually set the job repository and transaction manager on `JobBuilder` and `StepBuilder` instances with a chained call to `.repository(jobRepository)` and `.transactionManager(transactionManager)`. This is error prone and can lead to runtime errors if these properties are not set. This commit introduces new APIs to guide the user to set these properties at builder creation time. Resolves #4192
This commit is contained in:
@@ -51,7 +51,7 @@ public class JobBuilderFactory {
|
||||
* @return a job builder
|
||||
*/
|
||||
public JobBuilder get(String name) {
|
||||
return new JobBuilder(name).repository(this.jobRepository);
|
||||
return new JobBuilder(name, this.jobRepository);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class StepBuilderFactory {
|
||||
* @return a step builder
|
||||
*/
|
||||
public StepBuilder get(String name) {
|
||||
return new StepBuilder(name).repository(this.jobRepository);
|
||||
return new StepBuilder(name, this.jobRepository);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -274,7 +274,6 @@ public class StepParserStepFactoryBean<I, O> implements FactoryBean<Step>, BeanN
|
||||
if (startLimit != null) {
|
||||
builder.startLimit(startLimit);
|
||||
}
|
||||
builder.repository(jobRepository);
|
||||
for (Object listener : stepExecutionListeners) {
|
||||
if (listener instanceof StepExecutionListener) {
|
||||
builder.listener((StepExecutionListener) listener);
|
||||
@@ -290,10 +289,11 @@ public class StepParserStepFactoryBean<I, O> implements FactoryBean<Step>, BeanN
|
||||
|
||||
PartitionStepBuilder builder;
|
||||
if (partitioner != null) {
|
||||
builder = new StepBuilder(name).partitioner(step != null ? step.getName() : name, partitioner).step(step);
|
||||
builder = new StepBuilder(name, jobRepository)
|
||||
.partitioner(step != null ? step.getName() : name, partitioner).step(step);
|
||||
}
|
||||
else {
|
||||
builder = new StepBuilder(name).partitioner(step);
|
||||
builder = new StepBuilder(name, jobRepository).partitioner(step);
|
||||
}
|
||||
enhanceCommonStep(builder);
|
||||
|
||||
@@ -401,7 +401,7 @@ public class StepParserStepFactoryBean<I, O> implements FactoryBean<Step>, BeanN
|
||||
* @return the {@link FaultTolerantStepBuilder}.
|
||||
*/
|
||||
protected FaultTolerantStepBuilder<I, O> getFaultTolerantStepBuilder(String stepName) {
|
||||
return new FaultTolerantStepBuilder<>(new StepBuilder(stepName));
|
||||
return new FaultTolerantStepBuilder<>(new StepBuilder(stepName, jobRepository));
|
||||
}
|
||||
|
||||
protected void registerItemListeners(SimpleStepBuilder<I, O> builder) {
|
||||
@@ -445,7 +445,7 @@ public class StepParserStepFactoryBean<I, O> implements FactoryBean<Step>, BeanN
|
||||
}
|
||||
|
||||
protected SimpleStepBuilder<I, O> getSimpleStepBuilder(String stepName) {
|
||||
return new SimpleStepBuilder<>(new StepBuilder(stepName));
|
||||
return new SimpleStepBuilder<>(new StepBuilder(stepName, jobRepository));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -453,8 +453,8 @@ public class StepParserStepFactoryBean<I, O> implements FactoryBean<Step>, BeanN
|
||||
* @return a new {@link TaskletStep}
|
||||
*/
|
||||
protected TaskletStep createTaskletStep() {
|
||||
TaskletStepBuilder builder = new TaskletStepBuilder(new StepBuilder(name))
|
||||
.transactionManager(transactionManager).tasklet(tasklet);
|
||||
TaskletStepBuilder builder = new TaskletStepBuilder(new StepBuilder(name, jobRepository)).tasklet(tasklet,
|
||||
transactionManager);
|
||||
enhanceTaskletStepBuilder(builder);
|
||||
return builder.build();
|
||||
}
|
||||
@@ -512,14 +512,14 @@ public class StepParserStepFactoryBean<I, O> implements FactoryBean<Step>, BeanN
|
||||
* @return the {@link org.springframework.batch.core.job.flow.FlowStep}.
|
||||
*/
|
||||
protected Step createFlowStep() {
|
||||
FlowStepBuilder builder = new StepBuilder(name).flow(flow);
|
||||
FlowStepBuilder builder = new StepBuilder(name, jobRepository).flow(flow);
|
||||
enhanceCommonStep(builder);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private Step createJobStep() throws Exception {
|
||||
|
||||
JobStepBuilder builder = new StepBuilder(name).job(job);
|
||||
JobStepBuilder builder = new StepBuilder(name, jobRepository).job(job);
|
||||
enhanceCommonStep(builder);
|
||||
builder.parametersExtractor(jobParametersExtractor);
|
||||
builder.launcher(jobLauncher);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,11 +17,13 @@ package org.springframework.batch.core.job.builder;
|
||||
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.job.flow.Flow;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
|
||||
/**
|
||||
* Convenience for building jobs of various kinds.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 2.2
|
||||
*
|
||||
*/
|
||||
@@ -30,11 +32,24 @@ public class JobBuilder extends JobBuilderHelper<JobBuilder> {
|
||||
/**
|
||||
* Create a new builder for a job with the given name.
|
||||
* @param name the name of the job
|
||||
* @deprecated use {@link JobBuilder#JobBuilder(String, JobRepository)}
|
||||
*/
|
||||
@Deprecated(since = "5.0")
|
||||
public JobBuilder(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder for a job with the given name.
|
||||
* @param name the name of the job
|
||||
* @param jobRepository the job repository to which the job should report to
|
||||
* @since 5.0
|
||||
*/
|
||||
public JobBuilder(String name, JobRepository jobRepository) {
|
||||
super(name);
|
||||
super.repository(jobRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new job builder that will execute a step or sequence of steps.
|
||||
* @param step a step to execute
|
||||
|
||||
@@ -19,14 +19,17 @@ import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.job.flow.Flow;
|
||||
import org.springframework.batch.core.partition.support.Partitioner;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.CompletionPolicy;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
/**
|
||||
* Convenient entry point for building all kinds of steps. Use this as a factory for
|
||||
* fluent builders of any step.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 2.2
|
||||
*/
|
||||
public class StepBuilder extends StepBuilderHelper<StepBuilder> {
|
||||
@@ -34,20 +37,46 @@ public class StepBuilder extends StepBuilderHelper<StepBuilder> {
|
||||
/**
|
||||
* Initialize a step builder for a step with the given name.
|
||||
* @param name the name of the step
|
||||
* @deprecated use {@link StepBuilder#StepBuilder(String, JobRepository)}
|
||||
*/
|
||||
@Deprecated(since = "5.0")
|
||||
public StepBuilder(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a step builder for a step with the given name and job repository.
|
||||
* @param name the name of the step
|
||||
* @param jobRepository the job repository to which the step should report to.
|
||||
* @since 5.0
|
||||
*/
|
||||
public StepBuilder(String name, JobRepository jobRepository) {
|
||||
super(name);
|
||||
super.repository(jobRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a step with a custom tasklet, not necessarily item processing.
|
||||
* @param tasklet a tasklet
|
||||
* @return a {@link TaskletStepBuilder}
|
||||
* @deprecated use {@link StepBuilder#tasklet(Tasklet, PlatformTransactionManager)}
|
||||
*/
|
||||
@Deprecated(since = "5.0")
|
||||
public TaskletStepBuilder tasklet(Tasklet tasklet) {
|
||||
return new TaskletStepBuilder(this).tasklet(tasklet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a step with a custom tasklet, not necessarily item processing.
|
||||
* @param tasklet a tasklet
|
||||
* @param transactionManager the transaction manager to use for the tasklet
|
||||
* @return a {@link TaskletStepBuilder}
|
||||
* @since 5.0
|
||||
*/
|
||||
public TaskletStepBuilder tasklet(Tasklet tasklet, PlatformTransactionManager transactionManager) {
|
||||
return new TaskletStepBuilder(this).tasklet(tasklet, transactionManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a step that processes items in chunks with the size provided. To extend the
|
||||
* step to being fault tolerant, call the {@link SimpleStepBuilder#faultTolerant()}
|
||||
@@ -62,11 +91,35 @@ public class StepBuilder extends StepBuilderHelper<StepBuilder> {
|
||||
* @return a {@link SimpleStepBuilder}
|
||||
* @param <I> the type of item to be processed as input
|
||||
* @param <O> the type of item to be output
|
||||
* @deprecated use {@link StepBuilder#chunk(int, PlatformTransactionManager)}
|
||||
*/
|
||||
@Deprecated(since = "5.0")
|
||||
public <I, O> SimpleStepBuilder<I, O> chunk(int chunkSize) {
|
||||
return new SimpleStepBuilder<I, O>(this).chunk(chunkSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a step that processes items in chunks with the size provided. To extend the
|
||||
* step to being fault tolerant, call the {@link SimpleStepBuilder#faultTolerant()}
|
||||
* method on the builder. In most cases you will want to parameterize your call to
|
||||
* this method, to preserve the type safety of your readers and writers, e.g.
|
||||
*
|
||||
* <pre>
|
||||
* new StepBuilder("step1").<Order, Ledger> chunk(100, transactionManager).reader(new OrderReader()).writer(new LedgerWriter())
|
||||
* // ... etc.
|
||||
* </pre>
|
||||
* @param chunkSize the chunk size (commit interval)
|
||||
* @param transactionManager the transaction manager to use for the chunk-oriented
|
||||
* tasklet
|
||||
* @return a {@link SimpleStepBuilder}
|
||||
* @param <I> the type of item to be processed as input
|
||||
* @param <O> the type of item to be output
|
||||
* @since 5.0
|
||||
*/
|
||||
public <I, O> SimpleStepBuilder<I, O> chunk(int chunkSize, PlatformTransactionManager transactionManager) {
|
||||
return new SimpleStepBuilder<I, O>(this).transactionManager(transactionManager).chunk(chunkSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a step that processes items in chunks with the completion policy provided. To
|
||||
* extend the step to being fault tolerant, call the
|
||||
@@ -81,12 +134,39 @@ public class StepBuilder extends StepBuilderHelper<StepBuilder> {
|
||||
* @param completionPolicy the completion policy to use to control chunk processing
|
||||
* @return a {@link SimpleStepBuilder}
|
||||
* @param <I> the type of item to be processed as input
|
||||
* @param <O> the type of item to be output *
|
||||
* @param <O> the type of item to be output
|
||||
* @deprecated use
|
||||
* {@link StepBuilder#chunk(CompletionPolicy, PlatformTransactionManager)}
|
||||
*/
|
||||
@Deprecated(since = "5.0")
|
||||
public <I, O> SimpleStepBuilder<I, O> chunk(CompletionPolicy completionPolicy) {
|
||||
return new SimpleStepBuilder<I, O>(this).chunk(completionPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a step that processes items in chunks with the completion policy provided. To
|
||||
* extend the step to being fault tolerant, call the
|
||||
* {@link SimpleStepBuilder#faultTolerant()} method on the builder. In most cases you
|
||||
* will want to parameterize your call to this method, to preserve the type safety of
|
||||
* your readers and writers, e.g.
|
||||
*
|
||||
* <pre>
|
||||
* new StepBuilder("step1").<Order, Ledger> chunk(100, transactionManager).reader(new OrderReader()).writer(new LedgerWriter())
|
||||
* // ... etc.
|
||||
* </pre>
|
||||
* @param completionPolicy the completion policy to use to control chunk processing
|
||||
* @param transactionManager the transaction manager to use for the chunk-oriented
|
||||
* tasklet
|
||||
* @return a {@link SimpleStepBuilder}
|
||||
* @param <I> the type of item to be processed as input
|
||||
* @param <O> the type of item to be output
|
||||
* @since 5.0
|
||||
*/
|
||||
public <I, O> SimpleStepBuilder<I, O> chunk(CompletionPolicy completionPolicy,
|
||||
PlatformTransactionManager transactionManager) {
|
||||
return new SimpleStepBuilder<I, O>(this).transactionManager(transactionManager).chunk(completionPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a partition step builder for a remote (or local) step.
|
||||
* @param stepName the name of the remote or delegate step
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
package org.springframework.batch.core.step.builder;
|
||||
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
/**
|
||||
* Builder for tasklet step based on a custom tasklet (not item oriented).
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 2.2
|
||||
*/
|
||||
public class TaskletStepBuilder extends AbstractTaskletStepBuilder<TaskletStepBuilder> {
|
||||
@@ -39,12 +41,26 @@ public class TaskletStepBuilder extends AbstractTaskletStepBuilder<TaskletStepBu
|
||||
/**
|
||||
* @param tasklet the tasklet to use
|
||||
* @return this for fluent chaining
|
||||
* @deprecated use
|
||||
* {@link TaskletStepBuilder#tasklet(Tasklet, PlatformTransactionManager)}
|
||||
*/
|
||||
@Deprecated(since = "5.0")
|
||||
public TaskletStepBuilder tasklet(Tasklet tasklet) {
|
||||
this.tasklet = tasklet;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tasklet the tasklet to use
|
||||
* @return this for fluent chaining
|
||||
* @since 5.0
|
||||
*/
|
||||
public TaskletStepBuilder tasklet(Tasklet tasklet, PlatformTransactionManager transactionManager) {
|
||||
this.tasklet = tasklet;
|
||||
super.transactionManager(transactionManager);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TaskletStepBuilder self() {
|
||||
return this;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -214,7 +214,7 @@ public class FaultTolerantStepFactoryBean<T, S> extends SimpleStepFactoryBean<T,
|
||||
|
||||
@Override
|
||||
protected SimpleStepBuilder<T, S> createBuilder(String name) {
|
||||
return new FaultTolerantStepBuilder<>(new StepBuilder(name));
|
||||
return new FaultTolerantStepBuilder<>(new StepBuilder(name, jobRepository));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,6 +57,7 @@ import org.springframework.transaction.interceptor.TransactionAttribute;
|
||||
* @see FaultTolerantStepFactoryBean
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
public class SimpleStepFactoryBean<T, S> implements FactoryBean<Step>, BeanNameAware {
|
||||
@@ -81,7 +82,7 @@ public class SimpleStepFactoryBean<T, S> implements FactoryBean<Step>, BeanNameA
|
||||
|
||||
private int transactionTimeout = DefaultTransactionAttribute.TIMEOUT_DEFAULT;
|
||||
|
||||
private JobRepository jobRepository;
|
||||
protected JobRepository jobRepository;
|
||||
|
||||
private boolean singleton = true;
|
||||
|
||||
@@ -318,7 +319,7 @@ public class SimpleStepFactoryBean<T, S> implements FactoryBean<Step>, BeanNameA
|
||||
}
|
||||
|
||||
protected SimpleStepBuilder<T, S> createBuilder(String name) {
|
||||
return new SimpleStepBuilder<>(new StepBuilder(name));
|
||||
return new SimpleStepBuilder<>(new StepBuilder(name, jobRepository));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,7 +35,9 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.jdbc.support.JdbcTransactionManager;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@@ -57,12 +59,12 @@ class InlineDataSourceDefinitionTests {
|
||||
static class MyJobConfiguration {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("hello world");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
}, transactionManager).build()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -72,6 +74,11 @@ class InlineDataSourceDefinitionTests {
|
||||
.addScript("/org/springframework/batch/core/schema-h2.sql").generateUniqueName(true).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JdbcTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new JdbcTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -120,21 +120,18 @@ public class JobBuilderConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public Job testJob() throws Exception {
|
||||
SimpleJobBuilder builder = new JobBuilder("test").repository(this.jobRepository).start(step1())
|
||||
.next(step2());
|
||||
SimpleJobBuilder builder = new JobBuilder("test", this.jobRepository).start(step1()).next(step2());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step1() throws Exception {
|
||||
return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet())
|
||||
.transactionManager(this.transactionManager).build();
|
||||
return new StepBuilder("step1", jobRepository).tasklet(tasklet(), this.transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step2() throws Exception {
|
||||
return new StepBuilder("step2").repository(jobRepository).tasklet(tasklet())
|
||||
.transactionManager(this.transactionManager).build();
|
||||
return new StepBuilder("step2", jobRepository).tasklet(tasklet(), this.transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -166,14 +163,13 @@ public class JobBuilderConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public Job anotherJob(JobRepository jobRepository) throws Exception {
|
||||
SimpleJobBuilder builder = new JobBuilder("another").repository(jobRepository).start(step3(jobRepository));
|
||||
SimpleJobBuilder builder = new JobBuilder("another", jobRepository).start(step3(jobRepository));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step3(JobRepository jobRepository) throws Exception {
|
||||
return new StepBuilder("step3").repository(jobRepository).tasklet(tasklet)
|
||||
.transactionManager(this.transactionManager).build();
|
||||
return new StepBuilder("step3", jobRepository).tasklet(tasklet, this.transactionManager).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -189,7 +185,7 @@ public class JobBuilderConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public Job testConfigurerJob(JobRepository jobRepository) throws Exception {
|
||||
SimpleJobBuilder builder = new JobBuilder("configurer").repository(jobRepository).start(step1());
|
||||
SimpleJobBuilder builder = new JobBuilder("configurer", jobRepository).start(step1());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -218,20 +214,20 @@ public class JobBuilderConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public Job beansConfigurerJob(JobRepository jobRepository) throws Exception {
|
||||
SimpleJobBuilder builder = new JobBuilder("beans").repository(jobRepository).start(step1(jobRepository));
|
||||
SimpleJobBuilder builder = new JobBuilder("beans", jobRepository).start(step1(jobRepository));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step1(JobRepository jobRepository) throws Exception {
|
||||
return new StepBuilder("step1").repository(jobRepository).tasklet(new Tasklet() {
|
||||
return new StepBuilder("step1", jobRepository).tasklet(new Tasklet() {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
return null;
|
||||
}
|
||||
}).transactionManager(this.transactionManager).build();
|
||||
}, this.transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -127,21 +127,21 @@ class JobLoaderConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public Job testJob(JobRepository jobRepository) throws Exception {
|
||||
SimpleJobBuilder builder = new JobBuilder("test").repository(jobRepository).start(step1(jobRepository))
|
||||
SimpleJobBuilder builder = new JobBuilder("test", jobRepository).start(step1(jobRepository))
|
||||
.next(step2(jobRepository));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step1(JobRepository jobRepository) throws Exception {
|
||||
return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet())
|
||||
.transactionManager(new ResourcelessTransactionManager()).build();
|
||||
return new StepBuilder("step1", jobRepository).tasklet(tasklet(), new ResourcelessTransactionManager())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step2(JobRepository jobRepository) throws Exception {
|
||||
return new StepBuilder("step2").repository(jobRepository).tasklet(tasklet())
|
||||
.transactionManager(new ResourcelessTransactionManager()).build();
|
||||
return new StepBuilder("step2", jobRepository).tasklet(tasklet(), new ResourcelessTransactionManager())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -162,19 +162,19 @@ class JobLoaderConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public Job vanillaJob(JobRepository jobRepository) throws Exception {
|
||||
SimpleJobBuilder builder = new JobBuilder("vanilla").repository(jobRepository).start(step3(jobRepository));
|
||||
SimpleJobBuilder builder = new JobBuilder("vanilla", jobRepository).start(step3(jobRepository));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step3(JobRepository jobRepository) throws Exception {
|
||||
return new StepBuilder("step3").repository(jobRepository).tasklet(new Tasklet() {
|
||||
return new StepBuilder("step3", jobRepository).tasklet(new Tasklet() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext context) throws Exception {
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).transactionManager(new ResourcelessTransactionManager()).build();
|
||||
}, new ResourcelessTransactionManager()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ class SimpleJobExplorerIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Step flowStep(JobRepository jobRepository) {
|
||||
return new StepBuilder("flowStep").repository(jobRepository).flow(simpleFlow()).build();
|
||||
return new StepBuilder("flowStep", jobRepository).flow(simpleFlow()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -129,7 +129,7 @@ class SimpleJobExplorerIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(dummyStep()).build();
|
||||
return new JobBuilder("job", jobRepository).start(dummyStep()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ class FlowJobBuilderTests {
|
||||
|
||||
@Test
|
||||
void testBuildOnOneLine() {
|
||||
FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1).on("COMPLETED").to(step2)
|
||||
.end().preventRestart();
|
||||
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1).on("COMPLETED").to(step2).end()
|
||||
.preventRestart();
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(2, execution.getStepExecutions().size());
|
||||
@@ -132,7 +132,7 @@ class FlowJobBuilderTests {
|
||||
@Test
|
||||
void testBuildSingleFlow() {
|
||||
Flow flow = new FlowBuilder<Flow>("subflow").from(step1).next(step2).build();
|
||||
FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(flow).end().preventRestart();
|
||||
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(flow).end().preventRestart();
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(2, execution.getStepExecutions().size());
|
||||
@@ -140,8 +140,7 @@ class FlowJobBuilderTests {
|
||||
|
||||
@Test
|
||||
void testBuildOverTwoLines() {
|
||||
FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1).on("COMPLETED").to(step2)
|
||||
.end();
|
||||
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1).on("COMPLETED").to(step2).end();
|
||||
builder.preventRestart();
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -151,7 +150,7 @@ class FlowJobBuilderTests {
|
||||
@Test
|
||||
void testBuildSubflow() {
|
||||
Flow flow = new FlowBuilder<Flow>("subflow").from(step1).end();
|
||||
JobFlowBuilder builder = new JobBuilder("flow").repository(jobRepository).start(flow);
|
||||
JobFlowBuilder builder = new JobBuilder("flow", jobRepository).start(flow);
|
||||
builder.on("COMPLETED").to(step2);
|
||||
builder.end().preventRestart().build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -161,7 +160,7 @@ class FlowJobBuilderTests {
|
||||
@Test
|
||||
void testBuildSplit() {
|
||||
Flow flow = new FlowBuilder<Flow>("subflow").from(step1).end();
|
||||
SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step2);
|
||||
SimpleJobBuilder builder = new JobBuilder("flow", jobRepository).start(step2);
|
||||
builder.split(new SimpleAsyncTaskExecutor()).add(flow).end();
|
||||
builder.preventRestart().build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -175,7 +174,7 @@ class FlowJobBuilderTests {
|
||||
Flow splitflow = new FlowBuilder<Flow>("splitflow").start(subflow1).split(new SimpleAsyncTaskExecutor())
|
||||
.add(subflow2).build();
|
||||
|
||||
FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(splitflow).end();
|
||||
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(splitflow).end();
|
||||
builder.preventRestart().build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(2, execution.getStepExecutions().size());
|
||||
@@ -187,7 +186,7 @@ class FlowJobBuilderTests {
|
||||
Flow flow2 = new FlowBuilder<Flow>("subflow2").from(step2).end();
|
||||
Flow splitFlow = new FlowBuilder<Flow>("splitflow").split(new SimpleAsyncTaskExecutor()).add(flow1, flow2)
|
||||
.build();
|
||||
FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(splitFlow).end();
|
||||
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(splitFlow).end();
|
||||
builder.preventRestart().build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(2, execution.getStepExecutions().size());
|
||||
@@ -205,7 +204,7 @@ class FlowJobBuilderTests {
|
||||
}
|
||||
};
|
||||
step1.setAllowStartIfComplete(true);
|
||||
SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1);
|
||||
SimpleJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1);
|
||||
builder.next(decider).on("COMPLETED").end().from(decider).on("*").to(step1).end();
|
||||
builder.preventRestart().build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -214,7 +213,7 @@ class FlowJobBuilderTests {
|
||||
|
||||
@Test
|
||||
void testBuildWithIntermediateSimpleJob() {
|
||||
SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1);
|
||||
SimpleJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1);
|
||||
builder.on("COMPLETED").to(step2).end();
|
||||
builder.preventRestart();
|
||||
builder.build().execute(execution);
|
||||
@@ -224,7 +223,7 @@ class FlowJobBuilderTests {
|
||||
|
||||
@Test
|
||||
void testBuildWithIntermediateSimpleJobTwoSteps() {
|
||||
SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1).next(step2);
|
||||
SimpleJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1).next(step2);
|
||||
builder.on("FAILED").to(step3).end();
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -233,7 +232,7 @@ class FlowJobBuilderTests {
|
||||
|
||||
@Test
|
||||
void testBuildWithCustomEndState() {
|
||||
SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1);
|
||||
SimpleJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1);
|
||||
builder.on("COMPLETED").end("FOO");
|
||||
builder.preventRestart();
|
||||
builder.build().execute(execution);
|
||||
@@ -244,7 +243,7 @@ class FlowJobBuilderTests {
|
||||
|
||||
@Test
|
||||
void testBuildWithStop() {
|
||||
SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1);
|
||||
SimpleJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1);
|
||||
builder.on("COMPLETED").stop();
|
||||
builder.preventRestart();
|
||||
builder.build().execute(execution);
|
||||
@@ -255,7 +254,7 @@ class FlowJobBuilderTests {
|
||||
|
||||
@Test
|
||||
void testBuildWithStopAndRestart() throws Exception {
|
||||
SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(fails);
|
||||
SimpleJobBuilder builder = new JobBuilder("flow", jobRepository).start(fails);
|
||||
builder.on("FAILED").stopAndRestart(step2);
|
||||
Job job = builder.build();
|
||||
job.execute(execution);
|
||||
@@ -291,16 +290,15 @@ class FlowJobBuilderTests {
|
||||
@JobScope
|
||||
public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager,
|
||||
@Value("#{jobParameters['chunkSize']}") Integer chunkSize) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(chunkSize)
|
||||
.transactionManager(transactionManager).reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4)))
|
||||
.writer(items -> {
|
||||
return new StepBuilder("step", jobRepository).<Integer, Integer>chunk(chunkSize, transactionManager)
|
||||
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4))).writer(items -> {
|
||||
}).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
Step step = step(jobRepository, transactionManager, null);
|
||||
return new JobBuilder("job").repository(jobRepository).flow(step).build().build();
|
||||
return new JobBuilder("job", jobRepository).flow(step).build().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -71,11 +71,10 @@ class JobBuilderTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository).listener(new InterfaceBasedJobExecutionListener())
|
||||
return new JobBuilder("job", jobRepository).listener(new InterfaceBasedJobExecutionListener())
|
||||
.listener(new AnnotationBasedJobExecutionListener())
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -133,8 +133,7 @@ class ItemListenerErrorTests {
|
||||
|
||||
@Bean
|
||||
public Job testJob(JobRepository jobRepository, Step testStep) {
|
||||
return new JobBuilder("testJob").repository(jobRepository).incrementer(new RunIdIncrementer())
|
||||
.start(testStep).build();
|
||||
return new JobBuilder("testJob", jobRepository).incrementer(new RunIdIncrementer()).start(testStep).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -142,10 +141,9 @@ class ItemListenerErrorTests {
|
||||
ItemReader<String> fakeItemReader, ItemProcessor<String, String> fakeProcessor,
|
||||
ItemWriter<String> fakeItemWriter, ItemProcessListener<String, String> itemProcessListener) {
|
||||
|
||||
return new StepBuilder("testStep").repository(jobRepository).<String, String>chunk(10)
|
||||
.transactionManager(transactionManager).reader(fakeItemReader).processor(fakeProcessor)
|
||||
.writer(fakeItemWriter).listener(itemProcessListener).faultTolerant().skipLimit(50)
|
||||
.skip(RuntimeException.class).build();
|
||||
return new StepBuilder("testStep", jobRepository).<String, String>chunk(10, transactionManager)
|
||||
.reader(fakeItemReader).processor(fakeProcessor).writer(fakeItemWriter)
|
||||
.listener(itemProcessListener).faultTolerant().skipLimit(50).skip(RuntimeException.class).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -231,23 +231,20 @@ class BatchMetricsTests {
|
||||
|
||||
@Bean
|
||||
public Step step1(JobRepository jobRepository) {
|
||||
return new StepBuilder("step1").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(this.transactionManager).build();
|
||||
return new StepBuilder("step1", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, this.transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step2(JobRepository jobRepository) {
|
||||
return new StepBuilder("step2").repository(jobRepository).<Integer, Integer>chunk(2)
|
||||
.transactionManager(this.transactionManager)
|
||||
return new StepBuilder("step2", jobRepository).<Integer, Integer>chunk(2, this.transactionManager)
|
||||
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4, 5)))
|
||||
.writer(items -> items.forEach(System.out::println)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step3(JobRepository jobRepository) {
|
||||
return new StepBuilder("step3").repository(jobRepository).<Integer, Integer>chunk(2)
|
||||
.transactionManager(this.transactionManager)
|
||||
return new StepBuilder("step3", jobRepository).<Integer, Integer>chunk(2, this.transactionManager)
|
||||
.reader(new ListItemReader<>(Arrays.asList(6, 7, 8, 9, 10)))
|
||||
.writer(items -> items.forEach(System.out::println)).faultTolerant().skip(Exception.class)
|
||||
.skipLimit(3).build();
|
||||
@@ -255,8 +252,8 @@ class BatchMetricsTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step1(jobRepository))
|
||||
.next(step2(jobRepository)).next(step3(jobRepository)).build();
|
||||
return new JobBuilder("job", jobRepository).start(step1(jobRepository)).next(step2(jobRepository))
|
||||
.next(step3(jobRepository)).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,18 +30,18 @@ class FaultTolerantStepBuilderTests {
|
||||
|
||||
@Test
|
||||
void faultTolerantReturnsSameInstance() {
|
||||
FaultTolerantStepBuilder<Object, Object> builder = new FaultTolerantStepBuilder<>(new StepBuilder("test"));
|
||||
FaultTolerantStepBuilder<Object, Object> builder = new FaultTolerantStepBuilder<>(
|
||||
new StepBuilder("test", new DummyJobRepository()));
|
||||
assertEquals(builder, builder.faultTolerant());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAnnotationBasedStepExecutionListenerRegistration() {
|
||||
// given
|
||||
FaultTolerantStepBuilder<Object, Object> faultTolerantStepBuilder = new StepBuilder("myStep")
|
||||
.repository(new DummyJobRepository()).<Object, Object>chunk(5)
|
||||
.transactionManager(new ResourcelessTransactionManager()).reader(new DummyItemReader())
|
||||
.writer(new DummyItemWriter()).faultTolerant()
|
||||
.listener(new StepBuilderTests.AnnotationBasedStepExecutionListener());
|
||||
FaultTolerantStepBuilder<Object, Object> faultTolerantStepBuilder = new StepBuilder("myStep",
|
||||
new DummyJobRepository()).<Object, Object>chunk(5, new ResourcelessTransactionManager())
|
||||
.reader(new DummyItemReader()).writer(new DummyItemWriter()).faultTolerant()
|
||||
.listener(new StepBuilderTests.AnnotationBasedStepExecutionListener());
|
||||
|
||||
// when
|
||||
Step step = faultTolerantStepBuilder.build();
|
||||
|
||||
@@ -130,7 +130,7 @@ class RegisterMultiListenerTests {
|
||||
|
||||
@Bean
|
||||
public Job testJob(JobRepository jobRepository) {
|
||||
return new JobBuilder("testJob").repository(jobRepository).start(step(jobRepository)).build();
|
||||
return new JobBuilder("testJob", jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -204,8 +204,8 @@ class RegisterMultiListenerTests {
|
||||
@Override
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).listener(listener()).<String, String>chunk(2)
|
||||
.transactionManager(transactionManager(dataSource())).reader(reader()).writer(writer())
|
||||
return new StepBuilder("step", jobRepository).listener(listener())
|
||||
.<String, String>chunk(2, transactionManager(dataSource())).reader(reader()).writer(writer())
|
||||
.faultTolerant().skipLimit(1).skip(MySkippableException.class)
|
||||
// ChunkListener registered twice for checking BATCH-2149
|
||||
.listener((ChunkListener) listener()).build();
|
||||
@@ -233,8 +233,9 @@ class RegisterMultiListenerTests {
|
||||
@Override
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).listener(listener()).<String, String>chunk(2)
|
||||
.transactionManager(transactionManager(dataSource())).reader(reader()).writer(writer()).build();
|
||||
return new StepBuilder("step", jobRepository).listener(listener())
|
||||
.<String, String>chunk(2, transactionManager(dataSource())).reader(reader()).writer(writer())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,18 +94,18 @@ class StepBuilderTests {
|
||||
|
||||
@Test
|
||||
void test() throws Exception {
|
||||
TaskletStepBuilder builder = new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> null).transactionManager(transactionManager);
|
||||
TaskletStepBuilder builder = new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> null, transactionManager);
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListeners() throws Exception {
|
||||
TaskletStepBuilder builder = new StepBuilder("step").repository(jobRepository)
|
||||
TaskletStepBuilder builder = new StepBuilder("step", jobRepository)
|
||||
.listener(new InterfaceBasedStepExecutionListener())
|
||||
.listener(new AnnotationBasedStepExecutionListener()).tasklet((contribution, chunkContext) -> null)
|
||||
.transactionManager(transactionManager);
|
||||
.listener(new AnnotationBasedStepExecutionListener())
|
||||
.tasklet((contribution, chunkContext) -> null, transactionManager);
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(1, InterfaceBasedStepExecutionListener.beforeStepCount);
|
||||
@@ -118,8 +118,8 @@ class StepBuilderTests {
|
||||
|
||||
@Test
|
||||
void testAnnotationBasedChunkListenerForTaskletStep() throws Exception {
|
||||
TaskletStepBuilder builder = new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> null).transactionManager(transactionManager)
|
||||
TaskletStepBuilder builder = new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> null, transactionManager)
|
||||
.listener(new AnnotationBasedChunkListener());
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -129,8 +129,8 @@ class StepBuilderTests {
|
||||
|
||||
@Test
|
||||
void testAnnotationBasedChunkListenerForSimpleTaskletStep() throws Exception {
|
||||
SimpleStepBuilder<Object, Object> builder = new StepBuilder("step").repository(jobRepository).chunk(5)
|
||||
.transactionManager(transactionManager).reader(new DummyItemReader()).writer(new DummyItemWriter())
|
||||
SimpleStepBuilder<Object, Object> builder = new StepBuilder("step", jobRepository).chunk(5, transactionManager)
|
||||
.reader(new DummyItemReader()).writer(new DummyItemWriter())
|
||||
.listener(new AnnotationBasedChunkListener());
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -140,13 +140,13 @@ class StepBuilderTests {
|
||||
|
||||
@Test
|
||||
void testAnnotationBasedChunkListenerForFaultTolerantTaskletStep() throws Exception {
|
||||
SimpleStepBuilder<Object, Object> builder = new StepBuilder("step").repository(jobRepository).chunk(5)
|
||||
.transactionManager(transactionManager).reader(new DummyItemReader()).writer(new DummyItemWriter())
|
||||
.faultTolerant().listener(new AnnotationBasedChunkListener()); // TODO//
|
||||
// should
|
||||
// this
|
||||
// return
|
||||
// FaultTolerantStepBuilder?
|
||||
SimpleStepBuilder<Object, Object> builder = new StepBuilder("step", jobRepository).chunk(5, transactionManager)
|
||||
.reader(new DummyItemReader()).writer(new DummyItemWriter()).faultTolerant()
|
||||
.listener(new AnnotationBasedChunkListener()); // TODO//
|
||||
// should
|
||||
// this
|
||||
// return
|
||||
// FaultTolerantStepBuilder?
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(1, AnnotationBasedChunkListener.beforeChunkCount);
|
||||
@@ -157,7 +157,7 @@ class StepBuilderTests {
|
||||
void testAnnotationBasedChunkListenerForJobStepBuilder() throws Exception {
|
||||
SimpleJob job = new SimpleJob("job");
|
||||
job.setJobRepository(jobRepository);
|
||||
JobStepBuilder builder = new StepBuilder("step").repository(jobRepository).job(job)
|
||||
JobStepBuilder builder = new StepBuilder("step", jobRepository).job(job)
|
||||
.listener(new AnnotationBasedChunkListener());
|
||||
builder.build().execute(execution);
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -174,10 +174,9 @@ class StepBuilderTests {
|
||||
|
||||
ItemReader<String> reader = new ListItemReader<>(items);
|
||||
|
||||
SimpleStepBuilder<String, String> builder = new StepBuilder("step").repository(jobRepository)
|
||||
.<String, String>chunk(3).transactionManager(transactionManager).reader(reader)
|
||||
.processor(new PassThroughItemProcessor<>()).writer(new DummyItemWriter())
|
||||
.listener(new AnnotationBasedStepExecutionListener());
|
||||
SimpleStepBuilder<String, String> builder = new StepBuilder("step", jobRepository)
|
||||
.<String, String>chunk(3, transactionManager).reader(reader).processor(new PassThroughItemProcessor<>())
|
||||
.writer(new DummyItemWriter()).listener(new AnnotationBasedStepExecutionListener());
|
||||
builder.build().execute(execution);
|
||||
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -209,9 +208,9 @@ class StepBuilderTests {
|
||||
ItemReader<Long> reader = new ListItemReader<>(items);
|
||||
|
||||
ListItemWriter<String> itemWriter = new ListItemWriter<>();
|
||||
SimpleStepBuilder<Object, String> builder = new StepBuilder("step").repository(jobRepository)
|
||||
.<Object, String>chunk(3).transactionManager(transactionManager).reader(reader)
|
||||
.processor(Object::toString).writer(itemWriter).listener(new AnnotationBasedStepExecutionListener());
|
||||
SimpleStepBuilder<Object, String> builder = new StepBuilder("step", jobRepository)
|
||||
.<Object, String>chunk(3, transactionManager).reader(reader).processor(Object::toString)
|
||||
.writer(itemWriter).listener(new AnnotationBasedStepExecutionListener());
|
||||
|
||||
if (faultTolerantStep) {
|
||||
builder = builder.faultTolerant();
|
||||
@@ -291,9 +290,8 @@ class StepBuilderTests {
|
||||
List<String> items = Arrays.asList("1", "2", "3");
|
||||
ItemReader<String> reader = new ListItemReader<>(items);
|
||||
|
||||
SimpleStepBuilder<String, String> builder = new StepBuilder("step").repository(jobRepository)
|
||||
.<String, String>chunk(3).transactionManager(transactionManager).reader(reader)
|
||||
.writer(new DummyItemWriter());
|
||||
SimpleStepBuilder<String, String> builder = new StepBuilder("step", jobRepository)
|
||||
.<String, String>chunk(3, transactionManager).reader(reader).writer(new DummyItemWriter());
|
||||
configurer.apply(builder).listener(new InterfaceBasedItemReadListenerListener()).build().execute(execution);
|
||||
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
|
||||
@@ -102,46 +102,46 @@ class ConcurrentTransactionTests {
|
||||
@Bean
|
||||
public Flow flow(JobRepository jobRepository) {
|
||||
return new FlowBuilder<Flow>("flow")
|
||||
.start(new StepBuilder("flow.step1").repository(jobRepository).tasklet(new Tasklet() {
|
||||
.start(new StepBuilder("flow.step1", jobRepository).tasklet(new Tasklet() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
|
||||
throws Exception {
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).transactionManager(getTransactionManager()).build())
|
||||
.next(new StepBuilder("flow.step2").repository(jobRepository).tasklet(new Tasklet() {
|
||||
}, getTransactionManager()).build())
|
||||
.next(new StepBuilder("flow.step2", jobRepository).tasklet(new Tasklet() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
|
||||
throws Exception {
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).transactionManager(getTransactionManager()).build()).build();
|
||||
}, getTransactionManager()).build()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step firstStep(JobRepository jobRepository) {
|
||||
return new StepBuilder("firstStep").repository(jobRepository).tasklet(new Tasklet() {
|
||||
return new StepBuilder("firstStep", jobRepository).tasklet(new Tasklet() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println(">> Beginning concurrent job test");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).transactionManager(getTransactionManager()).build();
|
||||
}, getTransactionManager()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step lastStep(JobRepository jobRepository) {
|
||||
return new StepBuilder("lastStep").repository(jobRepository).tasklet(new Tasklet() {
|
||||
return new StepBuilder("lastStep", jobRepository).tasklet(new Tasklet() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println(">> Ending concurrent job test");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).transactionManager(getTransactionManager()).build();
|
||||
}, getTransactionManager()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -151,8 +151,8 @@ class ConcurrentTransactionTests {
|
||||
flow(jobRepository), flow(jobRepository), flow(jobRepository))
|
||||
.build();
|
||||
|
||||
return new JobBuilder("concurrentJob").repository(jobRepository).start(firstStep(jobRepository))
|
||||
.next(new StepBuilder("splitFlowStep").repository(jobRepository).flow(splitFlow).build())
|
||||
return new JobBuilder("concurrentJob", jobRepository).start(firstStep(jobRepository))
|
||||
.next(new StepBuilder("splitFlowStep", jobRepository).flow(splitFlow).build())
|
||||
.next(lastStep(jobRepository)).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -114,10 +114,9 @@ class Db2JobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,10 +84,9 @@ class DerbyJobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,9 @@ class H2CompatibilityModeJobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,10 +84,9 @@ class H2JobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,9 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.jdbc.support.JdbcTransactionManager;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import org.testcontainers.containers.JdbcDatabaseContainer;
|
||||
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
|
||||
@@ -121,9 +123,15 @@ class HANAJobRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step")
|
||||
.repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
|
||||
public JdbcTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new JdbcTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,10 +84,9 @@ class HSQLDBJobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -139,10 +139,10 @@ class MySQLJdbcJobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
throw new Exception("expected failure");
|
||||
}).transactionManager(transactionManager).build()).build();
|
||||
}, transactionManager).build()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -111,10 +111,9 @@ class MySQLJobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.jdbc.support.JdbcTransactionManager;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -111,9 +113,15 @@ class OracleJobRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step")
|
||||
.repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
|
||||
public JdbcTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new JdbcTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -110,10 +110,9 @@ class PostgreSQLJobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -111,10 +111,9 @@ class SQLServerJobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -91,10 +91,9 @@ class SQLiteJobRepositoryIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager).build())
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,9 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.jdbc.support.JdbcTransactionManager;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -105,9 +107,15 @@ class SybaseJobRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step")
|
||||
.repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
|
||||
public JdbcTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new JdbcTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,9 +77,8 @@ class FaultTolerantStepIntegrationTests {
|
||||
}
|
||||
};
|
||||
skipPolicy = new SkipIllegalArgumentExceptionSkipPolicy();
|
||||
stepBuilder = new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(CHUNK_SIZE)
|
||||
.transactionManager(transactionManager).reader(itemReader).processor(item -> item > 20 ? null : item)
|
||||
.writer(itemWriter).faultTolerant();
|
||||
stepBuilder = new StepBuilder("step", jobRepository).<Integer, Integer>chunk(CHUNK_SIZE, transactionManager)
|
||||
.reader(itemReader).processor(item -> item > 20 ? null : item).writer(itemWriter).faultTolerant();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,9 +177,9 @@ class FaultTolerantStepIntegrationTests {
|
||||
}
|
||||
};
|
||||
|
||||
Step step = new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(5)
|
||||
.transactionManager(transactionManager).reader(itemReader).processor(itemProcessor).writer(itemWriter)
|
||||
.faultTolerant().skip(Exception.class).skipLimit(3).build();
|
||||
Step step = new StepBuilder("step", jobRepository).<Integer, Integer>chunk(5, transactionManager)
|
||||
.reader(itemReader).processor(itemProcessor).writer(itemWriter).faultTolerant().skip(Exception.class)
|
||||
.skipLimit(3).build();
|
||||
|
||||
// When
|
||||
StepExecution stepExecution = execute(step);
|
||||
@@ -218,9 +217,9 @@ class FaultTolerantStepIntegrationTests {
|
||||
}
|
||||
};
|
||||
|
||||
Step step = new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(5)
|
||||
.transactionManager(transactionManager).reader(itemReader).processor(itemProcessor).writer(itemWriter)
|
||||
.faultTolerant().skipPolicy(new AlwaysSkipItemSkipPolicy()).build();
|
||||
Step step = new StepBuilder("step", jobRepository).<Integer, Integer>chunk(5, transactionManager)
|
||||
.reader(itemReader).processor(itemProcessor).writer(itemWriter).faultTolerant()
|
||||
.skipPolicy(new AlwaysSkipItemSkipPolicy()).build();
|
||||
|
||||
// When
|
||||
StepExecution stepExecution = execute(step);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -85,11 +85,23 @@ public class RemoteChunkingManagerStepBuilder<I, O> extends FaultTolerantStepBui
|
||||
/**
|
||||
* Create a new {@link RemoteChunkingManagerStepBuilder}.
|
||||
* @param stepName name of the manager step
|
||||
* @deprecated use {@link }
|
||||
*/
|
||||
@Deprecated(since = "5.0")
|
||||
public RemoteChunkingManagerStepBuilder(String stepName) {
|
||||
super(new StepBuilder(stepName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link RemoteChunkingManagerStepBuilder}.
|
||||
* @param stepName name of the manager step
|
||||
* @param jobRepository the job repository the step should report to
|
||||
* @since 5.0
|
||||
*/
|
||||
public RemoteChunkingManagerStepBuilder(String stepName, JobRepository jobRepository) {
|
||||
super(new StepBuilder(stepName, jobRepository));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the input channel on which replies from workers will be received. The provided
|
||||
* input channel will be set as a reply channel on the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,7 +52,7 @@ public class RemoteChunkingManagerStepBuilderFactory {
|
||||
* @return a {@link RemoteChunkingManagerStepBuilder}
|
||||
*/
|
||||
public <I, O> RemoteChunkingManagerStepBuilder<I, O> get(String name) {
|
||||
return new RemoteChunkingManagerStepBuilder<I, O>(name).repository(this.jobRepository)
|
||||
return new RemoteChunkingManagerStepBuilder<I, O>(name, this.jobRepository)
|
||||
.transactionManager(this.transactionManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,11 +82,24 @@ public class RemotePartitioningManagerStepBuilder extends PartitionStepBuilder {
|
||||
/**
|
||||
* Create a new {@link RemotePartitioningManagerStepBuilder}.
|
||||
* @param stepName name of the manager step
|
||||
* @deprecated use
|
||||
* {@link RemotePartitioningManagerStepBuilder#RemotePartitioningManagerStepBuilder(String, JobRepository)}
|
||||
*/
|
||||
@Deprecated
|
||||
public RemotePartitioningManagerStepBuilder(String stepName) {
|
||||
super(new StepBuilder(stepName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link RemotePartitioningManagerStepBuilder}.
|
||||
* @param stepName name of the manager step
|
||||
* @param jobRepository job repository to which the step should report to
|
||||
* @since 5.0
|
||||
*/
|
||||
public RemotePartitioningManagerStepBuilder(String stepName, JobRepository jobRepository) {
|
||||
super(new StepBuilder(stepName, jobRepository));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the input channel on which replies from workers will be received.
|
||||
* @param inputChannel the input channel
|
||||
|
||||
@@ -62,8 +62,8 @@ public class RemotePartitioningManagerStepBuilderFactory implements BeanFactoryA
|
||||
* @return a {@link RemotePartitioningManagerStepBuilder}
|
||||
*/
|
||||
public RemotePartitioningManagerStepBuilder get(String name) {
|
||||
return new RemotePartitioningManagerStepBuilder(name).repository(this.jobRepository)
|
||||
.jobExplorer(this.jobExplorer).beanFactory(this.beanFactory);
|
||||
return new RemotePartitioningManagerStepBuilder(name, this.jobRepository).jobExplorer(this.jobExplorer)
|
||||
.beanFactory(this.beanFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -83,11 +83,24 @@ public class RemotePartitioningWorkerStepBuilder extends StepBuilder {
|
||||
/**
|
||||
* Initialize a step builder for a step with the given name.
|
||||
* @param name the name of the step
|
||||
* @deprecated use
|
||||
* {@link RemotePartitioningWorkerStepBuilder#RemotePartitioningWorkerStepBuilder(String, JobRepository)}
|
||||
*/
|
||||
@Deprecated(since = "5.0")
|
||||
public RemotePartitioningWorkerStepBuilder(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a step builder for a step with the given name.
|
||||
* @param name the name of the step
|
||||
* @param jobRepository the job repository to which the step should report to
|
||||
* @since 5.0
|
||||
*/
|
||||
public RemotePartitioningWorkerStepBuilder(String name, JobRepository jobRepository) {
|
||||
super(name, jobRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the input channel on which step execution requests sent by the manager are
|
||||
* received.
|
||||
@@ -174,24 +187,46 @@ public class RemotePartitioningWorkerStepBuilder extends StepBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated(since = "5.0")
|
||||
@Override
|
||||
public TaskletStepBuilder tasklet(Tasklet tasklet) {
|
||||
configureWorkerIntegrationFlow();
|
||||
return super.tasklet(tasklet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskletStepBuilder tasklet(Tasklet tasklet, PlatformTransactionManager transactionManager) {
|
||||
configureWorkerIntegrationFlow();
|
||||
return super.tasklet(tasklet, transactionManager);
|
||||
}
|
||||
|
||||
@Deprecated(since = "5.0")
|
||||
@Override
|
||||
public <I, O> SimpleStepBuilder<I, O> chunk(int chunkSize) {
|
||||
configureWorkerIntegrationFlow();
|
||||
return super.chunk(chunkSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <I, O> SimpleStepBuilder<I, O> chunk(int chunkSize, PlatformTransactionManager transactionManager) {
|
||||
configureWorkerIntegrationFlow();
|
||||
return super.chunk(chunkSize, transactionManager);
|
||||
}
|
||||
|
||||
@Deprecated(since = "5.0")
|
||||
@Override
|
||||
public <I, O> SimpleStepBuilder<I, O> chunk(CompletionPolicy completionPolicy) {
|
||||
configureWorkerIntegrationFlow();
|
||||
return super.chunk(completionPolicy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <I, O> SimpleStepBuilder<I, O> chunk(CompletionPolicy completionPolicy,
|
||||
PlatformTransactionManager transactionManager) {
|
||||
configureWorkerIntegrationFlow();
|
||||
return super.chunk(completionPolicy, transactionManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartitionStepBuilder partitioner(String stepName, Partitioner partitioner) {
|
||||
configureWorkerIntegrationFlow();
|
||||
|
||||
@@ -62,8 +62,8 @@ public class RemotePartitioningWorkerStepBuilderFactory implements BeanFactoryAw
|
||||
* @return a {@link RemotePartitioningWorkerStepBuilder}
|
||||
*/
|
||||
public RemotePartitioningWorkerStepBuilder get(String name) {
|
||||
return new RemotePartitioningWorkerStepBuilder(name).repository(this.jobRepository)
|
||||
.jobExplorer(this.jobExplorer).beanFactory(this.beanFactory);
|
||||
return new RemotePartitioningWorkerStepBuilder(name, this.jobRepository).jobExplorer(this.jobExplorer)
|
||||
.beanFactory(this.beanFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,8 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
void inputChannelMustNotBeNull() {
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step").inputChannel(null).build());
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step", this.jobRepository)
|
||||
.inputChannel(null).build());
|
||||
|
||||
// then
|
||||
assertThat(expectedException).hasMessage("inputChannel must not be null");
|
||||
@@ -106,7 +107,8 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
void outputChannelMustNotBeNull() {
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step").outputChannel(null).build());
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step", this.jobRepository)
|
||||
.outputChannel(null).build());
|
||||
|
||||
// then
|
||||
assertThat(expectedException).hasMessage("outputChannel must not be null");
|
||||
@@ -116,7 +118,8 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
void messagingTemplateMustNotBeNull() {
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step").messagingTemplate(null).build());
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step", this.jobRepository)
|
||||
.messagingTemplate(null).build());
|
||||
|
||||
// then
|
||||
assertThat(expectedException).hasMessage("messagingTemplate must not be null");
|
||||
@@ -126,7 +129,8 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
void maxWaitTimeoutsMustBeGreaterThanZero() {
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step").maxWaitTimeouts(-1).build());
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step", this.jobRepository)
|
||||
.maxWaitTimeouts(-1).build());
|
||||
|
||||
// then
|
||||
assertThat(expectedException).hasMessage("maxWaitTimeouts must be greater than zero");
|
||||
@@ -136,7 +140,8 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
void throttleLimitMustNotBeGreaterThanZero() {
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step").throttleLimit(-1L).build());
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step", this.jobRepository)
|
||||
.throttleLimit(-1L).build());
|
||||
|
||||
// then
|
||||
assertThat(expectedException).hasMessage("throttleLimit must be greater than zero");
|
||||
@@ -145,7 +150,8 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
@Test
|
||||
void testMandatoryInputChannel() {
|
||||
// given
|
||||
RemoteChunkingManagerStepBuilder<String, String> builder = new RemoteChunkingManagerStepBuilder<>("step");
|
||||
RemoteChunkingManagerStepBuilder<String, String> builder = new RemoteChunkingManagerStepBuilder<>("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
@@ -158,7 +164,7 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
void eitherOutputChannelOrMessagingTemplateMustBeProvided() {
|
||||
// given
|
||||
RemoteChunkingManagerStepBuilder<String, String> builder = new RemoteChunkingManagerStepBuilder<String, String>(
|
||||
"step").inputChannel(this.inputChannel).outputChannel(new DirectChannel())
|
||||
"step", this.jobRepository).inputChannel(this.inputChannel).outputChannel(new DirectChannel())
|
||||
.messagingTemplate(new MessagingTemplate());
|
||||
|
||||
// when
|
||||
@@ -173,8 +179,8 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
void testUnsupportedOperationExceptionWhenSpecifyingAnItemWriter() {
|
||||
// when
|
||||
final Exception expectedException = assertThrows(UnsupportedOperationException.class,
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step").reader(this.itemReader)
|
||||
.writer(items -> {
|
||||
() -> new RemoteChunkingManagerStepBuilder<String, String>("step", this.jobRepository)
|
||||
.reader(this.itemReader).writer(items -> {
|
||||
}).repository(this.jobRepository).transactionManager(this.transactionManager)
|
||||
.inputChannel(this.inputChannel).outputChannel(this.outputChannel).build());
|
||||
|
||||
@@ -188,9 +194,9 @@ class RemoteChunkingManagerStepBuilderTests {
|
||||
@Test
|
||||
void testManagerStepCreation() {
|
||||
// when
|
||||
TaskletStep taskletStep = new RemoteChunkingManagerStepBuilder<String, String>("step").reader(this.itemReader)
|
||||
.repository(this.jobRepository).transactionManager(this.transactionManager)
|
||||
.inputChannel(this.inputChannel).outputChannel(this.outputChannel).build();
|
||||
TaskletStep taskletStep = new RemoteChunkingManagerStepBuilder<String, String>("step", this.jobRepository)
|
||||
.reader(this.itemReader).transactionManager(this.transactionManager).inputChannel(this.inputChannel)
|
||||
.outputChannel(this.outputChannel).build();
|
||||
|
||||
// then
|
||||
assertNotNull(taskletStep);
|
||||
|
||||
@@ -55,7 +55,8 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
@Test
|
||||
void inputChannelMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -68,7 +69,8 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
@Test
|
||||
void outputChannelMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -81,7 +83,8 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
@Test
|
||||
void messagingTemplateMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -94,7 +97,8 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
@Test
|
||||
void jobExplorerMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -107,7 +111,8 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
@Test
|
||||
void pollIntervalMustBeGreaterThanZero() {
|
||||
// given
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -120,8 +125,8 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
@Test
|
||||
void eitherOutputChannelOrMessagingTemplateMustBeProvided() {
|
||||
// given
|
||||
RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step")
|
||||
.outputChannel(new DirectChannel()).messagingTemplate(new MessagingTemplate());
|
||||
RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step",
|
||||
this.jobRepository).outputChannel(new DirectChannel()).messagingTemplate(new MessagingTemplate());
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalStateException.class, builder::build);
|
||||
@@ -135,7 +140,8 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
void testUnsupportedOperationExceptionWhenSpecifyingPartitionHandler() {
|
||||
// given
|
||||
PartitionHandler partitionHandler = Mockito.mock(PartitionHandler.class);
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(UnsupportedOperationException.class,
|
||||
@@ -161,7 +167,7 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
};
|
||||
|
||||
// when
|
||||
Step step = new RemotePartitioningManagerStepBuilder("managerStep").repository(jobRepository)
|
||||
Step step = new RemotePartitioningManagerStepBuilder("managerStep", this.jobRepository)
|
||||
.outputChannel(outputChannel).partitioner("workerStep", partitioner).gridSize(gridSize)
|
||||
.pollInterval(pollInterval).timeout(timeout).startLimit(startLimit).aggregator(stepExecutionAggregator)
|
||||
.allowStartIfComplete(true).build();
|
||||
@@ -198,7 +204,7 @@ class RemotePartitioningManagerStepBuilderTests {
|
||||
};
|
||||
|
||||
// when
|
||||
Step step = new RemotePartitioningManagerStepBuilder("managerStep").repository(jobRepository)
|
||||
Step step = new RemotePartitioningManagerStepBuilder("managerStep", this.jobRepository)
|
||||
.outputChannel(outputChannel).partitioner("workerStep", partitioner).gridSize(gridSize)
|
||||
.startLimit(startLimit).aggregator(stepExecutionAggregator).allowStartIfComplete(true).build();
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@ package org.springframework.batch.integration.partition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -33,10 +35,17 @@ class RemotePartitioningWorkerStepBuilderTests {
|
||||
@Mock
|
||||
private Tasklet tasklet;
|
||||
|
||||
@Mock
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Mock
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@Test
|
||||
void inputChannelMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step");
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -49,7 +58,8 @@ class RemotePartitioningWorkerStepBuilderTests {
|
||||
@Test
|
||||
void outputChannelMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step");
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -62,7 +72,8 @@ class RemotePartitioningWorkerStepBuilderTests {
|
||||
@Test
|
||||
void jobExplorerMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step");
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -75,7 +86,8 @@ class RemotePartitioningWorkerStepBuilderTests {
|
||||
@Test
|
||||
void stepLocatorMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step");
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -88,7 +100,8 @@ class RemotePartitioningWorkerStepBuilderTests {
|
||||
@Test
|
||||
void beanFactoryMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step");
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
@@ -101,11 +114,12 @@ class RemotePartitioningWorkerStepBuilderTests {
|
||||
@Test
|
||||
void testMandatoryInputChannel() {
|
||||
// given
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step");
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step",
|
||||
this.jobRepository);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.tasklet(this.tasklet));
|
||||
() -> builder.tasklet(this.tasklet, this.transactionManager));
|
||||
|
||||
// then
|
||||
assertThat(expectedException).hasMessage("An InputChannel must be provided");
|
||||
@@ -115,12 +129,12 @@ class RemotePartitioningWorkerStepBuilderTests {
|
||||
void testMandatoryJobExplorer() {
|
||||
// given
|
||||
DirectChannel inputChannel = new DirectChannel();
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step")
|
||||
.inputChannel(inputChannel);
|
||||
final RemotePartitioningWorkerStepBuilder builder = new RemotePartitioningWorkerStepBuilder("step",
|
||||
this.jobRepository).inputChannel(inputChannel);
|
||||
|
||||
// when
|
||||
final Exception expectedException = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.tasklet(this.tasklet));
|
||||
() -> builder.tasklet(this.tasklet, this.transactionManager));
|
||||
|
||||
// then
|
||||
assertThat(expectedException).hasMessage("A JobExplorer must be provided");
|
||||
|
||||
@@ -45,14 +45,13 @@ public class RetrySampleConfiguration {
|
||||
|
||||
@Bean
|
||||
public Job retrySample(JobRepository jobRepository) {
|
||||
return new JobBuilder("retrySample").repository(jobRepository).start(step(jobRepository)).build();
|
||||
return new JobBuilder("retrySample", jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Trade, Object>chunk(1)
|
||||
.transactionManager(this.transactionManager).reader(reader()).writer(writer()).faultTolerant()
|
||||
.retry(Exception.class).retryLimit(3).build();
|
||||
return new StepBuilder("step", jobRepository).<Trade, Object>chunk(1, this.transactionManager).reader(reader())
|
||||
.writer(writer()).faultTolerant().retry(Exception.class).retryLimit(3).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
@Configuration
|
||||
public class Job1Configuration {
|
||||
@@ -36,24 +37,24 @@ public class Job1Configuration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job1(JobRepository jobRepository) {
|
||||
return new JobBuilder("job1").repository(jobRepository).start(step1(jobRepository)).next(step2(jobRepository))
|
||||
.build();
|
||||
public Job job1(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job1", jobRepository).start(step1(jobRepository, transactionManager))
|
||||
.next(step2(jobRepository, transactionManager)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step1(JobRepository jobRepository) {
|
||||
return new StepBuilder("step1").repository(jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
public Step step1(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("hello");
|
||||
// simulate processing time
|
||||
Thread.sleep(random.nextInt(3000));
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build();
|
||||
}, transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step2(JobRepository jobRepository) {
|
||||
return new StepBuilder("step2").repository(jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
public Step step2(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new StepBuilder("step2", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("world");
|
||||
// simulate step failure
|
||||
int nextInt = random.nextInt(3000);
|
||||
@@ -62,7 +63,7 @@ public class Job1Configuration {
|
||||
throw new Exception("Boom!");
|
||||
}
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build();
|
||||
}, transactionManager).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
@Configuration
|
||||
public class Job2Configuration {
|
||||
@@ -40,14 +41,14 @@ public class Job2Configuration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job2(JobRepository jobRepository) {
|
||||
return new JobBuilder("job2").repository(jobRepository).start(step(jobRepository)).build();
|
||||
public Job job2(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job2", jobRepository).start(step(jobRepository, transactionManager)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step1").repository(jobRepository).<Integer, Integer>chunk(3).reader(itemReader())
|
||||
.writer(itemWriter()).build();
|
||||
public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new StepBuilder("step1", jobRepository).<Integer, Integer>chunk(3, transactionManager)
|
||||
.reader(itemReader()).writer(itemWriter()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.where;
|
||||
|
||||
@@ -60,15 +61,15 @@ public class DeletionJobConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step deletionStep(JobRepository jobRepository, MongoItemReader<Person> mongoPersonReader,
|
||||
MongoItemWriter<Person> mongoPersonRemover) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Person, Person>chunk(2).reader(mongoPersonReader)
|
||||
.writer(mongoPersonRemover).build();
|
||||
public Step deletionStep(JobRepository jobRepository, PlatformTransactionManager transactionManager,
|
||||
MongoItemReader<Person> mongoPersonReader, MongoItemWriter<Person> mongoPersonRemover) {
|
||||
return new StepBuilder("step", jobRepository).<Person, Person>chunk(2, transactionManager)
|
||||
.reader(mongoPersonReader).writer(mongoPersonRemover).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job deletionJob(JobRepository jobRepository, Step deletionStep) {
|
||||
return new JobBuilder("deletionJob").repository(jobRepository).start(deletionStep).build();
|
||||
return new JobBuilder("deletionJob", jobRepository).start(deletionStep).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.batch.item.data.builder.MongoItemWriterBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
/**
|
||||
* This job will copy documents from collection "person_in" into collection "person_out"
|
||||
@@ -55,15 +56,15 @@ public class InsertionJobConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository, MongoItemReader<Person> mongoItemReader,
|
||||
MongoItemWriter<Person> mongoItemWriter) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Person, Person>chunk(2).reader(mongoItemReader)
|
||||
.writer(mongoItemWriter).build();
|
||||
public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager,
|
||||
MongoItemReader<Person> mongoItemReader, MongoItemWriter<Person> mongoItemWriter) {
|
||||
return new StepBuilder("step", jobRepository).<Person, Person>chunk(2, transactionManager)
|
||||
.reader(mongoItemReader).writer(mongoItemWriter).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job insertionJob(JobRepository jobRepository, Step step) {
|
||||
return new JobBuilder("insertionJob").repository(jobRepository).start(step).build();
|
||||
return new JobBuilder("insertionJob", jobRepository).start(step).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
* Copyright 2020-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,10 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.MongoTransactionManager;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:/mongodb-sample.properties")
|
||||
@@ -38,10 +41,24 @@ public class MongoDBConfiguration {
|
||||
private String mongodbDatabase;
|
||||
|
||||
@Bean
|
||||
public MongoTemplate mongoTemplate() {
|
||||
public MongoClient mongoClient() {
|
||||
String connectionString = "mongodb://" + this.mongodbHost + ":" + this.mongodbPort + "/" + this.mongodbDatabase;
|
||||
MongoClient mongoClient = MongoClients.create(connectionString);
|
||||
return MongoClients.create(connectionString);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MongoTemplate mongoTemplate(MongoClient mongoClient) {
|
||||
return new MongoTemplate(mongoClient, "test");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MongoDatabaseFactory mongoDatabaseFactory(MongoClient mongoClient) {
|
||||
return new SimpleMongoClientDatabaseFactory(mongoClient, "test");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MongoTransactionManager transactionManager(MongoDatabaseFactory mongoDatabaseFactory) {
|
||||
return new MongoTransactionManager(mongoDatabaseFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class ManagerConfiguration {
|
||||
|
||||
@Bean
|
||||
public Job remoteChunkingJob(JobRepository jobRepository) {
|
||||
return new JobBuilder("remoteChunkingJob").repository(jobRepository).start(managerStep()).build();
|
||||
return new JobBuilder("remoteChunkingJob", jobRepository).start(managerStep()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class ManagerConfiguration {
|
||||
|
||||
@Bean
|
||||
public Job remotePartitioningJob(JobRepository jobRepository) {
|
||||
return new JobBuilder("remotePartitioningJob").repository(jobRepository).start(managerStep()).build();
|
||||
return new JobBuilder("remotePartitioningJob", jobRepository).start(managerStep()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class WorkerConfiguration {
|
||||
@Bean
|
||||
public Step workerStep(PlatformTransactionManager transactionManager) {
|
||||
return this.workerStepBuilderFactory.get("workerStep").inputChannel(requests()).outputChannel(replies())
|
||||
.tasklet(tasklet(null)).transactionManager(transactionManager).build();
|
||||
.tasklet(tasklet(null), transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ManagerConfiguration {
|
||||
|
||||
@Bean
|
||||
public Job remotePartitioningJob(JobRepository jobRepository) {
|
||||
return new JobBuilder("remotePartitioningJob").repository(jobRepository).start(managerStep()).build();
|
||||
return new JobBuilder("remotePartitioningJob", jobRepository).start(managerStep()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ public class WorkerConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
public Step workerStep(PlatformTransactionManager transactionManager) {
|
||||
return this.workerStepBuilderFactory.get("workerStep").inputChannel(requests()).tasklet(tasklet(null))
|
||||
.transactionManager(transactionManager).build();
|
||||
return this.workerStepBuilderFactory.get("workerStep").inputChannel(requests())
|
||||
.tasklet(tasklet(null), transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -83,14 +83,14 @@ public class SkippableExceptionDuringProcessSample {
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(3)
|
||||
.transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor())
|
||||
.writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
return new StepBuilder("step", jobRepository).<Integer, Integer>chunk(3, this.transactionManager)
|
||||
.reader(itemReader()).processor(itemProcessor()).writer(itemWriter()).faultTolerant()
|
||||
.skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
return new JobBuilder("job", jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -83,14 +83,14 @@ public class SkippableExceptionDuringReadSample {
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(3)
|
||||
.transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor())
|
||||
.writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
return new StepBuilder("step", jobRepository).<Integer, Integer>chunk(3, this.transactionManager)
|
||||
.reader(itemReader()).processor(itemProcessor()).writer(itemWriter()).faultTolerant()
|
||||
.skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
return new JobBuilder("job", jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -83,14 +83,14 @@ public class SkippableExceptionDuringWriteSample {
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(3)
|
||||
.transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor())
|
||||
.writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
return new StepBuilder("step", jobRepository).<Integer, Integer>chunk(3, this.transactionManager)
|
||||
.reader(itemReader()).processor(itemProcessor()).writer(itemWriter()).faultTolerant()
|
||||
.skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
return new JobBuilder("job", jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,14 +66,13 @@ public class ValidationSampleConfiguration {
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) throws Exception {
|
||||
return new StepBuilder("step").repository(jobRepository).<Person, Person>chunk(1)
|
||||
.transactionManager(transactionManager(dataSource())).reader(itemReader()).processor(itemValidator())
|
||||
.writer(itemWriter()).build();
|
||||
return new StepBuilder("step", jobRepository).<Person, Person>chunk(1, transactionManager(dataSource()))
|
||||
.reader(itemReader()).processor(itemValidator()).writer(itemWriter()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) throws Exception {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
return new JobBuilder("job", jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -90,14 +90,13 @@ class JsonSupportIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Trade, Trade>chunk(2)
|
||||
.transactionManager(transactionManager(dataSource())).reader(itemReader()).writer(itemWriter())
|
||||
.build();
|
||||
return new StepBuilder("step", jobRepository).<Trade, Trade>chunk(2, transactionManager(dataSource()))
|
||||
.reader(itemReader()).writer(itemWriter()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
return new JobBuilder("job", jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -82,18 +82,18 @@ class JobLauncherTestUtilsTests {
|
||||
|
||||
@Bean
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step1").repository(jobRepository).tasklet(new Tasklet() {
|
||||
return new StepBuilder("step1", jobRepository).tasklet(new Tasklet() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
return null;
|
||||
}
|
||||
}).transactionManager(transactionManager(dataSource())).build();
|
||||
}, transactionManager(dataSource())).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).flow(step(jobRepository)).end().build();
|
||||
return new JobBuilder("job", jobRepository).flow(step(jobRepository)).end().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -145,11 +145,9 @@ public class SpringBatchTestJUnit4Tests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager(dataSource())).build())
|
||||
.build();
|
||||
return new JobBuilder("job", jobRepository).start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager(dataSource()))
|
||||
.build()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -145,11 +145,9 @@ public class SpringBatchTestJUnit5Tests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository)
|
||||
.start(new StepBuilder("step").repository(jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
|
||||
.transactionManager(transactionManager(dataSource())).build())
|
||||
.build();
|
||||
return new JobBuilder("job", jobRepository).start(new StepBuilder("step", jobRepository)
|
||||
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager(dataSource()))
|
||||
.build()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -123,15 +123,13 @@ class StepScopeAnnotatedListenerIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Job jobUnderTest(JobRepository jobRepository) {
|
||||
return new JobBuilder("job-under-test").repository(jobRepository).start(stepUnderTest(jobRepository))
|
||||
.build();
|
||||
return new JobBuilder("job-under-test", jobRepository).start(stepUnderTest(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step stepUnderTest(JobRepository jobRepository) {
|
||||
return new StepBuilder("step-under-test").repository(jobRepository).<String, String>chunk(1)
|
||||
.transactionManager(this.transactionManager).reader(reader()).processor(processor())
|
||||
.writer(writer()).build();
|
||||
return new StepBuilder("step-under-test", jobRepository).<String, String>chunk(1, this.transactionManager)
|
||||
.reader(reader()).processor(processor()).writer(writer()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user