kezhuw commented on a change in pull request #15039: URL: https://github.com/apache/flink/pull/15039#discussion_r587362929
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/metrics/util/MetricUtilsTest.java ########## @@ -175,24 +183,20 @@ public MetricGroup addGroup(String name) { @SuppressWarnings("unchecked") final Gauge<Long> used = (Gauge<Long>) metaspaceMetrics.get(MetricNames.MEMORY_USED); - final long usedMetaspaceInitially = used.getValue(); + runUntilMetricChanged("Metaspace", 10, () -> redefineAsNewClass(MetricUtils.class), used); + } - // check memory usage difference multiple times since other tests may affect memory usage as - // well - for (int x = 0; x < 10; x++) { - List<Runnable> consumerList = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - consumerList.add(() -> {}); - } + @Test + public void testNonHeapMetricUsageNotStatic() throws Exception { + final InterceptingOperatorMetricGroup nonHeapMetrics = + new InterceptingOperatorMetricGroup(); - final long usedMetaspaceAfterAllocation = used.getValue(); + MetricUtils.instantiateNonHeapMemoryMetrics(nonHeapMetrics); - if (usedMetaspaceInitially != usedMetaspaceAfterAllocation) { - return; - } - Thread.sleep(50); - } - Assert.fail("Metaspace usage metric never changed it's value."); + @SuppressWarnings("unchecked") + final Gauge<Long> used = (Gauge<Long>) nonHeapMetrics.get(MetricNames.MEMORY_USED); + + runUntilMetricChanged("Non-heap", 10, () -> redefineAsNewClass(MetricUtils.class), used); Review comment: @zentol Did you means named method and method reference ? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org