Search in sources :

Example 86 with MotechEvent

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

the class SettingsServiceImpl method savePlatformSettings.

@Override
public void savePlatformSettings(List<Settings> settings) {
    for (Settings s : settings) {
        savePlatformSettings(s);
    }
    Map<String, Object> params = new HashMap<>();
    params.put(ConfigurationConstants.SETTINGS, settings);
    MotechEvent platformSettingsChangedEvent = new MotechEvent(ConfigurationConstants.PLATFORM_SETTINGS_CHANGED_EVENT_SUBJECT, params);
    eventRelay.sendEventMessage(platformSettingsChangedEvent);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MotechEvent(org.motechproject.event.MotechEvent) AdminSettings(org.motechproject.admin.settings.AdminSettings) Settings(org.motechproject.admin.settings.Settings) MotechSettings(org.motechproject.config.domain.MotechSettings)

Example 87 with MotechEvent

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

the class TestCronSchedulabeJob method setUp.

@Before
public void setUp() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("JobID", uuidStr);
    motechEvent1 = new MotechEvent("TestEvent", params);
    params = new HashMap<String, Object>();
    params.put("JobID", uuidStr2);
    motechEvent2 = new MotechEvent("TestEvent", params);
}
Also used : HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) Before(org.junit.Before)

Example 88 with MotechEvent

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobsBasicInfo.

@Test
public void shouldGetScheduledJobsBasicInfo() 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_2", params), "0 0 12 * * ?"));
        schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
        schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false));
        schedulerService.scheduleRepeatingPeriodJob(new RepeatingPeriodSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), new Period(4, 0, 0, 0), false));
        for (String groupName : scheduler.getJobGroupNames()) {
            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
                if (jobKey.getName().equals("test_event_2-job_id")) {
                    scheduler.pauseJob(jobKey);
                }
            }
        }
        List<JobBasicInfo> expectedJobBasicInfos = new ArrayList<>();
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_PAUSED, "test_event_2-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));
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-runonce", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_RUNONCE, "", false));
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-repeat", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-18 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_REPEATING, "", false));
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-period", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-18 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_PERIOD, "", false));
        List<JobBasicInfo> jobBasicInfos;
        JobsSearchSettings jobsSearchSettings = getGridSettings(0, 10, "name", "asc");
        jobBasicInfos = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        int testJobsCount = 0;
        for (JobBasicInfo job : jobBasicInfos) {
            for (JobBasicInfo expectedJob : expectedJobBasicInfos) {
                if (job.getName().equals(expectedJob.getName())) {
                    testJobsCount += 1;
                    assertEquals(expectedJob.getActivity(), job.getActivity());
                    assertEquals(expectedJob.getStatus(), job.getStatus());
                    assertEquals(expectedJob.getStartDate(), job.getStartDate());
                    assertEquals(expectedJob.getNextFireDate(), job.getNextFireDate());
                }
            }
        }
        assertEquals(4, testJobsCount);
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) JobKey(org.quartz.JobKey) RepeatingPeriodSchedulableJob(org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 89 with MotechEvent

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

the class SchedulerChannelProviderBundleIT method setUp.

@Before
public void setUp() {
    if (channelProvider == null) {
        channelProvider = (SchedulerChannelProvider) bundleContext.getService(bundleContext.getServiceReference("org.motechproject.tasks.service.DynamicChannelProvider"));
    }
    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 * * ?"));
    schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent(TEST_EVENT, params), DateTime.now().plusDays(1)));
    schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent(TEST_EVENT, params), DateTimeConstants.SECONDS_PER_DAY, DateTime.now().plusHours(1), DateTime.now().plusHours(3), false));
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Before(org.junit.Before)

Example 90 with MotechEvent

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

the class ServerEventRelayBundleIT method shouldNotTriggerAllListenersWhenOneListenerFails.

@Test
public void shouldNotTriggerAllListenersWhenOneListenerFails() throws InterruptedException {
    TrackingListener buggyListener = new BuggyListener(1);
    TrackingListener firstGoodListener = new TrackingListener("first");
    TrackingListener secondGoodListener = new TrackingListener("second");
    eventListenerRegistry.registerListener(buggyListener, EXCEPTION_HANDLING_TEST);
    eventListenerRegistry.registerListener(firstGoodListener, EXCEPTION_HANDLING_TEST);
    eventListenerRegistry.registerListener(secondGoodListener, EXCEPTION_HANDLING_TEST);
    MotechEvent testMessage = new MotechEvent(EXCEPTION_HANDLING_TEST);
    eventRelay.sendEventMessage(testMessage);
    while (buggyListener.getCount() < 2) {
        Thread.sleep(3000);
    }
    assertTrue(buggyListener.getCount() > 1);
    Thread.sleep(2000);
    assertEquals(1, firstGoodListener.getCount());
    assertEquals(1, secondGoodListener.getCount());
}
Also used : BuggyListener(org.motechproject.event.domain.BuggyListener) TrackingListener(org.motechproject.event.domain.TrackingListener) 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