Skip to content

Commit

Permalink
[hotfix] Simplify tests in ClassLoaderITCase
Browse files Browse the repository at this point in the history
This also makes child-first classloading explicit in the test instead of
relying on the default.
  • Loading branch information
aljoscha committed Nov 15, 2019
1 parent ae553ac commit a599b00
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void testProgramWithChildFirstClassLoader() throws IOException, ProgramIn
String childResourceDirName = "child0";
String testResourceName = "test-resource";
File childResourceDir = FOLDER.newFolder(childResourceDirName);
File childResource = new File(childResourceDir.getAbsolutePath() + File.separator + testResourceName);
File childResource = new File(childResourceDir, testResourceName);
assertTrue(childResource.createNewFile());

TestStreamEnvironment.setAsContext(
Expand All @@ -404,10 +404,14 @@ public void testProgramWithChildFirstClassLoader() throws IOException, ProgramIn
Collections.singleton(new Path(CLASSLOADING_POLICY_JAR_PATH)),
Collections.emptyList());

// default child first classloading
// child-first classloading
Configuration childFirstConf = new Configuration();
childFirstConf.setString("classloader.resolve-order", "child-first");

final PackagedProgram childFirstProgram = PackagedProgram.newBuilder()
.setJarFile(new File(CLASSLOADING_POLICY_JAR_PATH))
.setUserClassPaths(Collections.singletonList(childResourceDir.toURI().toURL()))
.setConfiguration(childFirstConf)
.setArguments(testResourceName, childResourceDirName)
.build();

Expand All @@ -427,15 +431,14 @@ public void testProgramWithParentFirstClassLoader() throws IOException, ProgramI
String childResourceDirName = "child1";
String testResourceName = "test-resource";
File childResourceDir = FOLDER.newFolder(childResourceDirName);
File childResource = new File(childResourceDir.getAbsolutePath() + File.separator + testResourceName);
File childResource = new File(childResourceDir, testResourceName);
assertTrue(childResource.createNewFile());

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();
Expand All @@ -448,6 +451,7 @@ public void testProgramWithParentFirstClassLoader() throws IOException, ProgramI
.setArguments(testResourceName, "test-classes")
.build();

final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(parentFirstProgram.getUserCodeClassLoader());
try {
parentFirstProgram.invokeInteractiveModeForExecution();
Expand Down

0 comments on commit a599b00

Please sign in to comment.