use of org.quartz.CronTrigger in project camel by apache.
the class QuartzCronRouteTest method testQuartzCronRoute.
@Test
public void testQuartzCronRoute() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(3);
assertMockEndpointsSatisfied();
Trigger trigger = mock.getReceivedExchanges().get(0).getIn().getHeader("trigger", Trigger.class);
Assert.assertThat(trigger instanceof CronTrigger, CoreMatchers.is(true));
JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
Assert.assertThat(detail.getJobClass().equals(CamelJob.class), CoreMatchers.is(true));
Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE).equals("cron"), CoreMatchers.is(true));
Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION).equals("0/2 * * * * ?"), CoreMatchers.is(true));
}
use of org.quartz.CronTrigger 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());
}
use of org.quartz.CronTrigger in project camel by apache.
the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method testRestartAppChangeTriggerType.
@Test
public void testRestartAppChangeTriggerType() throws Exception {
// Test creates application context twice with different simple trigger options in configuration xml.
// Both times it retrieves back the option, accessing it via trigger (so, using value stored in DB).
// After that it asserts that two options are not equal.
// load spring app
app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeCronExpressionTest1.xml");
app.start();
CamelContext camel = app.getBean("camelContext", CamelContext.class);
assertNotNull(camel);
assertTrue(getTrigger(camel, "quartzRoute") instanceof CronTrigger);
app.stop();
log.info("Restarting ...");
log.info("Restarting ...");
log.info("Restarting ...");
// load spring app
AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeOptionsTest2.xml");
app2.start();
CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
assertNotNull(camel2);
assertTrue(getTrigger(camel2, "quartzRoute") instanceof SimpleTrigger);
app2.stop();
// we're done so let's properly close the application contexts, but close
// the second app before the first one so that the quartz scheduler running
// inside it can be properly shutdown
IOHelper.close(app2, app);
}
use of org.quartz.CronTrigger in project opennms by OpenNMS.
the class ReportScheduler method printCurrentSchedule.
private void printCurrentSchedule() {
try {
LOG.info("calendarNames: {}", String.join(", ", getScheduler().getCalendarNames().toArray(new String[0])));
LOG.info("current executing jobs: {}", StringUtils.arrayToCommaDelimitedString(getScheduler().getCurrentlyExecutingJobs().toArray()));
LOG.info("current job names: {}", getScheduler().getJobKeys(GroupMatcher.<JobKey>groupEquals(JOB_GROUP)).stream().map(JobKey::getName).collect(Collectors.joining(", ")));
LOG.info("scheduler metadata: {}", getScheduler().getMetaData());
LOG.info("trigger names: {}", getScheduler().getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(JOB_GROUP)).stream().map(TriggerKey::getName).collect(Collectors.joining(", ")));
for (TriggerKey key : getScheduler().getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(JOB_GROUP))) {
CronTrigger t = (CronTrigger) getScheduler().getTrigger(key);
StringBuilder sb = new StringBuilder("trigger: ");
sb.append(key.getName());
sb.append(", calendar name: ");
sb.append(t.getCalendarName());
sb.append(", cron expression: ");
sb.append(t.getCronExpression());
sb.append(", URL: ");
sb.append(t.getJobDataMap().get(ReportJob.KEY));
sb.append(", next fire time: ");
sb.append(t.getNextFireTime());
sb.append(", previous fire time: ");
sb.append(t.getPreviousFireTime());
sb.append(", time zone: ");
sb.append(t.getTimeZone());
sb.append(", priority: ");
sb.append(t.getPriority());
LOG.info(sb.toString());
}
} catch (Throwable e) {
LOG.error("printCurrentSchedule: {}", e.getMessage(), e);
}
}
use of org.quartz.CronTrigger in project opennms by OpenNMS.
the class ImportScheduler method printCurrentSchedule.
private void printCurrentSchedule() {
try {
LOG.info("calendarNames: {}", String.join(", ", getScheduler().getCalendarNames().toArray(new String[0])));
LOG.info("current executing jobs: {}", StringUtils.arrayToCommaDelimitedString(getScheduler().getCurrentlyExecutingJobs().toArray()));
LOG.info("current job names: {}", getScheduler().getJobKeys(GroupMatcher.<JobKey>groupEquals(JOB_GROUP)).stream().map(JobKey::getName).collect(Collectors.joining(", ")));
LOG.info("scheduler metadata: {}", getScheduler().getMetaData());
LOG.info("trigger names: {}", getScheduler().getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(JOB_GROUP)).stream().map(TriggerKey::getName).collect(Collectors.joining(", ")));
for (TriggerKey key : getScheduler().getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(JOB_GROUP))) {
String triggerName = key.getName();
CronTrigger t = (CronTrigger) getScheduler().getTrigger(key);
LOG.info("trigger: {}, calendar name: {}, cron expression: {}, URL: {}, rescanExisting: {}, next fire time: {}, previous fire time: {}, time zone: {}, priority: {}", triggerName, t.getCalendarName(), t.getCronExpression(), t.getJobDataMap().get(ImportJob.URL), t.getJobDataMap().get(ImportJob.RESCAN_EXISTING), t.getNextFireTime(), t.getPreviousFireTime(), t.getTimeZone(), t.getPriority());
}
} catch (Throwable e) {
LOG.error("printCurrentSchedule: {}", e.getLocalizedMessage(), e);
}
}
Aggregations