use of org.pentaho.platform.api.scheduler2.IJobTrigger 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.IJobTrigger in project pentaho-platform by pentaho.
the class SchedulerServiceTest method testGetBlockStatus.
@Test
public void testGetBlockStatus() throws Exception {
JobScheduleRequest jobScheduleRequestMock = mock(JobScheduleRequest.class);
BlockStatusProxy blockStatusProxyMock = mock(BlockStatusProxy.class);
IJobTrigger jobTrigger = mock(IJobTrigger.class);
doReturn(jobTrigger).when(schedulerService).convertScheduleRequestToJobTrigger(jobScheduleRequestMock);
doReturn(true).when(schedulerService.blockoutManager).isPartiallyBlocked(jobTrigger);
doReturn(true).when(schedulerService.blockoutManager).willFire(jobTrigger);
doReturn(blockStatusProxyMock).when(schedulerService).getBlockStatusProxy(anyBoolean(), anyBoolean());
// Test 1
BlockStatusProxy blockStatusProxy = schedulerService.getBlockStatus(jobScheduleRequestMock);
assertNotNull(blockStatusProxy);
// Test 2
doReturn(false).when(schedulerService.blockoutManager).isPartiallyBlocked(jobTrigger);
blockStatusProxy = schedulerService.getBlockStatus(jobScheduleRequestMock);
assertNotNull(blockStatusProxy);
verify(schedulerService, times(2)).convertScheduleRequestToJobTrigger(jobScheduleRequestMock);
verify(schedulerService.blockoutManager, times(2)).isPartiallyBlocked(jobTrigger);
verify(schedulerService, times(2)).getBlockStatusProxy(anyBoolean(), anyBoolean());
verify(schedulerService.blockoutManager, times(1)).willFire(jobTrigger);
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class SchedulerServiceTest method testWillFire.
@Test
public void testWillFire() {
IJobTrigger jobTrigger = mock(IJobTrigger.class);
// Test 1
doReturn(true).when(schedulerService.blockoutManager).willFire(jobTrigger);
boolean willFire = schedulerService.willFire(jobTrigger);
assertTrue(willFire);
// Test 2
doReturn(false).when(schedulerService.blockoutManager).willFire(jobTrigger);
willFire = schedulerService.willFire(jobTrigger);
assertFalse(willFire);
verify(schedulerService.blockoutManager, times(2)).willFire(jobTrigger);
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.
the class PentahoBlockoutManagerIT method testGetBlockout.
/**
* Test method for
* {@link org.pentaho.platform.scheduler2.blockout.PentahoBlockoutManager#getBlockOut(java.lang.String)}.
*/
@Test
public void testGetBlockout() throws Exception {
IJobTrigger blockOutJobTrigger1 = new SimpleJobTrigger(new Date(), null, -1, 1000000);
IJobTrigger blockOutJobTrigger2 = new SimpleJobTrigger(new Date(), null, -1, 1000000);
Job blockOutJob1 = addBlockOutJob(blockOutJobTrigger1);
Job blockOutJob2 = addBlockOutJob(blockOutJobTrigger2);
assertEquals(blockOutManager.getBlockOut(blockOutJob1.getJobId()).toString(), blockOutJobTrigger1.toString());
assertEquals(blockOutManager.getBlockOut(blockOutJob2.getJobId()).toString(), blockOutJobTrigger2.toString());
assertNotSame(blockOutJobTrigger1, blockOutManager.getBlockOut(blockOutJob2.getJobId()));
}
use of org.pentaho.platform.api.scheduler2.IJobTrigger 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));
}
Aggregations