use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testDailyTriggerInLongMonth.
@Test
public void testDailyTriggerInLongMonth() throws Exception {
CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
// August: 31 days and not a daylight saving boundary
calendar.set(Calendar.MONTH, 7);
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));
// September
calendar.set(Calendar.MONTH, 8);
calendar.set(Calendar.DAY_OF_MONTH, 1);
TriggerContext context2 = getTriggerContext(date);
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testIncrementHour.
@Test
public void testIncrementHour() throws Exception {
CronTrigger trigger = new CronTrigger("0 0 * * * *", timeZone);
calendar.set(Calendar.MONTH, 9);
calendar.set(Calendar.DAY_OF_MONTH, 30);
calendar.set(Calendar.HOUR_OF_DAY, 11);
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, 12);
TriggerContext context1 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
calendar.set(Calendar.HOUR_OF_DAY, 13);
TriggerContext context2 = getTriggerContext(date);
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testIncrementDayOfWeekAndRollover.
@Test
public void testIncrementDayOfWeekAndRollover() throws Exception {
CronTrigger trigger = new CronTrigger("* * * * * 2", timeZone);
calendar.set(Calendar.DAY_OF_WEEK, 4);
Date date = calendar.getTime();
calendar.add(Calendar.DAY_OF_MONTH, 6);
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));
}
use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testIncrementMonthAndRollover.
@Test
public void testIncrementMonthAndRollover() throws Exception {
CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone);
calendar.set(Calendar.MONTH, 11);
calendar.set(Calendar.DAY_OF_MONTH, 31);
calendar.set(Calendar.YEAR, 2010);
Date date = calendar.getTime();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.YEAR, 2011);
TriggerContext context1 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
calendar.set(Calendar.MONTH, 1);
TriggerContext context2 = getTriggerContext(date);
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
use of org.springframework.scheduling.TriggerContext in project uPortal by Jasig.
the class DelegatingThreadPoolTaskScheduler method schedule.
@Override
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
task = wrapRunnable(task);
// Wrap the trigger so that the first call to nextExecutionTime adds in the
// additionalStartDelay
final Trigger wrappedTrigger = new Trigger() {
boolean firstExecution = false;
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
Date nextExecutionTime = trigger.nextExecutionTime(triggerContext);
if (nextExecutionTime == null) {
return null;
}
if (firstExecution) {
nextExecutionTime = getDelayedStartDate(nextExecutionTime);
firstExecution = true;
}
return nextExecutionTime;
}
};
final DelegatingRunnable delegatingRunnable = new DelegatingRunnable(this.executorService, task);
@SuppressWarnings("unchecked") final ScheduledFuture<?> future = super.schedule(delegatingRunnable, wrappedTrigger);
return (ScheduledFuture<ScheduledFuture<?>>) new DelegatingForwardingScheduledFuture(future);
}
Aggregations