Search in sources :

Example 21 with CronTrigger

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));
}
Also used : CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 22 with CronTrigger

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());
}
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 23 with CronTrigger

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);
}
Also used : CamelContext(org.apache.camel.CamelContext) CronTrigger(org.quartz.CronTrigger) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 24 with CronTrigger

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);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) CronTrigger(org.quartz.CronTrigger)

Example 25 with CronTrigger

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);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) CronTrigger(org.quartz.CronTrigger)

Aggregations

CronTrigger (org.quartz.CronTrigger)42 JobDetail (org.quartz.JobDetail)20 Test (org.junit.Test)17 Trigger (org.quartz.Trigger)14 SchedulerException (org.quartz.SchedulerException)13 Scheduler (org.quartz.Scheduler)12 SimpleTrigger (org.quartz.SimpleTrigger)11 TriggerKey (org.quartz.TriggerKey)7 JobKey (org.quartz.JobKey)5 Date (java.util.Date)4 CamelContext (org.apache.camel.CamelContext)4 JobDataMap (org.quartz.JobDataMap)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 CronScheduleBuilder (org.quartz.CronScheduleBuilder)2 JobExecutionException (org.quartz.JobExecutionException)2