NicoK commented on a change in pull request #10113: [FLINK-13749][client] Make 
PackagedProgram respect classloading policy
URL: https://github.com/apache/flink/pull/10113#discussion_r344183542
 
 

 ##########
 File path: 
flink-tests/src/test/java/org/apache/flink/test/classloading/ClassLoaderITCase.java
 ##########
 @@ -376,4 +390,72 @@ public void testDisposeSavepointWithCustomKvState() 
throws Exception {
                invokeThread.join(deadline.timeLeft().toMillis());
                assertFalse("Program invoke thread still running", 
invokeThread.isAlive());
        }
+
+       @Test
+       public void testProgramWithChildFirstClassLoader() throws IOException, 
ProgramInvocationException {
+               // We have two files named test-resource in src/resource 
(parent classloader classpath) and
+               // tmp folders (child classloader classpath) respectively.
+               String childResourceDirName = "child0";
+               String testResourceName = "test-resource";
+               File childResourceDir = FOLDER.newFolder(childResourceDirName);
+               File childResource = new 
File(childResourceDir.getAbsolutePath() + File.separator + testResourceName);
+               Files.touch(childResource);
+
+               TestStreamEnvironment.setAsContext(
+                       miniClusterResource.getMiniCluster(),
+                       parallelism,
+                       Collections.singleton(new 
Path(CLASSLOADING_POLICY_JAR_PATH)),
+                       Collections.emptyList());
+
+               // default child first classloading
+               final PackagedProgram childFirstProgram = new PackagedProgram(
+                               new File(CLASSLOADING_POLICY_JAR_PATH),
+                               
Lists.newArrayList(childResourceDir.toURI().toURL()),
+                               new Configuration(),
+                               new String[]{testResourceName, 
childResourceDirName}
+                       );
+
+               final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
+               
Thread.currentThread().setContextClassLoader(childFirstProgram.getUserCodeClassLoader());
+               try {
+                       childFirstProgram.invokeInteractiveModeForExecution();
+               } finally {
+                       
Thread.currentThread().setContextClassLoader(contextClassLoader);
+               }
+       }
+
+       @Test
+       public void testProgramWithParentFirstClassLoader() throws IOException, 
ProgramInvocationException {
+               // We have two files named test-resource in src/resource 
(parent classloader classpath) and
+               // tmp folders (child classloader classpath) respectively.
+               String childResourceDirName = "child1";
+               String testResourceName = "test-resource";
+               File childResourceDir = FOLDER.newFolder(childResourceDirName);
+               File childResource = new 
File(childResourceDir.getAbsolutePath() + File.separator + testResourceName);
+               Files.touch(childResource);
+
+               TestStreamEnvironment.setAsContext(
+                       miniClusterResource.getMiniCluster(),
+                       parallelism,
+                       Collections.singleton(new 
Path(CLASSLOADING_POLICY_JAR_PATH)),
+                       Collections.emptyList());
+               final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
+
+               // parent-first classloading
+               Configuration parentFirstConf = new Configuration();
+               parentFirstConf.setString("classloader.resolve-order", 
"parent-first");
+               final PackagedProgram parentFirstProgram = new PackagedProgram(
+                       new File(CLASSLOADING_POLICY_JAR_PATH),
+                       Lists.newArrayList(childResourceDir.toURI().toURL()),
+                       parentFirstConf,
+                       new String[]{testResourceName, "test-classes"}
 
 Review comment:
   ```suggestion
                        testResourceName, "test-classes"
   ```

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


With regards,
Apache Git Services

Reply via email to