@Test public void testInit() { Registry r = new DefaultRegistry(clock); clock.setWallTime(42 * 1000L); Id id = r.createId("test"); IntervalCounter c = IntervalCounter.get(r, id); Assertions.assertEquals(0L, c.count()); Assertions.assertEquals(42.0, c.secondsSinceLastUpdate(), EPSILON); }
@Test public void testInterval() { Registry r = new DefaultRegistry(clock); Id id = r.createId("test"); IntervalCounter c = IntervalCounter.get(r, id); Assertions.assertEquals(c.secondsSinceLastUpdate(), 0.0, EPSILON); clock.setWallTime(1000); Assertions.assertEquals(c.secondsSinceLastUpdate(), 1.0, EPSILON); c.increment(); Assertions.assertEquals(c.secondsSinceLastUpdate(), 0.0, EPSILON); }
@Test public void testIncrement() { Registry r = new DefaultRegistry(clock); Id id = r.createId("test"); Counter c = IntervalCounter.get(r, id); Assertions.assertEquals(0, c.count()); c.increment(); Assertions.assertEquals(1, c.count()); c.increment(41); Assertions.assertEquals(42, c.count()); }
@Test public void testMeasure() { Registry r = new DefaultRegistry(clock); clock.setWallTime(61000L); Id id = r.createId("test"); Counter c = IntervalCounter.get(r, id); // all meters should have the correct timestamp r.stream().forEach(meter -> { for (Measurement m : meter.measure()) { Assertions.assertEquals(m.timestamp(), 61000L); } }); final List<Measurement> measurements = getAllMeasurements(r); final double initAge = Utils.first(measurements, Statistic.duration).value(); final double initCount = Utils.first(measurements, Statistic.count).value(); Assertions.assertEquals(61.0, initAge, EPSILON); Assertions.assertEquals(0.0, initCount, EPSILON); clock.setWallTime(120000L); c.increment(); final List<Measurement> afterMeasurements = getAllMeasurements(r); final double afterAge = Utils.first(afterMeasurements, Statistic.duration).value(); final double afterCount = Utils.first(afterMeasurements, Statistic.count).value(); Assertions.assertEquals(0.0, afterAge, EPSILON); Assertions.assertEquals(1.0, afterCount, EPSILON); }