Search in sources :

Example 6 with IJobFilter

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

the class SchedulerServiceTest method testGetContentCleanerJob.

@Test
public void testGetContentCleanerJob() throws Exception {
    IJobFilter jobFilter = mock(IJobFilter.class);
    List<Job> jobs = new ArrayList<>();
    IPentahoSession session = mock(IPentahoSession.class);
    doReturn(session).when(schedulerService).getSession();
    doReturn("sessionName").when(session).getName();
    doReturn(true).when(schedulerService.policy).isAllowed(AdministerSecurityAction.NAME);
    doReturn(jobFilter).when(schedulerService).getJobFilter(anyBoolean(), anyString());
    doReturn(jobs).when(schedulerService.scheduler).getJobs(any(IJobFilter.class));
    // Test 1
    Job job = schedulerService.getContentCleanerJob();
    assertNull(job);
    // Test 2
    Job job1 = mock(Job.class);
    jobs.add(job1);
    job = schedulerService.getContentCleanerJob();
    assertNotNull(job);
    verify(schedulerService, times(2)).getSession();
    verify(session, times(2)).getName();
    verify(schedulerService.policy, times(2)).isAllowed(AdministerSecurityAction.NAME);
    verify(schedulerService.scheduler, times(2)).getJobs(any(IJobFilter.class));
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 7 with IJobFilter

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

the class SchedulerServiceTest method testGetContentCleanerJobException.

@Test
public void testGetContentCleanerJobException() throws Exception {
    IJobFilter jobFilter = mock(IJobFilter.class);
    List<Job> jobs = new ArrayList<>();
    IPentahoSession session = mock(IPentahoSession.class);
    doReturn(session).when(schedulerService).getSession();
    doReturn("sessionName").when(session).getName();
    doReturn(true).when(schedulerService.policy).isAllowed(AdministerSecurityAction.NAME);
    doReturn(jobFilter).when(schedulerService).getJobFilter(anyBoolean(), anyString());
    doThrow(new SchedulerException("")).when(schedulerService.scheduler).getJobs(any(IJobFilter.class));
    try {
        schedulerService.getContentCleanerJob();
        fail();
    } catch (SchedulerException e) {
    // Should catch the exception
    }
    verify(schedulerService).getSession();
    verify(session).getName();
    verify(schedulerService.policy).isAllowed(AdministerSecurityAction.NAME);
    verify(schedulerService.scheduler).getJobs(any(IJobFilter.class));
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 8 with IJobFilter

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

the class QuartzSchedulerIT method getJobsTest.

@Test
public void getJobsTest() throws Exception {
    final IJobFilter jobFilter = mock(IJobFilter.class);
    when(jobFilter.accept(any(Job.class))).thenReturn(true);
    final String groupName = "groupName";
    when(quartzScheduler.getJobGroupNames()).thenReturn(new String[] { groupName });
    when(quartzScheduler.getJobNames(eq(groupName))).thenReturn(new String[] { JOB_ID });
    final Trigger trigger = mock(Trigger.class);
    Date date1 = new Date();
    when(trigger.getPreviousFireTime()).thenReturn(new Date());
    when(trigger.getFireTimeAfter(any(Date.class))).thenReturn(date1);
    when(trigger.getNextFireTime()).thenReturn(date1);
    final Trigger trigger2 = mock(Trigger.class);
    when(trigger2.getGroup()).thenReturn("MANUAL_TRIGGER");
    when(quartzScheduler.getTriggersOfJob(eq(JOB_ID), eq(groupName))).thenReturn(new Trigger[] { trigger, trigger2 });
    setJobDataMap(groupName);
    final List<Job> jobs = scheduler.getJobs(jobFilter);
    assertNotNull(jobs);
    assertEquals(1, jobs.size());
    Job job = jobs.get(0);
    assertEquals(groupName, job.getGroupName());
    assertEquals(USER_NAME, job.getUserName());
    assertEquals(jobDetails, job.getJobParams());
    assertEquals(JOB_ID, job.getJobId());
    assertEquals(JOB_NAME, job.getJobName());
    assertEquals(trigger.getPreviousFireTime(), job.getLastRun());
    assertEquals(trigger.getNextFireTime(), job.getNextRun());
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) CronTrigger(org.quartz.CronTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Example 9 with IJobFilter

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

the class EmbeddedVersionCheckSystemListenerIT method testCreateJob.

@Test
public void testCreateJob() throws SchedulerException {
    IPentahoSession testSession = new StandaloneSession("TEST_USER");
    TestEmbeddedVersionCheckSystemListener listener = new TestEmbeddedVersionCheckSystemListener();
    // First setup like defaults
    listener.setDisableVersionCheck(false);
    listener.setRequestedReleases("Minor, GA");
    listener.setRepeatIntervalSeconds(86400);
    Assert.assertFalse(listener.isDisableVersionCheck());
    Assert.assertEquals("Minor, GA", listener.getRequestedReleases());
    Assert.assertEquals(86400, listener.getRepeatIntervalSeconds());
    listener.setRepeatIntervalSeconds(200);
    // makes sure that min isn't ignored
    Assert.assertEquals(43200, listener.calculateRepeatSeconds());
    // Expect 0 because Minor <> minor and GA <> ga
    Assert.assertEquals(0, listener.calculateRequestFlags());
    listener.setRequestedReleases("minor, ga");
    // should be 8 + 32 = 40
    Assert.assertEquals(40, listener.calculateRequestFlags());
    // Fake availability of version checker.
    listener.setFakeAvail();
    listener.startup(testSession);
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    IJobFilter filter = new IJobFilter() {

        public boolean accept(Job job) {
            return job.getJobName().contains("PentahoSystemVersionCheck");
        }
    };
    List<Job> matchingJobs = scheduler.getJobs(filter);
    Assert.assertEquals(1, matchingJobs.size());
    Job aJob = matchingJobs.get(0);
    Assert.assertTrue(aJob.getJobName().startsWith("PentahoSystemVersionCheck"));
    Assert.assertEquals(TEST_USER, aJob.getUserName());
    Map<String, Serializable> vcJobParms = aJob.getJobParams();
    Assert.assertTrue(vcJobParms.size() > 0);
    Assert.assertTrue(vcJobParms.containsKey(VersionCheckerAction.VERSION_REQUEST_FLAGS));
    Object val = vcJobParms.get(VersionCheckerAction.VERSION_REQUEST_FLAGS);
    Assert.assertNotNull(val);
    Assert.assertTrue(val instanceof Integer);
    Integer intVal = (Integer) val;
    Assert.assertEquals(40, intVal.intValue());
    listener.deleteJobIfNecessary();
    // Should have no jobs now
    matchingJobs = scheduler.getJobs(null);
    Assert.assertEquals(0, matchingJobs.size());
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Serializable(java.io.Serializable) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Job(org.pentaho.platform.api.scheduler2.Job) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) Test(org.junit.Test)

Example 10 with IJobFilter

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

the class JaxWsSchedulerServiceIT method testGetJobs.

@SuppressWarnings("unchecked")
@Test
public void testGetJobs() throws SchedulerException {
    scheduler.pause();
    schedulerSvc.createSimpleJob("testGetJobsJob", generateFullJobParams(), JobTrigger.ONCE_NOW);
    Job[] serviceJobs = schedulerSvc.getJobs();
    // 
    // First make sure the actual scheduler engine can find the newly created job
    // 
    List<Job> engineJobs = scheduler.getJobs(new IJobFilter() {

        public boolean accept(Job job) {
            return job.getJobName().contains("testGetJobsJob");
        }
    });
    Assert.assertEquals("The scheduler engine does not know about the job.", 1, engineJobs.size());
    Job engineJob = engineJobs.get(0);
    // 
    // Now make sure we have the same job available on the webservice client side
    // 
    Assert.assertEquals("The scheduler service does not know about the job.", 1, serviceJobs.length);
    Job serviceJob = schedulerSvc.getJobs()[0];
    Assert.assertEquals("jobName is wrong", engineJob.getJobName(), serviceJob.getJobName());
    Map<String, Serializable> params = serviceJob.getJobParams();
    Assert.assertTrue("string job parameter is wrong", "testStringValue".equals(params.get("stringParam")));
    Assert.assertTrue("list job parameter is missing", params.containsKey("listParam"));
    Assert.assertTrue("map job parameter is missing", params.containsKey("mapParam"));
    Assert.assertTrue("list job parameter is wrong type. Expected List but is " + params.get("listParam").getClass().getName(), params.get("listParam") instanceof List);
    Assert.assertTrue("map job parameter is wrong type. Expected Map but is " + params.get("mapParam").getClass().getName(), params.get("mapParam") instanceof Map);
    List<String> listParam = (List<String>) params.get("listParam");
    Assert.assertTrue("list job parameter has wrong value", "testListVal0".equals(listParam.get(0)));
    Assert.assertTrue("list job parameter has wrong value", "testListVal1".equals(listParam.get(1)));
    Map<String, String> mapParam = (Map<String, String>) params.get("mapParam");
    Assert.assertTrue("map job parameter has wrong value", "testMapVal0".equals(mapParam.get("testMapKey0")));
    Assert.assertTrue("map job parameter has wrong value", "testMapVal1".equals(mapParam.get("testMapKey1")));
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Serializable(java.io.Serializable) List(java.util.List) Job(org.pentaho.platform.api.scheduler2.Job) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)12 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)11 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 Serializable (java.io.Serializable)3 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)3 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)3 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)3 Date (java.util.Date)2 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)2 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CronTrigger (org.quartz.CronTrigger)2 SimpleTrigger (org.quartz.SimpleTrigger)2 Trigger (org.quartz.Trigger)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)1