@Test
  public void testMetricsFactoryInitMetrics2ReporterAddedTwice() throws Exception {
    Configuration conf = new Configuration();

    jsonReportFile = File.createTempFile("TestCodahaleMetrics", ".json");
    LOGGER.info("Json metrics saved in {}", jsonReportFile.getAbsolutePath());

    conf.set(MetastoreConf.ConfVars.METRICS_CLASS.getHiveName(), CodahaleMetrics.class.getCanonicalName());
    conf.set(MetastoreConf.ConfVars.HIVE_CODAHALE_METRICS_REPORTER_CLASSES.getHiveName(),
            "org.apache.hadoop.hive.common.metrics.metrics2.Metrics2Reporter, "
                    + "org.apache.hadoop.hive.common.metrics.metrics2.Metrics2Reporter");
    conf.set(MetastoreConf.ConfVars.METRICS_JSON_FILE_LOCATION.getHiveName(), jsonReportFile.getAbsolutePath());
    conf.setTimeDuration(MetastoreConf.ConfVars.METRICS_JSON_FILE_INTERVAL.getHiveName(), 2000,
            TimeUnit.MILLISECONDS);

    MetricsFactory.init(conf);
    Assert.assertNotNull(MetricsFactory.getInstance());
    // closing MetricsFactory and re-initiating it to check if everything works fine
    MetricsFactory.close();
    MetricsFactory.init(conf);
    Assert.assertNotNull(MetricsFactory.getInstance());
  }
Tests if MetricsFactory is initialised properly when Metrics2Reporter is tried to add more than once.
standalone-metastore/metastore-common/src/test/java/org/apache/hadoop/hive/common/metrics/metrics2/TestCodahaleReportersConf.java