@Test
public void aMethodAnnotatedWithBothATimerAndAnExceptionCounter() throws Exception {
final Timer timedMetric = registry.getTimers().get(name(InstrumentedWithExceptionMetered.class,
"timedAndException", TimedInterceptor.TIMED_SUFFIX));
final Meter errorMetric = registry.getMeters().get(name(InstrumentedWithExceptionMetered.class,
"timedAndException", DEFAULT_NAME_SUFFIX));
assertThat("Guice creates a metric",
timedMetric,
is(notNullValue()));
assertThat("Guice creates a timer",
timedMetric,
is(instanceOf(Timer.class)));
assertThat("Guice creates a metric",
errorMetric,
is(notNullValue()));
assertThat("Guice creates a meter",
errorMetric,
is(instanceOf(Meter.class)));
// Counts should start at zero
assertThat("Timer Metric should be zero when initialised",
timedMetric.getCount(),
is(0L));
assertThat("Error Metric should be zero when initialised",
errorMetric.getCount(),
is(0L));
// Invoke, but don't throw an exception
instance.timedAndException(null);
assertThat("Expected the meter metric to be marked on invocation",
timedMetric.getCount(),
is(1L));
assertThat("Expected the exception metric to be zero since no exceptions thrown",
errorMetric.getCount(),
is(0L));
// Invoke and throw an exception
try {
instance.timedAndException(new RuntimeException());
fail("Should have thrown an exception");
} catch (Exception ignored) {}
assertThat("Expected a count of 2, one for each invocation",
timedMetric.getCount(),
is(2L));
assertThat("Expected exception count to be 1 as one (of two) invocations threw an exception",
errorMetric.getCount(),
is(1L));