use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testIncrementDayOfMonth.
@Test
public void testIncrementDayOfMonth() throws Exception {
CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
calendar.set(Calendar.DAY_OF_MONTH, 1);
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 context1 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
assertEquals(2, calendar.get(Calendar.DAY_OF_MONTH));
calendar.add(Calendar.DAY_OF_MONTH, 1);
TriggerContext context2 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
assertEquals(3, calendar.get(Calendar.DAY_OF_MONTH));
}
use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testMonthlyTriggerInLongMonth.
@Test
public void testMonthlyTriggerInLongMonth() throws Exception {
CronTrigger trigger = new CronTrigger("0 0 0 31 * *", timeZone);
calendar.set(Calendar.MONTH, 9);
calendar.set(Calendar.DAY_OF_MONTH, 30);
Date date = calendar.getTime();
calendar.set(Calendar.DAY_OF_MONTH, 31);
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));
}
use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testSpecificDate.
@Test
public void testSpecificDate() throws Exception {
CronTrigger trigger = new CronTrigger("* * * 3 11 *", timeZone);
calendar.set(Calendar.DAY_OF_MONTH, 2);
calendar.set(Calendar.MONTH, 9);
Date date = calendar.getTime();
TriggerContext context1 = getTriggerContext(date);
calendar.add(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
// 10=November
calendar.set(Calendar.MONTH, 10);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
calendar.add(Calendar.SECOND, 1);
TriggerContext context2 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testSpecificMinuteHour.
@Test
public void testSpecificMinuteHour() throws Exception {
CronTrigger trigger = new CronTrigger("* 5 10 * * *", timeZone);
calendar.set(Calendar.MINUTE, 4);
calendar.set(Calendar.HOUR_OF_DAY, 9);
Date date = calendar.getTime();
calendar.add(Calendar.MINUTE, 1);
calendar.add(Calendar.HOUR_OF_DAY, 1);
calendar.set(Calendar.SECOND, 0);
TriggerContext context1 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
// next trigger is in one second because second is wildcard
calendar.add(Calendar.SECOND, 1);
TriggerContext context2 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testSpecificHourSecond.
@Test
public void testSpecificHourSecond() throws Exception {
CronTrigger trigger = new CronTrigger("55 * 10 * * *", timeZone);
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.SECOND, 54);
Date date = calendar.getTime();
TriggerContext context1 = getTriggerContext(date);
calendar.add(Calendar.HOUR_OF_DAY, 1);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 55);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
calendar.add(Calendar.MINUTE, 1);
TriggerContext context2 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
Aggregations