InstrumentedScheduledExecutorService implements ScheduledExecutorService { @Override public ScheduledFuture<?> scheduleWithFixedDelay( Runnable command, long initialDelay, long delay, TimeUnit unit ) { scheduledRepetitively.mark(); return delegate.scheduleWithFixedDelay(new InstrumentedRunnable(command), initialDelay, delay, unit); } InstrumentedScheduledExecutorService(
        ScheduledExecutorService delegate, SemanticMetricRegistry registry
    );  InstrumentedScheduledExecutorService(
        ScheduledExecutorService delegate, SemanticMetricRegistry registry, MetricId baseMetricId
    ); @Override ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); @Override ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); @Override ScheduledFuture<?> scheduleAtFixedRate(
        Runnable command, long initialDelay, long period, TimeUnit unit
    ); @Override ScheduledFuture<?> scheduleWithFixedDelay(
        Runnable command, long initialDelay, long delay, TimeUnit unit
    ); @Override void shutdown(); @Override List<Runnable> shutdownNow(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override Future<T> submit(Callable<T> task); @Override Future<T> submit(Runnable task, T result); @Override Future<?> submit(Runnable task); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks); @Override List<Future<T>> invokeAll(
        Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit
    ); @Override T invokeAny(Collection<? extends Callable<T>> tasks); @Override T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit); @Override void execute(Runnable command);  }
@Test public void testScheduleFixedDelayRunnable() throws Exception { assertEquals(0, submitted.getCount()); assertEquals(0, running.getCount()); assertEquals(0, completed.getCount()); assertEquals(0, duration.getCount()); assertEquals(0, scheduledOnce.getCount()); assertEquals(0, scheduledRepetitively.getCount()); assertEquals(0, scheduledOverrun.getCount()); assertEquals(0, percentOfPeriod.getCount()); ScheduledFuture<?> theFuture = instrumentedScheduledExecutor.scheduleWithFixedDelay(new Runnable() { @Override public void run() { assertEquals(0, submitted.getCount()); assertEquals(1, running.getCount()); assertEquals(0, scheduledOnce.getCount()); assertEquals(1, scheduledRepetitively.getCount()); try { TimeUnit.MILLISECONDS.sleep(50); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } }, 10L, 10L, TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS.sleep(100); theFuture.cancel(true); TimeUnit.MILLISECONDS.sleep(100); assertEquals(0, submitted.getCount()); assertEquals(0, running.getCount()); assertNotEquals(0, completed.getCount()); assertNotEquals(0, duration.getCount()); assertNotEquals(0, duration.getSnapshot().size()); }