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