use of org.pentaho.platform.api.scheduler2.IJobTrigger 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.IJobTrigger in project pentaho-platform by pentaho.
the class PentahoBlockoutManagerIT method addJob.
private Job addJob(IJobTrigger jobTrigger, String jobName, IAction action, Map<String, Serializable> jobParams) throws Exception {
Job job = this.scheduler.createJob(jobName, action.getClass(), jobParams, jobTrigger);
this.jobIdsToClear.add(job.getJobId());
return job;
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class PentahoBlockoutManagerIT method testShouldFireNow.
/**
* Test method for {@link org.pentaho.platform.scheduler2.blockout.PentahoBlockoutManager#shouldFireNow()}.
*/
@Test
public void testShouldFireNow() throws Exception {
Date blockOutStartDate = new Date(System.currentTimeMillis());
IJobTrigger blockOutJobTrigger = new SimpleJobTrigger(blockOutStartDate, null, -1, TIME.WEEK.time * 2 / 1000);
blockOutJobTrigger.setDuration(duration);
Job blockOutJob = addBlockOutJob(blockOutJobTrigger);
assertFalse(this.blockOutManager.shouldFireNow());
deleteJob(blockOutJob.getJobId());
blockOutStartDate = new Date(System.currentTimeMillis() + TIME.HOUR.time);
blockOutJobTrigger = new SimpleJobTrigger(blockOutStartDate, null, -1, TIME.WEEK.time * 2 / 1000);
blockOutJobTrigger.setDuration(duration);
addBlockOutJob(blockOutJobTrigger);
assertTrue(this.blockOutManager.shouldFireNow());
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method createQuartzTriggerNotDefinedTriggerTest.
@Test(expected = SchedulerException.class)
public void createQuartzTriggerNotDefinedTriggerTest() throws Exception {
final IJobTrigger trigger = mock(IJobTrigger.class);
QuartzScheduler.createQuartzTrigger(trigger, getJobKey());
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class BlockoutManagerUtil method getFireTimes.
public static List<Date> getFireTimes(IJobTrigger jobTrigger, IScheduler scheduler) {
// Determines the maximum amount of fire times allowed to be calculated
int n = 1000;
Date startDate = new Date(System.currentTimeMillis());
Date endDate = new Date(startDate.getTime() + 4 * TIME.YEAR.time);
// Quartz Triggers
if (scheduler instanceof QuartzScheduler) {
try {
List<Date> dates = new ArrayList<Date>();
boolean endDateIsNull = jobTrigger.getEndTime() == null;
// $NON-NLS-1$ //$NON-NLS-2$
Trigger trigger = QuartzScheduler.createQuartzTrigger(jobTrigger, new QuartzJobKey("test", "test"));
// add previous trigger (it might be currently active)
// $NON-NLS-1$;
IBlockoutManager manager = PentahoSystem.get(IBlockoutManager.class, "IBlockoutManager", null);
if (manager != null) {
List<Job> blockouts = manager.getBlockOutJobs();
for (Job blockout : blockouts) {
if (blockout.getLastRun() != null) {
dates.add(blockout.getLastRun());
}
}
}
for (int i = 0; i < n; i++) {
Date nextFireTime = trigger.getFireTimeAfter(startDate);
if ((nextFireTime == null) || (nextFireTime.after(endDate) || (!endDateIsNull && nextFireTime.after(jobTrigger.getEndTime())))) {
break;
}
dates.add(nextFireTime);
startDate = nextFireTime;
}
return dates;
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
throw new RuntimeException(// $NON-NLS-1$
"Can not calculate fire times for unsupported Scheduler Type: " + scheduler.getClass().getSimpleName());
}
Aggregations