private void testMetric(Scan scan, String metricKey, long expectedValue,
    CompareOperator compareOperator) throws Exception {
    assertTrue("Scan should be configured to record metrics", scan.isScanMetricsEnabled());
    ResultScanner scanner = TABLE.getScanner(scan);
    // Iterate through all the results
    while (scanner.next() != null) {
      continue;
    }
    scanner.close();
    ScanMetrics metrics = scanner.getScanMetrics();
    assertNotNull("Metrics are null", metrics);
    assertTrue("Metric : " + metricKey + " does not exist", metrics.hasCounter(metricKey));
    final long actualMetricValue = metrics.getCounter(metricKey).get();
    if (compareOperator == CompareOperator.EQUAL) {
      assertEquals(
        "Metric: " + metricKey + " Expected: " + expectedValue + " Actual: " + actualMetricValue,
        expectedValue, actualMetricValue);
    } else {
      assertTrue(
        "Metric: " + metricKey + " Expected: > " + expectedValue + " Actual: " + actualMetricValue,
        actualMetricValue > expectedValue);
    }
  }
Run the scan to completetion and check the metric against the specified value
@param scan          The scan instance to use to record metrics
@param metricKey     The metric key name
@param expectedValue The expected value of metric
@throws Exception on unexpected failure
hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerSideScanMetricsFromClientSide.java