### Question:
Metrics { @VisibleForTesting static List<Reporter> getReporters() { return self.reporters; } private  Metrics(Configuration conf); static synchronized Metrics initialize(Configuration conf); static MetricRegistry getRegistry(); static synchronized void shutdown(); static Counter getOrCreateCounter(String name); static Timer getOrCreateTimer(String name); static AtomicInteger getOrCreateGauge(String name); static Counter getOpenConnectionsCounter();  }### Answer:
@Test public void allReporters() throws Exception { String jsonFile = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "TestMetricsOutput.json"; Configuration conf = MetastoreConf.newMetastoreConf(); MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_REPORTERS, "json,jmx,console,hadoop"); MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_JSON_FILE_LOCATION, jsonFile); initializeMetrics(conf); Assert.assertEquals(4, Metrics.getReporters().size()); }
@Test public void allReportersHiveConfig() throws Exception { String jsonFile = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "TestMetricsOutput.json"; Configuration conf = MetastoreConf.newMetastoreConf(); conf.set(MetastoreConf.ConfVars.HIVE_CODAHALE_METRICS_REPORTER_CLASSES.getHiveName(), "org.apache.hadoop.hive.common.metrics.metrics2.JsonFileMetricsReporter," + "org.apache.hadoop.hive.common.metrics.metrics2.JmxMetricsReporter," + "org.apache.hadoop.hive.common.metrics.metrics2.ConsoleMetricsReporter," + "org.apache.hadoop.hive.common.metrics.metrics2.Metrics2Reporter"); MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_JSON_FILE_LOCATION, jsonFile); initializeMetrics(conf); Assert.assertEquals(4, Metrics.getReporters().size()); }
@Test public void allReportersOldHiveConfig() throws Exception { String jsonFile = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "TestMetricsOutput.json"; Configuration conf = MetastoreConf.newMetastoreConf(); conf.set(MetastoreConf.ConfVars.HIVE_METRICS_REPORTER.getHiveName(), "JSON_FILE,JMX,CONSOLE,HADOOP2"); MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_JSON_FILE_LOCATION, jsonFile); initializeMetrics(conf); Assert.assertEquals(4, Metrics.getReporters().size()); }
@Test public void defaults() throws Exception { String jsonFile = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "TestMetricsOutput.json"; Configuration conf = MetastoreConf.newMetastoreConf(); MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_JSON_FILE_LOCATION, jsonFile); initializeMetrics(conf); Assert.assertEquals(2, Metrics.getReporters().size()); }