Search in sources :

Example 16 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/quartz/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/quartz/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 17 with CronTrigger

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

the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method testRestartAppChangeCronExpression.

@Test
public void testRestartAppChangeCronExpression() throws Exception {
    // Test creates application context twice with different cron expressions in configuration xml.
    // Both times it retrieves back the cron expression, accessing it via trigger (so, using value stored in DB).
    // After that it asserts that two cron expressions are not equal.
    // load spring app
    app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartAppChangeCronExpressionTest1.xml");
    app.start();
    CamelContext camel = app.getBean("camelContext", CamelContext.class);
    assertNotNull(camel);
    String cronExpression = ((CronTrigger) getTrigger(camel, "quartzRoute")).getCronExpression();
    app.stop();
    log.info("Restarting ...");
    log.info("Restarting ...");
    log.info("Restarting ...");
    // load spring app
    app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartAppChangeCronExpressionTest2.xml");
    app2.start();
    CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
    assertNotNull(camel2);
    String cronExpression2 = ((CronTrigger) getTrigger(camel2, "quartzRoute")).getCronExpression();
    app2.stop();
    assertNotEquals(cronExpression, cronExpression2);
    app3 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartAppChangeCronExpressionTest3.xml");
    app3.start();
    CamelContext camel3 = app3.getBean("camelContext3", CamelContext.class);
    assertNotNull(camel3);
    String cronExpression3 = ((CronTrigger) getTrigger(camel3, "quartzRoute")).getCronExpression();
    app3.stop();
    assertEquals(cronExpression2, cronExpression3);
}
Also used : CamelContext(org.apache.camel.CamelContext) CronTrigger(org.quartz.CronTrigger) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 18 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("quartz://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI");
    CronTrigger trigger = assertIsInstanceOf(CronTrigger.class, endpoint.getTrigger());
    assertEquals("getName()", "myTimerName", trigger.getName());
    assertEquals("getGroup()", "myGroup", trigger.getGroup());
    assertEquals("cron expression", "0 0/5 12-18 ? * MON-FRI", trigger.getCronExpression());
    // default job name
    assertEquals("getJobName", "quartz-" + endpoint.getId(), endpoint.getJobName());
}
Also used : CronTrigger(org.quartz.CronTrigger) Test(org.junit.Test)

Example 19 with CronTrigger

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

the class QuartzEndpoint method hasTriggerChanged.

private boolean hasTriggerChanged(Trigger oldTrigger, Trigger newTrigger) {
    if (newTrigger instanceof CronTrigger && oldTrigger instanceof CronTrigger) {
        CronTrigger newCron = (CronTrigger) newTrigger;
        CronTrigger oldCron = (CronTrigger) oldTrigger;
        return !newCron.getCronExpression().equals(oldCron.getCronExpression());
    } else if (newTrigger instanceof SimpleTrigger && oldTrigger instanceof SimpleTrigger) {
        SimpleTrigger newSimple = (SimpleTrigger) newTrigger;
        SimpleTrigger oldSimple = (SimpleTrigger) oldTrigger;
        return newSimple.getRepeatInterval() != oldSimple.getRepeatInterval() || newSimple.getRepeatCount() != oldSimple.getRepeatCount();
    } else {
        return !newTrigger.getClass().equals(oldTrigger.getClass()) || !newTrigger.equals(oldTrigger);
    }
}
Also used : CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger)

Example 20 with CronTrigger

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

the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method testRestartAppChangeCronExpression.

@Test
public void testRestartAppChangeCronExpression() throws Exception {
    // Test creates application context twice with different cron expressions in configuration xml.
    // Both times it retrieves back the cron expression, accessing it via trigger (so, using value stored in DB).
    // After that it asserts that two cron expressions 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);
    String cronExpression = ((CronTrigger) getTrigger(camel, "quartzRoute")).getCronExpression();
    app.stop();
    log.info("Restarting ...");
    log.info("Restarting ...");
    log.info("Restarting ...");
    // load spring app
    app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeCronExpressionTest2.xml");
    app2.start();
    CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
    assertNotNull(camel2);
    String cronExpression2 = ((CronTrigger) getTrigger(camel2, "quartzRoute")).getCronExpression();
    app2.stop();
    assertNotEquals(cronExpression, cronExpression2);
    // load spring app
    app3 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeCronExpressionTest3.xml");
    app3.start();
    CamelContext camel3 = app3.getBean("camelContext3", CamelContext.class);
    assertNotNull(camel3);
    String cronExpression3 = ((CronTrigger) getTrigger(camel3, "quartzRoute")).getCronExpression();
    app3.stop();
    assertEquals(cronExpression2, cronExpression3);
}
Also used : CamelContext(org.apache.camel.CamelContext) CronTrigger(org.quartz.CronTrigger) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

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