use of com.netflix.servo.monitor.BucketTimer in project tutorials by eugenp.
the class MetricTypeTest method givenBucketTimer_whenRecord_thenStatsCalculated.
@Test
public void givenBucketTimer_whenRecord_thenStatsCalculated() throws Exception {
BucketTimer timer = new BucketTimer(MonitorConfig.builder("test").build(), new BucketConfig.Builder().withBuckets(new long[] { 2L, 5L }).withTimeUnit(SECONDS).build(), SECONDS);
timer.record(3);
timer.record(6);
assertEquals("timer should count 9 seconds in total", 9, timer.getTotalTime().intValue());
final Map<String, Long> metricMap = timer.getMonitors().stream().filter(monitor -> monitor.getConfig().getTags().containsKey("servo.bucket")).collect(toMap(monior -> getMonitorTagValue(monior, "servo.bucket"), monitor -> (Long) monitor.getValue()));
assertThat(metricMap, allOf(hasEntry("bucket=2s", 0L), hasEntry("bucket=5s", 1L), hasEntry("bucket=overflow", 1L)));
}
Aggregations