Search in sources :

Example 1 with TriggerFiredBundle

use of org.quartz.spi.TriggerFiredBundle in project head by mifos.

the class BatchJobCatchUpIntegrationTest method testIncompleteTaskDelay.

@Test
public void testIncompleteTaskDelay() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/catchUpTask.xml");
    Scheduler scheduler = mifosScheduler.getScheduler();
    ProductStatus productStatusTask = new ProductStatus();
    productStatusTask.setJobExplorer(mifosScheduler.getBatchJobExplorer());
    productStatusTask.setJobLauncher(mifosScheduler.getBatchJobLauncher());
    productStatusTask.setJobLocator(mifosScheduler.getBatchJobLocator());
    productStatusTask.setJobRepository(mifosScheduler.getBatchJobRepository());
    String quartzJobName = "ProductStatusJob";
    String quartzTriggerName = "ProductStatusTrigger2";
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 10);
    Date previousFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 21);
    Date quartzFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 22);
    Date quartzNextFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 20);
    Date quartzPrevFireTime = calendar.getTime();
    JobDetail jobDetail = scheduler.getJobDetail(quartzJobName, Scheduler.DEFAULT_GROUP);
    jobDetail.setJobDataMap(new JobDataMap());
    CronTrigger trigger = new CronTrigger(quartzTriggerName, Scheduler.DEFAULT_GROUP, quartzJobName, Scheduler.DEFAULT_GROUP, "* * * * * ?");
    trigger.setJobDataMap(new JobDataMap());
    TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(jobDetail, trigger, new BaseCalendar(), false, quartzFireTime, quartzFireTime, quartzPrevFireTime, quartzNextFireTime);
    JobExecutionContext jobExecutionContext = new JobExecutionContext(scheduler, triggerFiredBundle, productStatusTask);
    JobLauncher jobLauncher = mifosScheduler.getBatchJobLauncher();
    JobLocator jobLocator = mifosScheduler.getBatchJobLocator();
    jobLauncher.run(jobLocator.getJob(jobName), MifosBatchJob.createJobParameters(previousFireTime.getTime()));
    Thread.sleep(1500);
    productStatusTask.catchUpMissedLaunches(jobLocator.getJob(jobName), jobExecutionContext);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 20);
    Assert.assertEquals(11, jobInstances.size());
    for (JobInstance jobInstance : jobInstances) {
        List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstance);
        Assert.assertEquals(BatchStatus.COMPLETED, jobExecutions.get(0).getStatus());
        Assert.assertEquals(calendar.getTimeInMillis(), jobInstance.getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY));
        calendar.roll(Calendar.SECOND, false);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) CronTrigger(org.quartz.CronTrigger) JobLauncher(org.springframework.batch.core.launch.JobLauncher) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) JobInstance(org.springframework.batch.core.JobInstance) Scheduler(org.quartz.Scheduler) Calendar(java.util.Calendar) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) JobLocator(org.springframework.batch.core.configuration.JobLocator) ProductStatus(org.mifos.framework.components.batchjobs.helpers.ProductStatus) TriggerFiredBundle(org.quartz.spi.TriggerFiredBundle) Date(java.util.Date) JobExecution(org.springframework.batch.core.JobExecution) JobDetail(org.quartz.JobDetail) JobExecutionContext(org.quartz.JobExecutionContext) JobExplorer(org.springframework.batch.core.explore.JobExplorer) Test(org.junit.Test)

Example 2 with TriggerFiredBundle

use of org.quartz.spi.TriggerFiredBundle in project kylo by Teradata.

the class AutowiringSpringBeanJobFactoryTest method testSetApplicationContext.

@Test
public void testSetApplicationContext() throws Exception {
    JobDetailImpl jobDetail = new JobDetailImpl();
    jobDetail.setJobClass(MockJob.class);
    TriggerFiredBundle bundle = new TriggerFiredBundle(jobDetail, Mockito.mock(OperableTrigger.class), new BaseCalendar(), true, new Date(), new Date(), new Date(), new Date());
    assertNotNull(factory.createJobInstance(bundle));
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) JobDetailImpl(org.quartz.impl.JobDetailImpl) TriggerFiredBundle(org.quartz.spi.TriggerFiredBundle) Date(java.util.Date) Test(org.junit.Test)

Example 3 with TriggerFiredBundle

use of org.quartz.spi.TriggerFiredBundle in project candlepin by candlepin.

the class HighlanderFactoryTest method testNewJob.

@Test
public void testNewJob() throws SchedulerException, ParseException {
    assertNotNull(hf);
    try {
        hf.newJob(null, null);
        fail("should've died with npe");
    } catch (NullPointerException npe) {
    // Expected
    }
    String crontab = "0 0 12 * * ?";
    JobDetail jd = newJob(TestJob.class).withIdentity("testjob", "group").build();
    Trigger trigger = newTrigger().withIdentity("testjob", "group").withSchedule(cronSchedule(crontab)).build();
    TriggerFiredBundle tfb = new TriggerFiredBundle(jd, (OperableTrigger) trigger, null, false, null, null, null, null);
    Job j = hf.newJob(tfb, null);
    assertNotNull(j);
}
Also used : JobDetail(org.quartz.JobDetail) OperableTrigger(org.quartz.spi.OperableTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Trigger(org.quartz.Trigger) TriggerFiredBundle(org.quartz.spi.TriggerFiredBundle) JobBuilder.newJob(org.quartz.JobBuilder.newJob) Job(org.quartz.Job) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 TriggerFiredBundle (org.quartz.spi.TriggerFiredBundle)3 Date (java.util.Date)2 JobDetail (org.quartz.JobDetail)2 BaseCalendar (org.quartz.impl.calendar.BaseCalendar)2 OperableTrigger (org.quartz.spi.OperableTrigger)2 Calendar (java.util.Calendar)1 ProductStatus (org.mifos.framework.components.batchjobs.helpers.ProductStatus)1 CronTrigger (org.quartz.CronTrigger)1 Job (org.quartz.Job)1 JobBuilder.newJob (org.quartz.JobBuilder.newJob)1 JobDataMap (org.quartz.JobDataMap)1 JobExecutionContext (org.quartz.JobExecutionContext)1 Scheduler (org.quartz.Scheduler)1 Trigger (org.quartz.Trigger)1 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)1 JobDetailImpl (org.quartz.impl.JobDetailImpl)1 JobExecution (org.springframework.batch.core.JobExecution)1 JobInstance (org.springframework.batch.core.JobInstance)1 JobLocator (org.springframework.batch.core.configuration.JobLocator)1