Search in sources :

Example 66 with SchedulerException

use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testPauseJob.

@Test
public void testPauseJob() throws SchedulerException {
    Job job = mock(Job.class);
    doReturn(job).when(schedulerService).getJob(anyString());
    doReturn(true).when(schedulerService).isScheduleAllowed();
    doNothing().when(schedulerService.scheduler).pauseJob(anyString());
    doReturn(IScheduler.SchedulerStatus.PAUSED).when(schedulerService.scheduler).getStatus();
    schedulerService.pauseJob("job-id");
}
Also used : Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 67 with SchedulerException

use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method testJobRunsAsSchedulingUser.

@Test
public void testJobRunsAsSchedulingUser() throws SchedulerException {
    SimpleJobTrigger RUN_ONCE_IN_2_SECS = JobTrigger.ONCE_NOW;
    RUN_ONCE_IN_2_SECS.setStartTime(new Date(System.currentTimeMillis() + 2000L));
    scheduler.createJob("testName", TestAction.class, new HashMap<String, Serializable>(), RUN_ONCE_IN_2_SECS);
    SecurityHelper.getInstance().becomeUser("Ima Wronguser");
    sleep(3);
    Assert.assertEquals("Job did not run the correct number of times", 1, TestAction.counter);
    Assert.assertEquals("Job did not run as the correct user", TEST_USER, TestAction.executedAsUser);
    List<Job> jobs = scheduler.getJobs(null);
    Assert.assertEquals(0, jobs.size());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Example 68 with SchedulerException

use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method testStartAndEndDate.

@Test
public void testStartAndEndDate() throws SchedulerException {
    ComplexJobTrigger startEndJobTrigger = new ComplexJobTrigger();
    ComplexJobTrigger startJobTrigger = new ComplexJobTrigger();
    ComplexJobTrigger endJobTrigger = new ComplexJobTrigger();
    startEndJobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    startJobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    endJobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    startEndJobTrigger.setMinuteRecurrence((ITimeRecurrence) null);
    startJobTrigger.setMinuteRecurrence((ITimeRecurrence) null);
    endJobTrigger.setMinuteRecurrence((ITimeRecurrence) null);
    startEndJobTrigger.setSecondRecurrence(new IncrementalRecurrence(0, 1));
    startJobTrigger.setSecondRecurrence(new IncrementalRecurrence(0, 1));
    endJobTrigger.setSecondRecurrence(new IncrementalRecurrence(0, 1));
    Calendar calendar = Calendar.getInstance();
    int startingMin = calendar.get(Calendar.MINUTE);
    int startingSec = calendar.get(Calendar.SECOND) + 3;
    if (startingSec > 59) {
        startingSec = startingSec % 60;
        startingMin++;
        if (startingMin > 59) {
            startingMin = startingMin % 60;
        }
    }
    calendar.set(Calendar.MINUTE, startingMin);
    calendar.set(Calendar.SECOND, startingSec);
    startEndJobTrigger.setStartTime(calendar.getTime());
    startJobTrigger.setStartTime(calendar.getTime());
    calendar.add(Calendar.SECOND, 3);
    startEndJobTrigger.setEndTime(calendar.getTime());
    endJobTrigger.setEndTime(calendar.getTime());
    int startEndCounter = TestAction.counter;
    int startCounter = TestAction2.counter;
    int endCounter = TestAction3.counter;
    Job job = scheduler.createJob("startEndJob", TestAction.class, jobParams, startEndJobTrigger);
    Job job2 = scheduler.createJob("startJob", TestAction2.class, jobParams, startJobTrigger);
    Job job3 = scheduler.createJob("endJob", TestAction3.class, jobParams, endJobTrigger);
    try {
        sleep(2);
        Assert.assertEquals(startEndCounter, TestAction.counter);
        Assert.assertEquals(startCounter, TestAction2.counter);
        Assert.assertTrue(endCounter != TestAction3.counter);
        endCounter = TestAction3.counter;
        sleep(3);
        Assert.assertTrue(startEndCounter != TestAction.counter);
        Assert.assertTrue(startCounter != TestAction2.counter);
        Assert.assertTrue(endCounter != TestAction3.counter);
        sleep(3);
        startEndCounter = TestAction.counter;
        startCounter = TestAction2.counter;
        endCounter = TestAction3.counter;
        sleep(3);
        Assert.assertEquals(startEndCounter, TestAction.counter);
        Assert.assertTrue(startCounter != TestAction2.counter);
        Assert.assertEquals(endCounter, TestAction3.counter);
    } finally {
        scheduler.removeJob(job.getJobId());
        scheduler.removeJob(job2.getJobId());
        scheduler.removeJob(job3.getJobId());
    }
    Assert.assertEquals(0, scheduler.getJobs(null).size());
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IncrementalRecurrence(org.pentaho.platform.scheduler2.recur.IncrementalRecurrence) Calendar(java.util.Calendar) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 69 with SchedulerException

use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method testPauseAndResumeScheduler.

@Test
public void testPauseAndResumeScheduler() throws SchedulerException {
    Calendar calendar = Calendar.getInstance();
    int startingSec = calendar.get(Calendar.SECOND) + 1;
    if (startingSec > 59) {
        startingSec = startingSec % 60;
    }
    ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
    complexJobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    complexJobTrigger.setMinuteRecurrence((ITimeRecurrence) null);
    complexJobTrigger.setSecondRecurrence(startingSec);
    String jobName = "complexJob1";
    int counter = TestAction.counter;
    scheduler.pause();
    scheduler.createJob(jobName, TestAction.class, jobParams, complexJobTrigger);
    sleep(3);
    Assert.assertEquals("Job executed while scheduler is supposedly paused!", counter, TestAction.counter);
    Assert.assertEquals("Scheduler is not aware of the dormant job!", 1, scheduler.getJobs(null).size());
    scheduler.start();
    sleep(3);
    Assert.assertTrue("Job did not execute after scheduler started back up!", counter != TestAction.counter);
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 70 with SchedulerException

use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method runTenTimesJobTest.

@Test
public void runTenTimesJobTest() throws SchedulerException {
    SimpleJobTrigger repeater = new SimpleJobTrigger();
    repeater.setStartTime(new Date());
    repeater.setRepeatInterval(1);
    repeater.setRepeatCount(9);
    scheduler.createJob("testName", TestAction.class, new HashMap<String, Serializable>(), repeater);
    sleep(5);
    Assert.assertTrue("Job did not run the correct number of times", TestAction.counter > 3);
    System.out.println("Counter = " + TestAction.counter);
    Assert.assertTrue("Job did not run the correct number of times", TestAction.counter < 7);
    sleep(10);
    Assert.assertEquals("Job did not run the correct number of times", 10, TestAction.counter);
    List<Job> jobs = scheduler.getJobs(null);
    Assert.assertEquals(0, jobs.size());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)51 Test (org.junit.Test)49 Job (org.pentaho.platform.api.scheduler2.Job)43 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)23 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)16 Serializable (java.io.Serializable)15 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)11 Date (java.util.Date)10 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)9 Scheduler (org.quartz.Scheduler)9 ArrayList (java.util.ArrayList)8 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)8 IOException (java.io.IOException)6 Calendar (java.util.Calendar)6 HashMap (java.util.HashMap)6 CronTrigger (org.quartz.CronTrigger)6 SimpleTrigger (org.quartz.SimpleTrigger)6 Trigger (org.quartz.Trigger)6 Response (javax.ws.rs.core.Response)5