@Test
  public void testGauge() throws Exception {
    TestMetricsVariable testVar = new TestMetricsVariable();
    testVar.setValue(20);

    MetricsFactory.getInstance().addGauge("gauge1", testVar);
    String json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, "gauge1", testVar.getValue());


    testVar.setValue(40);
    json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, "gauge1", testVar.getValue());
  }
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