use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.
the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_weeksOfMonth.
@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_weeksOfMonth() throws Exception {
complex.setDaysOfWeek(new int[] { 1, 5 });
complex.setWeeksOfMonth(new int[] { 3, 4 });
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.getDayOfWeekRecurrences().getRecurrences();
assertEquals(4, recurrences.size());
QualifiedDayOfWeek rec = (QualifiedDayOfWeek) recurrences.get(0);
assertEquals("MON", rec.getDayOfWeek().toString());
assertEquals("FOURTH", rec.getQualifier().toString());
rec = (QualifiedDayOfWeek) recurrences.get(1);
assertEquals("MON", rec.getDayOfWeek().toString());
assertEquals("LAST", rec.getQualifier().toString());
rec = (QualifiedDayOfWeek) recurrences.get(2);
assertEquals("FRI", rec.getDayOfWeek().toString());
assertEquals("FOURTH", rec.getQualifier().toString());
rec = (QualifiedDayOfWeek) recurrences.get(3);
assertEquals("FRI", rec.getDayOfWeek().toString());
assertEquals("LAST", rec.getQualifier().toString());
}
use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.
the class PentahoBlockoutManagerIT method testWillFire.
/**
* Test method for
* {@link org.pentaho.platform.scheduler2.blockout.PentahoBlockoutManager#willFire(org.quartz.IJobTrigger)}.
*/
@Test
public void testWillFire() throws Exception {
Calendar blockOutStartDate = new GregorianCalendar(2013, Calendar.JANUARY, 7);
IJobTrigger blockOutJobTrigger = new SimpleJobTrigger(blockOutStartDate.getTime(), null, -1, TIME.WEEK.time / 1000);
blockOutJobTrigger.setDuration(duration);
/*
* Simple Schedule Triggers
*/
Calendar scheduleStartDate = new GregorianCalendar(2013, Calendar.JANUARY, 7, 1, 0, 0);
IJobTrigger trueScheduleTrigger = new SimpleJobTrigger(scheduleStartDate.getTime(), null, -1, TIME.DAY.time / 1000);
IJobTrigger falseScheduleTrigger = new SimpleJobTrigger(scheduleStartDate.getTime(), null, -1, TIME.WEEK.time / 1000);
Job blockOutJob = addBlockOutJob(blockOutJobTrigger);
assertTrue(this.blockOutManager.willFire(trueScheduleTrigger));
assertFalse(this.blockOutManager.willFire(falseScheduleTrigger));
/*
* Complex Schedule Triggers
*/
IJobTrigger trueComplexScheduleTrigger = new ComplexJobTrigger();
trueComplexScheduleTrigger.setStartTime(scheduleStartDate.getTime());
// $NON-NLS-1$
trueComplexScheduleTrigger.setCronString("0 0 1 ? * 2-3 *");
IJobTrigger falseComplexScheduleTrigger = new ComplexJobTrigger();
falseComplexScheduleTrigger.setStartTime(scheduleStartDate.getTime());
// $NON-NLS-1$
falseComplexScheduleTrigger.setCronString("0 0 1 ? * 2 *");
assertTrue(this.blockOutManager.willFire(trueComplexScheduleTrigger));
assertFalse(this.blockOutManager.willFire(falseComplexScheduleTrigger));
/*
* Complex Block out
*/
deleteJob(blockOutJob.getJobId());
blockOutJobTrigger = new ComplexJobTrigger();
blockOutJobTrigger.setStartTime(blockOutStartDate.getTime());
blockOutJobTrigger.setDuration(duration);
// $NON-NLS-1$
blockOutJobTrigger.setCronString("0 0 0 ? * 2 *");
addBlockOutJob(blockOutJobTrigger);
assertTrue(this.blockOutManager.willFire(trueScheduleTrigger));
assertFalse(this.blockOutManager.willFire(falseScheduleTrigger));
assertTrue(this.blockOutManager.willFire(trueComplexScheduleTrigger));
assertFalse(this.blockOutManager.willFire(falseComplexScheduleTrigger));
}
use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.
the class PentahoBlockoutManagerIT method testIsPartiallyBlocked.
/**
* Test method for
* {@link org.pentaho.platform.scheduler2.blockout.PentahoBlockoutManager#isPartiallyBlocked(org.quartz.IJobTrigger)}.
*/
@Test
public void testIsPartiallyBlocked() throws Exception {
Calendar blockOutStartDate = new GregorianCalendar(2013, Calendar.JANUARY, 1, 0, 0, 0);
IJobTrigger blockOutTrigger = new SimpleJobTrigger(blockOutStartDate.getTime(), null, -1, TIME.WEEK.time * 2 / 1000);
blockOutTrigger.setDuration(duration);
/*
* Simple Schedule Triggers
*/
Calendar trueScheduleStartDate1 = new GregorianCalendar(2013, Calendar.JANUARY, 15, 0, 0, 0);
IJobTrigger trueSchedule1 = new SimpleJobTrigger(trueScheduleStartDate1.getTime(), null, -1, TIME.WEEK.time * 2 / 1000);
Calendar trueScheduleStartDate2 = new GregorianCalendar(2013, Calendar.JANUARY, 15, 0, 0, 0);
IJobTrigger trueSchedule2 = new SimpleJobTrigger(trueScheduleStartDate2.getTime(), null, -1, TIME.WEEK.time / 1000);
Calendar falseScheduleStartDate1 = new GregorianCalendar(2013, Calendar.JANUARY, 1, 3, 0, 0);
IJobTrigger falseSchedule1 = new SimpleJobTrigger(falseScheduleStartDate1.getTime(), null, -1, TIME.WEEK.time / 1000);
Job blockOutJob = addBlockOutJob(blockOutTrigger);
assertTrue(this.blockOutManager.isPartiallyBlocked(trueSchedule1));
assertTrue(this.blockOutManager.isPartiallyBlocked(trueSchedule2));
assertFalse(this.blockOutManager.isPartiallyBlocked(falseSchedule1));
/*
* Complex Schedule Triggers
*/
IJobTrigger trueComplexScheduleTrigger = new ComplexJobTrigger();
trueComplexScheduleTrigger.setStartTime(trueScheduleStartDate1.getTime());
// $NON-NLS-1$
trueComplexScheduleTrigger.setCronString("0 0 1 ? * 2-3 *");
IJobTrigger falseComplexScheduleTrigger = new ComplexJobTrigger();
falseComplexScheduleTrigger.setStartTime(trueScheduleStartDate1.getTime());
// $NON-NLS-1$
falseComplexScheduleTrigger.setCronString("0 0 1 ? * 2 *");
assertTrue(this.blockOutManager.isPartiallyBlocked(trueComplexScheduleTrigger));
assertFalse(this.blockOutManager.isPartiallyBlocked(falseComplexScheduleTrigger));
/*
* Complex Block Out IJobTrigger
*/
deleteJob(blockOutJob.getJobId());
blockOutTrigger = new ComplexJobTrigger();
blockOutTrigger.setStartTime(blockOutStartDate.getTime());
// $NON-NLS-1$
blockOutTrigger.setCronString("0 0 0 ? * 3 *");
blockOutTrigger.setDuration(duration);
addBlockOutJob(blockOutTrigger);
assertTrue(this.blockOutManager.isPartiallyBlocked(trueSchedule1));
assertTrue(this.blockOutManager.isPartiallyBlocked(trueSchedule2));
assertFalse(this.blockOutManager.isPartiallyBlocked(falseSchedule1));
assertTrue(this.blockOutManager.isPartiallyBlocked(trueComplexScheduleTrigger));
assertFalse(this.blockOutManager.isPartiallyBlocked(falseComplexScheduleTrigger));
}
use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method getComplexJobTrigger.
private ComplexJobTrigger getComplexJobTrigger() {
final ComplexJobTrigger trigger = new ComplexJobTrigger();
trigger.setSecondRecurrence(1);
return trigger;
}
use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger 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());
}
Aggregations