@Test void runHooksShouldPublishTimerMetrics() { Duration sleepDuration = Duration.ofSeconds(1); Mono<Void> notifyDeleteAnswer = Mono.fromCallable(() -> { Thread.sleep(sleepDuration.toMillis()); return Mono.empty(); }).then(); when(hook1.notifyDelete(any())).thenReturn(notifyDeleteAnswer); when(hook2.notifyDelete(any())).thenReturn(notifyDeleteAnswer); testee.runHooks(DELETE_OPERATION).block(); assertThat(metricFactory.executionTimesFor(PRE_DELETION_HOOK_METRIC_NAME)) .hasSize(2) .allSatisfy(duration -> assertThat(duration).isGreaterThanOrEqualTo(sleepDuration)); }
public Mono<Void> runHooks(PreDeletionHook.DeleteOperation deleteOperation) { return Flux.fromIterable(hooks) .publishOn(Schedulers.elastic()) .flatMap(hook -> metricFactory.map(factory -> publishMetric(deleteOperation, hook, factory)) .orElse(Mono.empty()), CONCURRENCY) .then(); }
PreDeletionHooks { public Mono<Void> runHooks(PreDeletionHook.DeleteOperation deleteOperation) { return Flux.fromIterable(hooks) .publishOn(Schedulers.elastic()) .flatMap(hook -> metricFactory.map(factory -> publishMetric(deleteOperation, hook, factory)) .orElse(Mono.empty()), CONCURRENCY) .then(); } }
PreDeletionHooks { public Mono<Void> runHooks(PreDeletionHook.DeleteOperation deleteOperation) { return Flux.fromIterable(hooks) .publishOn(Schedulers.elastic()) .flatMap(hook -> metricFactory.map(factory -> publishMetric(deleteOperation, hook, factory)) .orElse(Mono.empty()), CONCURRENCY) .then(); } @Inject  PreDeletionHooks(Set<PreDeletionHook> hooks, MetricFactory metricFactory); private  PreDeletionHooks(Set<PreDeletionHook> hooks, Optional<MetricFactory> metricFactory); }
PreDeletionHooks { public Mono<Void> runHooks(PreDeletionHook.DeleteOperation deleteOperation) { return Flux.fromIterable(hooks) .publishOn(Schedulers.elastic()) .flatMap(hook -> metricFactory.map(factory -> publishMetric(deleteOperation, hook, factory)) .orElse(Mono.empty()), CONCURRENCY) .then(); } @Inject  PreDeletionHooks(Set<PreDeletionHook> hooks, MetricFactory metricFactory); private  PreDeletionHooks(Set<PreDeletionHook> hooks, Optional<MetricFactory> metricFactory); Mono<Void> runHooks(PreDeletionHook.DeleteOperation deleteOperation); }
PreDeletionHooks { public Mono<Void> runHooks(PreDeletionHook.DeleteOperation deleteOperation) { return Flux.fromIterable(hooks) .publishOn(Schedulers.elastic()) .flatMap(hook -> metricFactory.map(factory -> publishMetric(deleteOperation, hook, factory)) .orElse(Mono.empty()), CONCURRENCY) .then(); } @Inject  PreDeletionHooks(Set<PreDeletionHook> hooks, MetricFactory metricFactory); private  PreDeletionHooks(Set<PreDeletionHook> hooks, Optional<MetricFactory> metricFactory); Mono<Void> runHooks(PreDeletionHook.DeleteOperation deleteOperation); static final PreDeletionHooks NO_PRE_DELETION_HOOK; }