Search in sources :

Example 56 with Scheduler

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

the class QuartzCustomCalendarNoFireTest 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(true, c.isTimeIncluded(tomorrow.getTimeInMillis()));
    assertEquals(false, 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 57 with Scheduler

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

the class QuartzEndpointConfigureTest method testConfigureName.

@Test
public void testConfigureName() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myName");
    Scheduler scheduler = endpoint.getComponent().getScheduler();
    TriggerKey triggerKey = endpoint.getTriggerKey();
    JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
    assertEquals("getName()", "myName", triggerKey.getName());
    assertEquals("getGroup()", "Camel_" + context.getManagementName(), triggerKey.getGroup());
    assertEquals("getJobName", "myName", jobDetail.getKey().getName());
    assertEquals("getJobGroup", "Camel_" + context.getManagementName(), jobDetail.getKey().getGroup());
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) Scheduler(org.quartz.Scheduler) Test(org.junit.Test)

Example 58 with Scheduler

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

the class QuartzEndpointConfigureTest method testConfigureAnotherCronExpression.

@Test
public void testConfigureAnotherCronExpression() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myTimerName?cron=0+0+*+*+*+?");
    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 * * * ?", 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 59 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.getTrigger().getName(), endpoint.getTrigger().getGroup());
}
Also used : Scheduler(org.quartz.Scheduler)

Example 60 with Scheduler

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

the class QuartzComponentCamelContextSharedSchedulerTest method setUp.

@Before
public void setUp() throws Exception {
    camel1 = new DefaultCamelContext();
    camel1.setName("camel-1");
    camel1.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("quartz2://myGroup/myTimerName?cron=0/2+*+*+*+*+?").to("mock:one");
        }
    });
    camel1.start();
    camel2 = new DefaultCamelContext();
    camel2.setName("camel-2");
    Scheduler camel1Scheduler = camel1.getComponent("quartz2", QuartzComponent.class).getScheduler();
    QuartzComponent camel2QuartzComponent = camel2.getComponent("quartz2", QuartzComponent.class);
    camel2QuartzComponent.setScheduler(camel1Scheduler);
    camel2.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("quartz2://myOtherGroup/myOtherTimerName?cron=0/1+*+*+*+*+?").to("mock:two");
        }
    });
    camel2.start();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(org.quartz.Scheduler) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Before(org.junit.Before)

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