@Test public void testRecord0() throws Exception { BasicTimer c = newInstance("foo"); assertEquals(c.getCount().longValue(), 0L); c.record(42, TimeUnit.MILLISECONDS); assertEquals(c.getCount().longValue(), 1L); // Explicit 0 should be counted c.record(0, TimeUnit.MILLISECONDS); assertEquals(c.getCount().longValue(), 2L); // Negative values should be ignored c.record(-1, TimeUnit.MILLISECONDS); assertEquals(c.getCount().longValue(), 2L); }
@Test public void testFractional() throws Exception { BasicTimer timer = newInstance("foo"); timer.record(1000, TimeUnit.NANOSECONDS); assertEquals(timer.getTotalTime(), 0.001); assertEquals(timer.getMax(), 0.001); } }
@Test public void testGetValue() throws Exception { BasicTimer c = newInstance("foo"); assertEquals(c.getValue().longValue(), 0L); assertEquals(c.getTotalTime().longValue(), 0L); assertEquals(c.getCount().longValue(), 0L); assertEquals(c.getMax().longValue(), 0L); c.record(42, TimeUnit.MILLISECONDS); assertEquals(c.getValue().longValue(), 42L); assertEquals(c.getTotalTime().longValue(), 42L); assertEquals(c.getCount().longValue(), 1L); assertEquals(c.getMax().longValue(), 42L); c.record(21, TimeUnit.MILLISECONDS); assertEquals(c.getValue().longValue(), 31L); assertEquals(c.getTotalTime().longValue(), 63L); assertEquals(c.getCount().longValue(), 2L); assertEquals(c.getMax().longValue(), 42L); c.record(84, TimeUnit.MILLISECONDS); assertEquals(c.getValue().longValue(), 49L); assertEquals(c.getTotalTime().longValue(), 147L); assertEquals(c.getCount().longValue(), 3L); assertEquals(c.getMax().longValue(), 84L); assertEquals(c.getValue().longValue(), 49L); assertEquals(c.getTotalTime().longValue(), 147L); assertEquals(c.getCount().longValue(), 3L); assertEquals(c.getMax().longValue(), 84L); }
@Test public void testUnregisteredBasicTimerIncrement() { BasicTimer t = new BasicTimer(CONFIG); t.record(42, TimeUnit.MILLISECONDS); Id id = registry.createId("test") .withTag("unit", "MILLISECONDS"); assertEquals(3, registry.counters().count()); assertEquals(0, registry.timers().count()); assertEquals(1, registry.gauges().count()); assertEquals(0, registry.distributionSummaries().count()); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).count()); assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).count()); assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value()); }
@Test public void testBasicTimerRecordMillis() { BasicTimer d = new BasicTimer(CONFIG); register(d); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-6, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-6 * 42e-6, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-6, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testBasicTimerRecordSeconds() { BasicTimer d = new BasicTimer(CONFIG, TimeUnit.SECONDS); register(d); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "SECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-9, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-9 * 42e-9, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-9, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }