@Override
    public Future<?> submit(Runnable runnable) {
        submitted.mark();
        return delegate.submit(new InstrumentedRunnable(runnable));
    }
@Test
    @SuppressWarnings("unchecked")
    public void reportsTasksInformationForThreadPoolExecutor() throws Exception {
        executor = new ThreadPoolExecutor(4, 16,
                0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(32));
        instrumentedExecutorService = new InstrumentedExecutorService(executor, registry, "tp");
        submitted = registry.meter("tp.submitted");
        running = registry.counter("tp.running");
        completed = registry.meter("tp.completed");
        duration = registry.timer("tp.duration");
        idle = registry.timer("tp.idle");
        final Gauge<Integer> poolSize = (Gauge<Integer>) registry.getGauges().get("tp.pool.size");
        final Gauge<Integer> poolCoreSize = (Gauge<Integer>) registry.getGauges().get("tp.pool.core");
        final Gauge<Integer> poolMaxSize = (Gauge<Integer>) registry.getGauges().get("tp.pool.max");
        final Gauge<Integer> tasksActive = (Gauge<Integer>) registry.getGauges().get("tp.tasks.active");
        final Gauge<Long> tasksCompleted = (Gauge<Long>) registry.getGauges().get("tp.tasks.completed");
        final Gauge<Integer> tasksQueued = (Gauge<Integer>) registry.getGauges().get("tp.tasks.queued");
        final Gauge<Integer> tasksCapacityRemaining = (Gauge<Integer>) registry.getGauges().get("tp.tasks.capacity");

        assertThat(submitted.getCount()).isEqualTo(0);
        assertThat(running.getCount()).isEqualTo(0);
        assertThat(completed.getCount()).isEqualTo(0);
        assertThat(duration.getCount()).isEqualTo(0);
        assertThat(idle.getCount()).isEqualTo(0);
        assertThat(poolSize.getValue()).isEqualTo(0);
        assertThat(poolCoreSize.getValue()).isEqualTo(4);
        assertThat(poolMaxSize.getValue()).isEqualTo(16);
        assertThat(tasksActive.getValue()).isEqualTo(0);
        assertThat(tasksCompleted.getValue()).isEqualTo(0L);
        assertThat(tasksQueued.getValue()).isEqualTo(0);
        assertThat(tasksCapacityRemaining.getValue()).isEqualTo(32);

        Runnable runnable = () -> {
            assertThat(submitted.getCount()).isEqualTo(1);
            assertThat(running.getCount()).isEqualTo(1);
            assertThat(completed.getCount()).isEqualTo(0);
            assertThat(duration.getCount()).isEqualTo(0);
            assertThat(idle.getCount()).isEqualTo(1);
            assertThat(tasksActive.getValue()).isEqualTo(1);
            assertThat(tasksQueued.getValue()).isEqualTo(0);
        };

        Future<?> theFuture = instrumentedExecutorService.submit(runnable);

        assertThat(theFuture).succeedsWithin(Duration.ofSeconds(5L));

        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);
        assertThat(idle.getCount()).isEqualTo(1);
        assertThat(idle.getSnapshot().size()).isEqualTo(1);
        assertThat(poolSize.getValue()).isEqualTo(1);
    }