Skip to content

Commit 722ff96

Browse files
Marcelo Vanzinmtbrandy
authored andcommitted
[SPARK-8126] [BUILD] Use custom temp directory during build.
Even with all the efforts to cleanup the temp directories created by unit tests, Spark leaves a lot of garbage in /tmp after a test run. This change overrides java.io.tmpdir to place those files under the build directory instead. After an sbt full unit test run, I was left with > 400 MB of temp files. Since they're now under the build dir, it's much easier to clean them up. Also make a slight change to a unit test to make it not pollute the source directory with test data. Author: Marcelo Vanzin <[email protected]> Closes apache#6674 from vanzin/SPARK-8126 and squashes the following commits: 0f8ad41 [Marcelo Vanzin] Make sure tmp dir exists when tests run. 643e916 [Marcelo Vanzin] [MINOR] [BUILD] Use custom temp directory during build.
1 parent 7e670df commit 722ff96

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

core/src/test/scala/org/apache/spark/deploy/SparkSubmitUtilsSuite.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ import org.apache.ivy.core.settings.IvySettings
2727
import org.apache.ivy.plugins.resolver.IBiblioResolver
2828

2929
import org.apache.spark.deploy.SparkSubmitUtils.MavenCoordinate
30+
import org.apache.spark.util.Utils
3031

3132
class SparkSubmitUtilsSuite extends FunSuite with BeforeAndAfterAll {
3233

34+
private var tempIvyPath: String = _
35+
3336
private val noOpOutputStream = new OutputStream {
3437
def write(b: Int) = {}
3538
}
@@ -46,6 +49,7 @@ class SparkSubmitUtilsSuite extends FunSuite with BeforeAndAfterAll {
4649
super.beforeAll()
4750
// We don't want to write logs during testing
4851
SparkSubmitUtils.printStream = new BufferPrintStream
52+
tempIvyPath = Utils.createTempDir(namePrefix = "ivy").getAbsolutePath()
4953
}
5054

5155
test("incorrect maven coordinate throws error") {
@@ -89,21 +93,20 @@ class SparkSubmitUtilsSuite extends FunSuite with BeforeAndAfterAll {
8993
}
9094

9195
test("ivy path works correctly") {
92-
val ivyPath = "dummy" + File.separator + "ivy"
9396
val md = SparkSubmitUtils.getModuleDescriptor
9497
val artifacts = for (i <- 0 until 3) yield new MDArtifact(md, s"jar-$i", "jar", "jar")
95-
var jPaths = SparkSubmitUtils.resolveDependencyPaths(artifacts.toArray, new File(ivyPath))
98+
var jPaths = SparkSubmitUtils.resolveDependencyPaths(artifacts.toArray, new File(tempIvyPath))
9699
for (i <- 0 until 3) {
97-
val index = jPaths.indexOf(ivyPath)
100+
val index = jPaths.indexOf(tempIvyPath)
98101
assert(index >= 0)
99-
jPaths = jPaths.substring(index + ivyPath.length)
102+
jPaths = jPaths.substring(index + tempIvyPath.length)
100103
}
101104
val main = MavenCoordinate("my.awesome.lib", "mylib", "0.1")
102105
IvyTestUtils.withRepository(main, None, None) { repo =>
103106
// end to end
104107
val jarPath = SparkSubmitUtils.resolveMavenCoordinates(main.toString, Option(repo),
105-
Option(ivyPath), true)
106-
assert(jarPath.indexOf(ivyPath) >= 0, "should use non-default ivy path")
108+
Option(tempIvyPath), true)
109+
assert(jarPath.indexOf(tempIvyPath) >= 0, "should use non-default ivy path")
107110
}
108111
}
109112

@@ -122,13 +125,12 @@ class SparkSubmitUtilsSuite extends FunSuite with BeforeAndAfterAll {
122125
assert(jarPath.indexOf("mylib") >= 0, "should find artifact")
123126
}
124127
// Local ivy repository with modified home
125-
val dummyIvyPath = "dummy" + File.separator + "ivy"
126-
val dummyIvyLocal = new File(dummyIvyPath, "local" + File.separator)
128+
val dummyIvyLocal = new File(tempIvyPath, "local" + File.separator)
127129
IvyTestUtils.withRepository(main, None, Some(dummyIvyLocal), true) { repo =>
128130
val jarPath = SparkSubmitUtils.resolveMavenCoordinates(main.toString, None,
129-
Some(dummyIvyPath), true)
131+
Some(tempIvyPath), true)
130132
assert(jarPath.indexOf("mylib") >= 0, "should find artifact")
131-
assert(jarPath.indexOf(dummyIvyPath) >= 0, "should be in new ivy path")
133+
assert(jarPath.indexOf(tempIvyPath) >= 0, "should be in new ivy path")
132134
}
133135
}
134136

