3939import  org .springframework .beans .factory .config .PropertyPlaceholderConfigurer ;
4040import  org .springframework .beans .factory .support .RootBeanDefinition ;
4141import  org .springframework .context .support .StaticApplicationContext ;
42+ import  org .springframework .core .annotation .AliasFor ;
4243import  org .springframework .scheduling .Trigger ;
4344import  org .springframework .scheduling .TriggerContext ;
4445import  org .springframework .scheduling .config .CronTask ;
@@ -332,6 +333,32 @@ public void metaAnnotationWithFixedRate() {
332333		assertEquals (5000L , task .getInterval ());
333334	}
334335
336+ 	@ Test 
337+ 	public  void  composedAnnotationWithInitialDelayAndFixedRate () {
338+ 		BeanDefinition  processorDefinition  = new  RootBeanDefinition (ScheduledAnnotationBeanPostProcessor .class );
339+ 		BeanDefinition  targetDefinition  = new  RootBeanDefinition (ComposedAnnotationFixedRateTestBean .class );
340+ 		context .registerBeanDefinition ("postProcessor" , processorDefinition );
341+ 		context .registerBeanDefinition ("target" , targetDefinition );
342+ 		context .refresh ();
343+ 
344+ 		Object  postProcessor  = context .getBean ("postProcessor" );
345+ 		Object  target  = context .getBean ("target" );
346+ 		ScheduledTaskRegistrar  registrar  = (ScheduledTaskRegistrar ) new  DirectFieldAccessor (
347+ 			postProcessor ).getPropertyValue ("registrar" );
348+ 		@ SuppressWarnings ("unchecked" )
349+ 		List <IntervalTask > fixedRateTasks  = (List <IntervalTask >) new  DirectFieldAccessor (registrar ).getPropertyValue (
350+ 			"fixedRateTasks" );
351+ 		assertEquals (1 , fixedRateTasks .size ());
352+ 		IntervalTask  task  = fixedRateTasks .get (0 );
353+ 		ScheduledMethodRunnable  runnable  = (ScheduledMethodRunnable ) task .getRunnable ();
354+ 		Object  targetObject  = runnable .getTarget ();
355+ 		Method  targetMethod  = runnable .getMethod ();
356+ 		assertEquals (target , targetObject );
357+ 		assertEquals ("checkForUpdates" , targetMethod .getName ());
358+ 		assertEquals (5000L , task .getInterval ());
359+ 		assertEquals (1000L , task .getInitialDelay ());
360+ 	}
361+ 
335362	@ Test 
336363	public  void  metaAnnotationWithCronExpression () {
337364		BeanDefinition  processorDefinition  = new  RootBeanDefinition (ScheduledAnnotationBeanPostProcessor .class );
@@ -604,7 +631,7 @@ static class FixedRatesSubBean extends FixedRatesBaseBean {
604631	}
605632
606633
607- 	static   interface  FixedRatesDefaultMethod  {
634+ 	interface  FixedRatesDefaultMethod  {
608635
609636		@ Scheduled (fixedRate =4000 )
610637		@ Scheduled (fixedRate =4000 , initialDelay =2000 )
@@ -681,14 +708,25 @@ public void invalid(String oops) {
681708	@ Scheduled (fixedRate =5000 )
682709	@ Target (ElementType .METHOD )
683710	@ Retention (RetentionPolicy .RUNTIME )
684- 	private  static   @interface EveryFiveSeconds  {} 
685- 
711+ 	private  @interface EveryFiveSeconds  {
712+ 	} 
686713
687714	@ Scheduled (cron ="0 0 * * * ?" )
688715	@ Target (ElementType .METHOD )
689716	@ Retention (RetentionPolicy .RUNTIME )
690- 	private  static  @interface Hourly  {}
717+ 	private  @interface Hourly  {
718+ 	}
719+ 
720+ 	@ Scheduled (initialDelay  = 1000 )
721+ 	@ Retention (RetentionPolicy .RUNTIME )
722+ 	private  @interface WaitASec  {
723+ 
724+ 		@ AliasFor (annotation  = Scheduled .class )
725+ 		long  fixedDelay () default  -1 ;
691726
727+ 		@ AliasFor (annotation  = Scheduled .class )
728+ 		long  fixedRate () default  -1 ;
729+ 	}
692730
693731	static  class  MetaAnnotationFixedRateTestBean  {
694732
@@ -697,6 +735,12 @@ public void checkForUpdates() {
697735		}
698736	}
699737
738+ 	static  class  ComposedAnnotationFixedRateTestBean  {
739+ 
740+ 		@ WaitASec (fixedRate  = 5000 )
741+ 		public  void  checkForUpdates () {
742+ 		}
743+ 	}
700744
701745	static  class  MetaAnnotationCronTestBean  {
702746
@@ -705,7 +749,6 @@ public void generateReport() {
705749		}
706750	}
707751
708- 
709752	static  class  PropertyPlaceholderWithCronTestBean  {
710753
711754		@ Scheduled (cron  = "${schedules.businessHours}" )
@@ -741,7 +784,7 @@ public void x() {
741784	@ Scheduled (cron ="${schedules.businessHours}" )
742785	@ Target (ElementType .METHOD )
743786	@ Retention (RetentionPolicy .RUNTIME )
744- 	private  static   @interface BusinessHours  {
787+ 	private  @interface BusinessHours  {
745788	}
746789
747790
0 commit comments