diff options
-rw-r--r-- | repl/src/test/scala/org/apache/spark/repl/ExecutorClassLoaderSuite.scala | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/repl/src/test/scala/org/apache/spark/repl/ExecutorClassLoaderSuite.scala b/repl/src/test/scala/org/apache/spark/repl/ExecutorClassLoaderSuite.scala index 3d622d42f4..6d274bddb7 100644 --- a/repl/src/test/scala/org/apache/spark/repl/ExecutorClassLoaderSuite.scala +++ b/repl/src/test/scala/org/apache/spark/repl/ExecutorClassLoaderSuite.scala @@ -24,7 +24,6 @@ import java.nio.charset.StandardCharsets import java.nio.file.{Paths, StandardOpenOption} import java.util -import scala.concurrent.duration._ import scala.io.Source import scala.language.implicitConversions @@ -34,8 +33,6 @@ import org.mockito.Mockito._ import org.mockito.invocation.InvocationOnMock import org.mockito.stubbing.Answer import org.scalatest.BeforeAndAfterAll -import org.scalatest.concurrent.Interruptor -import org.scalatest.concurrent.Timeouts._ import org.scalatest.mock.MockitoSugar import org.apache.spark._ @@ -61,7 +58,7 @@ class ExecutorClassLoaderSuite super.beforeAll() tempDir1 = Utils.createTempDir() tempDir2 = Utils.createTempDir() - url1 = "file://" + tempDir1 + url1 = tempDir1.toURI.toURL.toString urls2 = List(tempDir2.toURI.toURL).toArray childClassNames.foreach(TestUtils.createCompiledClass(_, tempDir1, "1")) parentResourceNames.foreach { x => @@ -118,8 +115,14 @@ class ExecutorClassLoaderSuite val resourceName: String = parentResourceNames.head val is = classLoader.getResourceAsStream(resourceName) assert(is != null, s"Resource $resourceName not found") - val content = Source.fromInputStream(is, "UTF-8").getLines().next() - assert(content.contains("resource"), "File doesn't contain 'resource'") + + val bufferedSource = Source.fromInputStream(is, "UTF-8") + Utils.tryWithSafeFinally { + val content = bufferedSource.getLines().next() + assert(content.contains("resource"), "File doesn't contain 'resource'") + } { + bufferedSource.close() + } } test("resources from parent") { @@ -128,8 +131,14 @@ class ExecutorClassLoaderSuite val resourceName: String = parentResourceNames.head val resources: util.Enumeration[URL] = classLoader.getResources(resourceName) assert(resources.hasMoreElements, s"Resource $resourceName not found") - val fileReader = Source.fromInputStream(resources.nextElement().openStream()).bufferedReader() - assert(fileReader.readLine().contains("resource"), "File doesn't contain 'resource'") + + val bufferedSource = Source.fromInputStream(resources.nextElement().openStream()) + Utils.tryWithSafeFinally { + val fileReader = bufferedSource.bufferedReader() + assert(fileReader.readLine().contains("resource"), "File doesn't contain 'resource'") + } { + bufferedSource.close() + } } test("fetch classes using Spark's RpcEnv") { |