Search in sources :

Example 16 with JobBasicInfo

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

the class TestEventListener method shouldNotResumeJobIfItIsNotUiDefined.

@Test(expected = MotechSchedulerException.class)
public void shouldNotResumeJobIfItIsNotUiDefined() throws Exception {
    try {
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
        JobBasicInfo info = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_PAUSED, "test_event-job_id", "default", "start-time", "nex-fire-time", "end-time", JobBasicInfo.JOBTYPE_CRON, "test-info", false);
        schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?"));
        scheduler.pauseJob(new JobKey(info.getName(), info.getGroup()));
        assertEquals(PAUSED, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
        schedulerService.resumeJob(info);
    } finally {
        assertEquals(PAUSED, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
    }
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) JobKey(org.quartz.JobKey) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 17 with JobBasicInfo

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

the class TestEventListener method shouldDeleteJobIfItIsUiDefined.

@Test
public void shouldDeleteJobIfItIsUiDefined() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
    JobBasicInfo info = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_OK, "test_event-job_id", "default", "start-time", "nex-fire-time", "end-time", JobBasicInfo.JOBTYPE_CRON, "test-info", false);
    CronSchedulableJob job = new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?");
    job.setUiDefined(true);
    schedulerService.scheduleJob(job);
    schedulerService.deleteJob(info);
    assertNull(scheduler.getTrigger(triggerKey("test_event-job_id", "default")));
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 18 with JobBasicInfo

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

the class TestEventListener method shouldNotPauseJobIfItIsNotUiDefined.

@Test(expected = MotechSchedulerException.class)
public void shouldNotPauseJobIfItIsNotUiDefined() throws Exception {
    try {
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
        JobBasicInfo info = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_OK, "test_event-job_id", "default", "start-time", "nex-fire-time", "end-time", JobBasicInfo.JOBTYPE_CRON, "test-info", true);
        schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?"));
        assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
        schedulerService.pauseJob(info);
    } finally {
        assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
    }
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 19 with JobBasicInfo

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldFilterJobsWithSortingAndPagination.

@Test
public void shouldFilterJobsWithSortingAndPagination() {
    try {
        fakeNow(newDateTime(CURRENT_YEAR + 1, 7, 13, 10, 0, 0));
        addTestJobs();
        JobsSearchSettings jobsSearchSettings = getGridSettings(1, 5, "name", "asc");
        jobsSearchSettings.setName("event");
        List<JobBasicInfo> jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(5, jobs.size());
        assertEquals(6, databaseService.countJobs(jobsSearchSettings));
        assertEquals(printJobNames(jobs), "test_event_1-job_id1", jobs.get(0).getName());
        jobsSearchSettings.setPage(2);
        jobsSearchSettings.setName("test");
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(1, jobs.size());
        assertEquals(6, databaseService.countJobs(jobsSearchSettings));
        jobsSearchSettings.setPage(3);
        jobsSearchSettings.setRows(2);
        jobsSearchSettings.setSortDirection("desc");
        jobsSearchSettings.setActivity(JobBasicInfo.ACTIVITY_NOTSTARTED);
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(1, jobs.size());
        assertEquals(JobBasicInfo.ACTIVITY_NOTSTARTED, jobs.get(0).getActivity());
        assertEquals(5, databaseService.countJobs(jobsSearchSettings));
        jobsSearchSettings = getGridSettings(1, 2, "name", "asc");
        jobsSearchSettings.setTimeTo(format("%s-03-15 9:30:00", CURRENT_YEAR + 7));
        jobsSearchSettings.setTimeFrom(format("%s-03-15 9:30:00", CURRENT_YEAR + 3));
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertEquals(2, jobs.size());
        assertEquals(printJobNames(jobs), "test_event_3-job_id3", jobs.get(0).getName());
        assertEquals(3, databaseService.countJobs(jobsSearchSettings));
        jobsSearchSettings.setSortDirection("desc");
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertEquals(2, jobs.size());
        assertEquals(printJobNames(jobs), "test_event_6-job_id6-repeat", jobs.get(0).getName());
        assertEquals(3, databaseService.countJobs(jobsSearchSettings));
    } finally {
        stopFakingTime();
    }
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) Test(org.junit.Test)

Example 20 with JobBasicInfo

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldFilterJobsByActivity.

@Test
public void shouldFilterJobsByActivity() {
    try {
        fakeNow(newDateTime(CURRENT_YEAR + 1, 7, 13, 5, 0, 0));
        addTestJobs();
        JobsSearchSettings jobsSearchSettings = getGridSettings(null, null, "name", "asc");
        jobsSearchSettings.setActivity(JobBasicInfo.ACTIVITY_NOTSTARTED);
        List<JobBasicInfo> jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertNotNull(jobs);
        assertEquals(5, jobs.size());
        jobsSearchSettings.setActivity(JobBasicInfo.ACTIVITY_ACTIVE);
        jobs = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        assertEquals(1, jobs.size());
    } finally {
        stopFakingTime();
    }
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) Test(org.junit.Test)

Aggregations

JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)24 Test (org.junit.Test)21 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)11 HashMap (java.util.HashMap)10 MotechEvent (org.motechproject.event.MotechEvent)10 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)8 JobKey (org.quartz.JobKey)4 ArrayList (java.util.ArrayList)3 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)3 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)3 JobsRecords (org.motechproject.scheduler.web.domain.JobsRecords)3 Period (org.joda.time.Period)2 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Before (org.junit.Before)1 JobDetailedInfo (org.motechproject.scheduler.contract.JobDetailedInfo)1 MotechSchedulerJobRetrievalException (org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException)1