### Question:
Metrics { public static Counter getOrCreateCounter(String name) { if (self == null) return dummyCounter; Map<String, Counter> counters = self.registry.getCounters(); Counter counter = counters.get(name); if (counter != null) return counter; synchronized (Metrics.class) { counters = self.registry.getCounters(); counter = counters.get(name); if (counter != null) return counter; return self.registry.counter(name); } } 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 jsonReporter() throws Exception { File jsonReportFile = File.createTempFile("TestMetrics", ".json"); String jsonFile = jsonReportFile.getAbsolutePath(); Configuration conf = MetastoreConf.newMetastoreConf(); MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_REPORTERS, "json"); MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METRICS_JSON_FILE_LOCATION, jsonFile); MetastoreConf.setTimeVar(conf, MetastoreConf.ConfVars.METRICS_JSON_FILE_INTERVAL, REPORT_INTERVAL, TimeUnit.SECONDS); initializeMetrics(conf); Counter counter = Metrics.getOrCreateCounter("my-counter"); for (int i = 0; i < 5; i++) { counter.inc(); Thread.sleep(REPORT_INTERVAL * 1000 + REPORT_INTERVAL * 1000 / 2); String json = new String(MetricsTestUtils.getFileData(jsonFile, 200, 10)); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "my-counter", i + 1); } }