Added Java 8 compliant @Schedules container annotation for @Scheduled
Issue: SPR-10532
This commit is contained in:
@@ -128,6 +128,40 @@ public class ScheduledAnnotationBeanPostProcessorTests {
|
||||
assertEquals(3000L, task.getInterval());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalFixedRates() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(SeveralFixedRatesTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.registerBeanDefinition("target", targetDefinition);
|
||||
context.refresh();
|
||||
Object postProcessor = context.getBean("postProcessor");
|
||||
Object target = context.getBean("target");
|
||||
ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar)
|
||||
new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
|
||||
new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
|
||||
assertEquals(2, fixedRateTasks.size());
|
||||
IntervalTask task1 = fixedRateTasks.get(0);
|
||||
ScheduledMethodRunnable runnable1 = (ScheduledMethodRunnable) task1.getRunnable();
|
||||
Object targetObject = runnable1.getTarget();
|
||||
Method targetMethod = runnable1.getMethod();
|
||||
assertEquals(target, targetObject);
|
||||
assertEquals("fixedRate", targetMethod.getName());
|
||||
assertEquals(0, task1.getInitialDelay());
|
||||
assertEquals(4000L, task1.getInterval());
|
||||
IntervalTask task2 = fixedRateTasks.get(1);
|
||||
ScheduledMethodRunnable runnable2 = (ScheduledMethodRunnable) task2.getRunnable();
|
||||
targetObject = runnable2.getTarget();
|
||||
targetMethod = runnable2.getMethod();
|
||||
assertEquals(target, targetObject);
|
||||
assertEquals("fixedRate", targetMethod.getName());
|
||||
assertEquals(2000L, task2.getInitialDelay());
|
||||
assertEquals(4000L, task2.getInterval());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cronTask() throws InterruptedException {
|
||||
Assume.group(TestGroup.LONG_RUNNING);
|
||||
@@ -404,6 +438,15 @@ public class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
|
||||
static class SeveralFixedRatesTestBean {
|
||||
|
||||
@Scheduled(fixedRate=4000)
|
||||
@Scheduled(fixedRate=4000, initialDelay=2000)
|
||||
public void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class CronTestBean {
|
||||
|
||||
@Scheduled(cron="*/7 * * * * ?")
|
||||
|
||||
Reference in New Issue
Block a user