Counter { public void add() { add(1L, defaultPosition); } Counter(String name, Point defaultPosition, MetricReceiver receiver); void add(); void add(long n); void add(Point p); void add(long n, Point p); PointBuilder builder();  }
@Test public final void testAdd() throws InterruptedException { final String metricName = "unitTestCounter"; Counter c = receiver.declareCounter(metricName); c.add(); Bucket b = receiver.getSnapshot(); final Map<String, List<Entry<Point, UntypedMetric>>> valuesByMetricName = b.getValuesByMetricName(); assertEquals(1, valuesByMetricName.size()); List<Entry<Point, UntypedMetric>> x = valuesByMetricName.get(metricName); assertEquals(1, x.size()); assertEquals(Point.emptyPoint(), x.get(0).getKey()); assertEquals(1L, x.get(0).getValue().getCount()); }
@Test public final void testAddLong() throws InterruptedException { final String metricName = "unitTestCounter"; Counter c = receiver.declareCounter(metricName); final long twoToThePowerOfFourtyeight = 65536L * 65536L * 65536L; c.add(twoToThePowerOfFourtyeight); Bucket b = receiver.getSnapshot(); final Map<String, List<Entry<Point, UntypedMetric>>> valuesByMetricName = b.getValuesByMetricName(); assertEquals(1, valuesByMetricName.size()); List<Entry<Point, UntypedMetric>> x = valuesByMetricName.get(metricName); assertEquals(1, x.size()); assertEquals(Point.emptyPoint(), x.get(0).getKey()); assertEquals(twoToThePowerOfFourtyeight, x.get(0).getValue().getCount()); }
@Test public final void testAddPoint() throws InterruptedException { final String metricName = "unitTestCounter"; Point p = receiver.pointBuilder().set("x", 2L).set("y", 3.0d).set("z", "5").build(); Counter c = receiver.declareCounter(metricName, p); c.add(); Bucket b = receiver.getSnapshot(); final Map<String, List<Entry<Point, UntypedMetric>>> valuesByMetricName = b.getValuesByMetricName(); assertEquals(1, valuesByMetricName.size()); List<Entry<Point, UntypedMetric>> x = valuesByMetricName.get(metricName); assertEquals(1, x.size()); assertEquals(p, x.get(0).getKey()); assertEquals(1, x.get(0).getValue().getCount()); }