Search in sources :

Example 41 with TriggerContext

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));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) Test(org.junit.Test)

Example 42 with TriggerContext

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));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) Test(org.junit.Test)

Example 43 with TriggerContext

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));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) Test(org.junit.Test)

Example 44 with TriggerContext

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));
}
Also used : TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) Test(org.junit.Test)

Example 45 with TriggerContext

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);
}
Also used : Trigger(org.springframework.scheduling.Trigger) TriggerContext(org.springframework.scheduling.TriggerContext) Date(java.util.Date) ScheduledFuture(java.util.concurrent.ScheduledFuture)

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