### Question:
MetricUtils { @VisibleForTesting static void instantiateHeapMemoryMetrics(final MetricGroup metricGroup) { instantiateMemoryUsageMetrics(metricGroup, () -> ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()); } private  MetricUtils(); static JobManagerMetricGroup instantiateJobManagerMetricGroup(
			final MetricRegistry metricRegistry,
			final String hostname,
			final Optional<Time> systemResourceProbeInterval); static Tuple2<TaskManagerMetricGroup, MetricGroup> instantiateTaskManagerMetricGroup(
			MetricRegistry metricRegistry,
			String hostName,
			ResourceID resourceID,
			Optional<Time> systemResourceProbeInterval); static void instantiateStatusMetrics(
			MetricGroup metricGroup); static RpcService startMetricsRpcService(Configuration configuration, String hostname);  }### Answer:
@Test public void testHeapMetricsCompleteness() { final InterceptingOperatorMetricGroup heapMetrics = new InterceptingOperatorMetricGroup(); MetricUtils.instantiateHeapMemoryMetrics(heapMetrics); Assert.assertNotNull(heapMetrics.get(MetricNames.MEMORY_USED)); Assert.assertNotNull(heapMetrics.get(MetricNames.MEMORY_COMMITTED)); Assert.assertNotNull(heapMetrics.get(MetricNames.MEMORY_MAX)); }
@Test public void testHeapMetrics() throws Exception { final InterceptingOperatorMetricGroup heapMetrics = new InterceptingOperatorMetricGroup(); MetricUtils.instantiateHeapMemoryMetrics(heapMetrics); @SuppressWarnings("unchecked") final Gauge<Long> used = (Gauge<Long>) heapMetrics.get(MetricNames.MEMORY_USED); final long usedHeapInitially = used.getValue(); for (int x = 0; x < 10; x++) { final byte[] array = new byte[1024 * 1024 * 8]; final long usedHeapAfterAllocation = used.getValue(); if (usedHeapInitially != usedHeapAfterAllocation) { return; } Thread.sleep(50); } Assert.fail("Heap usage metric never changed it's value."); }