@Test
  public void testTableQueryMeterSwitch() {
    HRegion region = mock(HRegion.class);
    MetricsTableRequests metricsTableRequests = mock(MetricsTableRequests.class);
    when(region.getMetricsTableRequests()).thenReturn(metricsTableRequests);
    when(metricsTableRequests.isEnableTableLatenciesMetrics()).thenReturn(false);
    when(metricsTableRequests.isEnabTableQueryMeterMetrics()).thenReturn(false);
    Configuration conf = new Configuration(false);
    // disable
    rsm.updateReadQueryMeter(region, 500L);
    assertFalse(HELPER.checkGaugeExists("ServerReadQueryPerSecond_count", serverSource));
    rsm.updateWriteQueryMeter(region, 500L);
    assertFalse(HELPER.checkGaugeExists("ServerWriteQueryPerSecond_count", serverSource));

    // enable
    conf.setBoolean(MetricsRegionServer.RS_ENABLE_SERVER_QUERY_METER_METRICS_KEY, true);
    rsm = new MetricsRegionServer(wrapper, conf, null);
    serverSource = rsm.getMetricsSource();
    rsm.updateReadQueryMeter(region, 500L);
    assertTrue(HELPER.checkGaugeExists("ServerWriteQueryPerSecond_count", serverSource));
    HELPER.assertGauge("ServerReadQueryPerSecond_count", 500L, serverSource);
    assertTrue(HELPER.checkGaugeExists("ServerWriteQueryPerSecond_count", serverSource));
    rsm.updateWriteQueryMeter(region, 500L);
    HELPER.assertGauge("ServerWriteQueryPerSecond_count", 500L, serverSource);
  }
Unit test version of rs metrics tests.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java