Scheduled task introspection through ScheduledTaskHolder interface

Issue: SPR-15982
This commit is contained in:
Juergen Hoeller
2017-11-06 18:36:39 +01:00
parent 9511d29adb
commit ffd6eff369
12 changed files with 272 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -31,6 +31,7 @@ import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.IntervalTask;
import org.springframework.scheduling.config.ScheduledTaskHolder;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.config.TaskManagementConfigUtils;
import org.springframework.tests.Assume;
@@ -64,6 +65,7 @@ public class EnableSchedulingTests {
Assume.group(TestGroup.PERFORMANCE);
ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfig.class);
assertEquals(2, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size());
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
@@ -74,6 +76,7 @@ public class EnableSchedulingTests {
Assume.group(TestGroup.PERFORMANCE);
ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfigSubclass.class);
assertEquals(2, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size());
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
@@ -84,6 +87,7 @@ public class EnableSchedulingTests {
Assume.group(TestGroup.PERFORMANCE);
ctx = new AnnotationConfigApplicationContext(ExplicitSchedulerConfig.class);
assertEquals(1, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size());
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
@@ -103,6 +107,7 @@ public class EnableSchedulingTests {
Assume.group(TestGroup.PERFORMANCE);
ctx = new AnnotationConfigApplicationContext(ExplicitScheduledTaskRegistrarConfig.class);
assertEquals(1, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size());
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
@@ -179,7 +184,12 @@ public class EnableSchedulingTests {
@Configuration
@EnableScheduling
static class FixedRateTaskConfig {
static class FixedRateTaskConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.addFixedRateTask(() -> {}, 100);
}
@Bean
public AtomicInteger counter() {