kezhuw commented on a change in pull request #15039:
URL: https://github.com/apache/flink/pull/15039#discussion_r590220431
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/metrics/util/MetricUtilsTest.java
##########
@@ -243,4 +240,59 @@ public MetricGroup addGroup(String name) {
METRIC_GROUP_MEMORY,
METRIC_GROUP_MANAGED_MEMORY)));
}
+
+ // --------------- utility methods and classes ---------------
+
+ /**
+ * An extreme simple class with no dependencies outside "java" package to
ease re-defining from
+ * its bytecode.
+ */
+ private static class Dummy {}
+
+ /**
+ * Define an new class using {@link Dummy} class's name and bytecode to
consume Metaspace and
+ * NonHeap memory.
+ */
+ @SuppressWarnings("unchecked")
+ private static Class<Dummy> redefineDummyClass() throws
ClassNotFoundException {
+ Class<?> clazz = Dummy.class;
+ ChildFirstClassLoader classLoader =
+ new ChildFirstClassLoader(
+ ClassLoaderUtils.getClasspathURLs(),
+ clazz.getClassLoader(),
+ new String[] {"java."},
+ ignored -> {});
+
+ Class<?> newClass = Class.forName(clazz.getName(), true, classLoader);
Review comment:
I think both should work for `Dummy`. But `Class.forName(initialize =
true)` does not work for `MetricUtils`. I keep it mainly as stringent legacy
from `MetricUtils` attempt.
----------------------------------------------------------------
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]