Search in sources :

Example 1 with Job

use of org.apache.sling.commons.scheduler.Job in project sling by apache.

the class QuartzJobExecutorTest method testJobExecutedWithTwoRunOnParams.

@Test
public void testJobExecutedWithTwoRunOnParams() throws SchedulerException {
    Job job = new SimpleJob();
    String jobName = "testName";
    Map<String, Serializable> jobConfig = new HashMap<String, Serializable>();
    //Adding a job just to receive a JobDetail object which is needed for testing
    quartzScheduler.addJob(1L, 1L, jobName, job, jobConfig, "0 * * * * ?", true);
    JobDetail jobDetail = quartzScheduler.getSchedulers().get("testName").getScheduler().getJobDetail(JobKey.jobKey(jobName));
    when(executionContext.getJobDetail()).thenReturn(jobDetail);
    //Job with this config should not be executed
    jobDetail.getJobDataMap().put(QuartzScheduler.DATA_MAP_RUN_ON, new String[] { VALUE_RUN_ON_LEADER, VALUE_RUN_ON_SINGLE });
    //In this case, when SLING_ID is equal to one of values above
    //Job should be executed
    QuartzJobExecutor.SLING_ID = VALUE_RUN_ON_SINGLE;
    isRunnablePseudoJobCompleted = false;
    jobExecutor.execute(executionContext);
    assertTrue(isRunnablePseudoJobCompleted);
}
Also used : Serializable(java.io.Serializable) JobDetail(org.quartz.JobDetail) HashMap(java.util.HashMap) Job(org.apache.sling.commons.scheduler.Job) Test(org.junit.Test)

Example 2 with Job

use of org.apache.sling.commons.scheduler.Job in project sling by apache.

the class QuartzJobExecutorTest method testJobNotExecuted.

@Test
public void testJobNotExecuted() throws SchedulerException {
    Job job = new SimpleJob();
    String jobName = "testName";
    Map<String, Serializable> jobConfig = new HashMap<String, Serializable>();
    //Adding a job just to receive a JobDetail object which is needed for testing
    quartzScheduler.addJob(1L, 1L, jobName, job, jobConfig, "0 * * * * ?", true);
    JobDetail jobDetail = quartzScheduler.getSchedulers().get("testName").getScheduler().getJobDetail(JobKey.jobKey(jobName));
    when(executionContext.getJobDetail()).thenReturn(jobDetail);
    //Job with this config should not be executed
    jobDetail.getJobDataMap().put(QuartzScheduler.DATA_MAP_RUN_ON, new String[] { VALUE_RUN_ON_LEADER });
    isRunnablePseudoJobCompleted = false;
    jobExecutor.execute(executionContext);
    assertFalse(isRunnablePseudoJobCompleted);
}
Also used : Serializable(java.io.Serializable) JobDetail(org.quartz.JobDetail) HashMap(java.util.HashMap) Job(org.apache.sling.commons.scheduler.Job) Test(org.junit.Test)

Example 3 with Job

use of org.apache.sling.commons.scheduler.Job in project sling by apache.

the class QuartzJobExecutorTest method testJob.

@Test
public void testJob() throws SchedulerException {
    Job job = new SimpleJob();
    String jobName = "testName";
    Map<String, Serializable> jobConfig = new HashMap<String, Serializable>();
    //Adding a job just to receive a JobDetail object which is needed for testing
    quartzScheduler.addJob(1L, 1L, jobName, job, jobConfig, "0 * * * * ?", true);
    JobDetail jobDetail = quartzScheduler.getSchedulers().get("testName").getScheduler().getJobDetail(JobKey.jobKey(jobName));
    when(executionContext.getJobDetail()).thenReturn(jobDetail);
    isRunnablePseudoJobCompleted = false;
    jobExecutor.execute(executionContext);
    assertTrue(isRunnablePseudoJobCompleted);
}
Also used : Serializable(java.io.Serializable) JobDetail(org.quartz.JobDetail) HashMap(java.util.HashMap) Job(org.apache.sling.commons.scheduler.Job) Test(org.junit.Test)

Example 4 with Job

use of org.apache.sling.commons.scheduler.Job in project sling by apache.

the class QuartzJobExecutorTest method testJobNotExecutedWithTwoRunOnParams.

@Test
public void testJobNotExecutedWithTwoRunOnParams() throws SchedulerException {
    Job job = new SimpleJob();
    String jobName = "testName";
    Map<String, Serializable> jobConfig = new HashMap<String, Serializable>();
    //Adding a job just to receive a JobDetail object which is needed for testing
    quartzScheduler.addJob(1L, 1L, jobName, job, jobConfig, "0 * * * * ?", true);
    JobDetail jobDetail = quartzScheduler.getSchedulers().get("testName").getScheduler().getJobDetail(JobKey.jobKey(jobName));
    when(executionContext.getJobDetail()).thenReturn(jobDetail);
    //Job with this config should not be executed
    jobDetail.getJobDataMap().put(QuartzScheduler.DATA_MAP_RUN_ON, new String[] { VALUE_RUN_ON_LEADER, VALUE_RUN_ON_SINGLE });
    QuartzJobExecutor.SLING_ID = "ANY STRING NOT EQUAL TO OF VALUE_RUN_ON_LEADER OR" + "VALUE_RUN_ON_SINGLE JUST A TEST CASE, NOTHING MORE";
    isRunnablePseudoJobCompleted = false;
    jobExecutor.execute(executionContext);
    assertFalse(isRunnablePseudoJobCompleted);
}
Also used : Serializable(java.io.Serializable) JobDetail(org.quartz.JobDetail) HashMap(java.util.HashMap) Job(org.apache.sling.commons.scheduler.Job) Test(org.junit.Test)

Aggregations

Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 Job (org.apache.sling.commons.scheduler.Job)4 Test (org.junit.Test)4 JobDetail (org.quartz.JobDetail)4