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();
}
}
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();
}
}
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")));
}
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();
}
}
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")));
}
Aggregations