JvmMetrics implements MetricsSource { public static JvmMetrics initSingleton(String processName, String sessionId) { return Singleton.INSTANCE.init(processName, sessionId); } @VisibleForTesting  JvmMetrics(String processName, String sessionId, boolean useThreadMXBean); @VisibleForTesting synchronized void registerIfNeeded(); void setPauseMonitor(final JvmPauseMonitor pauseMonitor); void setGcTimeMonitor(GcTimeMonitor gcTimeMonitor); static JvmMetrics create(String processName, String sessionId,
                                  MetricsSystem ms); static void reattach(MetricsSystem ms, JvmMetrics jvmMetrics); static JvmMetrics initSingleton(String processName, String sessionId); static void shutdownSingleton(); @Override void getMetrics(MetricsCollector collector, boolean all); static final float MEMORY_MAX_UNLIMITED_MB; }
@Test public void testJvmMetricsSingletonWithSameProcessName() { JvmMetrics jvmMetrics1 = org.apache.hadoop.metrics2.source.JvmMetrics .initSingleton("test", null); JvmMetrics jvmMetrics2 = org.apache.hadoop.metrics2.source.JvmMetrics .initSingleton("test", null); Assert.assertEquals("initSingleton should return the singleton instance", jvmMetrics1, jvmMetrics2); }
@Test public void testJvmMetricsSingletonWithDifferentProcessNames() { final String process1Name = "process1"; JvmMetrics jvmMetrics1 = org.apache.hadoop.metrics2.source.JvmMetrics .initSingleton(process1Name, null); final String process2Name = "process2"; JvmMetrics jvmMetrics2 = org.apache.hadoop.metrics2.source.JvmMetrics .initSingleton(process2Name, null); Assert.assertEquals("initSingleton should return the singleton instance", jvmMetrics1, jvmMetrics2); Assert.assertEquals("unexpected process name of the singleton instance", process1Name, jvmMetrics1.processName); Assert.assertEquals("unexpected process name of the singleton instance", process1Name, jvmMetrics2.processName); }