assertEquals(2, countedMethod.getCount());
}
@Test
public void quadruplyMeteredMethod() throws Throwable {
Timer quadruple_Timed = forTimedMethod(metricRegistry, MeteredClass.class, "quadruplyMeteredMethod");
Meter quadruple_Metered = forMeteredMethod(metricRegistry, MeteredClass.class, "quadruplyMeteredMethod");
Meter quadruple_ExceptionMetered = forExceptionMeteredMethod(metricRegistry, MeteredClass.class, "quadruplyMeteredMethod");
final Counter quadruple_Counted = forCountedMethod(metricRegistry, MeteredClass.class, "quadruplyMeteredMethod");
assertEquals(0, quadruple_Metered.getCount());
assertEquals(0, quadruple_Timed.getCount());
assertEquals(0, quadruple_ExceptionMetered.getCount());
assertEquals(0, quadruple_Counted.getCount());
// doesn't throw an exception
meteredClass.quadruplyMeteredMethod(new Runnable() {
@Override
public void run() {
assertEquals(1, quadruple_Counted.getCount());
}
});
assertEquals(1, quadruple_Metered.getCount());
assertEquals(1, quadruple_Timed.getCount());
assertEquals(0, quadruple_ExceptionMetered.getCount());
assertEquals(0, quadruple_Counted.getCount());
// throws an exception
try {
meteredClass.quadruplyMeteredMethod(new Runnable() {
@Override
public void run() {
assertEquals(1, quadruple_Counted.getCount());
throw new BogusException();
}
});
fail();
}
catch (Throwable t) {
assertTrue(t instanceof BogusException);
}
assertEquals(2, quadruple_Metered.getCount());
assertEquals(2, quadruple_Timed.getCount());
assertEquals(1, quadruple_ExceptionMetered.getCount());
assertEquals(0, quadruple_Counted.getCount());
}