zentol commented on a change in pull request #15927:
URL: https://github.com/apache/flink/pull/15927#discussion_r635086541
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/execution/librarycache/FlinkUserCodeClassLoadersTest.java
##########
@@ -208,6 +212,64 @@ public void testRepeatedParentFirstPatternClass() throws
Exception {
childClassLoader.close();
}
+ @Test
+ public void testGetClassLoaderInfo() {
+ final String className = FlinkUserCodeClassLoadersTest.class.getName();
+ final String parentFirstPattern = className.substring(0,
className.lastIndexOf('.'));
+
+ final ClassLoader parentClassLoader = getClass().getClassLoader();
+
+ final URL childCodePath =
getClass().getProtectionDomain().getCodeSource().getLocation();
+
+ final URLClassLoader childClassLoader =
+ FlinkUserCodeClassLoaders.childFirst(
+ new URL[] {childCodePath},
+ parentClassLoader,
+ new String[] {parentFirstPattern},
+ NOOP_EXCEPTION_HANDLER,
+ true);
+
+ String formattedURL = null;
+ try {
+ formattedURL = ClassLoaderUtil.formatURL(childCodePath);
+ } catch (IOException e) {
+ // Should not fail here
+ fail();
+ }
Review comment:
```suggestion
String formattedURL = ClassLoaderUtil.formatURL(childCodePath);
```
Let the exception bubble up
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/execution/librarycache/FlinkUserCodeClassLoadersTest.java
##########
@@ -208,6 +212,64 @@ public void testRepeatedParentFirstPatternClass() throws
Exception {
childClassLoader.close();
}
+ @Test
+ public void testGetClassLoaderInfo() {
+ final String className = FlinkUserCodeClassLoadersTest.class.getName();
+ final String parentFirstPattern = className.substring(0,
className.lastIndexOf('.'));
Review comment:
why is this necessary?
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/execution/librarycache/FlinkUserCodeClassLoadersTest.java
##########
@@ -208,6 +212,64 @@ public void testRepeatedParentFirstPatternClass() throws
Exception {
childClassLoader.close();
}
+ @Test
+ public void testGetClassLoaderInfo() {
+ final String className = FlinkUserCodeClassLoadersTest.class.getName();
+ final String parentFirstPattern = className.substring(0,
className.lastIndexOf('.'));
+
+ final ClassLoader parentClassLoader = getClass().getClassLoader();
+
+ final URL childCodePath =
getClass().getProtectionDomain().getCodeSource().getLocation();
+
+ final URLClassLoader childClassLoader =
+ FlinkUserCodeClassLoaders.childFirst(
+ new URL[] {childCodePath},
+ parentClassLoader,
+ new String[] {parentFirstPattern},
+ NOOP_EXCEPTION_HANDLER,
+ true);
+
+ String formattedURL = null;
+ try {
+ formattedURL = ClassLoaderUtil.formatURL(childCodePath);
+ } catch (IOException e) {
+ // Should not fail here
+ fail();
+ }
+
+ assertEquals(
+ ClassLoaderUtil.getUserCodeClassLoaderInfo(childClassLoader),
+ "URL ClassLoader:" + formattedURL);
+ }
+
+ @Test
+ public void testGetClassLoaderInfoWithClassLoaderClosed() {
+ final String className = FlinkUserCodeClassLoadersTest.class.getName();
+ final String parentFirstPattern = className.substring(0,
className.lastIndexOf('.'));
+
+ final ClassLoader parentClassLoader = getClass().getClassLoader();
+
+ final URL childCodePath =
getClass().getProtectionDomain().getCodeSource().getLocation();
+
+ final URLClassLoader childClassLoader =
+ FlinkUserCodeClassLoaders.childFirst(
+ new URL[] {childCodePath},
+ parentClassLoader,
+ new String[] {parentFirstPattern},
+ NOOP_EXCEPTION_HANDLER,
+ true);
+
+ try {
+ childClassLoader.close();
+ } catch (IOException e) {
+ fail("Cannot close child classloader");
+ }
Review comment:
same as above
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/execution/librarycache/FlinkUserCodeClassLoadersTest.java
##########
@@ -208,6 +212,64 @@ public void testRepeatedParentFirstPatternClass() throws
Exception {
childClassLoader.close();
}
+ @Test
+ public void testGetClassLoaderInfo() {
+ final String className = FlinkUserCodeClassLoadersTest.class.getName();
+ final String parentFirstPattern = className.substring(0,
className.lastIndexOf('.'));
+
+ final ClassLoader parentClassLoader = getClass().getClassLoader();
+
+ final URL childCodePath =
getClass().getProtectionDomain().getCodeSource().getLocation();
+
+ final URLClassLoader childClassLoader =
+ FlinkUserCodeClassLoaders.childFirst(
+ new URL[] {childCodePath},
+ parentClassLoader,
+ new String[] {parentFirstPattern},
+ NOOP_EXCEPTION_HANDLER,
+ true);
+
+ String formattedURL = null;
+ try {
+ formattedURL = ClassLoaderUtil.formatURL(childCodePath);
+ } catch (IOException e) {
+ // Should not fail here
+ fail();
+ }
+
+ assertEquals(
+ ClassLoaderUtil.getUserCodeClassLoaderInfo(childClassLoader),
+ "URL ClassLoader:" + formattedURL);
+ }
+
+ @Test
+ public void testGetClassLoaderInfoWithClassLoaderClosed() {
+ final String className = FlinkUserCodeClassLoadersTest.class.getName();
+ final String parentFirstPattern = className.substring(0,
className.lastIndexOf('.'));
+
+ final ClassLoader parentClassLoader = getClass().getClassLoader();
+
+ final URL childCodePath =
getClass().getProtectionDomain().getCodeSource().getLocation();
+
+ final URLClassLoader childClassLoader =
+ FlinkUserCodeClassLoaders.childFirst(
+ new URL[] {childCodePath},
+ parentClassLoader,
+ new String[] {parentFirstPattern},
+ NOOP_EXCEPTION_HANDLER,
+ true);
+
+ try {
+ childClassLoader.close();
+ } catch (IOException e) {
+ fail("Cannot close child classloader");
+ }
+
+ assertTrue(
+ ClassLoaderUtil.getUserCodeClassLoaderInfo(childClassLoader)
+ .startsWith("Cannot access classloader info due to an
exception."));
Review comment:
use hamcrest matcher instead;
assertThat(...).(StringStartsWith.startsWith(...); it provides much better
error messages
--
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]