Search in sources :

Example 1 with ComplexJobTrigger

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

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

the class QuartzSchedulerIT method createJobTest.

@Test
public void createJobTest() throws Exception {
    String actionId = "actionId";
    ComplexJobTrigger trigger = getComplexJobTrigger();
    IBackgroundExecutionStreamProvider outputStreamProvider = mock(IBackgroundExecutionStreamProvider.class);
    final Job job = scheduler.createJob(JOB_NAME, actionId, null, trigger, outputStreamProvider);
    assertNotNull(job);
    assertEquals(Job.JobState.NORMAL, job.getState());
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_ACTIONID));
    assertEquals(actionId, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_ACTIONID));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER));
    assertEquals(outputStreamProvider, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID));
    assertNotNull(job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER));
    assertEquals(USER_NAME, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER));
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 3 with ComplexJobTrigger

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

the class QuartzSchedulerIT method createJobTest_ForUser.

@Test
public void createJobTest_ForUser() throws Exception {
    String actionId = "actionId";
    ComplexJobTrigger trigger = getComplexJobTrigger();
    IBackgroundExecutionStreamProvider outputStreamProvider = mock(IBackgroundExecutionStreamProvider.class);
    Map<String, Serializable> paramMap = new HashMap<>();
    paramMap.put(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER, "ninja");
    final Job job = scheduler.createJob(JOB_NAME, paramMap, trigger, outputStreamProvider);
    assertNotNull(job);
    assertEquals("ninja", job.getUserName());
    assertEquals(Job.JobState.NORMAL, job.getState());
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 4 with ComplexJobTrigger

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

the class QuartzSchedulerIT method runComplexTriggerTest.

@Test
public void runComplexTriggerTest() throws SchedulerException {
    Calendar calendar = Calendar.getInstance();
    // seconds
    final int testTime = 7;
    int startingMinute = calendar.get(Calendar.MINUTE);
    int startingSec = calendar.get(Calendar.SECOND) + 1;
    // we can't finish until end of the minute - sleep for this time
    if (startingSec > 59 - testTime) {
        sleep(59 - startingSec);
        startingSec = 0;
        startingMinute++;
        if (startingMinute > 59) {
            startingMinute = startingMinute % 60;
        }
    }
    int endingSecond = startingSec + 5;
    RecurrenceList recurrenceList = new RecurrenceList(startingSec, endingSecond);
    SequentialRecurrence sequentialRecurrence = new SequentialRecurrence(startingSec, endingSecond);
    IncrementalRecurrence incrementalRecurrence = new IncrementalRecurrence(startingSec, 1);
    ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
    jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    jobTrigger.setMinuteRecurrence(startingMinute);
    jobTrigger.setSecondRecurrence(recurrenceList);
    System.out.println(jobTrigger.toString());
    String jobName = "complexJob1";
    Job job = scheduler.createJob(jobName, TestAction.class, new HashMap<String, Serializable>(), jobTrigger);
    Assert.assertTrue(job.getJobName().contains(jobName));
    Assert.assertEquals(job.getSchedulableClass(), TestAction.class.getName());
    Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
    jobTrigger.setSecondRecurrence(sequentialRecurrence);
    jobName = "complexJob2";
    job = scheduler.createJob(jobName, TestAction2.class, new HashMap<String, Serializable>(), jobTrigger);
    Assert.assertTrue(job.getJobName().contains(jobName));
    Assert.assertEquals(job.getSchedulableClass(), TestAction2.class.getName());
    Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
    jobTrigger.setSecondRecurrence(incrementalRecurrence);
    jobName = "complexJob3";
    job = scheduler.createJob(jobName, TestAction3.class, new HashMap<String, Serializable>(), jobTrigger);
    Assert.assertTrue(job.getJobName().contains(jobName));
    Assert.assertEquals(job.getSchedulableClass(), TestAction3.class.getName());
    Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
    // 
    // Wait for the jobs to complete, then check that each action executed the correct number of times
    // 
    sleep(testTime);
    Assert.assertEquals("Job did not run the correct number of times", 2, TestAction.counter);
    Assert.assertEquals("Job did not run the correct number of times", 6, TestAction2.counter);
    System.out.println("Counter = " + TestAction3.counter);
    Assert.assertTrue("Job did not run.", TestAction3.counter > 3);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Calendar(java.util.Calendar) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) SequentialRecurrence(org.pentaho.platform.scheduler2.recur.SequentialRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IncrementalRecurrence(org.pentaho.platform.scheduler2.recur.IncrementalRecurrence) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 5 with ComplexJobTrigger

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

the class QuartzSchedulerIT method testPauseAndResumeJob.

@Test
public void testPauseAndResumeJob() throws SchedulerException {
    String jobName = "complexJob1";
    int counter = TestAction.counter;
    Calendar calendar = Calendar.getInstance();
    int startingMin = calendar.get(Calendar.MINUTE);
    int startingSec = calendar.get(Calendar.SECOND) + 1;
    if (startingSec > 59) {
        startingSec = startingSec % 60;
        startingMin++;
        if (startingMin > 59) {
            startingMin = startingMin % 60;
        }
    }
    ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
    complexJobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
    complexJobTrigger.setMinuteRecurrence(startingMin);
    complexJobTrigger.setSecondRecurrence(startingSec);
    Job job = scheduler.createJob(jobName, TestAction.class, jobParams, complexJobTrigger);
    scheduler.pauseJob(job.getJobId());
    sleep(2);
    Assert.assertEquals(counter, TestAction.counter);
    Assert.assertEquals(1, scheduler.getJobs(null).size());
    scheduler.resumeJob(job.getJobId());
    sleep(2);
    Assert.assertTrue(counter != TestAction.counter);
    scheduler.removeJob(job.getJobId());
    Assert.assertEquals(0, scheduler.getJobs(null).size());
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Calendar(java.util.Calendar) Job(org.pentaho.platform.api.scheduler2.Job) 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