Github user zsxwing commented on a diff in the pull request:
https://github.com/apache/spark/pull/12845#discussion_r62755446
--- Diff:
external/flume/src/test/scala/org/apache/spark/streaming/flume/FlumePollingStreamSuite.scala
---
@@ -24,29 +24,41 @@ import scala.collection.JavaConverters._
import scala.concurrent.duration._
import scala.language.postfixOps
-import org.scalatest.BeforeAndAfter
+import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.Eventually._
-import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.{SparkConf, SparkContext, SparkFunSuite}
import org.apache.spark.internal.Logging
import org.apache.spark.network.util.JavaUtils
import org.apache.spark.storage.StorageLevel
import org.apache.spark.streaming.{Seconds, StreamingContext,
TestOutputStream}
import org.apache.spark.streaming.dstream.ReceiverInputDStream
import org.apache.spark.util.{ManualClock, Utils}
-class FlumePollingStreamSuite extends SparkFunSuite with BeforeAndAfter
with Logging {
+class FlumePollingStreamSuite extends SparkFunSuite with BeforeAndAfterAll
with Logging {
val maxAttempts = 5
val batchDuration = Seconds(1)
+ @transient private var _sc: SparkContext = _
+
+ def sc: SparkContext = _sc
+
val conf = new SparkConf()
.setMaster("local[2]")
.setAppName(this.getClass.getSimpleName)
.set("spark.streaming.clock", "org.apache.spark.util.ManualClock")
val utils = new PollingFlumeTestUtils
+ override def beforeAll(): Unit = {
+ _sc = new SparkContext(conf)
+ }
+
+ override def afterAll(): Unit = {
+ _sc.stop()
--- End diff --
nit: it's better to check `_sc != null`:
```
if (_sc != null) {
_sc.stop()
_sc = null
}
```
So if `new SparkContext` fails, we don't hide it by a NPE.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]