@Test public void encodeSendsMax0() throws Exception { List<Measurement> ms = new ArrayList<>(); ms.add(max(0, "test")); Map<Id, Delta> values = decode(JsonUtils.encode(Collections.emptyMap(), ms)); Assertions.assertEquals(1, values.size()); ms.forEach(m -> { Id id = m.id(); Assertions.assertEquals(0.0, values.get(id).value, 1e-12); }); }
@Test public void encodeNoCommonTags() throws Exception { List<Measurement> ms = new ArrayList<>(); ms.add(count(42.0, "test")); Map<Id, Delta> values = decode(JsonUtils.encode(Collections.emptyMap(), ms)); Assertions.assertEquals(1, values.size()); ms.forEach(m -> { Assertions.assertEquals(42.0, values.get(m.id()).value, 1e-12); }); }
@Test public void encodeCommonTags() throws Exception { Map<String, String> commonTags = new HashMap<>(); commonTags.put("a", "1"); commonTags.put("b", "2"); List<Measurement> ms = new ArrayList<>(); ms.add(count(42.0, "test")); Map<Id, Delta> values = decode(JsonUtils.encode(commonTags, ms)); Assertions.assertEquals(1, values.size()); ms.forEach(m -> { Id id = m.id().withTags(commonTags); Assertions.assertEquals(42.0, values.get(id).value, 1e-12); }); }
@Test public void encodeSupportsKnownStats() throws Exception { for (Statistic stat : Statistic.values()) { List<Measurement> ms = new ArrayList<>(); ms.add(count(42, "test", "statistic", stat.value())); Map<Id, Delta> values = decode(JsonUtils.encode(Collections.emptyMap(), ms)); Assertions.assertEquals(1, values.size()); ms.forEach(m -> { Id id = m.id(); Assertions.assertEquals(42.0, values.get(id).value, 1e-12); }); } }