public static List<SlowPeerReportProto> convertSlowPeerInfo(
      SlowPeerReports slowPeers) {
    if (slowPeers.getSlowPeers().size() == 0) {
      return Collections.emptyList();
    }

    List<SlowPeerReportProto> slowPeerInfoProtos =
        new ArrayList<>(slowPeers.getSlowPeers().size());
    for (Map.Entry<String, OutlierMetrics> entry : slowPeers.getSlowPeers().entrySet()) {
      OutlierMetrics outlierMetrics = entry.getValue();
      slowPeerInfoProtos.add(
          SlowPeerReportProto.newBuilder()
              .setDataNodeId(entry.getKey())
              .setAggregateLatency(outlierMetrics.getActualLatency())
              .setMedian(outlierMetrics.getMedian())
              .setMad(outlierMetrics.getMad())
              .setUpperLimitLatency(outlierMetrics.getUpperLimitLatency())
              .build());
    }
    return slowPeerInfoProtos;
  }
@Test
  public void testSlowPeerInfoPBHelper() {
    // Test with a map that has a few slow peer entries.
    OutlierMetrics outlierMetrics1 = new OutlierMetrics(0.0, 0.0, 0.0, 0.0);
    OutlierMetrics outlierMetrics2 = new OutlierMetrics(0.0, 0.0, 0.0, 1.0);
    OutlierMetrics outlierMetrics3 = new OutlierMetrics(0.0, 0.0, 0.0, 2.0);
    final SlowPeerReports slowPeers = SlowPeerReports.create(
        ImmutableMap.of(
            "peer1", outlierMetrics1,
            "peer2", outlierMetrics2,
            "peer3", outlierMetrics3));
    SlowPeerReports slowPeersConverted1 = PBHelper.convertSlowPeerInfo(
        PBHelper.convertSlowPeerInfo(slowPeers));
    assertTrue(
        "Expected map:" + slowPeers + ", got map:" +
            slowPeersConverted1.getSlowPeers(),
        slowPeersConverted1.equals(slowPeers));

    // Test with an empty map.
    SlowPeerReports slowPeersConverted2 = PBHelper.convertSlowPeerInfo(
        PBHelper.convertSlowPeerInfo(SlowPeerReports.EMPTY_REPORT));
    assertTrue(
        "Expected empty map:" + ", got map:" + slowPeersConverted2,
        slowPeersConverted2.equals(SlowPeerReports.EMPTY_REPORT));
  }