Search in sources :

Example 6 with SchedulerException

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

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

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

the class JaxWsSchedulerServiceIT method init.

@Before
public void init() throws SchedulerException, PlatformInitializationException {
    schedulerSvc = (ISchedulerService) applicationContext.getBean("schedulerFromWs");
    MicroPlatform mp = new MicroPlatform();
    mp.define(IPluginManager.class, TstPluginManager.class);
    mp.define("IScheduler2", TestQuartzScheduler.class);
    mp.define(IUserRoleListService.class, StubUserRoleListService.class);
    mp.define(UserDetailsService.class, StubUserDetailsService.class);
    mp.start();
    scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    scheduler.start();
    MyAction.executed = false;
    MyAction.staticStringParam = null;
    jobParams = new HashMap<String, ParamValue>();
    jobParams.put("stringParam", new StringParamValue("testStringValue"));
    RUN_ONCE_IN_2_SECS = JobTrigger.ONCE_NOW;
    RUN_ONCE_IN_2_SECS.setStartTime(new Date(System.currentTimeMillis() + 2000L));
    RUN_ONCE_IN_3_SECS = JobTrigger.ONCE_NOW;
    RUN_ONCE_IN_3_SECS.setStartTime(new Date(System.currentTimeMillis() + 2000L));
}
Also used : MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) 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) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) Date(java.util.Date) Before(org.junit.Before)

Example 9 with SchedulerException

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

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

SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)51 Test (org.junit.Test)49 Job (org.pentaho.platform.api.scheduler2.Job)43 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)23 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)16 Serializable (java.io.Serializable)15 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)11 Date (java.util.Date)10 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)9 Scheduler (org.quartz.Scheduler)9 ArrayList (java.util.ArrayList)8 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)8 IOException (java.io.IOException)6 Calendar (java.util.Calendar)6 HashMap (java.util.HashMap)6 CronTrigger (org.quartz.CronTrigger)6 SimpleTrigger (org.quartz.SimpleTrigger)6 Trigger (org.quartz.Trigger)6 Response (javax.ws.rs.core.Response)5