diff --git a/streaming/src/test/scala/org/apache/spark/streaming/rdd/TrackStateRDDSuite.scala b/streaming/src/test/scala/org/apache/spark/streaming/rdd/TrackStateRDDSuite.scala index fc5f26607ef98..f396b76e8d251 100644 --- a/streaming/src/test/scala/org/apache/spark/streaming/rdd/TrackStateRDDSuite.scala +++ b/streaming/src/test/scala/org/apache/spark/streaming/rdd/TrackStateRDDSuite.scala @@ -28,11 +28,17 @@ import org.apache.spark.{HashPartitioner, SparkConf, SparkContext, SparkFunSuite class TrackStateRDDSuite extends SparkFunSuite with BeforeAndAfterAll { - private var sc = new SparkContext( - new SparkConf().setMaster("local").setAppName("TrackStateRDDSuite")) + private var sc: SparkContext = null + + override def beforeAll(): Unit = { + sc = new SparkContext( + new SparkConf().setMaster("local").setAppName("TrackStateRDDSuite")) + } override def afterAll(): Unit = { - sc.stop() + if (sc != null) { + sc.stop() + } } test("creation from pair RDD") {