Search in sources :

Example 31 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldScheduleRepeatJobBoundByEndDate.

@Test
public void shouldScheduleRepeatJobBoundByEndDate() throws SchedulerException {
    try {
        fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
        final String jobId = id("jobId");
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, jobId);
        schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(2020, 7, 15, 12, 0, 0), newDateTime(2020, 7, 18, 12, 0, 0), false));
        List<DateTime> fireTimes = getFireTimes("test_event-" + jobId + "-repeat");
        assertEquals(asList(newDateTime(2020, 7, 15, 12, 0, 0), newDateTime(2020, 7, 16, 12, 0, 0), newDateTime(2020, 7, 17, 12, 0, 0)), fireTimes);
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 32 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldGetNextFireTime.

@Test
public void shouldGetNextFireTime() {
    try {
        DateTime fireDate = new DateTime(2020, 7, 15, 10, 0, 0);
        fakeNow(fireDate);
        Map<String, Object> params = new HashMap<>();
        MotechEvent event = new MotechEvent("test_event", params);
        final String jobId = id("jobId");
        params.put(MotechSchedulerService.JOB_ID_KEY, jobId);
        schedulerService.scheduleJob(new CronSchedulableJob(event, "0 0 10 * * ?"));
        DateTime dateTime = schedulerService.getNextFireDate(new CronJobId(event));
        assertEquals(fireDate, dateTime);
    } finally {
        stopFakingTime();
    }
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) CronJobId(org.motechproject.scheduler.contract.CronJobId) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 33 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldResumeJobIfItIsUiDefined.

@Test
public void shouldResumeJobIfItIsUiDefined() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
    JobBasicInfo info = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_PAUSED, "test_event-job_id", "default", "start-time", "nex-fire-time", "end-time", JobBasicInfo.JOBTYPE_CRON, "test-info", true);
    CronSchedulableJob job = new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?");
    job.setUiDefined(true);
    schedulerService.scheduleJob(job);
    scheduler.pauseJob(new JobKey(info.getName(), info.getGroup()));
    assertEquals(PAUSED, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
    schedulerService.resumeJob(info);
    assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) JobKey(org.quartz.JobKey) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 34 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldScheduleRunOnceJob.

@Test
public void shouldScheduleRunOnceJob() throws SchedulerException {
    try {
        fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
        schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event", params), newDateTime(2020, 7, 15, 12, 0, 0)));
        List<DateTime> fireTimes = getFireTimes("test_event-job_id-runonce");
        assertEquals(asList(newDateTime(2020, 7, 15, 12, 0, 0)), fireTimes);
    } finally {
        stopFakingTime();
    }
}
Also used : HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 35 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestEventListener method shouldUnscheduleJob.

@Test
public void shouldUnscheduleJob() throws SchedulerException {
    Map<String, Object> params = new HashMap<>();
    final String jobId = id("jobId");
    params.put(MotechSchedulerService.JOB_ID_KEY, jobId);
    schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?"));
    schedulerService.unscheduleJob("test_event", jobId);
    assertNull(scheduler.getTrigger(triggerKey("test_event-" + jobId, "default")));
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Aggregations

MotechEvent (org.motechproject.event.MotechEvent)138 Test (org.junit.Test)87 HashMap (java.util.HashMap)79 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)28 DateTime (org.joda.time.DateTime)25 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)20 ArrayList (java.util.ArrayList)14 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)13 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)11 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)10 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)8 Matchers.anyString (org.mockito.Matchers.anyString)7 EventListener (org.motechproject.event.listener.EventListener)7 CronJobId (org.motechproject.scheduler.contract.CronJobId)7 Task (org.motechproject.tasks.domain.mds.task.Task)7 JobId (org.motechproject.scheduler.contract.JobId)6 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)6 Time (org.motechproject.commons.date.model.Time)5 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)5 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)5