use of reactor.core.scheduler.SchedulerMetricDecorator.TAG_SCHEDULER_ID in project reactor-core by reactor.
the class SchedulersMetricsTest method shouldReportExecutionTimes.
@ParameterizedTestWithName
@MethodSource("metricsSchedulers")
@Timeout(10)
void shouldReportExecutionTimes(Supplier<Scheduler> schedulerType) {
Scheduler scheduler = afterTest.autoDispose(schedulerType.get());
final int taskCount = 3;
Phaser phaser = new Phaser(1);
for (int i = 1; i <= taskCount; i++) {
phaser.register();
// bumped delay from 20ms to make actual scheduling times more precise
int delay = i * 200;
scheduler.schedule(() -> {
try {
Thread.sleep(delay);
phaser.arriveAndDeregister();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}
phaser.arriveAndAwaitAdvance();
Collection<Timer> timers = registry.find("executor").tag(TAG_SCHEDULER_ID, scheduler.toString()).timers();
// Use Awaitility because "count" is reported "eventually"
await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
assertThat(timers.stream().reduce(0d, (time, timer) -> time + timer.totalTime(TimeUnit.MILLISECONDS), Double::sum)).as("total durations").isEqualTo(600 + 400 + 200, offset(50d));
assertThat(timers.stream().mapToLong(Timer::count).sum()).as("count").isEqualTo(taskCount);
});
}
Aggregations