From f39f07075aced80ad06b9061b6daf6fedd9dee8b Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Sat, 17 Sep 2022 22:31:12 +0200 Subject: [PATCH] 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 --- .../annotation/JobBuilderFactory.java | 2 +- .../annotation/StepBuilderFactory.java | 2 +- .../xml/StepParserStepFactoryBean.java | 18 ++-- .../batch/core/job/builder/JobBuilder.java | 17 +++- .../batch/core/step/builder/StepBuilder.java | 82 ++++++++++++++++++- .../core/step/builder/TaskletStepBuilder.java | 16 ++++ .../factory/FaultTolerantStepFactoryBean.java | 4 +- .../step/factory/SimpleStepFactoryBean.java | 7 +- .../InlineDataSourceDefinitionTests.java | 15 +++- .../JobBuilderConfigurationTests.java | 22 ++--- .../JobLoaderConfigurationTests.java | 16 ++-- .../SimpleJobExplorerIntegrationTests.java | 4 +- .../core/job/builder/FlowJobBuilderTests.java | 36 ++++---- .../core/job/builder/JobBuilderTests.java | 7 +- .../core/listener/ItemListenerErrorTests.java | 10 +-- .../core/observability/BatchMetricsTests.java | 15 ++-- .../FaultTolerantStepBuilderTests.java | 12 +-- .../builder/RegisterMultiListenerTests.java | 11 +-- .../core/step/builder/StepBuilderTests.java | 52 ++++++------ .../ConcurrentTransactionTests.java | 20 ++--- .../Db2JobRepositoryIntegrationTests.java | 7 +- .../DerbyJobRepositoryIntegrationTests.java | 7 +- ...lityModeJobRepositoryIntegrationTests.java | 7 +- .../H2JobRepositoryIntegrationTests.java | 7 +- .../HANAJobRepositoryIntegrationTests.java | 14 +++- .../HSQLDBJobRepositoryIntegrationTests.java | 7 +- ...ySQLJdbcJobRepositoryIntegrationTests.java | 6 +- .../MySQLJobRepositoryIntegrationTests.java | 7 +- .../OracleJobRepositoryIntegrationTests.java | 14 +++- ...stgreSQLJobRepositoryIntegrationTests.java | 7 +- ...QLServerJobRepositoryIntegrationTests.java | 7 +- .../SQLiteJobRepositoryIntegrationTests.java | 7 +- .../SybaseJobRepositoryIntegrationTests.java | 14 +++- .../FaultTolerantStepIntegrationTests.java | 17 ++-- .../RemoteChunkingManagerStepBuilder.java | 14 +++- ...moteChunkingManagerStepBuilderFactory.java | 4 +- .../RemotePartitioningManagerStepBuilder.java | 13 +++ ...PartitioningManagerStepBuilderFactory.java | 4 +- .../RemotePartitioningWorkerStepBuilder.java | 35 ++++++++ ...ePartitioningWorkerStepBuilderFactory.java | 4 +- ...RemoteChunkingManagerStepBuilderTests.java | 30 ++++--- ...tePartitioningManagerStepBuilderTests.java | 26 +++--- ...otePartitioningWorkerStepBuilderTests.java | 34 +++++--- .../config/RetrySampleConfiguration.java | 7 +- .../sample/metrics/Job1Configuration.java | 19 +++-- .../sample/metrics/Job2Configuration.java | 11 +-- .../mongodb/DeletionJobConfiguration.java | 11 +-- .../mongodb/InsertionJobConfiguration.java | 11 +-- .../sample/mongodb/MongoDBConfiguration.java | 23 +++++- .../remotechunking/ManagerConfiguration.java | 2 +- .../aggregating/ManagerConfiguration.java | 2 +- .../aggregating/WorkerConfiguration.java | 2 +- .../polling/ManagerConfiguration.java | 2 +- .../polling/WorkerConfiguration.java | 4 +- ...SkippableExceptionDuringProcessSample.java | 8 +- .../SkippableExceptionDuringReadSample.java | 8 +- .../SkippableExceptionDuringWriteSample.java | 8 +- .../ValidationSampleConfiguration.java | 7 +- .../sample/JsonSupportIntegrationTests.java | 7 +- .../batch/test/JobLauncherTestUtilsTests.java | 6 +- .../test/SpringBatchTestJUnit4Tests.java | 8 +- .../test/SpringBatchTestJUnit5Tests.java | 8 +- ...copeAnnotatedListenerIntegrationTests.java | 8 +- 63 files changed, 520 insertions(+), 302 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobBuilderFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobBuilderFactory.java index 92965da77..c5f5e4b0a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobBuilderFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/JobBuilderFactory.java @@ -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); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepBuilderFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepBuilderFactory.java index e7f76ba86..32476fa05 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepBuilderFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/StepBuilderFactory.java @@ -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); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java index 6c505cf20..5a81c41ca 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java @@ -274,7 +274,6 @@ public class StepParserStepFactoryBean implements FactoryBean, 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 implements FactoryBean, 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 implements FactoryBean, BeanN * @return the {@link FaultTolerantStepBuilder}. */ protected FaultTolerantStepBuilder getFaultTolerantStepBuilder(String stepName) { - return new FaultTolerantStepBuilder<>(new StepBuilder(stepName)); + return new FaultTolerantStepBuilder<>(new StepBuilder(stepName, jobRepository)); } protected void registerItemListeners(SimpleStepBuilder builder) { @@ -445,7 +445,7 @@ public class StepParserStepFactoryBean implements FactoryBean, BeanN } protected SimpleStepBuilder getSimpleStepBuilder(String stepName) { - return new SimpleStepBuilder<>(new StepBuilder(stepName)); + return new SimpleStepBuilder<>(new StepBuilder(stepName, jobRepository)); } /** @@ -453,8 +453,8 @@ public class StepParserStepFactoryBean implements FactoryBean, 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 implements FactoryBean, 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); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/JobBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/JobBuilder.java index 4ead859e8..93ef4c63d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/JobBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/JobBuilder.java @@ -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 { /** * 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 diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/StepBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/StepBuilder.java index 8ef8ff959..a6982ebc9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/StepBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/StepBuilder.java @@ -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 { @@ -34,20 +37,46 @@ public class StepBuilder extends StepBuilderHelper { /** * 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 { * @return a {@link SimpleStepBuilder} * @param the type of item to be processed as input * @param the type of item to be output + * @deprecated use {@link StepBuilder#chunk(int, PlatformTransactionManager)} */ + @Deprecated(since = "5.0") public SimpleStepBuilder chunk(int chunkSize) { return new SimpleStepBuilder(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. + * + *
+	 * new StepBuilder("step1").<Order, Ledger> chunk(100, transactionManager).reader(new OrderReader()).writer(new LedgerWriter())
+	 * // ... etc.
+	 * 
+ * @param chunkSize the chunk size (commit interval) + * @param transactionManager the transaction manager to use for the chunk-oriented + * tasklet + * @return a {@link SimpleStepBuilder} + * @param the type of item to be processed as input + * @param the type of item to be output + * @since 5.0 + */ + public SimpleStepBuilder chunk(int chunkSize, PlatformTransactionManager transactionManager) { + return new SimpleStepBuilder(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 { * @param completionPolicy the completion policy to use to control chunk processing * @return a {@link SimpleStepBuilder} * @param the type of item to be processed as input - * @param the type of item to be output * + * @param the type of item to be output + * @deprecated use + * {@link StepBuilder#chunk(CompletionPolicy, PlatformTransactionManager)} */ + @Deprecated(since = "5.0") public SimpleStepBuilder chunk(CompletionPolicy completionPolicy) { return new SimpleStepBuilder(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. + * + *
+	 * new StepBuilder("step1").<Order, Ledger> chunk(100, transactionManager).reader(new OrderReader()).writer(new LedgerWriter())
+	 * // ... etc.
+	 * 
+ * @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 the type of item to be processed as input + * @param the type of item to be output + * @since 5.0 + */ + public SimpleStepBuilder chunk(CompletionPolicy completionPolicy, + PlatformTransactionManager transactionManager) { + return new SimpleStepBuilder(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 diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/TaskletStepBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/TaskletStepBuilder.java index a37036690..385b9b085 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/TaskletStepBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/TaskletStepBuilder.java @@ -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 { @@ -39,12 +41,26 @@ public class TaskletStepBuilder extends AbstractTaskletStepBuilder extends SimpleStepFactoryBean createBuilder(String name) { - return new FaultTolerantStepBuilder<>(new StepBuilder(name)); + return new FaultTolerantStepBuilder<>(new StepBuilder(name, jobRepository)); } @Override diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/factory/SimpleStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/factory/SimpleStepFactoryBean.java index 8c3b875b6..86c984bf8 100755 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/factory/SimpleStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/factory/SimpleStepFactoryBean.java @@ -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 implements FactoryBean, BeanNameAware { @@ -81,7 +82,7 @@ public class SimpleStepFactoryBean implements FactoryBean, BeanNameA private int transactionTimeout = DefaultTransactionAttribute.TIMEOUT_DEFAULT; - private JobRepository jobRepository; + protected JobRepository jobRepository; private boolean singleton = true; @@ -318,7 +319,7 @@ public class SimpleStepFactoryBean implements FactoryBean, BeanNameA } protected SimpleStepBuilder createBuilder(String name) { - return new SimpleStepBuilder<>(new StepBuilder(name)); + return new SimpleStepBuilder<>(new StepBuilder(name, jobRepository)); } @Override diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java index e1517683f..b579ddc81 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/InlineDataSourceDefinitionTests.java @@ -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); + } + } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java index fcb65ea29..23ff019d5 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobBuilderConfigurationTests.java @@ -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 diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java index 88709114a..b38475300 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobLoaderConfigurationTests.java @@ -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(); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java index 048b79183..068a678c0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java @@ -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(); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java index 3787c6be3..a372b632f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java @@ -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("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("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("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("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("subflow2").from(step2).end(); Flow splitFlow = new FlowBuilder("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).chunk(chunkSize) - .transactionManager(transactionManager).reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4))) - .writer(items -> { + return new StepBuilder("step", jobRepository).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 diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java index bc8e60d51..8f6618432 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java index b9d76c39e..e060a34d8 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java @@ -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 fakeItemReader, ItemProcessor fakeProcessor, ItemWriter fakeItemWriter, ItemProcessListener itemProcessListener) { - return new StepBuilder("testStep").repository(jobRepository).chunk(10) - .transactionManager(transactionManager).reader(fakeItemReader).processor(fakeProcessor) - .writer(fakeItemWriter).listener(itemProcessListener).faultTolerant().skipLimit(50) - .skip(RuntimeException.class).build(); + return new StepBuilder("testStep", jobRepository).chunk(10, transactionManager) + .reader(fakeItemReader).processor(fakeProcessor).writer(fakeItemWriter) + .listener(itemProcessListener).faultTolerant().skipLimit(50).skip(RuntimeException.class).build(); } @Bean diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java index b63e157d4..54501be2d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java @@ -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).chunk(2) - .transactionManager(this.transactionManager) + return new StepBuilder("step2", jobRepository).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).chunk(2) - .transactionManager(this.transactionManager) + return new StepBuilder("step3", jobRepository).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(); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/FaultTolerantStepBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/FaultTolerantStepBuilderTests.java index d00efa350..5131ca83d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/FaultTolerantStepBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/FaultTolerantStepBuilderTests.java @@ -30,18 +30,18 @@ class FaultTolerantStepBuilderTests { @Test void faultTolerantReturnsSameInstance() { - FaultTolerantStepBuilder builder = new FaultTolerantStepBuilder<>(new StepBuilder("test")); + FaultTolerantStepBuilder builder = new FaultTolerantStepBuilder<>( + new StepBuilder("test", new DummyJobRepository())); assertEquals(builder, builder.faultTolerant()); } @Test void testAnnotationBasedStepExecutionListenerRegistration() { // given - FaultTolerantStepBuilder faultTolerantStepBuilder = new StepBuilder("myStep") - .repository(new DummyJobRepository()).chunk(5) - .transactionManager(new ResourcelessTransactionManager()).reader(new DummyItemReader()) - .writer(new DummyItemWriter()).faultTolerant() - .listener(new StepBuilderTests.AnnotationBasedStepExecutionListener()); + FaultTolerantStepBuilder faultTolerantStepBuilder = new StepBuilder("myStep", + new DummyJobRepository()).chunk(5, new ResourcelessTransactionManager()) + .reader(new DummyItemReader()).writer(new DummyItemWriter()).faultTolerant() + .listener(new StepBuilderTests.AnnotationBasedStepExecutionListener()); // when Step step = faultTolerantStepBuilder.build(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/RegisterMultiListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/RegisterMultiListenerTests.java index cafa55b5b..9d31f63d0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/RegisterMultiListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/RegisterMultiListenerTests.java @@ -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()).chunk(2) - .transactionManager(transactionManager(dataSource())).reader(reader()).writer(writer()) + return new StepBuilder("step", jobRepository).listener(listener()) + .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()).chunk(2) - .transactionManager(transactionManager(dataSource())).reader(reader()).writer(writer()).build(); + return new StepBuilder("step", jobRepository).listener(listener()) + .chunk(2, transactionManager(dataSource())).reader(reader()).writer(writer()) + .build(); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java index e5360173d..c561f2b56 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java @@ -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 builder = new StepBuilder("step").repository(jobRepository).chunk(5) - .transactionManager(transactionManager).reader(new DummyItemReader()).writer(new DummyItemWriter()) + SimpleStepBuilder 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 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 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 reader = new ListItemReader<>(items); - SimpleStepBuilder builder = new StepBuilder("step").repository(jobRepository) - .chunk(3).transactionManager(transactionManager).reader(reader) - .processor(new PassThroughItemProcessor<>()).writer(new DummyItemWriter()) - .listener(new AnnotationBasedStepExecutionListener()); + SimpleStepBuilder builder = new StepBuilder("step", jobRepository) + .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 reader = new ListItemReader<>(items); ListItemWriter itemWriter = new ListItemWriter<>(); - SimpleStepBuilder builder = new StepBuilder("step").repository(jobRepository) - .chunk(3).transactionManager(transactionManager).reader(reader) - .processor(Object::toString).writer(itemWriter).listener(new AnnotationBasedStepExecutionListener()); + SimpleStepBuilder builder = new StepBuilder("step", jobRepository) + .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 items = Arrays.asList("1", "2", "3"); ItemReader reader = new ListItemReader<>(items); - SimpleStepBuilder builder = new StepBuilder("step").repository(jobRepository) - .chunk(3).transactionManager(transactionManager).reader(reader) - .writer(new DummyItemWriter()); + SimpleStepBuilder builder = new StepBuilder("step", jobRepository) + .chunk(3, transactionManager).reader(reader).writer(new DummyItemWriter()); configurer.apply(builder).listener(new InterfaceBasedItemReadListenerListener()).build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java index f5e2a701a..f3da0407b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java @@ -102,46 +102,46 @@ class ConcurrentTransactionTests { @Bean public Flow flow(JobRepository jobRepository) { return new FlowBuilder("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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java index 59f3c33d1..986ad6c86 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/DerbyJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/DerbyJobRepositoryIntegrationTests.java index 2e7c3419b..ff8ff6605 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/DerbyJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/DerbyJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java index 402dd0cc4..e0268fb12 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2JobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2JobRepositoryIntegrationTests.java index 4220842ca..b4cf66583 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2JobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/H2JobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java index cbfd8d954..9e70291e3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HSQLDBJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HSQLDBJobRepositoryIntegrationTests.java index 987ea321f..46e660683 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HSQLDBJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HSQLDBJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJdbcJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJdbcJobRepositoryIntegrationTests.java index 979483e8e..c2a6ce54e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJdbcJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJdbcJobRepositoryIntegrationTests.java @@ -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 diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJobRepositoryIntegrationTests.java index 5a210b31d..2f845d66e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/MySQLJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java index d3ee2cfb6..a0eb38f0a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/PostgreSQLJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/PostgreSQLJobRepositoryIntegrationTests.java index cb7f427a1..09d1b1cf6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/PostgreSQLJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/PostgreSQLJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLServerJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLServerJobRepositoryIntegrationTests.java index a3cf585f9..314351401 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLServerJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLServerJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLiteJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLiteJobRepositoryIntegrationTests.java index 7662c0e99..48b8295ad 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLiteJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SQLiteJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java index c46222861..5b6770a97 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java @@ -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(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java index 59231241d..80365a864 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java @@ -77,9 +77,8 @@ class FaultTolerantStepIntegrationTests { } }; skipPolicy = new SkipIllegalArgumentExceptionSkipPolicy(); - stepBuilder = new StepBuilder("step").repository(jobRepository).chunk(CHUNK_SIZE) - .transactionManager(transactionManager).reader(itemReader).processor(item -> item > 20 ? null : item) - .writer(itemWriter).faultTolerant(); + stepBuilder = new StepBuilder("step", jobRepository).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).chunk(5) - .transactionManager(transactionManager).reader(itemReader).processor(itemProcessor).writer(itemWriter) - .faultTolerant().skip(Exception.class).skipLimit(3).build(); + Step step = new StepBuilder("step", jobRepository).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).chunk(5) - .transactionManager(transactionManager).reader(itemReader).processor(itemProcessor).writer(itemWriter) - .faultTolerant().skipPolicy(new AlwaysSkipItemSkipPolicy()).build(); + Step step = new StepBuilder("step", jobRepository).chunk(5, transactionManager) + .reader(itemReader).processor(itemProcessor).writer(itemWriter).faultTolerant() + .skipPolicy(new AlwaysSkipItemSkipPolicy()).build(); // When StepExecution stepExecution = execute(step); diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilder.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilder.java index 8a684c704..cb3809e62 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilder.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilder.java @@ -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 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 diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderFactory.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderFactory.java index 5bb12d187..27ecd908f 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderFactory.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderFactory.java @@ -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 RemoteChunkingManagerStepBuilder get(String name) { - return new RemoteChunkingManagerStepBuilder(name).repository(this.jobRepository) + return new RemoteChunkingManagerStepBuilder(name, this.jobRepository) .transactionManager(this.transactionManager); } diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilder.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilder.java index f34d7fdfb..309fefae6 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilder.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilder.java @@ -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 diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilderFactory.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilderFactory.java index 37d54ca82..b5f87ad69 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilderFactory.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilderFactory.java @@ -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); } } diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilder.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilder.java index d207fa3ff..0bec965a4 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilder.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilder.java @@ -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 SimpleStepBuilder chunk(int chunkSize) { configureWorkerIntegrationFlow(); return super.chunk(chunkSize); } + @Override + public SimpleStepBuilder chunk(int chunkSize, PlatformTransactionManager transactionManager) { + configureWorkerIntegrationFlow(); + return super.chunk(chunkSize, transactionManager); + } + + @Deprecated(since = "5.0") @Override public SimpleStepBuilder chunk(CompletionPolicy completionPolicy) { configureWorkerIntegrationFlow(); return super.chunk(completionPolicy); } + @Override + public SimpleStepBuilder chunk(CompletionPolicy completionPolicy, + PlatformTransactionManager transactionManager) { + configureWorkerIntegrationFlow(); + return super.chunk(completionPolicy, transactionManager); + } + @Override public PartitionStepBuilder partitioner(String stepName, Partitioner partitioner) { configureWorkerIntegrationFlow(); diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilderFactory.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilderFactory.java index cd2c0d6e0..d94e21266 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilderFactory.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilderFactory.java @@ -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); } } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderTests.java index 930531a20..79c27195a 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderTests.java @@ -96,7 +96,8 @@ class RemoteChunkingManagerStepBuilderTests { void inputChannelMustNotBeNull() { // when final Exception expectedException = assertThrows(IllegalArgumentException.class, - () -> new RemoteChunkingManagerStepBuilder("step").inputChannel(null).build()); + () -> new RemoteChunkingManagerStepBuilder("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("step").outputChannel(null).build()); + () -> new RemoteChunkingManagerStepBuilder("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("step").messagingTemplate(null).build()); + () -> new RemoteChunkingManagerStepBuilder("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("step").maxWaitTimeouts(-1).build()); + () -> new RemoteChunkingManagerStepBuilder("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("step").throttleLimit(-1L).build()); + () -> new RemoteChunkingManagerStepBuilder("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 builder = new RemoteChunkingManagerStepBuilder<>("step"); + RemoteChunkingManagerStepBuilder 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 builder = new RemoteChunkingManagerStepBuilder( - "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("step").reader(this.itemReader) - .writer(items -> { + () -> new RemoteChunkingManagerStepBuilder("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("step").reader(this.itemReader) - .repository(this.jobRepository).transactionManager(this.transactionManager) - .inputChannel(this.inputChannel).outputChannel(this.outputChannel).build(); + TaskletStep taskletStep = new RemoteChunkingManagerStepBuilder("step", this.jobRepository) + .reader(this.itemReader).transactionManager(this.transactionManager).inputChannel(this.inputChannel) + .outputChannel(this.outputChannel).build(); // then assertNotNull(taskletStep); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilderTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilderTests.java index 68221a604..17a3650f4 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilderTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningManagerStepBuilderTests.java @@ -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(); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilderTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilderTests.java index 2834e82d4..e781cf06c 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilderTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningWorkerStepBuilderTests.java @@ -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"); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/config/RetrySampleConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/config/RetrySampleConfiguration.java index d721c1eb3..b0d24e442 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/config/RetrySampleConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/config/RetrySampleConfiguration.java @@ -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).chunk(1) - .transactionManager(this.transactionManager).reader(reader()).writer(writer()).faultTolerant() - .retry(Exception.class).retryLimit(3).build(); + return new StepBuilder("step", jobRepository).chunk(1, this.transactionManager).reader(reader()) + .writer(writer()).faultTolerant().retry(Exception.class).retryLimit(3).build(); } @Bean diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job1Configuration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job1Configuration.java index 7bdc605d5..0a001f6f4 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job1Configuration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job1Configuration.java @@ -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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job2Configuration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job2Configuration.java index 330aedd0d..1d09d3147 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job2Configuration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/Job2Configuration.java @@ -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).chunk(3).reader(itemReader()) - .writer(itemWriter()).build(); + public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager) { + return new StepBuilder("step1", jobRepository).chunk(3, transactionManager) + .reader(itemReader()).writer(itemWriter()).build(); } @Bean diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/DeletionJobConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/DeletionJobConfiguration.java index d88e90a9b..782ffde48 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/DeletionJobConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/DeletionJobConfiguration.java @@ -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 mongoPersonReader, - MongoItemWriter mongoPersonRemover) { - return new StepBuilder("step").repository(jobRepository).chunk(2).reader(mongoPersonReader) - .writer(mongoPersonRemover).build(); + public Step deletionStep(JobRepository jobRepository, PlatformTransactionManager transactionManager, + MongoItemReader mongoPersonReader, MongoItemWriter mongoPersonRemover) { + return new StepBuilder("step", jobRepository).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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/InsertionJobConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/InsertionJobConfiguration.java index 5dc07dd7c..cda2b3741 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/InsertionJobConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/InsertionJobConfiguration.java @@ -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 mongoItemReader, - MongoItemWriter mongoItemWriter) { - return new StepBuilder("step").repository(jobRepository).chunk(2).reader(mongoItemReader) - .writer(mongoItemWriter).build(); + public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager, + MongoItemReader mongoItemReader, MongoItemWriter mongoItemWriter) { + return new StepBuilder("step", jobRepository).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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/MongoDBConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/MongoDBConfiguration.java index 207079fd0..f68b60c33 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/MongoDBConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/MongoDBConfiguration.java @@ -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); + } + } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/ManagerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/ManagerConfiguration.java index 9b59521cb..725ef9810 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/ManagerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/ManagerConfiguration.java @@ -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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/ManagerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/ManagerConfiguration.java index 29a140bc4..baa6fc8ee 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/ManagerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/ManagerConfiguration.java @@ -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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/WorkerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/WorkerConfiguration.java index b0306f1c5..6f0069c53 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/WorkerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/WorkerConfiguration.java @@ -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 diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/ManagerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/ManagerConfiguration.java index 46f522ffe..820a92990 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/ManagerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/ManagerConfiguration.java @@ -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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/WorkerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/WorkerConfiguration.java index e4e146daf..98012b37a 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/WorkerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/polling/WorkerConfiguration.java @@ -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 diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringProcessSample.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringProcessSample.java index 54d3c1000..805d16b8a 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringProcessSample.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringProcessSample.java @@ -83,14 +83,14 @@ public class SkippableExceptionDuringProcessSample { @Bean public Step step(JobRepository jobRepository) { - return new StepBuilder("step").repository(jobRepository).chunk(3) - .transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor()) - .writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build(); + return new StepBuilder("step", jobRepository).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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringReadSample.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringReadSample.java index f85c4dac2..9bda9cbe3 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringReadSample.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringReadSample.java @@ -83,14 +83,14 @@ public class SkippableExceptionDuringReadSample { @Bean public Step step(JobRepository jobRepository) { - return new StepBuilder("step").repository(jobRepository).chunk(3) - .transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor()) - .writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build(); + return new StepBuilder("step", jobRepository).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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringWriteSample.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringWriteSample.java index 6f3c82d66..225f0949f 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringWriteSample.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/skip/SkippableExceptionDuringWriteSample.java @@ -83,14 +83,14 @@ public class SkippableExceptionDuringWriteSample { @Bean public Step step(JobRepository jobRepository) { - return new StepBuilder("step").repository(jobRepository).chunk(3) - .transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor()) - .writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build(); + return new StepBuilder("step", jobRepository).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(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/validation/ValidationSampleConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/validation/ValidationSampleConfiguration.java index fd460b408..4e351f251 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/validation/ValidationSampleConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/validation/ValidationSampleConfiguration.java @@ -66,14 +66,13 @@ public class ValidationSampleConfiguration { @Bean public Step step(JobRepository jobRepository) throws Exception { - return new StepBuilder("step").repository(jobRepository).chunk(1) - .transactionManager(transactionManager(dataSource())).reader(itemReader()).processor(itemValidator()) - .writer(itemWriter()).build(); + return new StepBuilder("step", jobRepository).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 diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java index 01efe6a8c..b966c9bdb 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JsonSupportIntegrationTests.java @@ -90,14 +90,13 @@ class JsonSupportIntegrationTests { @Bean public Step step(JobRepository jobRepository) { - return new StepBuilder("step").repository(jobRepository).chunk(2) - .transactionManager(transactionManager(dataSource())).reader(itemReader()).writer(itemWriter()) - .build(); + return new StepBuilder("step", jobRepository).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 diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/JobLauncherTestUtilsTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/JobLauncherTestUtilsTests.java index ed05c6934..3a3bb48d2 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/JobLauncherTestUtilsTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/JobLauncherTestUtilsTests.java @@ -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 diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java index 97c736c30..3bdc4a303 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java @@ -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(); } } diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java index 13d019276..e588876c9 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java @@ -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(); } } diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/StepScopeAnnotatedListenerIntegrationTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/StepScopeAnnotatedListenerIntegrationTests.java index ee8eb8ce5..7b548a4f5 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/StepScopeAnnotatedListenerIntegrationTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/StepScopeAnnotatedListenerIntegrationTests.java @@ -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).chunk(1) - .transactionManager(this.transactionManager).reader(reader()).processor(processor()) - .writer(writer()).build(); + return new StepBuilder("step-under-test", jobRepository).chunk(1, this.transactionManager) + .reader(reader()).processor(processor()).writer(writer()).build(); } @Bean