use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method runComplexTriggerTest.
@Test
public void runComplexTriggerTest() throws SchedulerException {
Calendar calendar = Calendar.getInstance();
// seconds
final int testTime = 7;
int startingMinute = calendar.get(Calendar.MINUTE);
int startingSec = calendar.get(Calendar.SECOND) + 1;
// we can't finish until end of the minute - sleep for this time
if (startingSec > 59 - testTime) {
sleep(59 - startingSec);
startingSec = 0;
startingMinute++;
if (startingMinute > 59) {
startingMinute = startingMinute % 60;
}
}
int endingSecond = startingSec + 5;
RecurrenceList recurrenceList = new RecurrenceList(startingSec, endingSecond);
SequentialRecurrence sequentialRecurrence = new SequentialRecurrence(startingSec, endingSecond);
IncrementalRecurrence incrementalRecurrence = new IncrementalRecurrence(startingSec, 1);
ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
jobTrigger.setMinuteRecurrence(startingMinute);
jobTrigger.setSecondRecurrence(recurrenceList);
System.out.println(jobTrigger.toString());
String jobName = "complexJob1";
Job job = scheduler.createJob(jobName, TestAction.class, new HashMap<String, Serializable>(), jobTrigger);
Assert.assertTrue(job.getJobName().contains(jobName));
Assert.assertEquals(job.getSchedulableClass(), TestAction.class.getName());
Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
jobTrigger.setSecondRecurrence(sequentialRecurrence);
jobName = "complexJob2";
job = scheduler.createJob(jobName, TestAction2.class, new HashMap<String, Serializable>(), jobTrigger);
Assert.assertTrue(job.getJobName().contains(jobName));
Assert.assertEquals(job.getSchedulableClass(), TestAction2.class.getName());
Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
jobTrigger.setSecondRecurrence(incrementalRecurrence);
jobName = "complexJob3";
job = scheduler.createJob(jobName, TestAction3.class, new HashMap<String, Serializable>(), jobTrigger);
Assert.assertTrue(job.getJobName().contains(jobName));
Assert.assertEquals(job.getSchedulableClass(), TestAction3.class.getName());
Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
//
// Wait for the jobs to complete, then check that each action executed the correct number of times
//
sleep(testTime);
Assert.assertEquals("Job did not run the correct number of times", 2, TestAction.counter);
Assert.assertEquals("Job did not run the correct number of times", 6, TestAction2.counter);
System.out.println("Counter = " + TestAction3.counter);
Assert.assertTrue("Job did not run.", TestAction3.counter > 3);
}
use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method testPauseAndResumeJob.
@Test
public void testPauseAndResumeJob() throws SchedulerException {
String jobName = "complexJob1";
int counter = TestAction.counter;
Calendar calendar = Calendar.getInstance();
int startingMin = calendar.get(Calendar.MINUTE);
int startingSec = calendar.get(Calendar.SECOND) + 1;
if (startingSec > 59) {
startingSec = startingSec % 60;
startingMin++;
if (startingMin > 59) {
startingMin = startingMin % 60;
}
}
ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
complexJobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
complexJobTrigger.setMinuteRecurrence(startingMin);
complexJobTrigger.setSecondRecurrence(startingSec);
Job job = scheduler.createJob(jobName, TestAction.class, jobParams, complexJobTrigger);
scheduler.pauseJob(job.getJobId());
sleep(2);
Assert.assertEquals(counter, TestAction.counter);
Assert.assertEquals(1, scheduler.getJobs(null).size());
scheduler.resumeJob(job.getJobId());
sleep(2);
Assert.assertTrue(counter != TestAction.counter);
scheduler.removeJob(job.getJobId());
Assert.assertEquals(0, scheduler.getJobs(null).size());
}
use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class JaxWsSchedulerServiceIT method testCreateComplexJob.
@Test
public void testCreateComplexJob() throws SchedulerException {
int startingMinute = (Calendar.getInstance().get(Calendar.MINUTE)) % 60;
ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 1));
jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
System.out.println(jobTrigger.toString());
schedulerSvc.createComplexJob("test job", jobParams, jobTrigger);
int tries = 0;
do {
sleep(10);
} while (!MyAction.executed && tries++ < 13);
Assert.assertTrue("the action was not executed in the expected window", MyAction.executed);
}
use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class JaxWsSchedulerServiceIT method testUpdateComplexJob.
/*
public static class TestQuartzScheduler extends QuartzScheduler {
@Override
protected String getCurrentUser() {
SecurityHelper.getInstance().becomeUser( TEST_USER );
return super.getCurrentUser();
}
}
*/
@Test(timeout = 1000 * 5 * 60)
public void testUpdateComplexJob() throws SchedulerException {
long start = System.currentTimeMillis() + 1000;
long end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
int startingMinute = (Calendar.getInstance().get(Calendar.MINUTE) + 10) % 60;
ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
jobTrigger.setStartTime(new Date(start));
jobTrigger.setEndTime(new Date(end));
jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 1));
jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
System.out.println(jobTrigger.toString());
String jobId = schedulerSvc.createComplexJob("test job", jobParams, jobTrigger);
Assert.assertEquals(1, schedulerSvc.getJobs().length);
jobTrigger = new ComplexJobTrigger();
start = System.currentTimeMillis() + 2 * 1000;
end = System.currentTimeMillis() + 1000 + 7 * 60 * 60 * 100;
jobTrigger.setStartTime(new Date(start));
jobTrigger.setEndTime(new Date(end));
startingMinute = (Calendar.getInstance().get(Calendar.MINUTE) + 20) % 60;
jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 5));
jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
System.out.println(jobTrigger.toString());
HashMap<String, ParamValue> newJobParams = new HashMap<String, ParamValue>(jobParams);
newJobParams.put("newKey", new StringParamValue(""));
schedulerSvc.updateJobToUseComplexTrigger(jobId, newJobParams, jobTrigger);
Assert.assertEquals(1, schedulerSvc.getJobs().length);
Job job = schedulerSvc.getJobs()[0];
jobTrigger = (ComplexJobTrigger) job.getJobTrigger();
Assert.assertEquals((Integer) startingMinute, ((IncrementalRecurrence) jobTrigger.getMinuteRecurrences().get(0)).getStartingValue());
Assert.assertEquals((Integer) 5, ((IncrementalRecurrence) jobTrigger.getMinuteRecurrences().get(0)).getIncrement());
Assert.assertTrue(job.getJobParams().containsKey("newKey"));
Assert.assertEquals(new Date(start), jobTrigger.getStartTime());
Assert.assertEquals(new Date(end), jobTrigger.getEndTime());
}
use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_daysOfMonth.
@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_daysOfMonth() throws Exception {
complex.setDaysOfMonth(new int[] { 1, 25 });
when(scheduleRequest.getComplexJobTrigger()).thenReturn(complex);
IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
assertNotNull(trigger);
assertTrue(trigger instanceof ComplexJobTrigger);
ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
List<ITimeRecurrence> recurrences = trig.getDayOfMonthRecurrences().getRecurrences();
assertEquals(2, recurrences.size());
RecurrenceList rec = (RecurrenceList) recurrences.get(0);
assertEquals(1, rec.getValues().get(0).intValue());
rec = (RecurrenceList) recurrences.get(1);
assertEquals(25, rec.getValues().get(0).intValue());
}
Aggregations