Search in sources :

Example 16 with IJobTrigger

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());
}
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) Test(org.junit.Test)

Example 17 with IJobTrigger

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);
}
Also used : BlockStatusProxy(org.pentaho.platform.web.http.api.resources.proxies.BlockStatusProxy) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 18 with IJobTrigger

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

Example 19 with IJobTrigger

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

Example 20 with IJobTrigger

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));
}
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) Job(org.pentaho.platform.api.scheduler2.Job) 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