DropwizardMetrics implements MetricsSpi { @Override public TimerSpi createTimer() { return new TimerAdapter(metrics.timer("timer-" + nextTimerId.incrementAndGet())); }  @Override TimerSpi createTimer();  }
@Test public void timeExecution() throws Throwable { TimerSpi timer = dropwizardMetrics.createTimer(); CheckedCommand<String> execution = timer.timeExecution(() -> { Thread.sleep(10); return "foo-bar"; }); assertEquals("foo-bar", execution.call()); TimerSnaphot timerSnapshot = timer.getSnapshot(); assertEquals(1, timerSnapshot.getCount()); assertThat(timerSnapshot.getMax(), greaterThan(8D)); }
@Test public void timeObservable() throws Throwable { TimerSpi timer = dropwizardMetrics.createTimer(); Supplier<Observable<String>> observable = timer.timeObservable(() -> Observable.unsafeCreate(subscriber -> { try { Thread.sleep(10); subscriber.onNext("foo"); subscriber.onCompleted(); } catch (InterruptedException e) { subscriber.onError(e); } })); assertEquals("foo", observable.get().toBlocking().first()); TimerSnaphot timerSnapshot = timer.getSnapshot(); assertEquals(1, timerSnapshot.getCount()); assertThat(timerSnapshot.getMax(), greaterThan(8D)); }