Search in sources :

Example 1 with JobKey

use of org.quartz.JobKey in project elastic-job by dangdangdotcom.

the class JobScheduleControllerTest method assertGetNextFireTime.

@SuppressWarnings("unchecked")
@Test
public void assertGetNextFireTime() throws NoSuchFieldException, SchedulerException {
    ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler);
    ReflectionUtils.setFieldValue(jobScheduleController, "jobDetail", jobDetail);
    JobKey jobKey = new JobKey("test_job");
    Trigger trigger1 = mock(Trigger.class);
    Trigger trigger2 = mock(Trigger.class);
    Trigger trigger3 = mock(Trigger.class);
    Trigger trigger4 = mock(Trigger.class);
    @SuppressWarnings("rawtypes") List triggers = Arrays.asList(trigger1, trigger2, trigger3, trigger4);
    when(trigger1.getNextFireTime()).thenReturn(null);
    when(trigger2.getNextFireTime()).thenReturn(new Date(1L));
    when(trigger3.getNextFireTime()).thenReturn(new Date(100L));
    when(trigger4.getNextFireTime()).thenReturn(new Date(0L));
    when(jobDetail.getKey()).thenReturn(jobKey);
    when(scheduler.getTriggersOfJob(jobKey)).thenReturn(triggers);
    assertThat(jobScheduleController.getNextFireTime().getTime(), is(0L));
}
Also used : JobKey(org.quartz.JobKey) Trigger(org.quartz.Trigger) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Example 2 with JobKey

use of org.quartz.JobKey in project elastic-job by dangdangdotcom.

the class JobScheduleControllerTest method assertTriggerJobSuccess.

@Test
public void assertTriggerJobSuccess() throws NoSuchFieldException, SchedulerException {
    JobKey jobKey = new JobKey("test_job");
    when(jobDetail.getKey()).thenReturn(jobKey);
    when(scheduler.isShutdown()).thenReturn(false);
    ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler);
    ReflectionUtils.setFieldValue(jobScheduleController, "jobDetail", jobDetail);
    jobScheduleController.triggerJob();
    verify(jobDetail).getKey();
    verify(scheduler).triggerJob(jobKey);
}
Also used : JobKey(org.quartz.JobKey) Test(org.junit.Test)

Example 3 with JobKey

use of org.quartz.JobKey in project elastic-job by dangdangdotcom.

the class JobScheduleControllerTest method assertGetNextFireTimeWhenSchedulerExceptionOccur.

@Test
public void assertGetNextFireTimeWhenSchedulerExceptionOccur() throws NoSuchFieldException, SchedulerException {
    ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler);
    ReflectionUtils.setFieldValue(jobScheduleController, "jobDetail", jobDetail);
    JobKey jobKey = new JobKey("test_job");
    when(jobDetail.getKey()).thenReturn(jobKey);
    doThrow(SchedulerException.class).when(scheduler).getTriggersOfJob(jobKey);
    assertNull(jobScheduleController.getNextFireTime());
}
Also used : JobKey(org.quartz.JobKey) Test(org.junit.Test)

Example 4 with JobKey

use of org.quartz.JobKey in project elastic-job by dangdangdotcom.

the class TransientProducerRepository method remove.

synchronized void remove(final String jobName) {
    for (Entry<JobKey, List<String>> each : cronTasks.entrySet()) {
        JobKey jobKey = each.getKey();
        List<String> jobNames = each.getValue();
        jobNames.remove(jobName);
        if (jobNames.isEmpty()) {
            cronTasks.remove(jobKey);
        }
    }
}
Also used : JobKey(org.quartz.JobKey) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 5 with JobKey

use of org.quartz.JobKey in project elastic-job by dangdangdotcom.

the class TransientProducerRepositoryTest method assertPutMoreJobWithChangedCron.

@Test
public void assertPutMoreJobWithChangedCron() throws JobExecutionException {
    String jobName2 = "other_test_job";
    transientProducerRepository.put(jobKey, jobName);
    transientProducerRepository.put(jobKey, jobName2);
    JobKey newJobKey = JobKey.jobKey("0/15 * * * * ?");
    transientProducerRepository.put(newJobKey, jobName);
    assertThat(transientProducerRepository.get(jobKey).get(0), is(jobName2));
    assertThat(transientProducerRepository.get(newJobKey).get(0), is(jobName));
    transientProducerRepository.remove(jobName);
    transientProducerRepository.remove(jobName2);
}
Also used : JobKey(org.quartz.JobKey) Test(org.junit.Test)

Aggregations

JobKey (org.quartz.JobKey)65 SchedulerException (org.quartz.SchedulerException)33 JobDetail (org.quartz.JobDetail)22 Trigger (org.quartz.Trigger)19 Scheduler (org.quartz.Scheduler)17 TriggerKey (org.quartz.TriggerKey)15 Test (org.junit.Test)13 List (java.util.List)6 CronTrigger (org.quartz.CronTrigger)6 JobDataMap (org.quartz.JobDataMap)6 ArrayList (java.util.ArrayList)5 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 Hashtable (java.util.Hashtable)2 Scheduled (org.apache.deltaspike.scheduler.api.Scheduled)2 CronScheduleBuilder (org.quartz.CronScheduleBuilder)2