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);
}
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);
}
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);
}
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);
}
Aggregations