use of org.motechproject.event.MotechEvent in project motech by motech.
the class TestEventListener method shouldScheduleCronJob.
@Test
public void shouldScheduleCronJob() throws SchedulerException {
try {
fakeNow(new DateTime(2020, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
final String job_id = id("job_id");
params.put(MotechSchedulerService.JOB_ID_KEY, job_id);
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 10 * * ?"));
List<DateTime> first3FireTimes = getFireTimes("test_event-" + job_id).subList(0, 3);
assertEquals(asList(newDateTime(2020, 7, 15, 10, 0, 0), newDateTime(2020, 7, 16, 10, 0, 0), newDateTime(2020, 7, 17, 10, 0, 0)), first3FireTimes);
} finally {
stopFakingTime();
}
}
use of org.motechproject.event.MotechEvent in project motech by motech.
the class TestEventListener method shouldScheduleInterveningRepeatJobWithoutEndDate.
@Test
public void shouldScheduleInterveningRepeatJobWithoutEndDate() 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");
RepeatingSchedulableJob repeatJob = new RepeatingSchedulableJob(new MotechEvent("test_event", params), 3, DateTimeConstants.SECONDS_PER_DAY, newDateTime(2020, 7, 13, 12, 0, 0), null, true);
repeatJob.setUseOriginalFireTimeAfterMisfire(false);
schedulerService.scheduleRepeatingJob(repeatJob);
List<DateTime> fireTimes = getFireTimes("test_event-job_id-repeat");
assertEquals(asList(newDateTime(2020, 7, 15, 12, 0, 0), newDateTime(2020, 7, 16, 12, 0, 0)), fireTimes);
} finally {
stopFakingTime();
}
}
use of org.motechproject.event.MotechEvent in project motech by motech.
the class TestEventListener method shouldScheduleDayOfWeekJob.
@Test
public void shouldScheduleDayOfWeekJob() 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.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event", params), // friday
newDateTime(2020, 7, 10), newDateTime(2020, 7, 22), asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
List<DateTime> fireTimes = getFireTimes("test_event-job_id");
assertEquals(asList(newDateTime(2020, 7, 13, 10, 10, 0), newDateTime(2020, 7, 16, 10, 10, 0), newDateTime(2020, 7, 20, 10, 10, 0)), fireTimes);
} finally {
stopFakingTime();
}
}
use of org.motechproject.event.MotechEvent in project motech by motech.
the class TestEventListener method shouldScheduleRepeatingPeriodSchedulableJob.
@Test
public void shouldScheduleRepeatingPeriodSchedulableJob() throws SchedulerException {
try {
fakeNow(new DateTime(2020, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleRepeatingPeriodJob(new RepeatingPeriodSchedulableJob(new MotechEvent("test_event_3", params), newDateTime(2020, 7, 15, 12, 0, 0), newDateTime(2020, 7, 16, 12, 0, 0), new Period(4, 0, 0, 0), true));
List<DateTime> fireTimes = getFireTimes("test_event_3-job_id-period");
assertEquals(asList(new DateTime(2020, 7, 15, 12, 0, 0), new DateTime(2020, 7, 15, 16, 0, 0), new DateTime(2020, 7, 15, 20, 0, 0), new DateTime(2020, 7, 16, 0, 0, 0), new DateTime(2020, 7, 16, 4, 0, 0), new DateTime(2020, 7, 16, 8, 0, 0), new DateTime(2020, 7, 16, 12, 0, 0)), fireTimes);
} finally {
stopFakingTime();
}
}
use of org.motechproject.event.MotechEvent in project motech by motech.
the class TestEventListener method shouldIgnoreFiresInPastWhenSchedulingCronJob.
@Test
public void shouldIgnoreFiresInPastWhenSchedulingCronJob() throws InterruptedException, SchedulerException {
String subject = "cron_ignore_misfire";
try {
TestEventListener listener = new TestEventListener();
eventRegistry.registerListener(listener, subject);
DateTime now;
for (now = now(); now.getSecondOfMinute() > 55 || now.getSecondOfMinute() < 5; now = now()) {
// we don't want triggers now, only misfires
Thread.sleep(1000);
}
DateTime jobStartTime = now.minusMinutes(3);
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent(subject, params), "0 0/1 * 1/1 * ? *", jobStartTime, null, true));
synchronized (listener.getReceivedEvents()) {
listener.getReceivedEvents().wait(2000);
}
assertTrue(listener.getReceivedEvents().size() == 0);
} finally {
eventRegistry.clearListenersForBean("test");
schedulerService.unscheduleAllJobs(subject);
}
}
Aggregations