use of org.quartz.Scheduler in project camel by apache.
the class QuartzCustomCalendarFireTest method testQuartzCustomCronRouteNoFire.
@Test
public void testQuartzCustomCronRouteNoFire() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(0);
QuartzComponent component = context.getComponent("quartz2", QuartzComponent.class);
Scheduler scheduler = component.getScheduler();
Calendar c = scheduler.getCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR);
Date now = new Date();
java.util.Calendar tomorrow = java.util.Calendar.getInstance();
tomorrow.setTime(now);
tomorrow.add(java.util.Calendar.DAY_OF_MONTH, 1);
assertEquals(false, c.isTimeIncluded(tomorrow.getTimeInMillis()));
assertEquals(true, c.isTimeIncluded(now.getTime()));
assertMockEndpointsSatisfied();
}
use of org.quartz.Scheduler in project camel by apache.
the class QuartzEndpointConfigureTest method testConfigureGroupAndName.
@Test
public void testConfigureGroupAndName() throws Exception {
QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myName?trigger.repeatCount=3&trigger.repeatInterval=1000");
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()", "myName", triggerKey.getName());
assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
assertEquals("getJobName", "myName", jobDetail.getKey().getName());
assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
SimpleTrigger simpleTrigger = assertIsInstanceOf(SimpleTrigger.class, trigger);
assertEquals("getRepeatCount()", 3, simpleTrigger.getRepeatCount());
}
use of org.quartz.Scheduler 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.Scheduler in project camel by apache.
the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method getTrigger.
private Trigger getTrigger(CamelContext camel, String routeId) throws SchedulerException {
QuartzEndpoint endpoint = (QuartzEndpoint) (camel.getRoute(routeId).getEndpoint());
QuartzComponent component = endpoint.getComponent();
Scheduler scheduler = component.getScheduler();
return scheduler.getTrigger(endpoint.getTriggerKey());
}
use of org.quartz.Scheduler in project opennms by OpenNMS.
the class PollerTest method testSchedule.
public void testSchedule(boolean reschedule, OnmsMonitoredService svc) throws Exception {
Scheduler scheduler = createMock(Scheduler.class);
PollService pollService = createNiceMock(PollService.class);
PollerFrontEnd pollerFrontEnd = createMock(PollerFrontEnd.class);
svc.setId(7);
PollConfiguration pollConfig = new PollConfiguration(svc, new HashMap<String, Object>(), 300000);
PolledService polledService = new PolledService(pollConfig.getMonitoredService(), pollConfig.getMonitorConfiguration(), pollConfig.getPollModel());
Set<PolledService> polledServices = Collections.singleton(polledService);
Poller poller = new Poller();
pollerFrontEnd.addConfigurationChangedListener(poller);
pollerFrontEnd.addPropertyChangeListener(poller);
expect(pollerFrontEnd.getPolledServices()).andReturn(polledServices);
expect(pollerFrontEnd.isStarted()).andReturn(true);
expect(scheduler.deleteJob(new JobKey(polledService.toString(), PollJobDetail.GROUP))).andReturn(reschedule);
pollerFrontEnd.setInitialPollTime(eq(svc.getId()), isA(Date.class));
expect(scheduler.scheduleJob(isA(PollJobDetail.class), isA(Trigger.class))).andReturn(new Date());
replay(scheduler, pollService, pollerFrontEnd);
poller.setScheduler(scheduler);
poller.setPollerFrontEnd(pollerFrontEnd);
poller.afterPropertiesSet();
verify(scheduler, pollService, pollerFrontEnd);
}
Aggregations