Skip to content

Commit 362d736

Browse files
committed
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
1 parent aeff4b0 commit 362d736

File tree

7 files changed

+25
-44
lines changed

7 files changed

+25
-44
lines changed

spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherApplicationRunnerFactoryBean.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2020 the original author or authors.
2+
* Copyright 2020-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class TaskJobLauncherApplicationRunnerFactoryBean
4444

4545
private List<Job> jobs;
4646

47-
private String jobNames;
47+
private String jobName;
4848

4949
private JobRegistry jobRegistry;
5050

@@ -65,14 +65,14 @@ public TaskJobLauncherApplicationRunnerFactoryBean(JobLauncher jobLauncher,
6565
this.jobLauncher = jobLauncher;
6666
this.jobExplorer = jobExplorer;
6767
this.jobs = jobs;
68-
this.jobNames = taskBatchProperties.getJobNames();
68+
this.jobName = taskBatchProperties.getJobNames();
6969
this.jobRegistry = jobRegistry;
7070
this.taskBatchProperties = taskBatchProperties;
71-
if (StringUtils.hasText(batchProperties.getJob().getNames())) {
72-
this.jobNames = batchProperties.getJob().getNames();
71+
if (StringUtils.hasText(batchProperties.getJob().getName())) {
72+
this.jobName = batchProperties.getJob().getName();
7373
}
7474
else {
75-
this.jobNames = taskBatchProperties.getJobNames();
75+
this.jobName = taskBatchProperties.getJobNames();
7676
}
7777
this.order = taskBatchProperties.getCommandLineRunnerOrder();
7878
this.jobRepository = jobRepository;
@@ -88,8 +88,8 @@ public TaskJobLauncherApplicationRunner getObject() {
8888
this.jobLauncher, this.jobExplorer, this.jobRepository,
8989
this.taskBatchProperties);
9090
taskJobLauncherApplicationRunner.setJobs(this.jobs);
91-
if (StringUtils.hasText(this.jobNames)) {
92-
taskJobLauncherApplicationRunner.setJobNames(this.jobNames);
91+
if (StringUtils.hasText(this.jobName)) {
92+
taskJobLauncherApplicationRunner.setJobName(this.jobName);
9393
}
9494
taskJobLauncherApplicationRunner.setJobRegistry(this.jobRegistry);
9595

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2020 the original author or authors.
2+
* Copyright 2018-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,10 +70,10 @@ public void testAutoBuiltDataSourceWithTaskJobLauncherCLROrder() {
7070
public void testAutoBuiltDataSourceWithBatchJobNames() {
7171
this.contextRunner
7272
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
73-
"spring.batch.job.names=job1,job2",
74-
"spring.cloud.task.batch.jobNames=foobar")
73+
"spring.batch.job.name=job1",
74+
"spring.cloud.task.batch.jobName=foobar")
7575
.run(context -> {
76-
validateJobNames(context, "job1,job2");
76+
validateJobNames(context, "job1");
7777
});
7878
}
7979

@@ -93,7 +93,7 @@ private void validateJobNames(AssertableApplicationContext context, String jobNa
9393
.getBean(TaskJobLauncherApplicationRunner.class);
9494

9595
Object names = ReflectionTestUtils.getField(jobLauncherApplicationRunner,
96-
"jobNames");
96+
"jobName");
9797
assertThat(names).isEqualTo(jobNames);
9898
}
9999

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -217,7 +217,7 @@ public void testMapBased() {
217217
@Test
218218
public void testMultipleJobs() {
219219
this.applicationContext = SpringApplication.run(MultipleJobConfiguration.class,
220-
ARGS);
220+
"--spring.batch.job.name=job1");
221221

222222
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
223223

@@ -227,14 +227,12 @@ public void testMultipleJobs() {
227227
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
228228
page.iterator().next().getExecutionId());
229229

230-
assertThat(jobExecutionIds.size()).isEqualTo(2);
230+
assertThat(jobExecutionIds.size()).isEqualTo(1);
231231
Iterator<Long> jobExecutionIdsIterator = jobExecutionIds.iterator();
232232
assertThat((long) taskExplorer
233233
.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()))
234234
.isEqualTo(1);
235-
assertThat((long) taskExplorer
236-
.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()))
237-
.isEqualTo(1);
235+
238236
}
239237

240238
@Test

spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void testRepositoryNotInitialized() {
136136
applicationContextRunner);
137137
}
138138

139-
// @Test
139+
@Test
140140
public void testMultipleConfigurers() {
141141
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
142142
.withConfiguration(AutoConfigurations.of(
@@ -150,7 +150,7 @@ public void testMultipleConfigurers() {
150150
applicationContextRunner);
151151
}
152152

153-
// @Test
153+
@Test
154154
public void testMultipleDataSources() {
155155
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
156156
.withConfiguration(AutoConfigurations.of(

spring-cloud-task-core/src/test/java/org/springframework/cloud/task/configuration/observation/ObservationIntegrationTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.micrometer.tracing.brave.bridge.BraveFinishedSpan;
2929
import io.micrometer.tracing.exporter.FinishedSpan;
3030
import io.micrometer.tracing.test.simple.SpansAssert;
31+
import org.junit.jupiter.api.Test;
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

@@ -41,13 +42,14 @@
4142
import org.springframework.boot.actuate.autoconfigure.tracing.MicrometerTracingAutoConfiguration;
4243
import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinAutoConfiguration;
4344
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
45+
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
4446
import org.springframework.boot.test.context.SpringBootTest;
4547
import org.springframework.cloud.task.configuration.EnableTask;
4648
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
4749
import org.springframework.context.annotation.Bean;
4850
import org.springframework.context.annotation.Configuration;
4951

50-
//@AutoConfigureObservability
52+
@AutoConfigureObservability
5153
@SpringBootTest(classes = ObservationIntegrationTests.Config.class)
5254
class ObservationIntegrationTests {
5355

@@ -57,7 +59,7 @@ class ObservationIntegrationTests {
5759
@Autowired
5860
MeterRegistry meterRegistry;
5961

60-
// @Test
62+
@Test
6163
void testSuccessfulObservation() {
6264
List<FinishedSpan> finishedSpans = finishedSpans();
6365

spring-cloud-task-samples/batch-job/src/main/java/io/spring/configuration/JobConfiguration.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,19 +58,4 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
5858
.build())
5959
.build();
6060
}
61-
62-
@Bean
63-
public Job job2() {
64-
return this.jobBuilderFactory.get("job2")
65-
.start(this.stepBuilderFactory.get("job2step1")
66-
.tasklet(new Tasklet() {
67-
@Override
68-
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
69-
logger.info("Job2 was run");
70-
return RepeatStatus.FINISHED;
71-
}
72-
})
73-
.build())
74-
.build();
75-
}
7661
}

spring-cloud-task-samples/batch-job/src/test/java/io/spring/BatchJobApplicationTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,10 +58,6 @@ public void testBatchJobApp(CapturedOutput capturedOutput) throws Exception {
5858

5959
assertThat(i).isGreaterThan(0);
6060

61-
int j = output.indexOf(JOB_ASSOCIATION_MESSAGE, i + 1);
62-
63-
assertThat(j).isGreaterThan(i);
64-
6561

6662
String taskTitle = "Demo Batch Job Task";
6763
Pattern pattern = Pattern.compile(taskTitle);

0 commit comments

Comments
 (0)