Skip to content

Commit e221108

Browse files
andrewor14pwendell
authored andcommitted
[HOTFIX] Do not throw NPE if spark.test.home is not set
`spark.test.home` was introduced in #1734. This is fine for SBT but is failing maven tests. Either way it shouldn't throw an NPE. Author: Andrew Or <[email protected]> Closes #1739 from andrewor14/fix-spark-test-home and squashes the following commits: ce2624c [Andrew Or] Do not throw NPE if spark.test.home is not set
1 parent 87738bf commit e221108

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

core/src/main/scala/org/apache/spark/deploy/worker/Worker.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private[spark] class Worker(
7171
// TTL for app folders/data; after TTL expires it will be cleaned up
7272
val APP_DATA_RETENTION_SECS = conf.getLong("spark.worker.cleanup.appDataTtl", 7 * 24 * 3600)
7373

74-
74+
val testing: Boolean = sys.props.contains("spark.testing")
7575
val masterLock: Object = new Object()
7676
var master: ActorSelection = null
7777
var masterAddress: Address = null
@@ -82,7 +82,12 @@ private[spark] class Worker(
8282
@volatile var connected = false
8383
val workerId = generateWorkerId()
8484
val sparkHome =
85-
new File(sys.props.get("spark.test.home").orElse(sys.env.get("SPARK_HOME")).getOrElse("."))
85+
if (testing) {
86+
assert(sys.props.contains("spark.test.home"), "spark.test.home is not set!")
87+
new File(sys.props("spark.test.home"))
88+
} else {
89+
new File(sys.env.get("SPARK_HOME").getOrElse("."))
90+
}
8691
var workDir: File = null
8792
val executors = new HashMap[String, ExecutorRunner]
8893
val finishedExecutors = new HashMap[String, ExecutorRunner]

core/src/test/scala/org/apache/spark/DriverSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import scala.language.postfixOps
3434
class DriverSuite extends FunSuite with Timeouts {
3535

3636
test("driver should exit after finishing") {
37-
val sparkHome = sys.props("spark.test.home")
37+
val sparkHome = sys.props.getOrElse("spark.test.home", fail("spark.test.home is not set!"))
3838
// Regression test for SPARK-530: "Spark driver process doesn't exit after finishing"
3939
val masters = Table(("master"), ("local"), ("local-cluster[2,1,512]"))
4040
forAll(masters) { (master: String) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class SparkSubmitSuite extends FunSuite with Matchers {
295295

296296
// NOTE: This is an expensive operation in terms of time (10 seconds+). Use sparingly.
297297
def runSparkSubmit(args: Seq[String]): String = {
298-
val sparkHome = sys.props("spark.test.home")
298+
val sparkHome = sys.props.getOrElse("spark.test.home", fail("spark.test.home is not set!"))
299299
Utils.executeAndGetOutput(
300300
Seq("./bin/spark-submit") ++ args,
301301
new File(sparkHome),

core/src/test/scala/org/apache/spark/deploy/worker/ExecutorRunnerTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.apache.spark.SparkConf
2727
class ExecutorRunnerTest extends FunSuite {
2828
test("command includes appId") {
2929
def f(s:String) = new File(s)
30-
val sparkHome = sys.props("spark.test.home")
30+
val sparkHome = sys.props.getOrElse("spark.test.home", fail("spark.test.home is not set!"))
3131
val appDesc = new ApplicationDescription("app name", Some(8), 500,
3232
Command("foo", Seq(), Map(), Seq(), Seq(), Seq()), "appUiUrl")
3333
val appId = "12345-worker321-9876"

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,10 @@
868868
<filereports>${project.build.directory}/SparkTestSuite.txt</filereports>
869869
<argLine>-Xmx3g -XX:MaxPermSize=${MaxPermGen} -XX:ReservedCodeCacheSize=512m</argLine>
870870
<stderr/>
871-
<environmentVariables>
872-
<SPARK_HOME>${session.executionRootDirectory}</SPARK_HOME>
873-
<SPARK_TESTING>1</SPARK_TESTING>
874-
</environmentVariables>
871+
<systemProperties>
872+
<spark.test.home>${session.executionRootDirectory}</spark.test.home>
873+
<spark.testing>1</spark.testing>
874+
</systemProperties>
875875
</configuration>
876876
<executions>
877877
<execution>

0 commit comments

Comments
 (0)