StructMetricManagerReporter extends MetricManagerReporter { @Override public void start(long period, TimeUnit unit) { String initFlag = System.getProperty(INIT_FLAG); if ("false".equals(initFlag)) { logger.info("StructMetricManagerReporter disabled..."); return; } if (initFlag == null) { System.setProperty(INIT_FLAG, "true"); super.start(period, unit); } else { logger.info("StructMetricManagerReporter has been started..."); } } StructMetricManagerReporter(IMetricManager metricManager, BinAppender binAppender, FileAppender fileAppender,
                                       LogDescriptionManager logDescriptionManager);  StructMetricManagerReporter(IMetricManager metricManager, BinAppender binAppender, FileAppender fileAppender,
            Clock clock, TimeUnit rateUnit, TimeUnit timestampPrecision, TimeUnit durationUnit, MetricFilter filter,
            MetricsCollectPeriodConfig metricsReportPeriodConfig, Map<String, String> globalTags,
            MetricFormat metricFormat, CollectLevel collectLevel); @Override void start(long period, TimeUnit unit); @Override void report(Map<MetricName, Gauge> gauges, Map<MetricName, Counter> counters,
            Map<MetricName, Histogram> histograms, Map<MetricName, Meter> meters, Map<MetricName, Timer> timers,
            Map<MetricName, Compass> compasses, Map<MetricName, FastCompass> fastCompasses,
                       Map<MetricName, ClusterHistogram> clusterHistogrames); void writeMetricObjectToFile(List<MetricObject> metricObjects); void setAdvancedMetricsReport(boolean advancedMetricsReport); void setWriteMetricToFile(boolean writeMetricToFile);  }
@Test public void testDisableWriteToFile() throws InterruptedException { IMetricManager metricManager = MetricManager.getIMetricManager(); metricManager.clear(); RollingFileAppender fileAppender = mock(RollingFileAppender.class); BinAppender binAppender = mock(BinAppender.class); MetricsCollectPeriodConfig config = new MetricsCollectPeriodConfig(3); config.configPeriod(MetricLevel.CRITICAL, 1); StructMetricManagerReporter reporter = new StructMetricManagerReporter(metricManager, binAppender, fileAppender, Clock.defaultClock(), TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, MetricFilter.ALL, config, new HashMap<String, String>(), new JsonMetricFormat(), CollectLevel.CLASSIFIER); long period = 1; try { reporter.start(period, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); } Counter c = MetricManager.getCounter("struct", MetricName.build("AAA") .tagged("hi", null).level(MetricLevel.CRITICAL)); c.inc(10000); TimeUnit.MILLISECONDS.sleep(2200); verify(fileAppender, times(0)).append((byte[]) any()); }