kezhuw commented on a change in pull request #15039:
URL: https://github.com/apache/flink/pull/15039#discussion_r590244694



##########
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:
       Hi @zentol, I have changed to `loadClass`, now the test concentrates 
more on define/load a class but not initialize. 

##########
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);
+
+        Assert.assertNotSame(clazz, newClass);
+        Assert.assertEquals(clazz.getName(), newClass.getName());
+        return (Class<Dummy>) newClass;
+    }

Review comment:
       Changed.




----------------------------------------------------------------
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


Reply via email to