Skip to content

Commit

Permalink
Fix parent calling class loader issue
Browse files Browse the repository at this point in the history
  • Loading branch information
holdenk committed Apr 8, 2014
1 parent 8a67302 commit 4919bf9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public ParentClassLoader(ClassLoader myParent) {

@Override
public Class<?> findClass(String name) throws ClassNotFoundException {
return super.findClass(name);
return super.loadClass(name);
}

@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
return super.loadClass(name);
}
}
9 changes: 9 additions & 0 deletions core/src/test/resources/classes2/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Implementation-Vendor: fake-spark-class
Implementation-Title: fake spark class
Implementation-Version: 0.0.1
Implementation-Vendor-Id: fake-spark-class
Specification-Vendor: fake-spark-class
Specification-Title: fake spark class
Specification-Version: 0.0.1

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified core/src/test/resources/fake-spark-class-2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ExecutorURLClassLoaderSuite extends FunSuite {
val spark_home = sys.env.get("SPARK_HOME").orElse(sys.props.get("spark.home")).get
val urls = List(new File(spark_home + "/core/src/test/resources/fake-spark-class.jar").toURI.toURL).toArray
val urls2 = List(new File(spark_home + "/core/src/test/resources/fake-spark-class-2.jar").toURI.toURL).toArray

test("child first") {
val parentLoader = new URLClassLoader(urls2, null)
val classLoader = new ChildExecutorURLClassLoader(urls, parentLoader)
Expand All @@ -42,4 +43,13 @@ class ExecutorURLClassLoaderSuite extends FunSuite {
val fakeClassVersion = fakeClass.toString
assert(fakeClassVersion === "2")
}

test("child first can fall back") {
val parentLoader = new URLClassLoader(urls2, null)
val classLoader = new ChildExecutorURLClassLoader(urls, parentLoader)
val fakeClass = classLoader.loadClass("org.apache.spark.test.FakeClass3").newInstance()
val fakeClassVersion = fakeClass.toString
assert(fakeClassVersion === "2")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ class ExecutorClassLoaderSuite extends FunSuite {
val fakeClassVersion = fakeClass.toString
assert(fakeClassVersion === "2")
}

test("child first can fall back") {
println("url1 "+url1)
val parentLoader = new URLClassLoader(urls2, null)
val classLoader = new ExecutorClassLoader(url1, parentLoader, true)
val fakeClass = classLoader.loadClass("org.apache.spark.test.FakeClass3").newInstance()
val fakeClassVersion = fakeClass.toString
assert(fakeClassVersion === "2")
}

}

0 comments on commit 4919bf9

Please sign in to comment.