Skip to content

Commit 51f6357

Browse files
committed
Move ObservabilitySampleStepTests to spring-batch-core
This test class dot not belong to the spring-batch-test module.
1 parent dc6a4eb commit 51f6357

File tree

3 files changed

+46
-35
lines changed

3 files changed

+46
-35
lines changed

spring-batch-core/pom.xml

+24
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,30 @@
304304
</exclusion>
305305
</exclusions>
306306
</dependency>
307+
<dependency>
308+
<groupId>io.micrometer</groupId>
309+
<artifactId>micrometer-tracing-integration-test</artifactId>
310+
<version>${micrometer-tracing.version}</version>
311+
<scope>test</scope>
312+
<exclusions>
313+
<exclusion>
314+
<groupId>org.junit.jupiter</groupId>
315+
<artifactId>junit-jupiter</artifactId>
316+
</exclusion>
317+
<exclusion>
318+
<groupId>com.fasterxml.jackson.core</groupId>
319+
<artifactId>jackson-databind</artifactId>
320+
</exclusion>
321+
<exclusion>
322+
<groupId>com.fasterxml.jackson.core</groupId>
323+
<artifactId>jackson-annotations</artifactId>
324+
</exclusion>
325+
<exclusion>
326+
<groupId>com.fasterxml.jackson.dataformat</groupId>
327+
<artifactId>jackson-dataformat-yaml</artifactId>
328+
</exclusion>
329+
</exclusions>
330+
</dependency>
307331
</dependencies>
308332

309333
</project>
+21-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 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.
@@ -13,7 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.batch.test.observability;
16+
package org.springframework.batch.core.observability;
17+
18+
import java.util.UUID;
1719

1820
import javax.sql.DataSource;
1921

@@ -23,35 +25,39 @@
2325
import io.micrometer.core.tck.MeterRegistryAssert;
2426
import io.micrometer.observation.ObservationRegistry;
2527
import io.micrometer.tracing.test.SampleTestRunner;
28+
import io.micrometer.tracing.test.simple.SpansAssert;
2629
import org.assertj.core.api.Assertions;
2730
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.extension.ExtendWith;
2832

2933
import org.springframework.batch.core.ExitStatus;
3034
import org.springframework.batch.core.Job;
3135
import org.springframework.batch.core.JobExecution;
3236
import org.springframework.batch.core.JobParameters;
37+
import org.springframework.batch.core.JobParametersBuilder;
3338
import org.springframework.batch.core.Step;
3439
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
3540
import org.springframework.batch.core.job.builder.JobBuilder;
41+
import org.springframework.batch.core.launch.JobLauncher;
3642
import org.springframework.batch.core.repository.JobRepository;
3743
import org.springframework.batch.core.step.builder.StepBuilder;
3844
import org.springframework.batch.repeat.RepeatStatus;
39-
import org.springframework.batch.test.JobLauncherTestUtils;
40-
import org.springframework.batch.test.context.SpringBatchTest;
4145
import org.springframework.beans.factory.annotation.Autowired;
4246
import org.springframework.context.annotation.Bean;
4347
import org.springframework.context.annotation.Configuration;
4448
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
4549
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
4650
import org.springframework.jdbc.support.JdbcTransactionManager;
51+
import org.springframework.test.context.junit.jupiter.SpringExtension;
4752

48-
import static io.micrometer.tracing.test.simple.SpansAssert.assertThat;
49-
50-
@SpringBatchTest
53+
@ExtendWith(SpringExtension.class)
5154
class ObservabilitySampleStepTests extends SampleTestRunner {
5255

5356
@Autowired
54-
private JobLauncherTestUtils jobLauncherTestUtils;
57+
private Job job;
58+
59+
@Autowired
60+
private JobLauncher jobLauncher;
5561

5662
@Autowired
5763
private ObservationRegistry observationRegistry;
@@ -80,16 +86,20 @@ protected void closeMeterRegistry() {
8086
public SampleTestRunnerConsumer yourCode() {
8187
return (bb, meterRegistry) -> {
8288
// given
83-
JobParameters jobParameters = this.jobLauncherTestUtils.getUniqueJobParameters();
89+
JobParameters jobParameters = new JobParametersBuilder().addString("uuid", UUID.randomUUID().toString())
90+
.toJobParameters();
8491

8592
// when
86-
JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(jobParameters);
93+
JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters);
8794

8895
// then
8996
Assertions.assertThat(jobExecution.getExitStatus()).isEqualTo(ExitStatus.COMPLETED);
9097

9198
// and
92-
assertThat(bb.getFinishedSpans()).haveSameTraceId().hasASpanWithName("job").hasASpanWithName("step");
99+
SpansAssert.assertThat(bb.getFinishedSpans())
100+
.haveSameTraceId()
101+
.hasASpanWithName("job")
102+
.hasASpanWithName("step");
93103

94104
// and
95105
MeterRegistryAssert.assertThat(meterRegistry)

spring-batch-test/pom.xml

+1-24
Original file line numberDiff line numberDiff line change
@@ -99,30 +99,7 @@
9999
<version>${slf4j.version}</version>
100100
<scope>test</scope>
101101
</dependency>
102-
<dependency>
103-
<groupId>io.micrometer</groupId>
104-
<artifactId>micrometer-tracing-integration-test</artifactId>
105-
<version>${micrometer-tracing.version}</version>
106-
<scope>test</scope>
107-
<exclusions>
108-
<exclusion>
109-
<groupId>org.junit.jupiter</groupId>
110-
<artifactId>junit-jupiter</artifactId>
111-
</exclusion>
112-
<exclusion>
113-
<groupId>com.fasterxml.jackson.core</groupId>
114-
<artifactId>jackson-databind</artifactId>
115-
</exclusion>
116-
<exclusion>
117-
<groupId>com.fasterxml.jackson.core</groupId>
118-
<artifactId>jackson-annotations</artifactId>
119-
</exclusion>
120-
<exclusion>
121-
<groupId>com.fasterxml.jackson.dataformat</groupId>
122-
<artifactId>jackson-dataformat-yaml</artifactId>
123-
</exclusion>
124-
</exclusions>
125-
</dependency>
102+
126103
<dependency>
127104
<groupId>io.micrometer</groupId>
128105
<artifactId>micrometer-test</artifactId>

0 commit comments

Comments
 (0)