mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Update Spring Batch to upstream API changes
Fix Spring Batch tests following upstream changes related to Spring Batch issue 4130. Closes gh-32237
This commit is contained in:
parent
127d320636
commit
6e239d551a
@ -98,9 +98,11 @@ class JobLauncherApplicationRunnerTests {
|
||||
@Test
|
||||
void retryFailedExecution() {
|
||||
this.contextRunner.run((context) -> {
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||
Job job = jobLauncherContext.jobBuilder()
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet()).build())
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
|
||||
.transactionManager(transactionManager).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
jobLauncherContext.runner.execute(job, new JobParameters());
|
||||
jobLauncherContext.runner.execute(job, new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
|
||||
@ -111,9 +113,10 @@ class JobLauncherApplicationRunnerTests {
|
||||
@Test
|
||||
void runDifferentInstances() {
|
||||
this.contextRunner.run((context) -> {
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||
Job job = jobLauncherContext.jobBuilder()
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet()).build()).build();
|
||||
Job job = jobLauncherContext.jobBuilder().start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
|
||||
.transactionManager(transactionManager).build()).build();
|
||||
// start a job instance
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo").toJobParameters();
|
||||
jobLauncherContext.runner.execute(job, jobParameters);
|
||||
@ -128,9 +131,11 @@ class JobLauncherApplicationRunnerTests {
|
||||
@Test
|
||||
void retryFailedExecutionOnNonRestartableJob() {
|
||||
this.contextRunner.run((context) -> {
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||
Job job = jobLauncherContext.jobBuilder().preventRestart()
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet()).build())
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
|
||||
.transactionManager(transactionManager).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
jobLauncherContext.runner.execute(job, new JobParameters());
|
||||
jobLauncherContext.runner.execute(job, new JobParameters());
|
||||
@ -149,9 +154,11 @@ class JobLauncherApplicationRunnerTests {
|
||||
@Test
|
||||
void retryFailedExecutionWithNonIdentifyingParameters() {
|
||||
this.contextRunner.run((context) -> {
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||
Job job = jobLauncherContext.jobBuilder()
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet()).build())
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet())
|
||||
.transactionManager(transactionManager).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
|
||||
.toJobParameters();
|
||||
@ -187,9 +194,11 @@ class JobLauncherApplicationRunnerTests {
|
||||
JobLauncherApplicationRunnerContext(ApplicationContext context) {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
JobRepository jobRepository = context.getBean(JobRepository.class);
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
this.jobs = new JobBuilderFactory(jobRepository);
|
||||
this.steps = new StepBuilderFactory(jobRepository, context.getBean(PlatformTransactionManager.class));
|
||||
this.step = this.steps.get("step").tasklet((contribution, chunkContext) -> null).build();
|
||||
this.steps = new StepBuilderFactory(jobRepository);
|
||||
this.step = this.steps.get("step").tasklet((contribution, chunkContext) -> null)
|
||||
.transactionManager(transactionManager).build();
|
||||
this.job = this.jobs.get("job").start(this.step).build();
|
||||
this.jobExplorer = context.getBean(JobExplorer.class);
|
||||
this.runner = new JobLauncherApplicationRunner(jobLauncher, this.jobExplorer, jobRepository);
|
||||
|
@ -18,38 +18,36 @@ package smoketest.batch;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
|
||||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableBatchProcessing
|
||||
public class SampleBatchApplication {
|
||||
|
||||
@Autowired
|
||||
private JobBuilderFactory jobs;
|
||||
|
||||
@Autowired
|
||||
private StepBuilderFactory steps;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
public SampleBatchApplication(JobBuilderFactory jobs, StepBuilderFactory steps,
|
||||
PlatformTransactionManager transactionManager) {
|
||||
this.jobs = jobs;
|
||||
this.steps = steps;
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Tasklet tasklet() {
|
||||
|
||||
return new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext context) {
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
};
|
||||
|
||||
return (contribution, context) -> RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ -59,7 +57,7 @@ public class SampleBatchApplication {
|
||||
|
||||
@Bean
|
||||
protected Step step1() {
|
||||
return this.steps.get("step1").tasklet(tasklet()).build();
|
||||
return this.steps.get("step1").tasklet(tasklet()).transactionManager(this.transactionManager).build();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
Loading…
Reference in New Issue
Block a user