StartupProgressMetrics implements MetricsSource { @Override public void getMetrics(MetricsCollector collector, boolean all) { StartupProgressView prog = startupProgress.createView(); MetricsRecordBuilder builder = collector.addRecord( STARTUP_PROGRESS_METRICS_INFO); builder.addCounter(info("ElapsedTime", "overall elapsed time"), prog.getElapsedTime()); builder.addGauge(info("PercentComplete", "overall percent complete"), prog.getPercentComplete()); for (Phase phase: prog.getPhases()) { addCounter(builder, phase, "Count", " count", prog.getCount(phase)); addCounter(builder, phase, "ElapsedTime", " elapsed time", prog.getElapsedTime(phase)); addCounter(builder, phase, "Total", " total", prog.getTotal(phase)); addGauge(builder, phase, "PercentComplete", " percent complete", prog.getPercentComplete(phase)); } } StartupProgressMetrics(StartupProgress startupProgress); static void register(StartupProgress prog); @Override void getMetrics(MetricsCollector collector, boolean all);  }
@Test public void testInitialState() { MetricsRecordBuilder builder = getMetrics(metrics, true); assertCounter("ElapsedTime", 0L, builder); assertGauge("PercentComplete", 0.0f, builder); assertCounter("SafeModeCount", 0L, builder); assertCounter("SafeModeElapsedTime", 0L, builder); assertCounter("SafeModeTotal", 0L, builder); assertGauge("SafeModePercentComplete", 0.0f, builder); }
@Test public void testFinalState() { setStartupProgressForFinalState(startupProgress); MetricsRecordBuilder builder = getMetrics(metrics, true); assertTrue(getLongCounter("ElapsedTime", builder) >= 0L); assertGauge("PercentComplete", 1.0f, builder); assertCounter("SafeModeCount", 400L, builder); assertTrue(getLongCounter("SafeModeElapsedTime", builder) >= 0L); assertCounter("SafeModeTotal", 400L, builder); assertGauge("SafeModePercentComplete", 1.0f, builder); }