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);
}
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);
}
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());
}
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();
}
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);
}
Aggregations