private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger( RecorderTest.class );
@Test
public void testTryTimer() throws Exception {
TimingMetric metric = new BasicTimingMetric( "test" );
TimingMetric exMetric = new BasicTimingMetric( "exTest" );
DistributingMetric distMetric = new DistributingMetric( "distTest",
map( pairOf( Conditions.all(), "test" ), pairOf( Conditions.exception(), "exTest" ) ),
metric, exMetric );
try ( Recorder t = Recorder.recordFor( distMetric ) ) {
Thread.sleep( 100L );
}
assertEquals( metric.getCount(), BigInteger.ONE );
assertEquals( exMetric.getCount(), BigInteger.ZERO );
try ( Recorder t = Recorder.recordFor( distMetric, "foo", "bar", "snafu" ) ) {
Thread.sleep( 100L );
}
assertEquals( metric.getCount(), BigInteger.valueOf( 2 ) );
assertEquals( exMetric.getCount(), BigInteger.ZERO );
Recorder t = Recorder.recordFor( distMetric );
try {
Thread.sleep( 100L );
throw new RuntimeException( "test exception" );
} catch ( RuntimeException ex ) {
t.setException( ex );
} finally {
t.close();
}
assertEquals( metric.getCount(), BigInteger.valueOf( 3 ) );
assertEquals( exMetric.getCount(), BigInteger.ONE );
}