Search in sources :

Example 26 with Scheduler

use of org.quartz.Scheduler in project camel by apache.

the class QuartzCustomCalendarFireTest method testQuartzCustomCronRouteNoFire.

@Test
public void testQuartzCustomCronRouteNoFire() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(0);
    QuartzComponent component = context.getComponent("quartz2", QuartzComponent.class);
    Scheduler scheduler = component.getScheduler();
    Calendar c = scheduler.getCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR);
    Date now = new Date();
    java.util.Calendar tomorrow = java.util.Calendar.getInstance();
    tomorrow.setTime(now);
    tomorrow.add(java.util.Calendar.DAY_OF_MONTH, 1);
    assertEquals(false, c.isTimeIncluded(tomorrow.getTimeInMillis()));
    assertEquals(true, c.isTimeIncluded(now.getTime()));
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Scheduler(org.quartz.Scheduler) Calendar(org.quartz.Calendar) HolidayCalendar(org.quartz.impl.calendar.HolidayCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 27 with Scheduler

use of org.quartz.Scheduler in project camel by apache.

the class QuartzEndpointConfigureTest method testConfigureGroupAndName.

@Test
public void testConfigureGroupAndName() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myName?trigger.repeatCount=3&trigger.repeatInterval=1000");
    Scheduler scheduler = endpoint.getComponent().getScheduler();
    TriggerKey triggerKey = endpoint.getTriggerKey();
    Trigger trigger = scheduler.getTrigger(triggerKey);
    JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
    assertEquals("getName()", "myName", triggerKey.getName());
    assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
    assertEquals("getJobName", "myName", jobDetail.getKey().getName());
    assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
    SimpleTrigger simpleTrigger = assertIsInstanceOf(SimpleTrigger.class, trigger);
    assertEquals("getRepeatCount()", 3, simpleTrigger.getRepeatCount());
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 28 with Scheduler

use of org.quartz.Scheduler in project camel by apache.

the class QuartzEndpointConfigureTest method testConfigureCronExpression.

@Test
public void testConfigureCronExpression() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI");
    Scheduler scheduler = endpoint.getComponent().getScheduler();
    TriggerKey triggerKey = endpoint.getTriggerKey();
    Trigger trigger = scheduler.getTrigger(triggerKey);
    JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
    assertEquals("getName()", "myTimerName", triggerKey.getName());
    assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
    assertEquals("getJobName", "myTimerName", jobDetail.getKey().getName());
    assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
    assertIsInstanceOf(CronTrigger.class, trigger);
    CronTrigger cronTrigger = (CronTrigger) trigger;
    assertEquals("cron expression", "0 0/5 12-18 ? * MON-FRI", cronTrigger.getCronExpression());
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) Test(org.junit.Test)

Example 29 with Scheduler

use of org.quartz.Scheduler in project camel by apache.

the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method getTrigger.

private Trigger getTrigger(CamelContext camel, String routeId) throws SchedulerException {
    QuartzEndpoint endpoint = (QuartzEndpoint) (camel.getRoute(routeId).getEndpoint());
    QuartzComponent component = endpoint.getComponent();
    Scheduler scheduler = component.getScheduler();
    return scheduler.getTrigger(endpoint.getTriggerKey());
}
Also used : Scheduler(org.quartz.Scheduler)

Example 30 with Scheduler

use of org.quartz.Scheduler in project opennms by OpenNMS.

the class PollerTest method testSchedule.

public void testSchedule(boolean reschedule, OnmsMonitoredService svc) throws Exception {
    Scheduler scheduler = createMock(Scheduler.class);
    PollService pollService = createNiceMock(PollService.class);
    PollerFrontEnd pollerFrontEnd = createMock(PollerFrontEnd.class);
    svc.setId(7);
    PollConfiguration pollConfig = new PollConfiguration(svc, new HashMap<String, Object>(), 300000);
    PolledService polledService = new PolledService(pollConfig.getMonitoredService(), pollConfig.getMonitorConfiguration(), pollConfig.getPollModel());
    Set<PolledService> polledServices = Collections.singleton(polledService);
    Poller poller = new Poller();
    pollerFrontEnd.addConfigurationChangedListener(poller);
    pollerFrontEnd.addPropertyChangeListener(poller);
    expect(pollerFrontEnd.getPolledServices()).andReturn(polledServices);
    expect(pollerFrontEnd.isStarted()).andReturn(true);
    expect(scheduler.deleteJob(new JobKey(polledService.toString(), PollJobDetail.GROUP))).andReturn(reschedule);
    pollerFrontEnd.setInitialPollTime(eq(svc.getId()), isA(Date.class));
    expect(scheduler.scheduleJob(isA(PollJobDetail.class), isA(Trigger.class))).andReturn(new Date());
    replay(scheduler, pollService, pollerFrontEnd);
    poller.setScheduler(scheduler);
    poller.setPollerFrontEnd(pollerFrontEnd);
    poller.afterPropertiesSet();
    verify(scheduler, pollService, pollerFrontEnd);
}
Also used : Scheduler(org.quartz.Scheduler) Date(java.util.Date) JobKey(org.quartz.JobKey) Trigger(org.quartz.Trigger)

Aggregations

Scheduler (org.quartz.Scheduler)73 SchedulerException (org.quartz.SchedulerException)37 JobDetail (org.quartz.JobDetail)33 Trigger (org.quartz.Trigger)22 Test (org.junit.Test)19 JobKey (org.quartz.JobKey)17 SimpleTrigger (org.quartz.SimpleTrigger)16 CronTrigger (org.quartz.CronTrigger)15 JobDataMap (org.quartz.JobDataMap)10 TriggerKey (org.quartz.TriggerKey)10 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)6 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 IOException (java.io.IOException)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)3