Metrics { public Gauge declareGauge(String name) { return declareGauge(name, Dimensions.NONE); } @Inject  Metrics(); Counter declareCounter(String name); Counter declareCounter(String name, Dimensions dimensions); Counter declareCounter(String application, String name, Dimensions dimensions, DimensionType type); Gauge declareGauge(String name); Gauge declareGauge(String name, Dimensions dimensions); Gauge declareGauge(String application, String name, Dimensions dimensions, DimensionType type); List<DimensionMetrics> getDefaultMetrics(); List<DimensionMetrics> getMetricsByType(DimensionType type); void deleteMetricByDimension(String name,  Dimensions dimensionsToRemove, DimensionType type); static final String APPLICATION_HOST; static final String APPLICATION_NODE; }
@Test public void testSimpleGauge() { Gauge gauge = metrics.declareGauge("test.gauge", hostDimension); gauge.sample(42); gauge.sample(-342.23); Map<String, Number> latestMetrics = getMetricsForDimension(hostDimension); assertEquals("Expected only 1 metric value to be set", 1, latestMetrics.size()); assertEquals(latestMetrics.get("test.gauge"), -342.23); }
@Test public void testRedeclaringSameGauge() { Gauge gauge = metrics.declareGauge("test.gauge", hostDimension); gauge.sample(42); Dimensions newDimension = new Dimensions.Builder().add("host", "abc.yahoo.com").build(); Gauge newGauge = metrics.declareGauge("test.gauge", newDimension); newGauge.sample(56); assertEquals(getMetricsForDimension(hostDimension).get("test.gauge"), 56.); }
@Test public void testSameMetricNameButDifferentDimensions() { Gauge gauge = metrics.declareGauge("test.gauge", hostDimension); gauge.sample(42); Dimensions newDimension = new Dimensions.Builder().add("host", "abcd.yahoo.com").build(); Gauge newGauge = metrics.declareGauge("test.gauge", newDimension); newGauge.sample(56); assertEquals(getMetricsForDimension(hostDimension).get("test.gauge"), 42.); assertEquals(getMetricsForDimension(newDimension).get("test.gauge"), 56.); }