mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:03:22 +08:00
Merge branch '3.1.x'
Closes gh-36130
This commit is contained in:
commit
ea73203219
@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.actuate.scheduling;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -186,7 +187,8 @@ public class ScheduledTasksEndpoint {
|
||||
|
||||
protected IntervalTaskDescriptor(TaskType type, TriggerTask task, PeriodicTrigger trigger) {
|
||||
super(type, task.getRunnable());
|
||||
this.initialDelay = trigger.getInitialDelayDuration().toMillis();
|
||||
Duration initialDelayDuration = trigger.getInitialDelayDuration();
|
||||
this.initialDelay = (initialDelayDuration != null) ? initialDelayDuration.toMillis() : 0;
|
||||
this.interval = trigger.getPeriodDuration().toMillis();
|
||||
}
|
||||
|
||||
|
@ -113,6 +113,20 @@ class ScheduledTasksEndpointTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void noInitialDelayFixedDelayTriggerIsReported() {
|
||||
run(NoInitialDelayFixedDelayTriggerTask.class, (tasks) -> {
|
||||
assertThat(tasks.getCron()).isEmpty();
|
||||
assertThat(tasks.getFixedRate()).isEmpty();
|
||||
assertThat(tasks.getCustom()).isEmpty();
|
||||
assertThat(tasks.getFixedDelay()).hasSize(1);
|
||||
FixedDelayTaskDescriptor description = (FixedDelayTaskDescriptor) tasks.getFixedDelay().get(0);
|
||||
assertThat(description.getInitialDelay()).isEqualTo(0);
|
||||
assertThat(description.getInterval()).isEqualTo(1000);
|
||||
assertThat(description.getRunnable().getTarget()).isEqualTo(FixedDelayTriggerRunnable.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void fixedRateScheduledMethodIsReported() {
|
||||
run(FixedRateScheduledMethod.class, (tasks) -> {
|
||||
@ -142,6 +156,20 @@ class ScheduledTasksEndpointTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void noInitialDelayFixedRateTriggerIsReported() {
|
||||
run(NoInitialDelayFixedRateTriggerTask.class, (tasks) -> {
|
||||
assertThat(tasks.getCron()).isEmpty();
|
||||
assertThat(tasks.getFixedDelay()).isEmpty();
|
||||
assertThat(tasks.getCustom()).isEmpty();
|
||||
assertThat(tasks.getFixedRate()).hasSize(1);
|
||||
FixedRateTaskDescriptor description = (FixedRateTaskDescriptor) tasks.getFixedRate().get(0);
|
||||
assertThat(description.getInitialDelay()).isEqualTo(0);
|
||||
assertThat(description.getInterval()).isEqualTo(2000);
|
||||
assertThat(description.getRunnable().getTarget()).isEqualTo(FixedRateTriggerRunnable.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskWithCustomTriggerIsReported() {
|
||||
run(CustomTriggerTask.class, (tasks) -> {
|
||||
@ -223,6 +251,16 @@ class ScheduledTasksEndpointTests {
|
||||
|
||||
}
|
||||
|
||||
static class NoInitialDelayFixedDelayTriggerTask implements SchedulingConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
PeriodicTrigger trigger = new PeriodicTrigger(Duration.ofSeconds(1));
|
||||
taskRegistrar.addTriggerTask(new FixedDelayTriggerRunnable(), trigger);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class FixedRateTriggerTask implements SchedulingConfigurer {
|
||||
|
||||
@Override
|
||||
@ -235,6 +273,17 @@ class ScheduledTasksEndpointTests {
|
||||
|
||||
}
|
||||
|
||||
static class NoInitialDelayFixedRateTriggerTask implements SchedulingConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
PeriodicTrigger trigger = new PeriodicTrigger(Duration.ofSeconds(2));
|
||||
trigger.setFixedRate(true);
|
||||
taskRegistrar.addTriggerTask(new FixedRateTriggerRunnable(), trigger);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class CronTriggerTask implements SchedulingConfigurer {
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user