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