use of org.quartz.TriggerListener in project opennms by OpenNMS.
the class ImportSchedulerIT method createJobAndVerifyImportJobFactoryIsRegistered.
@Test
public void createJobAndVerifyImportJobFactoryIsRegistered() throws SchedulerException, InterruptedException {
RequisitionDef def = m_dao.getDefs().get(0);
JobDetail detail = new JobDetailImpl("test", ImportScheduler.JOB_GROUP, ImportJob.class, false, false);
detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource());
detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
class MyBoolWrapper {
volatile Boolean m_called = false;
public Boolean getCalled() {
return m_called;
}
public void setCalled(Boolean called) {
m_called = called;
}
}
final MyBoolWrapper callTracker = new MyBoolWrapper();
m_importScheduler.getScheduler().getListenerManager().addTriggerListener(new TriggerListener() {
@Override
public String getName() {
return "TestTriggerListener";
}
@Override
public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
LOG.info("triggerComplete called on trigger listener");
callTracker.setCalled(true);
}
@Override
public void triggerFired(Trigger trigger, JobExecutionContext context) {
LOG.info("triggerFired called on trigger listener");
Job jobInstance = context.getJobInstance();
if (jobInstance instanceof ImportJob) {
Assert.assertNotNull(((ImportJob) jobInstance).getProvisioner());
Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.URL));
Assert.assertEquals("dns://localhost/localhost", context.getJobDetail().getJobDataMap().get(ImportJob.URL));
Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.RESCAN_EXISTING));
Assert.assertEquals("dbonly", context.getJobDetail().getJobDataMap().get(ImportJob.RESCAN_EXISTING));
}
callTracker.setCalled(true);
}
@Override
public void triggerMisfired(Trigger trigger) {
LOG.info("triggerMisFired called on trigger listener");
callTracker.setCalled(true);
}
@Override
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
LOG.info("vetoJobExecution called on trigger listener");
callTracker.setCalled(true);
return false;
}
});
Calendar testCal = Calendar.getInstance();
testCal.add(Calendar.SECOND, 5);
SimpleTriggerImpl trigger = new SimpleTriggerImpl("test", ImportScheduler.JOB_GROUP, testCal.getTime());
m_importScheduler.getScheduler().scheduleJob(detail, trigger);
m_importScheduler.start();
int callCheck = 0;
while (!callTracker.getCalled() && callCheck++ < 2) {
Thread.sleep(5000);
}
//TODO: need to fix the interrupted exception that occurs in the provisioner
}
Aggregations