Search in sources :

Example 41 with MotechEvent

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();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Test(org.junit.Test)

Example 42 with MotechEvent

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();
    }
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) 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 43 with MotechEvent

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();
    }
}
Also used : JobDetailedInfo(org.motechproject.scheduler.contract.JobDetailedInfo) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Test(org.junit.Test)

Example 44 with MotechEvent

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);
}
Also used : ArrayList(java.util.ArrayList) EventListener(org.motechproject.event.listener.EventListener) MotechEvent(org.motechproject.event.MotechEvent) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Date(java.util.Date) Test(org.junit.Test)

Example 45 with MotechEvent

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);
}
Also used : 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