tm.addEvent( new BasicTimingEvent( now - 3, now ) );
tm.addEvent( new BasicTimingEvent( now - 4, now ) );
tm.addEvent( new BasicTimingEvent( now - 5, now ) );
tm.addEvent( new BasicTimingEvent( now - 2, now ) );
Timing mean = tm.getMean();
Timing median = tm.getCentile( new BigDecimal( 50L ) );
BigDecimal stddev = tm.getStandardDeviation().getValue();
Timing total = tm.getTotal();
Rate rate = tm.getRate();
try {
tm.getCentile( BigDecimal.valueOf( 105.0 ) );
fail( "failed to trigger expected exception: IllegalArgumentException" );
} catch ( IllegalArgumentException ex ) {
// Expected
}
try {
tm.getCentile( BigDecimal.valueOf( -1.0 ) );
fail( "failed to trigger expected exception: IllegalArgumentException" );
} catch ( IllegalArgumentException ex ) {
// Expected
}
assertEquals( tm.getCentile( BigDecimal.valueOf( 100L ) ).getValue(), BigDecimal.valueOf( 10L ) );
assertNotNull( mean );
assertNotNull( median );
assertNotNull( stddev );
assertNotNull( total );
assertNotNull( rate );
assertBigDecimalEquals( mean.getValue(), BigDecimal.valueOf( 48333333333L, 10 ) );
assertBigDecimalEquals( median.getValue(), new BigDecimal( 4 ) );
assertBigDecimalEquals( stddev, BigDecimal.valueOf( 2786873996L, 9 ) );
assertBigDecimalEquals( total.getValue(), new BigDecimal( 29 ) );
assertBigDecimalEquals( rate.getValue(), new BigDecimal( 6 ) );
TimingMetric<TimingMetric, TimingEvent> snapshot = tm.getSnapshot();
mean = snapshot.getMean();
median = snapshot.getCentile( new BigDecimal( 50L ) );
stddev = snapshot.getStandardDeviation().getValue();
total = snapshot.getTotal();
rate = snapshot.getRate();
assertNotNull( mean );
assertNotNull( median );
assertNotNull( stddev );
assertNotNull( total );
assertNotNull( rate );
assertBigDecimalEquals( mean.getValue(), BigDecimal.valueOf( 48333333333L, 10 ) );
assertBigDecimalEquals( median.getValue(), new BigDecimal( 4 ) );
assertBigDecimalEquals( stddev, BigDecimal.valueOf( 2786873996L, 9 ) );
assertBigDecimalEquals( total.getValue(), new BigDecimal( 29 ) );
assertBigDecimalEquals( rate.getValue(), new BigDecimal( 6 ) );
snapshot = tm.reset();
mean = snapshot.getMean();
median = snapshot.getCentile( new BigDecimal( 50L ) );
stddev = snapshot.getStandardDeviation().getValue();
total = snapshot.getTotal();
rate = snapshot.getRate();
assertNotNull( mean );
assertNotNull( median );
assertNotNull( stddev );
assertNotNull( total );
assertNotNull( rate );
assertBigDecimalEquals( mean.getValue(), BigDecimal.valueOf( 48333333333L, 10 ) );
assertBigDecimalEquals( median.getValue(), new BigDecimal( 4 ) );
assertBigDecimalEquals( stddev, BigDecimal.valueOf( 2786873996L, 9 ) );
assertBigDecimalEquals( total.getValue(), new BigDecimal( 29 ) );
assertBigDecimalEquals( rate.getValue(), new BigDecimal( 6 ) );
mean = tm.getMean();
median = tm.getCentile( new BigDecimal( 50L ) );
stddev = tm.getStandardDeviation().getValue();
total = tm.getTotal();
rate = tm.getRate();
assertNull( mean );
assertNull( median );
assertEquals( stddev, ZERO );
assertEquals( total.getValue(), ZERO );
assertNull( rate );
}