use of org.motechproject.commons.api.NanoStopWatch in project motech by motech.
the class TestListener method scheduleJobs.
private void scheduleJobs(MotechSchedulerFactoryBean schedulerFactoryBean, SettingsFacade settings) throws InterruptedException, SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getQuartzScheduler();
scheduler.clear();
try {
Map<String, Object> params = new HashMap<>();
params.put("foo", "bar");
params.put("fii", "bor");
params.put("fuu", "baz");
String eventSubject = "test_event";
MotechEvent motechEvent = new MotechEvent(eventSubject, params);
int maxJobs = 1;
int repeatCount = 1;
TestListener listener = new TestListener("test_listener", maxJobs, repeatCount);
eventListenerRegistryService.registerListener(listener, eventSubject);
DateTime startTime = now().plusSeconds(0);
Integer repeatInterval = 1;
System.out.println("startTime: " + startTime);
NanoStopWatch timeToSchedule = new NanoStopWatch().start();
for (int i = 0; i < maxJobs; i++) {
params.put(MotechSchedulerService.JOB_ID_KEY, "test_job_" + String.valueOf(i));
RepeatingSchedulableJob repeatingJob = new RepeatingSchedulableJob(motechEvent, repeatCount, repeatInterval, startTime, null, false);
repeatingJob.setUseOriginalFireTimeAfterMisfire(false);
schedulerService.scheduleRepeatingJob(repeatingJob);
}
System.out.println(format("Time to schedule : %dms", timeToSchedule.duration()));
scheduler.start();
synchronized (listener) {
while (scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains("default")).size() > 0) {
listener.wait(5000);
}
}
System.out.println(listener.getReport());
assertEquals(maxJobs * (repeatCount + 1), listener.getCount());
} finally {
eventListenerRegistryService.clearListenersForBean("test_listener");
schedulerFactoryBean.getQuartzScheduler().standby();
}
}
Aggregations