private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger( CounterTest.class );
@Test
public void testCounter() throws Exception {
MeteringMetric metric = new BasicMeteringMetric( "test" );
Counter counter = new Counter( metric );
String result = counter.count( new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep( 1000 );
return "Done";
}
} );
assertEquals( result, "Done" );
assertEquals( metric.getCount(), BigInteger.ONE );
counter = new Counter();
counter.setMetric( metric );
final Exception theException = new Exception();
try {
counter.count( new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep( 1000 );
throw theException;
}
} );
assertEquals( result, "Done" );
} catch ( Exception ex ) {
assertSame( ex, theException );
}
assertEquals( metric.getCount(), BigInteger.valueOf( 2 ) );
}