|
|
@ -17,17 +17,20 @@
|
|
|
|
package org.springframework.boot.actuate.scheduling;
|
|
|
|
package org.springframework.boot.actuate.scheduling;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.CronTaskDescription;
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.CronTaskDescription;
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.CustomTriggerTaskDescription;
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.FixedDelayTaskDescription;
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.FixedDelayTaskDescription;
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.FixedRateTaskDescription;
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.FixedRateTaskDescription;
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.ScheduledTasksReport;
|
|
|
|
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.ScheduledTasksReport;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
|
|
|
import org.springframework.scheduling.Trigger;
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|
|
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|
|
@ -53,6 +56,7 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
run(CronScheduledMethod.class, (tasks) -> {
|
|
|
|
run(CronScheduledMethod.class, (tasks) -> {
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getCustom()).isEmpty();
|
|
|
|
assertThat(tasks.getCron()).hasSize(1);
|
|
|
|
assertThat(tasks.getCron()).hasSize(1);
|
|
|
|
CronTaskDescription description = (CronTaskDescription) tasks.getCron()
|
|
|
|
CronTaskDescription description = (CronTaskDescription) tasks.getCron()
|
|
|
|
.get(0);
|
|
|
|
.get(0);
|
|
|
@ -67,6 +71,7 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
run(CronTriggerTask.class, (tasks) -> {
|
|
|
|
run(CronTriggerTask.class, (tasks) -> {
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getCustom()).isEmpty();
|
|
|
|
assertThat(tasks.getCron()).hasSize(1);
|
|
|
|
assertThat(tasks.getCron()).hasSize(1);
|
|
|
|
CronTaskDescription description = (CronTaskDescription) tasks.getCron()
|
|
|
|
CronTaskDescription description = (CronTaskDescription) tasks.getCron()
|
|
|
|
.get(0);
|
|
|
|
.get(0);
|
|
|
@ -81,6 +86,7 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
run(FixedDelayScheduledMethod.class, (tasks) -> {
|
|
|
|
run(FixedDelayScheduledMethod.class, (tasks) -> {
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getCustom()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).hasSize(1);
|
|
|
|
assertThat(tasks.getFixedDelay()).hasSize(1);
|
|
|
|
FixedDelayTaskDescription description = (FixedDelayTaskDescription) tasks
|
|
|
|
FixedDelayTaskDescription description = (FixedDelayTaskDescription) tasks
|
|
|
|
.getFixedDelay().get(0);
|
|
|
|
.getFixedDelay().get(0);
|
|
|
@ -96,6 +102,7 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
run(FixedDelayTriggerTask.class, (tasks) -> {
|
|
|
|
run(FixedDelayTriggerTask.class, (tasks) -> {
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getCustom()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).hasSize(1);
|
|
|
|
assertThat(tasks.getFixedDelay()).hasSize(1);
|
|
|
|
FixedDelayTaskDescription description = (FixedDelayTaskDescription) tasks
|
|
|
|
FixedDelayTaskDescription description = (FixedDelayTaskDescription) tasks
|
|
|
|
.getFixedDelay().get(0);
|
|
|
|
.getFixedDelay().get(0);
|
|
|
@ -111,6 +118,7 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
run(FixedRateScheduledMethod.class, (tasks) -> {
|
|
|
|
run(FixedRateScheduledMethod.class, (tasks) -> {
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getCustom()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).hasSize(1);
|
|
|
|
assertThat(tasks.getFixedRate()).hasSize(1);
|
|
|
|
FixedRateTaskDescription description = (FixedRateTaskDescription) tasks
|
|
|
|
FixedRateTaskDescription description = (FixedRateTaskDescription) tasks
|
|
|
|
.getFixedRate().get(0);
|
|
|
|
.getFixedRate().get(0);
|
|
|
@ -126,6 +134,7 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
run(FixedRateTriggerTask.class, (tasks) -> {
|
|
|
|
run(FixedRateTriggerTask.class, (tasks) -> {
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getCustom()).isEmpty();
|
|
|
|
assertThat(tasks.getFixedRate()).hasSize(1);
|
|
|
|
assertThat(tasks.getFixedRate()).hasSize(1);
|
|
|
|
FixedRateTaskDescription description = (FixedRateTaskDescription) tasks
|
|
|
|
FixedRateTaskDescription description = (FixedRateTaskDescription) tasks
|
|
|
|
.getFixedRate().get(0);
|
|
|
|
.getFixedRate().get(0);
|
|
|
@ -136,6 +145,22 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void taskWithCustomTriggerIsReported() {
|
|
|
|
|
|
|
|
run(CustomTriggerTask.class, (tasks) -> {
|
|
|
|
|
|
|
|
assertThat(tasks.getCron()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getFixedDelay()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getFixedRate()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(tasks.getCustom()).hasSize(1);
|
|
|
|
|
|
|
|
CustomTriggerTaskDescription description = (CustomTriggerTaskDescription) tasks
|
|
|
|
|
|
|
|
.getCustom().get(0);
|
|
|
|
|
|
|
|
assertThat(description.getRunnable().getTarget())
|
|
|
|
|
|
|
|
.isEqualTo(CustomTriggerRunnable.class.getName());
|
|
|
|
|
|
|
|
assertThat(description.getTrigger())
|
|
|
|
|
|
|
|
.isEqualTo(CustomTriggerTask.trigger.toString());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void run(Class<?> configuration, Consumer<ScheduledTasksReport> consumer) {
|
|
|
|
private void run(Class<?> configuration, Consumer<ScheduledTasksReport> consumer) {
|
|
|
|
this.contextRunner.withUserConfiguration(configuration).run((context) -> consumer
|
|
|
|
this.contextRunner.withUserConfiguration(configuration).run((context) -> consumer
|
|
|
|
.accept(context.getBean(ScheduledTasksEndpoint.class).scheduledTasks()));
|
|
|
|
.accept(context.getBean(ScheduledTasksEndpoint.class).scheduledTasks()));
|
|
|
@ -212,6 +237,17 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class CustomTriggerTask implements SchedulingConfigurer {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Trigger trigger = (context) -> new Date();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
|
|
|
|
|
|
|
taskRegistrar.addTriggerTask(new CustomTriggerRunnable(), trigger);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class CronTriggerRunnable implements Runnable {
|
|
|
|
private static class CronTriggerRunnable implements Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -239,4 +275,13 @@ public class ScheduledTasksEndpointTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class CustomTriggerRunnable implements Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|