pom.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
<parquet.deps.scope>compile</parquet.deps.scope>
181181

182182
<!--
183-
Overridable test home. So that you can call individual pom files directory without
183+
Overridable test home. So that you can call individual pom files directly without
184184
things breaking.
185185
-->
186186
<spark.test.home>${session.executionRootDirectory}</spark.test.home>
@@ -1253,6 +1253,7 @@
12531253
</environmentVariables>
12541254
<systemProperties>
12551255
<java.awt.headless>true</java.awt.headless>
1256+
<java.io.tmpdir>${project.build.directory}/tmp</java.io.tmpdir>
12561257
<spark.test.home>${spark.test.home}</spark.test.home>
12571258
<spark.testing>1</spark.testing>
12581259
<spark.ui.enabled>false</spark.ui.enabled>
@@ -1285,6 +1286,7 @@
12851286
</environmentVariables>
12861287
<systemProperties>
12871288
<java.awt.headless>true</java.awt.headless>
1289+
<java.io.tmpdir>${project.build.directory}/tmp</java.io.tmpdir>
12881290
<spark.test.home>${spark.test.home}</spark.test.home>
12891291
<spark.testing>1</spark.testing>
12901292
<spark.ui.enabled>false</spark.ui.enabled>
@@ -1542,6 +1544,26 @@
15421544
</execution>
15431545
</executions>
15441546
</plugin>
1547+
1548+
<plugin>
1549+
<groupId>org.apache.maven.plugins</groupId>
1550+
<artifactId>maven-antrun-plugin</artifactId>
1551+
<executions>
1552+
<execution>
1553+
<id>create-tmp-dir</id>
1554+
<phase>generate-test-resources</phase>
1555+
<goals>
1556+
<goal>run</goal>
1557+
</goals>
1558+
<configuration>
1559+
<target>
1560+
<mkdir dir="${project.build.directory}/tmp" />
1561+
</target>
1562+
</configuration>
1563+
</execution>
1564+
</executions>
1565+
</plugin>
1566+
15451567
<!-- Enable surefire and scalatest in all children, in one place: -->
15461568
<plugin>
15471569
<groupId>org.apache.maven.plugins</groupId>

project/SparkBuild.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ object BuildCommons {
5151
// Root project.
5252
val spark = ProjectRef(buildLocation, "spark")
5353
val sparkHome = buildLocation
54+
55+
val testTempDir = s"$sparkHome/target/tmp"
56+
if (!new File(testTempDir).isDirectory()) {
57+
require(new File(testTempDir).mkdirs())
58+
}
5459
}
5560

5661
object SparkBuild extends PomBuild {
@@ -507,6 +512,7 @@ object TestSettings {
507512
"SPARK_DIST_CLASSPATH" ->
508513
(fullClasspath in Test).value.files.map(_.getAbsolutePath).mkString(":").stripSuffix(":"),
509514
"JAVA_HOME" -> sys.env.get("JAVA_HOME").getOrElse(sys.props("java.home"))),
515+
javaOptions in Test += s"-Djava.io.tmpdir=$testTempDir",
510516
javaOptions in Test += "-Dspark.test.home=" + sparkHome,
511517
javaOptions in Test += "-Dspark.testing=1",
512518
javaOptions in Test += "-Dspark.port.maxRetries=100",

0 commit comments

Comments
 (0)