Move observation support classes to scheduling.support package
Avoids a package cycle between config and support (only config->support allowed). See gh-29883
This commit is contained in:
@@ -36,8 +36,8 @@ import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.scheduling.config.ScheduledTask;
|
||||
import org.springframework.scheduling.config.ScheduledTaskHolder;
|
||||
import org.springframework.scheduling.config.ScheduledTaskObservationContext;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.ScheduledTaskObservationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -55,11 +55,13 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
|
||||
private final TestObservationRegistry observationRegistry = TestObservationRegistry.create();
|
||||
|
||||
|
||||
@AfterEach
|
||||
void closeContext() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void shouldRecordSuccessObservationsForTasks() throws Exception {
|
||||
registerScheduledBean(FixedDelayBean.class);
|
||||
@@ -185,6 +187,7 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
.hasObservationWithNameEqualTo("tasks.scheduled.execution").that();
|
||||
}
|
||||
|
||||
|
||||
static abstract class TaskTester {
|
||||
|
||||
ObservationRegistry observationRegistry;
|
||||
@@ -200,13 +203,13 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class FixedDelayBean extends TaskTester {
|
||||
|
||||
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
|
||||
public void fixedDelay() {
|
||||
this.latch.countDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -217,18 +220,18 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
this.latch.countDown();
|
||||
throw new IllegalStateException("test error");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class FixedDelayReactiveBean extends TaskTester {
|
||||
|
||||
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
|
||||
public Mono<Object> fixedDelay() {
|
||||
return Mono.empty().doOnTerminate(() -> this.latch.countDown());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class FixedDelayReactiveErrorBean extends TaskTester {
|
||||
|
||||
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
|
||||
@@ -236,9 +239,9 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
return Mono.error(new IllegalStateException("test error"))
|
||||
.doOnTerminate(() -> this.latch.countDown());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class CancelledTaskBean extends TaskTester {
|
||||
|
||||
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
|
||||
@@ -251,9 +254,9 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
// ignore cancelled task
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class CancelledReactiveTaskBean extends TaskTester {
|
||||
|
||||
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
|
||||
@@ -261,9 +264,9 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
return Flux.interval(Duration.ZERO, Duration.ofSeconds(1))
|
||||
.doOnNext(el -> this.latch.countDown());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class CurrentObservationBean extends TaskTester {
|
||||
|
||||
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
|
||||
@@ -272,9 +275,9 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
assertThat(this.observationRegistry.getCurrentObservation().getContext()).isInstanceOf(ScheduledTaskObservationContext.class);
|
||||
this.latch.countDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class CurrentObservationReactiveBean extends TaskTester {
|
||||
|
||||
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
|
||||
@@ -290,7 +293,6 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
|
||||
})
|
||||
.doOnTerminate(() -> this.latch.countDown());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.scheduling.config;
|
||||
package org.springframework.scheduling.support;
|
||||
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -37,6 +37,7 @@ class DefaultScheduledTaskObservationConventionTests {
|
||||
|
||||
private final ScheduledTaskObservationConvention convention = new DefaultScheduledTaskObservationConvention();
|
||||
|
||||
|
||||
@Test
|
||||
void observationShouldHaveDefaultName() {
|
||||
assertThat(convention.getName()).isEqualTo("tasks.scheduled.execution");
|
||||
@@ -92,17 +93,16 @@ class DefaultScheduledTaskObservationConventionTests {
|
||||
}
|
||||
|
||||
|
||||
static class BeanWithScheduledMethods implements TaskProcessor {
|
||||
|
||||
public void process() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface TaskProcessor {
|
||||
|
||||
void process();
|
||||
}
|
||||
|
||||
|
||||
static class BeanWithScheduledMethods implements TaskProcessor {
|
||||
|
||||
public void process() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user