Search in sources :

Example 1 with QuartzScheduler

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

use of org.pentaho.platform.scheduler2.quartz.QuartzScheduler 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 3 with QuartzScheduler

use of org.pentaho.platform.scheduler2.quartz.QuartzScheduler in project pdi-platform-plugin by pentaho.

the class PdiActionTest method init.

@Before
public void init() throws SchedulerException, PlatformInitializationException {
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.root", SOLUTION_REPOSITORY);
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.delimiter", "/");
    // $NON-NLS-2$
    System.setProperty("PENTAHO_SYS_CFG_PATH", new File(SOLUTION_REPOSITORY + "/pentaho.xml").getAbsolutePath());
    IPentahoSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    scheduler = new QuartzScheduler();
    scheduler.start();
    mp.define(IUserRoleListService.class, StubUserRoleListService.class);
    mp.define(UserDetailsService.class, StubUserDetailService.class);
    mp.defineInstance(IAuthorizationPolicy.class, new TestAuthorizationPolicy());
    mp.setSettingsProvider(new PathBasedSystemSettings());
    mp.defineInstance(IScheduler.class, scheduler);
    mp.define(ISolutionEngine.class, SolutionEngine.class);
    FileSystemBackedUnifiedRepository repo = new FileSystemBackedUnifiedRepository(SOLUTION_REPOSITORY);
    mp.defineInstance(IUnifiedRepository.class, repo);
    mp.start();
    SecurityHelper.getInstance().becomeUser(TEST_USER);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) File(java.io.File) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) Before(org.junit.Before)

Example 4 with QuartzScheduler

use of org.pentaho.platform.scheduler2.quartz.QuartzScheduler in project pdi-platform-plugin by pentaho.

the class PdiContentGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.root", SOLUTION_REPOSITORY);
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.delimiter", "/");
    // $NON-NLS-2$
    System.setProperty("PENTAHO_SYS_CFG_PATH", new File(SOLUTION_REPOSITORY + "/pentaho.xml").getAbsolutePath());
    IPentahoSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    pdiContentGenerator = new PdiContentGenerator();
    pdiAction = new PdiAction();
    pdiAction.setRepositoryName(KettleFileRepositoryMeta.REPOSITORY_TYPE_ID);
    pdiContentGenerator.setPdiAction(pdiAction);
    outputStream = mock(OutputStream.class);
    repositoryFile = mock(RepositoryFile.class);
    pdiContentGenerator.setOutputStream(outputStream);
    pdiContentGenerator.setRepositoryFile(repositoryFile);
    scheduler = new QuartzScheduler();
    scheduler.start();
    mp.define(IUserRoleListService.class, StubUserRoleListService.class);
    mp.define(UserDetailsService.class, StubUserDetailService.class);
    mp.defineInstance(IAuthorizationPolicy.class, new TestAuthorizationPolicy());
    mp.defineInstance(IScheduler.class, scheduler);
    mp.define(ISolutionEngine.class, SolutionEngine.class);
    FileSystemBackedUnifiedRepository repo = new FileSystemBackedUnifiedRepository(SOLUTION_REPOSITORY);
    mp.defineInstance(IUnifiedRepository.class, repo);
    mp.start();
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) OutputStream(java.io.OutputStream) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) Before(org.junit.Before)

Example 5 with QuartzScheduler

use of org.pentaho.platform.scheduler2.quartz.QuartzScheduler in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method init.

@Before
public void init() throws SchedulerException, PlatformInitializationException {
    scheduler = new QuartzScheduler();
    scheduler.start();
    TestAction.reset();
    TestAction2.reset();
    TestAction3.reset();
    TestActionCustomParam.reset();
    MicroPlatform mp = new MicroPlatform();
    // $NON-NLS-1$
    mp.define("IScheduler2", TestQuartzScheduler.class);
    mp.define(IUserRoleListService.class, StubUserRoleListService.class);
    mp.define(UserDetailsService.class, StubUserDetailsService.class);
    mp.define(IAuditEntry.class, TestAuditEntry.class);
    mp.start();
    SecurityHelper.getInstance().becomeUser(TEST_USER);
    jobParams = new HashMap<String, Serializable>();
}
Also used : Serializable(java.io.Serializable) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) TestQuartzScheduler(org.pentaho.platform.scheduler2.ws.test.TestQuartzScheduler) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) Before(org.junit.Before)

Aggregations

QuartzScheduler (org.pentaho.platform.scheduler2.quartz.QuartzScheduler)7 Before (org.junit.Before)4 Date (java.util.Date)3 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)3 Job (org.pentaho.platform.api.scheduler2.Job)3 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)3 File (java.io.File)2 Calendar (java.util.Calendar)2 Test (org.junit.Test)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)2 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)2 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)2 TestQuartzScheduler (org.pentaho.platform.scheduler2.ws.test.TestQuartzScheduler)2 OutputStream (java.io.OutputStream)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1