Search in sources :

Example 11 with TriggerContext

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

the class CronTriggerTests method testIncrementMinute.

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

Example 12 with TriggerContext

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

the class CronTriggerTests method testIncrementMinuteByOne.

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

Example 13 with TriggerContext

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

the class CronTriggerTests method testIncrementSecondByOne.

@Test
public void testIncrementSecondByOne() throws Exception {
    CronTrigger trigger = new CronTrigger("11 * * * * *", timeZone);
    calendar.set(Calendar.SECOND, 10);
    Date date = calendar.getTime();
    calendar.add(Calendar.SECOND, 1);
    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 14 with TriggerContext

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

the class CronTriggerTests method testIncrementDayOfWeekByOne.

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

Example 15 with TriggerContext

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

the class CronTriggerTests method testIncrementDayOfMonthByOne.

@Test
public void testIncrementDayOfMonthByOne() throws Exception {
    CronTrigger trigger = new CronTrigger("* * * 10 * *", timeZone);
    calendar.set(Calendar.DAY_OF_MONTH, 9);
    Date date = calendar.getTime();
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    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)

Aggregations

TriggerContext (org.springframework.scheduling.TriggerContext)33 Date (java.util.Date)31 Test (org.junit.Test)31 Trigger (org.springframework.scheduling.Trigger)2 Method (java.lang.reflect.Method)1 Calendar (java.util.Calendar)1 List (java.util.List)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 CronTask (org.springframework.scheduling.config.CronTask)1 ScheduledTaskRegistrar (org.springframework.scheduling.config.ScheduledTaskRegistrar)1 CronTrigger (org.springframework.scheduling.support.CronTrigger)1 ScheduledMethodRunnable (org.springframework.scheduling.support.ScheduledMethodRunnable)1 SimpleTriggerContext (org.springframework.scheduling.support.SimpleTriggerContext)1