@Test
  @org.junit.Ignore("flaky test HIVE-23692")
  public void testFileReporting() throws Exception {
    int runs = 5;
    String  counterName = "count2";

    // on the first write the metrics writer should initialize stuff
    MetricsFactory.getInstance().incrementCounter(counterName);
    sleep(5 * REPORT_INTERVAL_MS);

    for (int i = 1; i <= runs; i++) {
      MetricsFactory.getInstance().incrementCounter(counterName);
      sleep(REPORT_INTERVAL_MS + REPORT_INTERVAL_MS / 2);
      Assert.assertEquals(i + 1, getCounterValue(counterName));
    }
  }
Test JSON reporter.
<ul>
  <li>increment the counter value</li>
  <li>wait a bit for the new repor to be written</li>
  <li>read the value from JSON file</li>
  <li>verify that the value matches expectation</li>
</ul>
This check is repeated a few times to verify that the values are updated over time.
@throws Exception if fails to read counter value
standalone-metastore/metastore-common/src/test/java/org/apache/hadoop/hive/common/metrics/metrics2/TestCodahaleMetrics.java