Search in sources :

Example 6 with QuartzJobDetails

use of org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzJobOrdersTriggersAccordingToNextFireTime.

@Test
void quartzJobOrdersTriggersAccordingToNextFireTime() throws SchedulerException {
    JobDetail job = JobBuilder.newJob(Job.class).withIdentity("hello", "samples").build();
    mockJobs(job);
    Date triggerOneNextFireTime = Date.from(Instant.parse("2020-12-01T03:00:00Z"));
    CronTrigger triggerOne = TriggerBuilder.newTrigger().withIdentity("one", "samples").withPriority(5).withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(3, 0)).build();
    ((OperableTrigger) triggerOne).setNextFireTime(triggerOneNextFireTime);
    Date triggerTwoNextFireTime = Date.from(Instant.parse("2020-12-01T02:00:00Z"));
    CronTrigger triggerTwo = TriggerBuilder.newTrigger().withIdentity("two", "samples").withPriority(10).withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(2, 0)).build();
    ((OperableTrigger) triggerTwo).setNextFireTime(triggerTwoNextFireTime);
    mockTriggers(triggerOne, triggerTwo);
    given(this.scheduler.getTriggersOfJob(JobKey.jobKey("hello", "samples"))).willAnswer((invocation) -> Arrays.asList(triggerOne, triggerTwo));
    QuartzJobDetails jobDetails = this.endpoint.quartzJob("samples", "hello");
    assertThat(jobDetails.getTriggers()).hasSize(2);
    assertThat(jobDetails.getTriggers().get(0)).containsEntry("name", "two");
    assertThat(jobDetails.getTriggers().get(1)).containsEntry("name", "one");
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) QuartzJobDetails(org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 JobDetail (org.quartz.JobDetail)6 QuartzJobDetails (org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails)6 Date (java.util.Date)3 CronTrigger (org.quartz.CronTrigger)3 OperableTrigger (org.quartz.spi.OperableTrigger)3 Job (org.quartz.Job)2 DelegatingJob (org.springframework.scheduling.quartz.DelegatingJob)2 TimeZone (java.util.TimeZone)1 CalendarIntervalTrigger (org.quartz.CalendarIntervalTrigger)1 DailyTimeIntervalTrigger (org.quartz.DailyTimeIntervalTrigger)1 SimpleTrigger (org.quartz.SimpleTrigger)1 Trigger (org.quartz.Trigger)1 Sanitizer (org.springframework.boot.actuate.endpoint.Sanitizer)1