Search in sources :

Example 6 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.

the class JaxWsSchedulerServiceIT method testCreateComplexJob.

@Test
public void testCreateComplexJob() throws SchedulerException {
    int startingMinute = (Calendar.getInstance().get(Calendar.MINUTE)) % 60;
    ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
    jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 1));
    jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    System.out.println(jobTrigger.toString());
    schedulerSvc.createComplexJob("test job", jobParams, jobTrigger);
    int tries = 0;
    do {
        sleep(10);
    } while (!MyAction.executed && tries++ < 13);
    Assert.assertTrue("the action was not executed in the expected window", MyAction.executed);
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IncrementalRecurrence(org.pentaho.platform.scheduler2.recur.IncrementalRecurrence) Test(org.junit.Test)

Example 7 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.

the class JaxWsSchedulerServiceIT method testUpdateComplexJob.

/*
  public static class TestQuartzScheduler extends QuartzScheduler {
    @Override
    protected String getCurrentUser() {
      SecurityHelper.getInstance().becomeUser( TEST_USER );
      return super.getCurrentUser();
    }
  }
*/
@Test(timeout = 1000 * 5 * 60)
public void testUpdateComplexJob() throws SchedulerException {
    long start = System.currentTimeMillis() + 1000;
    long end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
    int startingMinute = (Calendar.getInstance().get(Calendar.MINUTE) + 10) % 60;
    ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
    jobTrigger.setStartTime(new Date(start));
    jobTrigger.setEndTime(new Date(end));
    jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 1));
    jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    System.out.println(jobTrigger.toString());
    String jobId = schedulerSvc.createComplexJob("test job", jobParams, jobTrigger);
    Assert.assertEquals(1, schedulerSvc.getJobs().length);
    jobTrigger = new ComplexJobTrigger();
    start = System.currentTimeMillis() + 2 * 1000;
    end = System.currentTimeMillis() + 1000 + 7 * 60 * 60 * 100;
    jobTrigger.setStartTime(new Date(start));
    jobTrigger.setEndTime(new Date(end));
    startingMinute = (Calendar.getInstance().get(Calendar.MINUTE) + 20) % 60;
    jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 5));
    jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    System.out.println(jobTrigger.toString());
    HashMap<String, ParamValue> newJobParams = new HashMap<String, ParamValue>(jobParams);
    newJobParams.put("newKey", new StringParamValue(""));
    schedulerSvc.updateJobToUseComplexTrigger(jobId, newJobParams, jobTrigger);
    Assert.assertEquals(1, schedulerSvc.getJobs().length);
    Job job = schedulerSvc.getJobs()[0];
    jobTrigger = (ComplexJobTrigger) job.getJobTrigger();
    Assert.assertEquals((Integer) startingMinute, ((IncrementalRecurrence) jobTrigger.getMinuteRecurrences().get(0)).getStartingValue());
    Assert.assertEquals((Integer) 5, ((IncrementalRecurrence) jobTrigger.getMinuteRecurrences().get(0)).getIncrement());
    Assert.assertTrue(job.getJobParams().containsKey("newKey"));
    Assert.assertEquals(new Date(start), jobTrigger.getStartTime());
    Assert.assertEquals(new Date(end), jobTrigger.getEndTime());
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) HashMap(java.util.HashMap) IncrementalRecurrence(org.pentaho.platform.scheduler2.recur.IncrementalRecurrence) ListParamValue(org.pentaho.platform.scheduler2.ws.ListParamValue) ParamValue(org.pentaho.platform.scheduler2.ws.ParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) MapParamValue(org.pentaho.platform.scheduler2.ws.MapParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Example 8 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger 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 9 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger 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)

Example 10 with ComplexJobTrigger

use of org.pentaho.platform.api.scheduler2.ComplexJobTrigger in project pentaho-platform by pentaho.

the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_daysOfWeek.

@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_daysOfWeek() throws Exception {
    complex.setDaysOfWeek(new int[] { 1, 5 });
    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(2, recurrences.size());
    RecurrenceList rec = (RecurrenceList) recurrences.get(0);
    assertEquals(2, rec.getValues().get(0).intValue());
    rec = (RecurrenceList) recurrences.get(1);
    assertEquals(6, 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)

Aggregations

ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)28 Test (org.junit.Test)21 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 Job (org.pentaho.platform.api.scheduler2.Job)12 Calendar (java.util.Calendar)8 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)8 ITimeRecurrence (org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence)7 RecurrenceList (org.pentaho.platform.scheduler2.recur.RecurrenceList)6 IncrementalRecurrence (org.pentaho.platform.scheduler2.recur.IncrementalRecurrence)5 Serializable (java.io.Serializable)4 Date (java.util.Date)4 GregorianCalendar (java.util.GregorianCalendar)4 QualifiedDayOfWeek (org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek)4 HashMap (java.util.HashMap)3 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)3 Calendar (org.quartz.Calendar)3 CronTrigger (org.quartz.CronTrigger)3 SimpleTrigger (org.quartz.SimpleTrigger)3 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)2 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)2