Search in sources :

Example 61 with TriggerContext

use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.

the class CronTriggerTests method specificMinuteHour.

@ParameterizedCronTriggerTest
void specificMinuteHour(Date localDateTime, TimeZone timeZone) {
    setup(localDateTime, timeZone);
    CronTrigger trigger = new CronTrigger("* 5 10 * * *", timeZone);
    this.calendar.set(Calendar.MINUTE, 4);
    this.calendar.set(Calendar.HOUR_OF_DAY, 9);
    Date localDate = this.calendar.getTime();
    this.calendar.add(Calendar.MINUTE, 1);
    this.calendar.add(Calendar.HOUR_OF_DAY, 1);
    this.calendar.set(Calendar.SECOND, 0);
    TriggerContext context1 = getTriggerContext(localDate);
    Object actual1 = localDate = trigger.nextExecutionTime(context1);
    assertThat(actual1).isEqualTo(this.calendar.getTime());
    // next trigger is in one second because second is wildcard
    this.calendar.add(Calendar.SECOND, 1);
    TriggerContext context2 = getTriggerContext(localDate);
    Object actual = trigger.nextExecutionTime(context2);
    assertThat(actual).isEqualTo(this.calendar.getTime());
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date)

Example 62 with TriggerContext

use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.

the class CronTriggerTests method leapYearSpecificDate.

@ParameterizedCronTriggerTest
void leapYearSpecificDate(Date localDateTime, TimeZone timeZone) {
    setup(localDateTime, timeZone);
    CronTrigger trigger = new CronTrigger("0 0 0 29 2 *", timeZone);
    this.calendar.set(Calendar.YEAR, 2007);
    this.calendar.set(Calendar.DAY_OF_MONTH, 10);
    // 2=February
    this.calendar.set(Calendar.MONTH, 1);
    Date localDate = this.calendar.getTime();
    TriggerContext context1 = getTriggerContext(localDate);
    this.calendar.set(Calendar.YEAR, 2008);
    this.calendar.set(Calendar.DAY_OF_MONTH, 29);
    this.calendar.set(Calendar.HOUR_OF_DAY, 0);
    this.calendar.set(Calendar.MINUTE, 0);
    this.calendar.set(Calendar.SECOND, 0);
    Object actual1 = localDate = trigger.nextExecutionTime(context1);
    assertThat(actual1).isEqualTo(this.calendar.getTime());
    this.calendar.add(Calendar.YEAR, 4);
    TriggerContext context2 = getTriggerContext(localDate);
    Object actual = trigger.nextExecutionTime(context2);
    assertThat(actual).isEqualTo(this.calendar.getTime());
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date)

Example 63 with TriggerContext

use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.

the class CronTriggerTests method incrementDayOfMonth.

@ParameterizedCronTriggerTest
void incrementDayOfMonth(Date localDateTime, TimeZone timeZone) {
    setup(localDateTime, timeZone);
    CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
    this.calendar.set(Calendar.DAY_OF_MONTH, 1);
    Date localDate = this.calendar.getTime();
    this.calendar.add(Calendar.DAY_OF_MONTH, 1);
    this.calendar.set(Calendar.HOUR_OF_DAY, 0);
    this.calendar.set(Calendar.MINUTE, 0);
    this.calendar.set(Calendar.SECOND, 0);
    TriggerContext context1 = getTriggerContext(localDate);
    Object actual1 = localDate = trigger.nextExecutionTime(context1);
    assertThat(actual1).isEqualTo(this.calendar.getTime());
    assertThat(this.calendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(2);
    this.calendar.add(Calendar.DAY_OF_MONTH, 1);
    TriggerContext context2 = getTriggerContext(localDate);
    Object actual = trigger.nextExecutionTime(context2);
    assertThat(actual).isEqualTo(this.calendar.getTime());
    assertThat(this.calendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(3);
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date)

Example 64 with TriggerContext

use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.

the class CronTriggerTests method dailyTriggerInShortMonth.

@ParameterizedCronTriggerTest
void dailyTriggerInShortMonth(Date localDateTime, TimeZone timeZone) {
    setup(localDateTime, timeZone);
    CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
    // September: 30 days
    this.calendar.set(Calendar.MONTH, 8);
    this.calendar.set(Calendar.DAY_OF_MONTH, 30);
    Date localDate = this.calendar.getTime();
    // October
    this.calendar.set(Calendar.MONTH, 9);
    this.calendar.set(Calendar.HOUR_OF_DAY, 0);
    this.calendar.set(Calendar.MINUTE, 0);
    this.calendar.set(Calendar.SECOND, 0);
    this.calendar.set(Calendar.DAY_OF_MONTH, 1);
    TriggerContext context1 = getTriggerContext(localDate);
    Object actual = localDate = trigger.nextExecutionTime(context1);
    assertThat(actual).isEqualTo(this.calendar.getTime());
    this.calendar.set(Calendar.DAY_OF_MONTH, 2);
    TriggerContext context2 = getTriggerContext(localDate);
    assertThat(trigger.nextExecutionTime(context2)).isEqualTo(this.calendar.getTime());
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date)

Example 65 with TriggerContext

use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.

the class CronTriggerTests method incrementDayOfWeekByOne.

@ParameterizedCronTriggerTest
void incrementDayOfWeekByOne(Date localDateTime, TimeZone timeZone) {
    setup(localDateTime, timeZone);
    CronTrigger trigger = new CronTrigger("* * * * * 2", timeZone);
    this.calendar.set(Calendar.DAY_OF_WEEK, 2);
    Date localDate = this.calendar.getTime();
    this.calendar.add(Calendar.DAY_OF_WEEK, 1);
    this.calendar.set(Calendar.HOUR_OF_DAY, 0);
    this.calendar.set(Calendar.MINUTE, 0);
    this.calendar.set(Calendar.SECOND, 0);
    TriggerContext context = getTriggerContext(localDate);
    assertThat(trigger.nextExecutionTime(context)).isEqualTo(this.calendar.getTime());
    assertThat(this.calendar.get(Calendar.DAY_OF_WEEK)).isEqualTo(Calendar.TUESDAY);
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date)

Aggregations

TriggerContext (org.springframework.scheduling.TriggerContext)66 Date (java.util.Date)61 Test (org.junit.Test)33 Trigger (org.springframework.scheduling.Trigger)5 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 Advice (org.aopalliance.aop.Advice)2 AbstractMessageSourceAdvice (org.springframework.integration.aop.AbstractMessageSourceAdvice)2 CompoundTriggerAdvice (org.springframework.integration.aop.CompoundTriggerAdvice)2 SimpleActiveIdleMessageSourceAdvice (org.springframework.integration.aop.SimpleActiveIdleMessageSourceAdvice)2 PollSkipAdvice (org.springframework.integration.scheduling.PollSkipAdvice)2 OnlyOnceTrigger (org.springframework.integration.test.util.OnlyOnceTrigger)2 CompoundTrigger (org.springframework.integration.util.CompoundTrigger)2 DynamicPeriodicTrigger (org.springframework.integration.util.DynamicPeriodicTrigger)2 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)2 ScheduledMethodRunnable (org.springframework.scheduling.support.ScheduledMethodRunnable)2 Method (java.lang.reflect.Method)1 Calendar (java.util.Calendar)1 List (java.util.List)1