protected void compareMetrics(String metricPrefix, MetricRegistry metricRegistry, boolean failed) {
    Map<String, Histogram> histograms = metricRegistry.getHistograms();
    assertEquals("NIO request processing time unequal", nioLayerRequestProcessingTime,
        histograms.get(metricPrefix + RestRequestMetrics.NIO_REQUEST_PROCESSING_TIME_SUFFIX)
            .getSnapshot()
            .getValues()[0]);
    assertEquals("NIO response processing time unequal", nioLayerResponseProcessingTime,
        histograms.get(metricPrefix + RestRequestMetrics.NIO_RESPONSE_PROCESSING_TIME_SUFFIX)
            .getSnapshot()
            .getValues()[0]);

    long timeToFirstByte =
        histograms.get(metricPrefix + RestRequestMetrics.NIO_TIME_TO_FIRST_BYTE_SUFFIX).getSnapshot().getValues()[0];
    assertTrue("NIO time to first byte " + timeToFirstByte + "<" + REQUEST_SLEEP_TIME_MS,
        timeToFirstByte >= REQUEST_SLEEP_TIME_MS);
    long roundTripTime =
        histograms.get(metricPrefix + RestRequestMetrics.NIO_ROUND_TRIP_TIME_SUFFIX).getSnapshot().getValues()[0];
    assertTrue("NIO round trip time " + roundTripTime + "<" + REQUEST_SLEEP_TIME_MS * 2,
        roundTripTime >= REQUEST_SLEEP_TIME_MS * 2);

    assertEquals("SC request processing time unequal", scRequestProcessingTime,
        histograms.get(metricPrefix + RestRequestMetrics.SC_REQUEST_PROCESSING_TIME_SUFFIX)
            .getSnapshot()
            .getValues()[0]);
    assertEquals("SC request processing wait time unequal", scRequestProcessingWaitTime,
        histograms.get(metricPrefix + RestRequestMetrics.SC_REQUEST_PROCESSING_WAIT_TIME_SUFFIX)
            .getSnapshot()
            .getValues()[0]);
    assertEquals("SC response processing time unequal", scResponseProcessingTime,
        histograms.get(metricPrefix + RestRequestMetrics.SC_RESPONSE_PROCESSING_TIME_SUFFIX)
            .getSnapshot()
            .getValues()[0]);
    assertEquals("SC response processing wait time unequal", scResponseProcessingWaitTime,
        histograms.get(metricPrefix + RestRequestMetrics.SC_RESPONSE_PROCESSING_WAIT_TIME_SUFFIX)
            .getSnapshot()
            .getValues()[0]);

    assertEquals("Rate metric has not fired", 1,
        metricRegistry.getMeters().get(metricPrefix + RestRequestMetrics.OPERATION_RATE_SUFFIX).getCount());
    assertEquals("Error metric value is not as expected", operationErrorCount,
        metricRegistry.getCounters().get(metricPrefix + RestRequestMetrics.OPERATION_ERROR_SUFFIX).getCount());

    if (failed) {
      assertTrue("Expected throughput to not have been calculated when request failed",
          histograms.get(metricPrefix + RestRequestMetrics.THROUGHPUT_SUFFIX).getSnapshot().getValues().length == 0);
    } else {
      assertTrue("Expected throughput to have been calculated when request succeeded",
          histograms.get(metricPrefix + RestRequestMetrics.THROUGHPUT_SUFFIX).getSnapshot().getValues()[0] > 0);
    }
  }
Compares metrics generated inside this instance with what was recorded in the given {@code metricRegistry}.
@param metricPrefix the prefix of the metrics to look for.
@param metricRegistry the {@link MetricRegistry} where metrics were recorded.
ambry-api/src/test/java/com/github/ambry/rest/RestRequestMetricsTrackerTest.java