InstrumentedExecutorService implements ExecutorService { @Override public Future<?> submit(Runnable runnable) { submitted.mark(); try { return delegate.submit(new InstrumentedRunnable(runnable)); } catch (RejectedExecutionException e) { rejected.mark(); throw e; } } InstrumentedExecutorService(ExecutorService delegate, MetricRegistry registry);  InstrumentedExecutorService(ExecutorService delegate, MetricRegistry registry, String name); @Override void execute(Runnable runnable); @Override Future<?> submit(Runnable runnable); @Override Future<T> submit(Runnable runnable, T result); @Override Future<T> submit(Callable<T> 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 shutdown(); @Override List<Runnable> shutdownNow(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override boolean awaitTermination(long l, TimeUnit timeUnit);  }
@Test public void reportsTasksInformation() throws Exception { final Meter submitted = registry.meter("xs.submitted"); final Counter running = registry.counter("xs.running"); final Meter completed = registry.meter("xs.completed"); final Timer duration = registry.timer("xs.duration"); assertThat(submitted.getCount()).isEqualTo(0); assertThat(running.getCount()).isEqualTo(0); assertThat(completed.getCount()).isEqualTo(0); assertThat(duration.getCount()).isEqualTo(0); Future<?> theFuture = instrumentedExecutorService.submit(new Runnable() { public void run() { assertThat(submitted.getCount()).isEqualTo(1); assertThat(running.getCount()).isEqualTo(1); assertThat(completed.getCount()).isEqualTo(0); assertThat(duration.getCount()).isEqualTo(0); } }); theFuture.get(); assertThat(submitted.getCount()).isEqualTo(1); assertThat(running.getCount()).isEqualTo(0); assertThat(completed.getCount()).isEqualTo(1); assertThat(duration.getCount()).isEqualTo(1); assertThat(duration.getSnapshot().size()).isEqualTo(1); }