Search in sources :

Example 61 with Scheduler

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

the class QuartzNameCollisionTest method testRemoveJob.

/**
     * Confirm the quartz trigger is removed on route stop.
     */
@Test
public void testRemoveJob() throws Exception {
    camel1 = new DefaultCamelContext();
    camel1.setName("camel-1");
    camel1.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").id("route-1").to("log:one", "mock:one");
        }
    });
    camel1.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("quartz://myGroup2/myTimerName?cron=0/1+*+*+*+*+?").id("route-2").to("log:one", "mock:one");
        }
    });
    camel1.start();
    QuartzComponent component = (QuartzComponent) camel1.getComponent("quartz");
    Scheduler scheduler = component.getScheduler();
    Trigger trigger = scheduler.getTrigger("myTimerName", "myGroup");
    Assert.assertNotNull(trigger);
    camel1.stopRoute("route-1");
    int triggerState = component.getScheduler().getTriggerState("myTimerName", "myGroup");
    Assert.assertNotNull(trigger);
    Assert.assertEquals(Trigger.STATE_PAUSED, triggerState);
}
Also used : Trigger(org.quartz.Trigger) RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(org.quartz.Scheduler) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 62 with Scheduler

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

the class QuartzEndpointConfigureTest method testConfigureJobName.

@Test
public void testConfigureJobName() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myTimerName?job.name=hadrian&cron=0+0+*+*+*+?");
    Scheduler scheduler = endpoint.getComponent().getScheduler();
    TriggerKey triggerKey = endpoint.getTriggerKey();
    Trigger trigger = scheduler.getTrigger(triggerKey);
    JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey("hadrian", triggerKey.getGroup()));
    assertEquals("getName()", "myTimerName", triggerKey.getName());
    assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
    assertEquals("getJobName", "hadrian", jobDetail.getKey().getName());
    assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
    assertIsInstanceOf(CronTrigger.class, trigger);
}
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) Test(org.junit.Test)

Example 63 with Scheduler

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

the class QuartzEndpointConfigureTest method testConfigureNoDoubleSlashQuestionCron.

@Test
public void testConfigureNoDoubleSlashQuestionCron() 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 64 with Scheduler

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

the class QuartzManuallyTriggerJobTest method testQuartzCronRoute.

@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    QuartzComponent component = context.getComponent("quartz2", QuartzComponent.class);
    Scheduler scheduler = component.getScheduler();
    // collect all jobKeys of this route (ideally only one).
    ArrayList<JobKey> jobKeys = new ArrayList<JobKey>();
    for (String group : scheduler.getJobGroupNames()) {
        for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
            jobKeys.add(jobKey);
        }
    }
    JobDataMap jobDataMap = scheduler.getJobDetail(jobKeys.get(0)).getJobDataMap();
    // trigger job manually
    scheduler.triggerJob(jobKeys.get(0), jobDataMap);
    assertMockEndpointsSatisfied();
}
Also used : JobKey(org.quartz.JobKey) JobDataMap(org.quartz.JobDataMap) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Scheduler(org.quartz.Scheduler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 65 with Scheduler

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

the class QuartzNameCollisionTest method testRemoveJob.

/**
     * Confirm the quartz trigger is removed on route stop.
     */
@Test
public void testRemoveJob() 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/1+*+*+*+*+?").id("route-1").to("log:one", "mock:one");
        }
    });
    camel1.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("quartz2://myGroup2/myTimerName?cron=0/1+*+*+*+*+?").id("route-2").to("log:one", "mock:one");
        }
    });
    camel1.start();
    QuartzComponent component = (QuartzComponent) camel1.getComponent("quartz2");
    Scheduler scheduler = component.getScheduler();
    TriggerKey triggerKey = TriggerKey.triggerKey("myTimerName", "myGroup");
    Trigger trigger = scheduler.getTrigger(triggerKey);
    Assert.assertNotNull(trigger);
    camel1.stopRoute("route-1");
    Trigger.TriggerState triggerState = component.getScheduler().getTriggerState(triggerKey);
    Assert.assertNotNull(trigger);
    Assert.assertEquals(Trigger.TriggerState.PAUSED, triggerState);
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(org.quartz.Scheduler) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

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