/** * If {@link #enableMetrics()} has been previously called, removes the decorator. * No-op if {@link #enableMetrics()} hasn't been called. */ public static void disableMetrics() { removeExecutorServiceDecorator(SchedulerMetricDecorator.METRICS_DECORATOR_KEY); }
@Test public void schedulerDecoratorRemovesKnown() { BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator1 = (scheduler, serv) -> serv; BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator2 = (scheduler, serv) -> serv; BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService> decorator3 = (scheduler, serv) -> serv; Schedulers.DECORATORS.put("k1", decorator1); Schedulers.DECORATORS.put("k2", decorator2); Schedulers.DECORATORS.put("k3", decorator3); assertThat(Schedulers.DECORATORS).hasSize(3); assertThat(Schedulers.removeExecutorServiceDecorator("k1")).as("decorator1 when present").isSameAs(decorator1); assertThat(Schedulers.removeExecutorServiceDecorator("k1")).as("decorator1 once removed").isNull(); assertThat(Schedulers.removeExecutorServiceDecorator("k2")).as("decorator2").isSameAs(decorator2); assertThat(Schedulers.removeExecutorServiceDecorator("k3")).as("decorator3").isSameAs(decorator3); assertThat(Schedulers.DECORATORS).isEmpty(); }
@Test public void schedulerDecoratorRemoveUnknownIgnored() { assertThat(Schedulers.removeExecutorServiceDecorator("keyfoo")) .as("unknown decorator ignored") .isNull(); }
@Test public void schedulerDecoratorDisposedWhenRemoved() { AtomicBoolean disposeTracker = new AtomicBoolean(); class DisposableDecorator implements BiFunction<Scheduler, ScheduledExecutorService, ScheduledExecutorService>, Disposable { @Override public ScheduledExecutorService apply(Scheduler scheduler, ScheduledExecutorService service) { return service; } @Override public void dispose() { disposeTracker.set(true); } } DisposableDecorator decorator = new DisposableDecorator(); Schedulers.addExecutorServiceDecorator("k1", decorator); assertThat(Schedulers.removeExecutorServiceDecorator("k1")) .as("decorator removed") .isSameAs(decorator); assertThat(disposeTracker) .as("decorator disposed") .isTrue(); }
/** * If {@link #enableMetrics()} has been previously called, removes the decorator. * No-op if {@link #enableMetrics()} hasn't been called. */ public static void disableMetrics() { removeExecutorServiceDecorator(SchedulerMetricDecorator.METRICS_DECORATOR_KEY); }