kezhuw commented on a change in pull request #15039:
URL: https://github.com/apache/flink/pull/15039#discussion_r584126047
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/metrics/util/MetricUtilsTest.java
##########
@@ -180,21 +241,54 @@ public MetricGroup addGroup(String name) {
// 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(() -> {});
- }
+ Class<MetricUtils> redefinedMetricUtilsClass =
redefineAsNewClass(MetricUtils.class);
final long usedMetaspaceAfterAllocation = used.getValue();
if (usedMetaspaceInitially != usedMetaspaceAfterAllocation) {
return;
}
+
+ // This assertion try to prevent local variable from gc in absent
of
+ // Reference.reachabilityFence.
+ Assert.assertNotSame(MetricUtils.class, redefinedMetricUtilsClass);
+
Thread.sleep(50);
}
Assert.fail("Metaspace usage metric never changed it's value.");
}
+ @Test
+ public void testNonHeapMetricUsageNotStatic() throws Exception {
+ final InterceptingOperatorMetricGroup nonHeapMetrics =
+ new InterceptingOperatorMetricGroup();
+
+ MetricUtils.instantiateNonHeapMemoryMetrics(nonHeapMetrics);
+
+ @SuppressWarnings("unchecked")
+ final Gauge<Long> used = (Gauge<Long>)
nonHeapMetrics.get(MetricNames.MEMORY_USED);
+
+ final long usedNonHeapInitially = used.getValue();
+
+ // check memory usage difference multiple times since other tests may
affect memory usage as
+ // well
+ for (int x = 0; x < 10; x++) {
Review comment:
@XComp Add `runUntilMetricChanged` to cover this.
----------------------------------------------------------------
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:
[email protected]