|
1 | 1 | /* |
2 | | - * Copyright 2022 the original author or authors. |
| 2 | + * Copyright 2022-2023 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | -package org.springframework.batch.test.observability; |
| 16 | +package org.springframework.batch.core.observability; |
| 17 | + |
| 18 | +import java.util.UUID; |
17 | 19 |
|
18 | 20 | import javax.sql.DataSource; |
19 | 21 |
|
|
23 | 25 | import io.micrometer.core.tck.MeterRegistryAssert; |
24 | 26 | import io.micrometer.observation.ObservationRegistry; |
25 | 27 | import io.micrometer.tracing.test.SampleTestRunner; |
| 28 | +import io.micrometer.tracing.test.simple.SpansAssert; |
26 | 29 | import org.assertj.core.api.Assertions; |
27 | 30 | import org.junit.jupiter.api.AfterEach; |
| 31 | +import org.junit.jupiter.api.extension.ExtendWith; |
28 | 32 |
|
29 | 33 | import org.springframework.batch.core.ExitStatus; |
30 | 34 | import org.springframework.batch.core.Job; |
31 | 35 | import org.springframework.batch.core.JobExecution; |
32 | 36 | import org.springframework.batch.core.JobParameters; |
| 37 | +import org.springframework.batch.core.JobParametersBuilder; |
33 | 38 | import org.springframework.batch.core.Step; |
34 | 39 | import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; |
35 | 40 | import org.springframework.batch.core.job.builder.JobBuilder; |
| 41 | +import org.springframework.batch.core.launch.JobLauncher; |
36 | 42 | import org.springframework.batch.core.repository.JobRepository; |
37 | 43 | import org.springframework.batch.core.step.builder.StepBuilder; |
38 | 44 | import org.springframework.batch.repeat.RepeatStatus; |
39 | | -import org.springframework.batch.test.JobLauncherTestUtils; |
40 | | -import org.springframework.batch.test.context.SpringBatchTest; |
41 | 45 | import org.springframework.beans.factory.annotation.Autowired; |
42 | 46 | import org.springframework.context.annotation.Bean; |
43 | 47 | import org.springframework.context.annotation.Configuration; |
44 | 48 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
45 | 49 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; |
46 | 50 | import org.springframework.jdbc.support.JdbcTransactionManager; |
| 51 | +import org.springframework.test.context.junit.jupiter.SpringExtension; |
47 | 52 |
|
48 | | -import static io.micrometer.tracing.test.simple.SpansAssert.assertThat; |
49 | | - |
50 | | -@SpringBatchTest |
| 53 | +@ExtendWith(SpringExtension.class) |
51 | 54 | class ObservabilitySampleStepTests extends SampleTestRunner { |
52 | 55 |
|
53 | 56 | @Autowired |
54 | | - private JobLauncherTestUtils jobLauncherTestUtils; |
| 57 | + private Job job; |
| 58 | + |
| 59 | + @Autowired |
| 60 | + private JobLauncher jobLauncher; |
55 | 61 |
|
56 | 62 | @Autowired |
57 | 63 | private ObservationRegistry observationRegistry; |
@@ -80,16 +86,20 @@ protected void closeMeterRegistry() { |
80 | 86 | public SampleTestRunnerConsumer yourCode() { |
81 | 87 | return (bb, meterRegistry) -> { |
82 | 88 | // given |
83 | | - JobParameters jobParameters = this.jobLauncherTestUtils.getUniqueJobParameters(); |
| 89 | + JobParameters jobParameters = new JobParametersBuilder().addString("uuid", UUID.randomUUID().toString()) |
| 90 | + .toJobParameters(); |
84 | 91 |
|
85 | 92 | // when |
86 | | - JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(jobParameters); |
| 93 | + JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters); |
87 | 94 |
|
88 | 95 | // then |
89 | 96 | Assertions.assertThat(jobExecution.getExitStatus()).isEqualTo(ExitStatus.COMPLETED); |
90 | 97 |
|
91 | 98 | // and |
92 | | - assertThat(bb.getFinishedSpans()).haveSameTraceId().hasASpanWithName("job").hasASpanWithName("step"); |
| 99 | + SpansAssert.assertThat(bb.getFinishedSpans()) |
| 100 | + .haveSameTraceId() |
| 101 | + .hasASpanWithName("job") |
| 102 | + .hasASpanWithName("step"); |
93 | 103 |
|
94 | 104 | // and |
95 | 105 | MeterRegistryAssert.assertThat(meterRegistry) |
|
0 commit comments