Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ object SparkSession extends Logging {
sparkContext.addSparkListener(new SparkListener {
override def onApplicationEnd(applicationEnd: SparkListenerApplicationEnd): Unit = {
defaultSession.set(null)
listenerRegistered.set(false)
}
})
listenerRegistered.set(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,21 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
assert(session.conf.get(GLOBAL_TEMP_DATABASE) === "globaltempdb-spark-31532-2")
assert(session.conf.get(WAREHOUSE_PATH) === "SPARK-31532-db-2")
}

test("SPARK-32062: reset listenerRegistered in SparkSession") {
Copy link
Contributor

@cloud-fan cloud-fan Jun 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test relies on other tests to create and stop spark session, which is fragile.

Can we explicitly create and stop a spark session in this test?

(1 to 2).foreach { i =>
val conf = new SparkConf()
.setMaster("local")
.setAppName(s"test-SPARK-32062-$i")
val context = new SparkContext(conf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work? The test doesn't stop the spark context, and AFAIK we don't support having multiple spark context instance at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed it.

val beforeListenerSize = context.listenerBus.listeners.size()
SparkSession
.builder()
.sparkContext(context)
.getOrCreate()
val afterListenerSize = context.listenerBus.listeners.size()
assert(beforeListenerSize + 1 == afterListenerSize)
context.stop()
}
}
}