@Test
  public void testScope() throws Exception {
    int runs = 5;
    for (int i = 0; i < runs; i++) {
      MetricsFactory.getInstance().startStoredScope("method1");
      MetricsFactory.getInstance().endStoredScope("method1");
      Timer timer = metricRegistry.getTimers().get("method1");
      Assert.assertEquals(i + 1, timer.getCount());
    }

    Timer timer = metricRegistry.getTimers().get("method1");
    Assert.assertTrue(timer.getMeanRate() > 0);
  }
Unit test for new Metrics subsystem.
standalone-metastore/metastore-common/src/test/java/org/apache/hadoop/hive/common/metrics/metrics2/TestCodahaleMetrics.java