use of org.motechproject.event.MotechEvent in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobsBasicInfoWithSortingAndPagination.
@Test
public void shouldGetScheduledJobsBasicInfoWithSortingAndPagination() throws SchedulerException, SQLException {
try {
fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event_2a", params), "0 0 12 * * ?"));
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2b", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2c", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false));
JobBasicInfo expected = new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2a-job_id", DEFAULT_GROUP, format("%s-07-15 10:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), "-", JobBasicInfo.JOBTYPE_CRON, "", false);
List<JobBasicInfo> jobBasicInfos;
JobsSearchSettings jobsSearchSettings = getGridSettings(2, 2, "name", "desc");
jobBasicInfos = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
assertEquals(expected.getActivity(), jobBasicInfos.get(0).getActivity());
assertEquals(expected.getStatus(), jobBasicInfos.get(0).getStatus());
assertEquals(expected.getStartDate(), jobBasicInfos.get(0).getStartDate());
assertEquals(expected.getNextFireDate(), jobBasicInfos.get(0).getNextFireDate());
} finally {
stopFakingTime();
}
}
use of org.motechproject.event.MotechEvent in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetJobTimes.
@Test
public void shouldGetJobTimes() {
try {
fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?"));
List<DateTime> eventTimes = schedulerService.getScheduledJobTimings("test_event", "job_id", newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 17, 12, 0, 0));
assertEquals(asList(newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 16, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 17, 12, 0, 0)), eventTimes);
} finally {
stopFakingTime();
}
}
use of org.motechproject.event.MotechEvent in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobDetailedInfo.
@Test
public void shouldGetScheduledJobDetailedInfo() throws SchedulerException, SQLException {
try {
fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
JobDetailedInfo jobDetailedInfo = null;
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id_2");
params.put("param1", "value1");
params.put("param2", "value2");
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
JobsSearchSettings jobsSearchSettings = getGridSettings(0, 10, "name", "asc");
for (JobBasicInfo job : databaseService.getScheduledJobsBasicInfo(jobsSearchSettings)) {
if (job.getName().equals("test_event_2-job_id_2-runonce")) {
jobDetailedInfo = databaseService.getScheduledJobDetailedInfo(job);
}
}
assertNotNull(jobDetailedInfo);
assertEquals("test_event_2", jobDetailedInfo.getEventInfoList().get(0).getSubject());
assertEquals(4, jobDetailedInfo.getEventInfoList().get(0).getParameters().size());
} finally {
stopFakingTime();
}
}
use of org.motechproject.event.MotechEvent in project motech by motech.
the class SchedulerBundleIT method testRunOnceJob.
@Test
public void testRunOnceJob() throws InterruptedException {
waitForEventConsumerToStart();
final List<String> receivedEvents = new ArrayList<>();
eventRegistry.registerListener(new EventListener() {
@Override
public void handle(MotechEvent event) {
synchronized (receivedEvents) {
receivedEvents.add(event.getSubject());
receivedEvents.notify();
}
}
@Override
public String getIdentifier() {
return TEST_SUBJECT;
}
}, TEST_SUBJECT);
final MotechEvent motechEvent = new MotechEvent(TEST_SUBJECT);
motechEvent.getParameters().put(MotechSchedulerService.JOB_ID_KEY, "jobId");
schedulerService.unscheduleAllJobs("SchedulerBundleIT");
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(motechEvent, DateTime.now().plusSeconds(5)));
synchronized (receivedEvents) {
System.out.print("\nEvent waiting " + new Date() + "\n");
receivedEvents.wait(15000);
}
assertEquals(1, receivedEvents.size());
assertEquals(receivedEvents.get(0), TEST_SUBJECT);
}
use of org.motechproject.event.MotechEvent in project motech by motech.
the class MessageHandlerTest method shouldPostMessageWithoutTimeout.
@Test
public void shouldPostMessageWithoutTimeout() {
Map<String, Object> params = new HashMap<>();
params.put(EventKeys.MESSAGE, "testMsg");
params.put(EventKeys.MODULE_NAME, "testModule");
params.put(EventKeys.LEVEL, "warn");
MotechEvent event = new MotechEvent(EventSubjects.MESSAGE_SUBJECT, params);
messageHandler.messageReceived(event);
verify(statusMessageService).postMessage("testMsg", "testModule", Level.WARN);
}
Aggregations