Search in sources :

Example 1 with IJobTrigger

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());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Date(java.util.Date) Test(org.junit.Test)

Example 2 with IJobTrigger

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());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Example 3 with IJobTrigger

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());
}
Also used : Response(javax.ws.rs.core.Response) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Example 4 with IJobTrigger

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());
}
Also used : ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Example 5 with IJobTrigger

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());
}
Also used : QualifiedDayOfWeek(org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek) ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Aggregations

IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)28 Test (org.junit.Test)18 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)13 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)12 Job (org.pentaho.platform.api.scheduler2.Job)11 Date (java.util.Date)8 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)7 ITimeRecurrence (org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence)6 Serializable (java.io.Serializable)4 Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 RecurrenceList (org.pentaho.platform.scheduler2.recur.RecurrenceList)4 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)3 QualifiedDayOfWeek (org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek)3 Trigger (org.quartz.Trigger)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IAction (org.pentaho.platform.api.action.IAction)2 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)2 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)2