Batch Boot Runner only supports one job.

Needed to update TaskJobLauncher to support only one job.
Updated tests accordingly
Re-added Added tests removed from M3 release
This commit is contained in:
Glenn Renfro
2022-06-16 17:26:49 -04:00
parent aeff4b02e4
commit 362d73650b
7 changed files with 25 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020-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.
@@ -44,7 +44,7 @@ public class TaskJobLauncherApplicationRunnerFactoryBean
private List<Job> jobs;
private String jobNames;
private String jobName;
private JobRegistry jobRegistry;
@@ -65,14 +65,14 @@ public class TaskJobLauncherApplicationRunnerFactoryBean
this.jobLauncher = jobLauncher;
this.jobExplorer = jobExplorer;
this.jobs = jobs;
this.jobNames = taskBatchProperties.getJobNames();
this.jobName = taskBatchProperties.getJobNames();
this.jobRegistry = jobRegistry;
this.taskBatchProperties = taskBatchProperties;
if (StringUtils.hasText(batchProperties.getJob().getNames())) {
this.jobNames = batchProperties.getJob().getNames();
if (StringUtils.hasText(batchProperties.getJob().getName())) {
this.jobName = batchProperties.getJob().getName();
}
else {
this.jobNames = taskBatchProperties.getJobNames();
this.jobName = taskBatchProperties.getJobNames();
}
this.order = taskBatchProperties.getCommandLineRunnerOrder();
this.jobRepository = jobRepository;
@@ -88,8 +88,8 @@ public class TaskJobLauncherApplicationRunnerFactoryBean
this.jobLauncher, this.jobExplorer, this.jobRepository,
this.taskBatchProperties);
taskJobLauncherApplicationRunner.setJobs(this.jobs);
if (StringUtils.hasText(this.jobNames)) {
taskJobLauncherApplicationRunner.setJobNames(this.jobNames);
if (StringUtils.hasText(this.jobName)) {
taskJobLauncherApplicationRunner.setJobName(this.jobName);
}
taskJobLauncherApplicationRunner.setJobRegistry(this.jobRegistry);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-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.
@@ -70,10 +70,10 @@ public class TaskJobLauncherAutoConfigurationTests {
public void testAutoBuiltDataSourceWithBatchJobNames() {
this.contextRunner
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
"spring.batch.job.names=job1,job2",
"spring.cloud.task.batch.jobNames=foobar")
"spring.batch.job.name=job1",
"spring.cloud.task.batch.jobName=foobar")
.run(context -> {
validateJobNames(context, "job1,job2");
validateJobNames(context, "job1");
});
}
@@ -93,7 +93,7 @@ public class TaskJobLauncherAutoConfigurationTests {
.getBean(TaskJobLauncherApplicationRunner.class);
Object names = ReflectionTestUtils.getField(jobLauncherApplicationRunner,
"jobNames");
"jobName");
assertThat(names).isEqualTo(jobNames);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-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.
@@ -217,7 +217,7 @@ public class TaskBatchExecutionListenerTests {
@Test
public void testMultipleJobs() {
this.applicationContext = SpringApplication.run(MultipleJobConfiguration.class,
ARGS);
"--spring.batch.job.name=job1");
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
@@ -227,14 +227,12 @@ public class TaskBatchExecutionListenerTests {
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
page.iterator().next().getExecutionId());
assertThat(jobExecutionIds.size()).isEqualTo(2);
assertThat(jobExecutionIds.size()).isEqualTo(1);
Iterator<Long> jobExecutionIdsIterator = jobExecutionIds.iterator();
assertThat((long) taskExplorer
.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()))
.isEqualTo(1);
assertThat((long) taskExplorer
.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()))
.isEqualTo(1);
}
@Test

View File

@@ -136,7 +136,7 @@ public class SimpleTaskAutoConfigurationTests {
applicationContextRunner);
}
// @Test
@Test
public void testMultipleConfigurers() {
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
@@ -150,7 +150,7 @@ public class SimpleTaskAutoConfigurationTests {
applicationContextRunner);
}
// @Test
@Test
public void testMultipleDataSources() {
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(

View File

@@ -28,6 +28,7 @@ import io.micrometer.tracing.Tracer;
import io.micrometer.tracing.brave.bridge.BraveFinishedSpan;
import io.micrometer.tracing.exporter.FinishedSpan;
import io.micrometer.tracing.test.simple.SpansAssert;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,13 +42,14 @@ import org.springframework.boot.actuate.autoconfigure.tracing.BraveAutoConfigura
import org.springframework.boot.actuate.autoconfigure.tracing.MicrometerTracingAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//@AutoConfigureObservability
@AutoConfigureObservability
@SpringBootTest(classes = ObservationIntegrationTests.Config.class)
class ObservationIntegrationTests {
@@ -57,7 +59,7 @@ class ObservationIntegrationTests {
@Autowired
MeterRegistry meterRegistry;
// @Test
@Test
void testSuccessfulObservation() {
List<FinishedSpan> finishedSpans = finishedSpans();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-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.
@@ -58,19 +58,4 @@ public class JobConfiguration {
.build())
.build();
}
@Bean
public Job job2() {
return this.jobBuilderFactory.get("job2")
.start(this.stepBuilderFactory.get("job2step1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
logger.info("Job2 was run");
return RepeatStatus.FINISHED;
}
})
.build())
.build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-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.
@@ -58,10 +58,6 @@ public class BatchJobApplicationTests {
assertThat(i).isGreaterThan(0);
int j = output.indexOf(JOB_ASSOCIATION_MESSAGE, i + 1);
assertThat(j).isGreaterThan(i);
String taskTitle = "Demo Batch Job Task";
Pattern pattern = Pattern.compile(taskTitle);