Search in sources :

Example 1 with SimpleJobTrigger

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

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

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

the class QuartzSchedulerIT method testGetJobs.

@Test
public void testGetJobs() throws SchedulerException {
    QuartzScheduler testGetJobsSchduler = new QuartzScheduler();
    Assert.assertEquals(0, testGetJobsSchduler.getJobs(null).size());
    String PARAM_KEY = "testGetJobsKey";
    jobParams.put(PARAM_KEY, "testParam1-value");
    Calendar calendar = Calendar.getInstance();
    int startingMin = calendar.get(Calendar.MINUTE);
    int startingSec = calendar.get(Calendar.SECOND) + 10;
    if (startingSec > 59) {
        startingSec = startingSec % 60;
        startingMin++;
        if (startingMin > 59) {
            startingMin = startingMin % 60;
        }
    }
    calendar.set(Calendar.MINUTE, startingMin);
    calendar.set(Calendar.SECOND, startingSec);
    SimpleJobTrigger jobTrigger = new SimpleJobTrigger(calendar.getTime(), null, 0, 0);
    testGetJobsSchduler.createJob("getJobsTestJob", TestAction.class, jobParams, jobTrigger);
    List<Job> jobs = testGetJobsSchduler.getJobs(null);
    Assert.assertEquals(1, jobs.size());
    Job theJob = jobs.get(0);
    Assert.assertTrue(theJob.getJobParams().containsKey(PARAM_KEY));
    Assert.assertTrue(theJob.getJobName().contains("getJobsTestJob"));
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Calendar(java.util.Calendar) TestQuartzScheduler(org.pentaho.platform.scheduler2.ws.test.TestQuartzScheduler) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 4 with SimpleJobTrigger

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

the class QuartzSchedulerIT method editJobTest.

@Test
public void editJobTest() throws SchedulerException {
    SimpleJobTrigger repeater = new SimpleJobTrigger();
    repeater.setStartTime(new Date());
    repeater.setRepeatInterval(2);
    repeater.setRepeatCount(20);
    Job job = scheduler.createJob("testName", TestAction.class, new HashMap<String, Serializable>(), repeater);
    sleep(3);
    Assert.assertTrue("Job did not run the correct number of times", TestAction.counter >= 2);
    repeater = new SimpleJobTrigger();
    repeater.setStartTime(new Date());
    repeater.setRepeatInterval(5);
    repeater.setRepeatCount(3);
    int count = TestAction.counter;
    System.out.println("updating job! " + new Date());
    scheduler.updateJob(job.getJobId(), new HashMap<String, Serializable>(), repeater);
    List<Job> jobs = scheduler.getJobs(null);
    Assert.assertEquals("Unexpected number of scheduled jobs", 1, jobs.size());
    SimpleJobTrigger simpleJobTrigger = (SimpleJobTrigger) jobs.get(0).getJobTrigger();
    Assert.assertEquals(5, simpleJobTrigger.getRepeatInterval());
    Assert.assertEquals(3, simpleJobTrigger.getRepeatCount());
    sleep(1);
    Assert.assertEquals("Job did not run the correct number of times", count + 1, TestAction.counter);
    count = TestAction.counter;
    sleep(3);
    Assert.assertEquals("Job ran unexpectedly", count, TestAction.counter);
    sleep(3);
    Assert.assertTrue("Job did not run the correct number of times", count < TestAction.counter);
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Example 5 with SimpleJobTrigger

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

the class JaxWsSchedulerServiceIT method testUpdateSimpleJob.

@Test
public void testUpdateSimpleJob() throws SchedulerException {
    long start = System.currentTimeMillis() + 1000;
    long end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
    SimpleJobTrigger jobTrigger = new SimpleJobTrigger();
    jobTrigger.setStartTime(new Date(start));
    jobTrigger.setEndTime(new Date(end));
    jobTrigger.setRepeatInterval(10);
    jobTrigger.setRepeatCount(20);
    System.out.println(jobTrigger.toString());
    String jobId = schedulerSvc.createSimpleJob("test job", jobParams, jobTrigger);
    Assert.assertEquals(1, schedulerSvc.getJobs().length);
    jobTrigger = new SimpleJobTrigger();
    start = System.currentTimeMillis() + 1000;
    end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
    jobTrigger.setStartTime(new Date(start));
    jobTrigger.setEndTime(new Date(end));
    jobTrigger.setRepeatInterval(40);
    jobTrigger.setRepeatCount(50);
    System.out.println(jobTrigger.toString());
    HashMap<String, ParamValue> newJobParams = new HashMap<String, ParamValue>(jobParams);
    newJobParams.put("newKey", new StringParamValue(""));
    schedulerSvc.updateJobToUseSimpleTrigger(jobId, newJobParams, jobTrigger);
    Assert.assertEquals(1, schedulerSvc.getJobs().length);
    Job job = schedulerSvc.getJobs()[0];
    jobTrigger = (SimpleJobTrigger) job.getJobTrigger();
    Assert.assertEquals(40, jobTrigger.getRepeatInterval());
    Assert.assertEquals(50, jobTrigger.getRepeatCount());
    Assert.assertTrue(job.getJobParams().containsKey("newKey"));
    jobTrigger.getStartTime();
    Assert.assertEquals(new Date(start), jobTrigger.getStartTime());
    Assert.assertEquals(new Date(end), jobTrigger.getEndTime());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) HashMap(java.util.HashMap) 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)

Aggregations

SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)29 Test (org.junit.Test)23 Date (java.util.Date)14 Job (org.pentaho.platform.api.scheduler2.Job)14 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 Serializable (java.io.Serializable)10 Calendar (java.util.Calendar)7 HashMap (java.util.HashMap)7 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)7 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)6 GregorianCalendar (java.util.GregorianCalendar)4 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)3 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)3 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)3 JobScheduleParam (org.pentaho.platform.web.http.api.resources.JobScheduleParam)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Matchers.anyString (org.mockito.Matchers.anyString)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)2