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");
}
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());
}
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());
}
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);
}
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());
}
Aggregations