Search in sources :

Example 1 with RepeatingPeriodSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob 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();
    }
}
Also used : RepeatingPeriodSchedulableJob(org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob) HashMap(java.util.HashMap) Period(org.joda.time.Period) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with RepeatingPeriodSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob in project motech by motech.

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldCheckIFJobIsUIDefined.

@Test
public void shouldCheckIFJobIsUIDefined() {
    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.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2", params), null, DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false, false, true));
        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, false, false));
        List<JobBasicInfo> expectedJobBasicInfos = new ArrayList<>();
        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, "", true));
        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));
        int testJobsCount = 0;
        for (JobBasicInfo job : expectedJobBasicInfos) {
            for (JobBasicInfo expectedJob : expectedJobBasicInfos) {
                if (job.getName().equals(expectedJob.getName())) {
                    testJobsCount += 1;
                    assertEquals(expectedJob.isUiDefined(), job.isUiDefined());
                }
            }
        }
        assertEquals(2, testJobsCount);
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) RepeatingPeriodSchedulableJob(org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 3 with RepeatingPeriodSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob in project motech by motech.

the class SchedulableJobValidatorTest method shouldThrowIllegalArgumentExceptionIfStartDateIsNullInRepeatingPeriodJob.

@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionIfStartDateIsNullInRepeatingPeriodJob() {
    RepeatingPeriodSchedulableJob job = new RepeatingPeriodSchedulableJob(motechEvent, null, null, null, false, true, true);
    SchedulableJobValidator.validateRepeatingPeriodSchedulableJob(job);
}
Also used : RepeatingPeriodSchedulableJob(org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob) Test(org.junit.Test)

Example 4 with RepeatingPeriodSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob 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 5 with RepeatingPeriodSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob in project motech by motech.

the class SchedulableJobValidatorTest method shouldValidateRepeatingPeriodJob.

@Test
public void shouldValidateRepeatingPeriodJob() {
    RepeatingPeriodSchedulableJob job = new RepeatingPeriodSchedulableJob(motechEvent, DateTime.now(), null, Period.hours(1), false, true, true);
    SchedulableJobValidator.validateRepeatingPeriodSchedulableJob(job);
}
Also used : RepeatingPeriodSchedulableJob(org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob) Test(org.junit.Test)

Aggregations

RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)9 Test (org.junit.Test)7 MotechEvent (org.motechproject.event.MotechEvent)4 HashMap (java.util.HashMap)3 Period (org.joda.time.Period)3 ArrayList (java.util.ArrayList)2 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)2 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)2 DateTime (org.joda.time.DateTime)1 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)1 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)1 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)1 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)1 PeriodIntervalTrigger (org.motechproject.scheduler.trigger.PeriodIntervalTrigger)1 JobKey (org.quartz.JobKey)1