QuartzPendingJobsReportingTask { @Scheduled(fixedRateString = "${l10n.management.metrics.quartz.sql-queue-monitoring.execution-rate}") public void reportPendingJobs() { Map<String, PendingJob> results = fetchResults(); updateQueueSizes(results); results.forEach(this::registerJobQueueSize); } QuartzPendingJobsReportingTask(@Autowired DataSource dataSource,
                                          @Autowired MeterRegistry meterRegistry); @Scheduled(fixedRateString = "${l10n.management.metrics.quartz.sql-queue-monitoring.execution-rate}") void reportPendingJobs();  }
@Test public void testGaugesCountPendingJobsForNonDynamicGroup() throws Exception { JobDetail job; TriggerBuilder<Trigger> builder; job = newJob(Test1Job.class).withIdentity(testIdWatcher.getEntityName("Test1Job"), MY_GROUP).build(); builder = TriggerBuilder.newTrigger() .forJob(job) .startAt(Date.from(ZonedDateTime.now().plusMinutes(5).toInstant())); scheduler.scheduleJob(job, builder.build()); job = newJob(Test2Job.class).withIdentity(testIdWatcher.getEntityName("Test2Job"), MY_GROUP).build(); builder = TriggerBuilder.newTrigger() .forJob(job) .startAt(Date.from(ZonedDateTime.now().plusMinutes(5).toInstant())); scheduler.scheduleJob(job, builder.build()); task.reportPendingJobs(); RequiredSearch search1 = meterRegistry.get("quartz.pending.jobs") .tag("jobGroup", MY_GROUP) .tag("jobClass", "QuartzPendingJobsReportingTaskTest$Test1Job"); RequiredSearch search2 = meterRegistry.get("quartz.pending.jobs") .tag("jobGroup", MY_GROUP) .tag("jobClass", "QuartzPendingJobsReportingTaskTest$Test2Job"); await.untilAsserted(() -> assertThat(search1.gauge().value()).isEqualTo(1)); await.untilAsserted(() -> assertThat(search2.gauge().value()).isEqualTo(1)); }
@Test public void testGaugesCountPendingJobsForDynamicGroup() throws Exception { JobDetail job; TriggerBuilder<Trigger> builder; for (int i = 1; i <= 5; i++) { job = newJob(Test1Job.class).withIdentity(testIdWatcher.getEntityName("Test1Job_" + i), DYNAMIC_GROUP_NAME) .build(); builder = TriggerBuilder.newTrigger() .forJob(job) .startAt(Date.from(ZonedDateTime.now().plusHours(i).toInstant())); scheduler.scheduleJob(job, builder.build()); job = newJob(EmptyTestJob.class).withIdentity(testIdWatcher.getEntityName("EmptyJob_" + i), DYNAMIC_GROUP_NAME) .build(); builder = TriggerBuilder.newTrigger() .forJob(job) .startAt(Date.from(ZonedDateTime.now().plusHours(i).toInstant())); scheduler.scheduleJob(job, builder.build()); } task.reportPendingJobs(); RequiredSearch test1Gauges = meterRegistry.get("quartz.pending.jobs") .tag("jobClass", "QuartzPendingJobsReportingTaskTest$Test1Job") .tag("jobGroup", DYNAMIC_GROUP_NAME); RequiredSearch test2Gauges = meterRegistry.get("quartz.pending.jobs") .tag("jobClass", "EmptyTestJob") .tag("jobGroup", DYNAMIC_GROUP_NAME); await.untilAsserted(() -> assertThat(test1Gauges.gauges()).isNotEmpty()); await.untilAsserted(() -> assertThat(test2Gauges.gauges()).isNotEmpty()); assertThat(test1Gauges.gauge().value()).isEqualTo(5); assertThat(test2Gauges.gauge().value()).isEqualTo(5); for (int i = 6; i <= 9; i++) { job = newJob(Test1Job.class).withIdentity(testIdWatcher.getEntityName("Test1Job_" + i), DYNAMIC_GROUP_NAME) .build(); builder = TriggerBuilder.newTrigger() .forJob(job) .startAt(Date.from(ZonedDateTime.now().plusHours(i).toInstant())); scheduler.scheduleJob(job, builder.build()); job = newJob(EmptyTestJob.class).withIdentity(testIdWatcher.getEntityName("EmptyJob_" + i), DYNAMIC_GROUP_NAME) .build(); builder = TriggerBuilder.newTrigger() .forJob(job) .startAt(Date.from(ZonedDateTime.now().plusHours(i).toInstant())); scheduler.scheduleJob(job, builder.build()); } task.reportPendingJobs(); assertThat(test1Gauges.gauge().value()).isEqualTo(9); assertThat(test2Gauges.gauge().value()).isEqualTo(9); for (int i = 11; i <= 21; i++) { job = newJob(Test1Job.class).withIdentity(testIdWatcher.getEntityName("Test1Job_" + i), DYNAMIC_GROUP_NAME) .build(); builder = TriggerBuilder.newTrigger() .forJob(job) .startAt(Date.from(ZonedDateTime.now().plusHours(i).toInstant())); scheduler.scheduleJob(job, builder.build()); } task.reportPendingJobs(); assertThat(test1Gauges.gauge().value()).isEqualTo(20); assertThat(test2Gauges.gauge().value()).isEqualTo(9); scheduler.clear(); for (int i = 1; i <= 5; i++) { job = newJob(EmptyTestJob.class).withIdentity(testIdWatcher.getEntityName("EmptyJob_" + i), DYNAMIC_GROUP_NAME) .build(); builder = TriggerBuilder.newTrigger() .forJob(job) .startAt(Date.from(ZonedDateTime.now().plusHours(i).toInstant())); scheduler.scheduleJob(job, builder.build()); } task.reportPendingJobs(); assertThat(test1Gauges.gauge().value()).isEqualTo(0); assertThat(test2Gauges.gauge().value()).isEqualTo(5); }