Search in sources :

Example 36 with TriggerContext

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

the class CronTriggerTests method testMatchAll.

@Test
public void testMatchAll() throws Exception {
    CronTrigger trigger = new CronTrigger("* * * * * *", timeZone);
    TriggerContext context = getTriggerContext(date);
    assertEquals(calendar.getTime(), trigger.nextExecutionTime(context));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Test(org.junit.Test)

Example 37 with TriggerContext

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

the class CronTriggerTests method testIncrementMinuteAndRollover.

@Test
public void testIncrementMinuteAndRollover() throws Exception {
    CronTrigger trigger = new CronTrigger("0 10 * * * *", timeZone);
    calendar.set(Calendar.MINUTE, 11);
    calendar.set(Calendar.SECOND, 0);
    Date date = calendar.getTime();
    calendar.add(Calendar.MINUTE, 59);
    TriggerContext context = getTriggerContext(date);
    assertEquals(calendar.getTime(), trigger.nextExecutionTime(context));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) Test(org.junit.Test)

Example 38 with TriggerContext

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

the class CronTriggerTests method testIncrementHourAndRollover.

@Test
public void testIncrementHourAndRollover() throws Exception {
    CronTrigger trigger = new CronTrigger("0 0 * * * *", timeZone);
    calendar.set(Calendar.MONTH, 9);
    calendar.set(Calendar.DAY_OF_MONTH, 10);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 1);
    calendar.set(Calendar.SECOND, 0);
    Date date = calendar.getTime();
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 11);
    TriggerContext context1 = getTriggerContext(date);
    assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
    calendar.set(Calendar.HOUR_OF_DAY, 1);
    TriggerContext context2 = getTriggerContext(date);
    assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) Test(org.junit.Test)

Example 39 with TriggerContext

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

the class CronTriggerTests method testLeapYearSpecificDate.

@Test
public void testLeapYearSpecificDate() throws Exception {
    CronTrigger trigger = new CronTrigger("0 0 0 29 2 *", timeZone);
    calendar.set(Calendar.YEAR, 2007);
    calendar.set(Calendar.DAY_OF_MONTH, 10);
    // 2=February
    calendar.set(Calendar.MONTH, 1);
    Date date = calendar.getTime();
    TriggerContext context1 = getTriggerContext(date);
    calendar.set(Calendar.YEAR, 2008);
    calendar.set(Calendar.DAY_OF_MONTH, 29);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
    calendar.add(Calendar.YEAR, 4);
    TriggerContext context2 = getTriggerContext(date);
    assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) Test(org.junit.Test)

Example 40 with TriggerContext

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

the class CronTriggerTests method testDailyTriggerOnDaylightSavingBoundary.

@Test
public void testDailyTriggerOnDaylightSavingBoundary() throws Exception {
    CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
    // October: 31 days and a daylight saving boundary in CET
    calendar.set(Calendar.MONTH, 9);
    calendar.set(Calendar.DAY_OF_MONTH, 30);
    Date date = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 31);
    TriggerContext context1 = getTriggerContext(date);
    assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
    // November
    calendar.set(Calendar.MONTH, 10);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    TriggerContext context2 = getTriggerContext(date);
    assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) Test(org.junit.Test)

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