aboutsummaryrefslogtreecommitdiff
path: root/mllib/src/test/scala/org/apache
diff options
context:
space:
mode:
authorHyukjin Kwon <gurwls223@gmail.com>2016-11-07 12:47:39 -0800
committerMridul Muralidharan <mridul@gmail.com>2016-11-07 12:47:39 -0800
commit8f0ea011a7294679ec4275b2fef349ef45b6eb81 (patch)
tree9599da11d56741c69b408771fa59255541f0e57d /mllib/src/test/scala/org/apache
parent0d95662e7fff26669d4f70e88fdac7a4128a4f49 (diff)
downloadspark-8f0ea011a7294679ec4275b2fef349ef45b6eb81.tar.gz
spark-8f0ea011a7294679ec4275b2fef349ef45b6eb81.tar.bz2
spark-8f0ea011a7294679ec4275b2fef349ef45b6eb81.zip
[SPARK-14914][CORE] Fix Resource not closed after using, mostly for unit tests
## What changes were proposed in this pull request? Close `FileStreams`, `ZipFiles` etc to release the resources after using. Not closing the resources will cause IO Exception to be raised while deleting temp files. ## How was this patch tested? Existing tests Author: U-FAREAST\tl <tl@microsoft.com> Author: hyukjinkwon <gurwls223@gmail.com> Author: Tao LI <tl@microsoft.com> Closes #15618 from HyukjinKwon/SPARK-14914-1.
Diffstat (limited to 'mllib/src/test/scala/org/apache')
-rw-r--r--mllib/src/test/scala/org/apache/spark/mllib/util/MLUtilsSuite.scala16
1 files changed, 10 insertions, 6 deletions
diff --git a/mllib/src/test/scala/org/apache/spark/mllib/util/MLUtilsSuite.scala b/mllib/src/test/scala/org/apache/spark/mllib/util/MLUtilsSuite.scala
index e4e9be39ff..665708a780 100644
--- a/mllib/src/test/scala/org/apache/spark/mllib/util/MLUtilsSuite.scala
+++ b/mllib/src/test/scala/org/apache/spark/mllib/util/MLUtilsSuite.scala
@@ -155,13 +155,17 @@ class MLUtilsSuite extends SparkFunSuite with MLlibTestSparkContext {
val tempDir = Utils.createTempDir()
val outputDir = new File(tempDir, "output")
MLUtils.saveAsLibSVMFile(examples, outputDir.toURI.toString)
- val lines = outputDir.listFiles()
+ val sources = outputDir.listFiles()
.filter(_.getName.startsWith("part-"))
- .flatMap(Source.fromFile(_).getLines())
- .toSet
- val expected = Set("1.1 1:1.23 3:4.56", "0.0 1:1.01 2:2.02 3:3.03")
- assert(lines === expected)
- Utils.deleteRecursively(tempDir)
+ .map(Source.fromFile)
+ Utils.tryWithSafeFinally {
+ val lines = sources.flatMap(_.getLines()).toSet
+ val expected = Set("1.1 1:1.23 3:4.56", "0.0 1:1.01 2:2.02 3:3.03")
+ assert(lines === expected)
+ } {
+ sources.foreach(_.close())
+ Utils.deleteRecursively(tempDir)
+ }
}
test("appendBias") {