public void addReport(String slowNode, String reportingNode, OutlierMetrics slowNodeMetrics) {
    ConcurrentMap<String, LatencyWithLastReportTime> nodeEntries = allReports.get(slowNode);

    if (nodeEntries == null) {
      // putIfAbsent guards against multiple writers.
      allReports.putIfAbsent(slowNode, new ConcurrentHashMap<>());
      nodeEntries = allReports.get(slowNode);
    }

    // Replace the existing entry from this node, if any.
    nodeEntries.put(reportingNode,
        new LatencyWithLastReportTime(timer.monotonicNow(), slowNodeMetrics));
  }
@Test
  public void testGetJsonSizeIsLimited() throws IOException {
    tracker.addReport("node1", "node2", new OutlierMetrics(0.0, 0.0, 0.0, 1.634));
    tracker.addReport("node1", "node3", new OutlierMetrics(0.0, 0.0, 0.0, 2.3566));
    tracker.addReport("node2", "node3", new OutlierMetrics(0.0, 0.0, 0.0, 3.869));
    tracker.addReport("node2", "node4", new OutlierMetrics(0.0, 0.0, 0.0, 4.1356));
    tracker.addReport("node3", "node4", new OutlierMetrics(0.0, 0.0, 0.0, 1.73057));
    tracker.addReport("node3", "node5", new OutlierMetrics(0.0, 0.0, 0.0, 2.4956730));
    tracker.addReport("node4", "node6", new OutlierMetrics(0.0, 0.0, 0.0, 3.29847));
    tracker.addReport("node5", "node6", new OutlierMetrics(0.0, 0.0, 0.0, 4.13444));
    tracker.addReport("node5", "node7", new OutlierMetrics(0.0, 0.0, 0.0, 5.10845));
    tracker.addReport("node6", "node8", new OutlierMetrics(0.0, 0.0, 0.0, 2.37464));
    tracker.addReport("node6", "node7", new OutlierMetrics(0.0, 0.0, 0.0, 1.29475656));

    final Set<SlowPeerJsonReport> reports = getAndDeserializeJson();

    // Ensure that node4 is not in the list since it was
    // tagged by just one peer and we already have 5 other nodes.
    assertFalse(isNodeInReports(reports, "node4"));

    // Remaining nodes should be in the list.
    assertTrue(isNodeInReports(reports, "node1"));
    assertTrue(isNodeInReports(reports, "node2"));
    assertTrue(isNodeInReports(reports, "node3"));
    assertTrue(isNodeInReports(reports, "node5"));
    assertTrue(isNodeInReports(reports, "node6"));

    assertEquals(1, reports.stream().filter(
        e -> e.getSlowNode().equals("node1") && e.getSlowPeerLatencyWithReportingNodes().size() == 2
            && e.getSlowPeerLatencyWithReportingNodes().first().getReportedLatency().equals(1.634)
            && e.getSlowPeerLatencyWithReportingNodes().last().getReportedLatency().equals(2.3566))
        .count());

    assertEquals(1, reports.stream().filter(
        e -> e.getSlowNode().equals("node2") && e.getSlowPeerLatencyWithReportingNodes().size() == 2
            && e.getSlowPeerLatencyWithReportingNodes().first().getReportedLatency().equals(3.869)
            && e.getSlowPeerLatencyWithReportingNodes().last().getReportedLatency().equals(4.1356))
        .count());

    assertEquals(1, reports.stream().filter(
        e -> e.getSlowNode().equals("node3") && e.getSlowPeerLatencyWithReportingNodes().size() == 2
            && e.getSlowPeerLatencyWithReportingNodes().first().getReportedLatency().equals(1.73057)
            && e.getSlowPeerLatencyWithReportingNodes().last().getReportedLatency()
            .equals(2.4956730)).count());

    assertEquals(1, reports.stream().filter(
        e -> e.getSlowNode().equals("node6") && e.getSlowPeerLatencyWithReportingNodes().size() == 2
            && e.getSlowPeerLatencyWithReportingNodes().first().getReportedLatency()
            .equals(1.29475656) && e.getSlowPeerLatencyWithReportingNodes().last()
            .getReportedLatency().equals(2.37464)).count());
  }