diff options
author | wm624@hotmail.com <wm624@hotmail.com> | 2016-11-10 10:54:36 +0000 |
---|---|---|
committer | Sean Owen <sowen@cloudera.com> | 2016-11-10 10:54:36 +0000 |
commit | 22a9d064e95af71f757113f1869f754cc862df35 (patch) | |
tree | 84ef9a282f54df6be1e44642863db65d2f4f8512 /core | |
parent | 96a59109a912db9d5f6fc07dedd9d8a3eee97b96 (diff) | |
download | spark-22a9d064e95af71f757113f1869f754cc862df35.tar.gz spark-22a9d064e95af71f757113f1869f754cc862df35.tar.bz2 spark-22a9d064e95af71f757113f1869f754cc862df35.zip |
[SPARK-14914][CORE] Fix Resource not closed after using, for unit tests and example
## What changes were proposed in this pull request?
This is a follow-up work of #15618.
Close file source;
For any newly created streaming context outside the withContext, explicitly close the context.
## How was this patch tested?
Existing unit tests.
Author: wm624@hotmail.com <wm624@hotmail.com>
Closes #15818 from wangmiao1981/rtest.
Diffstat (limited to 'core')
-rw-r--r-- | core/src/test/scala/org/apache/spark/util/MutableURLClassLoaderSuite.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/src/test/scala/org/apache/spark/util/MutableURLClassLoaderSuite.scala b/core/src/test/scala/org/apache/spark/util/MutableURLClassLoaderSuite.scala index 8b53d4f14a..f6ac89fc27 100644 --- a/core/src/test/scala/org/apache/spark/util/MutableURLClassLoaderSuite.scala +++ b/core/src/test/scala/org/apache/spark/util/MutableURLClassLoaderSuite.scala @@ -51,6 +51,8 @@ class MutableURLClassLoaderSuite extends SparkFunSuite with Matchers { assert(fakeClassVersion === "1") val fakeClass2 = classLoader.loadClass("FakeClass2").newInstance() assert(fakeClass.getClass === fakeClass2.getClass) + classLoader.close() + parentLoader.close() } test("parent first") { @@ -61,6 +63,8 @@ class MutableURLClassLoaderSuite extends SparkFunSuite with Matchers { assert(fakeClassVersion === "2") val fakeClass2 = classLoader.loadClass("FakeClass1").newInstance() assert(fakeClass.getClass === fakeClass2.getClass) + classLoader.close() + parentLoader.close() } test("child first can fall back") { @@ -69,6 +73,8 @@ class MutableURLClassLoaderSuite extends SparkFunSuite with Matchers { val fakeClass = classLoader.loadClass("FakeClass3").newInstance() val fakeClassVersion = fakeClass.toString assert(fakeClassVersion === "2") + classLoader.close() + parentLoader.close() } test("child first can fail") { @@ -77,6 +83,8 @@ class MutableURLClassLoaderSuite extends SparkFunSuite with Matchers { intercept[java.lang.ClassNotFoundException] { classLoader.loadClass("FakeClassDoesNotExist").newInstance() } + classLoader.close() + parentLoader.close() } test("default JDK classloader get resources") { @@ -84,6 +92,8 @@ class MutableURLClassLoaderSuite extends SparkFunSuite with Matchers { val classLoader = new URLClassLoader(fileUrlsChild, parentLoader) assert(classLoader.getResources("resource1").asScala.size === 2) assert(classLoader.getResources("resource2").asScala.size === 1) + classLoader.close() + parentLoader.close() } test("parent first get resources") { @@ -91,6 +101,8 @@ class MutableURLClassLoaderSuite extends SparkFunSuite with Matchers { val classLoader = new MutableURLClassLoader(fileUrlsChild, parentLoader) assert(classLoader.getResources("resource1").asScala.size === 2) assert(classLoader.getResources("resource2").asScala.size === 1) + classLoader.close() + parentLoader.close() } test("child first get resources") { @@ -103,6 +115,8 @@ class MutableURLClassLoaderSuite extends SparkFunSuite with Matchers { res1.map(scala.io.Source.fromURL(_).mkString) should contain inOrderOnly ("resource1Contents-child", "resource1Contents-parent") + classLoader.close() + parentLoader.close() } |