use of org.quartz.DailyTimeIntervalTrigger in project spring-boot by spring-projects.
the class QuartzEndpointTests method quartzTriggerWithDailyTimeIntervalTrigger.
@Test
void quartzTriggerWithDailyTimeIntervalTrigger() throws SchedulerException {
Date previousFireTime = Date.from(Instant.parse("2020-11-30T03:00:00Z"));
Date nextFireTime = Date.from(Instant.parse("2020-12-01T03:00:00Z"));
DailyTimeIntervalTrigger trigger = TriggerBuilder.newTrigger().withIdentity("every-hour-mon-wed", "samples").withDescription("Every working hour Mon Wed").withPriority(4).withSchedule(DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule().onDaysOfTheWeek(Calendar.MONDAY, Calendar.WEDNESDAY).startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 0)).endingDailyAt(TimeOfDay.hourAndMinuteOfDay(18, 0)).withInterval(1, IntervalUnit.HOUR)).build();
((OperableTrigger) trigger).setPreviousFireTime(previousFireTime);
((OperableTrigger) trigger).setNextFireTime(nextFireTime);
mockTriggers(trigger);
given(this.scheduler.getTriggerState(TriggerKey.triggerKey("every-hour-mon-wed", "samples"))).willReturn(TriggerState.NORMAL);
Map<String, Object> triggerDetails = this.endpoint.quartzTrigger("samples", "every-hour-mon-wed");
assertThat(triggerDetails).contains(entry("group", "samples"), entry("name", "every-hour-mon-wed"), entry("description", "Every working hour Mon Wed"), entry("type", "dailyTimeInterval"), entry("state", TriggerState.NORMAL), entry("priority", 4));
assertThat(triggerDetails).contains(entry("previousFireTime", previousFireTime), entry("nextFireTime", nextFireTime));
assertThat(triggerDetails).doesNotContainKeys("cron", "simple", "calendarInterval", "custom");
assertThat(triggerDetails).extractingByKey("dailyTimeInterval", nestedMap()).containsOnly(entry("interval", 3600000L), entry("startTimeOfDay", LocalTime.of(9, 0)), entry("endTimeOfDay", LocalTime.of(18, 0)), entry("daysOfWeek", new LinkedHashSet<>(Arrays.asList(2, 4))), entry("repeatCount", -1), entry("timesTriggered", 0));
}
use of org.quartz.DailyTimeIntervalTrigger in project spring-boot by spring-projects.
the class QuartzEndpointTests method quartzTriggerGroupSummaryWithDailyIntervalTrigger.
@Test
void quartzTriggerGroupSummaryWithDailyIntervalTrigger() throws SchedulerException {
DailyTimeIntervalTrigger trigger = TriggerBuilder.newTrigger().withIdentity("every-hour-9am", "samples").withSchedule(DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule().startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 0)).withInterval(1, IntervalUnit.HOUR)).build();
mockTriggers(trigger);
QuartzTriggerGroupSummary summary = this.endpoint.quartzTriggerGroupSummary("samples");
assertThat(summary.getGroup()).isEqualTo("samples");
assertThat(summary.isPaused()).isFalse();
assertThat(summary.getTriggers().getCron()).isEmpty();
assertThat(summary.getTriggers().getSimple()).isEmpty();
assertThat(summary.getTriggers().getDailyTimeInterval()).containsOnlyKeys("every-hour-9am");
assertThat(summary.getTriggers().getCalendarInterval()).isEmpty();
assertThat(summary.getTriggers().getCustom()).isEmpty();
}
use of org.quartz.DailyTimeIntervalTrigger in project spring-boot by spring-projects.
the class QuartzEndpointTests method quartzTriggerGroupSummaryWithDailyIntervalTriggerDetails.
@Test
void quartzTriggerGroupSummaryWithDailyIntervalTriggerDetails() throws SchedulerException {
Date previousFireTime = Date.from(Instant.parse("2020-11-30T03:00:00Z"));
Date nextFireTime = Date.from(Instant.parse("2020-12-01T03:00:00Z"));
DailyTimeIntervalTrigger trigger = TriggerBuilder.newTrigger().withIdentity("every-hour-tue-thu", "samples").withPriority(4).withSchedule(DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule().onDaysOfTheWeek(Calendar.TUESDAY, Calendar.THURSDAY).startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 0)).endingDailyAt(TimeOfDay.hourAndMinuteOfDay(18, 0)).withInterval(1, IntervalUnit.HOUR)).build();
((OperableTrigger) trigger).setPreviousFireTime(previousFireTime);
((OperableTrigger) trigger).setNextFireTime(nextFireTime);
mockTriggers(trigger);
QuartzTriggerGroupSummary summary = this.endpoint.quartzTriggerGroupSummary("samples");
Map<String, Object> triggers = summary.getTriggers().getDailyTimeInterval();
assertThat(triggers).containsOnlyKeys("every-hour-tue-thu");
assertThat(triggers).extractingByKey("every-hour-tue-thu", nestedMap()).containsOnly(entry("previousFireTime", previousFireTime), entry("nextFireTime", nextFireTime), entry("priority", 4), entry("interval", 3600000L), entry("startTimeOfDay", LocalTime.of(9, 0)), entry("endTimeOfDay", LocalTime.of(18, 0)), entry("daysOfWeek", new LinkedHashSet<>(Arrays.asList(3, 5))));
}
use of org.quartz.DailyTimeIntervalTrigger in project spring-boot by spring-projects.
the class QuartzEndpointDocumentationTests method quartzTriggerGroup.
@Test
void quartzTriggerGroup() throws Exception {
CronTrigger cron = cronTrigger.getTriggerBuilder().startAt(fromUtc("2020-11-30T17:00:00Z")).endAt(fromUtc("2020-12-30T03:00:00Z")).withIdentity("3am-week", "tests").build();
setPreviousNextFireTime(cron, "2020-12-04T03:00:00Z", "2020-12-07T03:00:00Z");
SimpleTrigger simple = simpleTrigger.getTriggerBuilder().withIdentity("every-day", "tests").build();
setPreviousNextFireTime(simple, null, "2020-12-04T12:00:00Z");
CalendarIntervalTrigger calendarInterval = calendarIntervalTrigger.getTriggerBuilder().withIdentity("once-a-week", "tests").startAt(fromUtc("2019-07-10T14:00:00Z")).endAt(fromUtc("2023-01-01T12:00:00Z")).build();
setPreviousNextFireTime(calendarInterval, "2020-12-02T14:00:00Z", "2020-12-08T14:00:00Z");
DailyTimeIntervalTrigger tueThuTrigger = dailyTimeIntervalTrigger.getTriggerBuilder().withIdentity("tue-thu", "tests").build();
Trigger customTrigger = mock(Trigger.class);
given(customTrigger.getKey()).willReturn(TriggerKey.triggerKey("once-a-year-custom", "tests"));
given(customTrigger.toString()).willReturn("com.example.CustomTrigger@fdsfsd");
given(customTrigger.getPriority()).willReturn(10);
given(customTrigger.getPreviousFireTime()).willReturn(fromUtc("2020-07-14T16:00:00Z"));
given(customTrigger.getNextFireTime()).willReturn(fromUtc("2021-07-14T16:00:00Z"));
mockTriggers(cron, simple, calendarInterval, tueThuTrigger, customTrigger);
this.mockMvc.perform(get("/actuator/quartz/triggers/tests")).andExpect(status().isOk()).andDo(document("quartz/trigger-group", responseFields(fieldWithPath("group").description("Name of the group."), fieldWithPath("paused").description("Whether the group is paused."), fieldWithPath("triggers.cron").description("Cron triggers keyed by name, if any."), fieldWithPath("triggers.simple").description("Simple triggers keyed by name, if any."), fieldWithPath("triggers.dailyTimeInterval").description("Daily time interval triggers keyed by name, if any."), fieldWithPath("triggers.calendarInterval").description("Calendar interval triggers keyed by name, if any."), fieldWithPath("triggers.custom").description("Any other triggers keyed by name, if any.")).andWithPrefix("triggers.cron.*.", concat(triggerSummary, cronTriggerSummary)).andWithPrefix("triggers.simple.*.", concat(triggerSummary, simpleTriggerSummary)).andWithPrefix("triggers.dailyTimeInterval.*.", concat(triggerSummary, dailyTimeIntervalTriggerSummary)).andWithPrefix("triggers.calendarInterval.*.", concat(triggerSummary, calendarIntervalTriggerSummary)).andWithPrefix("triggers.custom.*.", concat(triggerSummary, customTriggerSummary))));
}
Aggregations