use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class PentahoBlockoutManagerIT method testGetBlockouts.
@Test
public void testGetBlockouts() throws Exception {
IJobTrigger trigger1 = new SimpleJobTrigger(new Date(), null, -1, 1000000);
IJobTrigger trigger2 = new SimpleJobTrigger(new Date(), null, -1, 1000000);
addBlockOutJob(trigger1);
addBlockOutJob(trigger2);
assertEquals(2, this.blockOutManager.getBlockOutJobs().size());
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class PentahoBlockoutManagerIT method testWillBlockSchedules.
/**
* Test method for
* {@link org.pentaho.platform.scheduler2.blockout.PentahoBlockoutManager#willBlockSchedules
* (org.pentaho.platform.scheduler2.blockout.SimpleBlockoutTrigger)}
* .
*/
@Test
public void testWillBlockSchedules() throws Exception {
Calendar trueBlockOutStartDate = new GregorianCalendar(2013, Calendar.JANUARY, 7);
IJobTrigger trueBlockOutTrigger = new SimpleJobTrigger(trueBlockOutStartDate.getTime(), null, -1, TIME.WEEK.time / 1000);
trueBlockOutTrigger.setDuration(duration);
Calendar falseBlockOutStartDate = new GregorianCalendar(2013, Calendar.JANUARY, 9);
IJobTrigger falseBlockOutTrigger = new SimpleJobTrigger(falseBlockOutStartDate.getTime(), null, -1, TIME.WEEK.time / 1000);
falseBlockOutTrigger.setDuration(duration);
IJobTrigger trueComplexBlockOutTrigger = new ComplexJobTrigger();
trueComplexBlockOutTrigger.setStartTime(trueBlockOutStartDate.getTime());
// $NON-NLS-1$
trueComplexBlockOutTrigger.setCronString("0 0 0 ? * 2 *");
trueComplexBlockOutTrigger.setDuration(duration);
IJobTrigger falseComplexBlockOutTrigger = new ComplexJobTrigger();
falseComplexBlockOutTrigger.setStartTime(falseBlockOutStartDate.getTime());
// $NON-NLS-1$
falseComplexBlockOutTrigger.setCronString("0 0 0 ? * WED *");
falseComplexBlockOutTrigger.setDuration(duration);
Calendar scheduleStartDate = new GregorianCalendar(2013, Calendar.JANUARY, 7, 1, 0, 0);
IJobTrigger scheduleTrigger = new SimpleJobTrigger(scheduleStartDate.getTime(), null, -1, TIME.WEEK.time / 1000);
// $NON-NLS-1$
addJob(scheduleTrigger, "scheduleTrigger");
assertEquals(1, this.blockOutManager.willBlockSchedules(trueBlockOutTrigger).size());
assertEquals(1, this.blockOutManager.willBlockSchedules(trueComplexBlockOutTrigger).size());
assertEquals(0, this.blockOutManager.willBlockSchedules(falseBlockOutTrigger).size());
assertEquals(0, this.blockOutManager.willBlockSchedules(falseComplexBlockOutTrigger).size());
IJobTrigger cronTrigger = new ComplexJobTrigger();
cronTrigger.setStartTime(scheduleStartDate.getTime());
// $NON-NLS-1$
cronTrigger.setCronString("0 0 1 ? * 2-3 *");
// $NON-NLS-1$
addJob(cronTrigger, "cronTrigger");
assertEquals(2, this.blockOutManager.willBlockSchedules(trueBlockOutTrigger).size());
assertEquals(2, this.blockOutManager.willBlockSchedules(trueComplexBlockOutTrigger).size());
assertEquals(0, this.blockOutManager.willBlockSchedules(falseBlockOutTrigger).size());
assertEquals(0, this.blockOutManager.willBlockSchedules(falseComplexBlockOutTrigger).size());
IJobTrigger complexJobTrigger1 = new ComplexJobTrigger(null, null, null, ComplexJobTrigger.MONDAY, 0);
complexJobTrigger1.setStartTime(scheduleStartDate.getTime());
// $NON-NLS-1$
addJob(complexJobTrigger1, "complexJobTrigger1");
assertEquals(3, this.blockOutManager.willBlockSchedules(trueBlockOutTrigger).size());
assertEquals(3, this.blockOutManager.willBlockSchedules(trueComplexBlockOutTrigger).size());
assertEquals(0, this.blockOutManager.willBlockSchedules(falseBlockOutTrigger).size());
assertEquals(0, this.blockOutManager.willBlockSchedules(falseComplexBlockOutTrigger).size());
// Test non-standard interval
IJobTrigger complexJobTrigger2 = new ComplexJobTrigger(null, null, 1, null, 0);
complexJobTrigger2.setStartTime(scheduleStartDate.getTime());
// $NON-NLS-1$
addJob(complexJobTrigger2, "complexJobTrigger2");
assertEquals(4, this.blockOutManager.willBlockSchedules(trueBlockOutTrigger).size());
assertEquals(4, this.blockOutManager.willBlockSchedules(trueComplexBlockOutTrigger).size());
assertEquals(1, this.blockOutManager.willBlockSchedules(falseBlockOutTrigger).size());
assertEquals(1, this.blockOutManager.willBlockSchedules(falseComplexBlockOutTrigger).size());
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class SchedulerResourceTest method testBlockoutWillFire.
@Test
public void testBlockoutWillFire() throws Exception {
JobScheduleRequest mockJobScheduleRequest = mock(JobScheduleRequest.class);
IJobTrigger mockJobTrigger = mock(IJobTrigger.class);
doReturn(mockJobTrigger).when(schedulerResource).convertScheduleRequestToJobTrigger(mockJobScheduleRequest);
Boolean willFire = Boolean.FALSE;
doReturn(willFire).when(schedulerResource.schedulerService).willFire(mockJobTrigger);
Response mockResponse = mock(Response.class);
doReturn(mockResponse).when(schedulerResource).buildOkResponse(willFire.toString());
Response testResponse = schedulerResource.blockoutWillFire(mockJobScheduleRequest);
assertEquals(mockResponse, testResponse);
verify(schedulerResource, times(1)).convertScheduleRequestToJobTrigger(mockJobScheduleRequest);
verify(schedulerResource.schedulerService, times(1)).willFire(mockJobTrigger);
verify(schedulerResource, times(1)).buildOkResponse(willFire.toString());
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger 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());
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_CronString.
@Test
public void testConvertScheduleRequestToJobTrigger_CronString() throws Exception {
cron = new CronJobTrigger();
cron.setCronString("0 45 16 ? * 2#4,2L,6#4,6L *");
cron.setDuration(200000);
cron.setStartTime(now);
cron.setUiPassParam("param");
cron.setEndTime(now);
when(scheduleRequest.getCronJobTrigger()).thenReturn(cron);
IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
assertTrue(trigger instanceof ComplexJobTrigger);
ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
assertEquals(now, trig.getStartTime());
assertEquals(now, trig.getEndTime());
assertEquals(200000, trig.getDuration());
assertEquals("param", trig.getUiPassParam());
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());
}
Aggregations