MetricsPacket { public Map<MetricId, Number> metrics() { return unmodifiableMap(metrics); } private  MetricsPacket(int statusCode, String statusMessage, long timestamp, ServiceId service,
                          Map<MetricId, Number> metrics, Map<DimensionId, String> dimensions, Set<ConsumerId> consumers ); Map<MetricId, Number> metrics(); Map<DimensionId, String> dimensions(); List<ConsumerId> consumers(); @Override String toString(); final int statusCode; final String statusMessage; final long timestamp; final ServiceId service; }
@Test public void builder_can_retain_subset_of_metrics() { MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo")) .putMetrics(ImmutableList.of( new Metric("remove", 1), new Metric("keep", 2))) .retainMetrics(ImmutableSet.of(toMetricId("keep"), toMetricId("non-existent"))) .build(); assertFalse("should not contain 'remove'", packet.metrics().containsKey(toMetricId("remove"))); assertTrue("should contain 'keep'", packet.metrics().containsKey(toMetricId("keep"))); assertFalse("should not contain 'non-existent'", packet.metrics().containsKey(toMetricId("non-existent"))); }
@Test public void builder_applies_output_names() { String ONE = "one"; String TWO = "two"; String THREE = "three"; String NON_EXISTENT = "non-existent"; MetricId ONE_ID = toMetricId(ONE); MetricId TWO_ID = toMetricId(TWO); MetricId THREE_ID = toMetricId(THREE); MetricId NON_EXISTENT_ID = toMetricId(NON_EXISTENT); Map<MetricId, List<String>> outputNamesById = ImmutableMap.of( toMetricId(ONE), ImmutableList.of(ONE), toMetricId(TWO), ImmutableList.of(TWO, "dos"), toMetricId(THREE), ImmutableList.of("3"), toMetricId(NON_EXISTENT), ImmutableList.of(NON_EXISTENT)); MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo")) .putMetrics(ImmutableList.of( new Metric(ONE, 1), new Metric(TWO, 2), new Metric(THREE, 3))) .applyOutputNames(outputNamesById) .build(); assertTrue(packet.metrics().containsKey(ONE_ID)); assertTrue(packet.metrics().containsKey(TWO_ID)); assertTrue(packet.metrics().containsKey(toMetricId("dos"))); assertFalse(packet.metrics().containsKey(THREE_ID)); assertTrue(packet.metrics().containsKey(toMetricId("3"))); assertFalse(packet.metrics().containsKey(NON_EXISTENT_ID)); }