-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21345][SQL][TEST][test-maven] SparkSessionBuilderSuite should clean up stopped sessions. #18567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
[SPARK-21345][SQL][TEST][test-maven] SparkSessionBuilderSuite should clean up stopped sessions. #18567
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
443b33e
SparkSessionBuilderSuite should clean up stopped sessions.
dongjoon-hyun 1d5a0d0
Address comments.
dongjoon-hyun 9825810
Use BeforeAndAfterEach.
dongjoon-hyun 802163d
Clear afterEach instead of checking.
dongjoon-hyun 4f4b452
Address comment.
dongjoon-hyun 04f47ed
Remove session.stop at the end of the test.
dongjoon-hyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,50 +17,49 @@ | |
|
|
||
| package org.apache.spark.sql | ||
|
|
||
| import org.scalatest.BeforeAndAfterEach | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkContext, SparkFunSuite} | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| /** | ||
| * Test cases for the builder pattern of [[SparkSession]]. | ||
| */ | ||
| class SparkSessionBuilderSuite extends SparkFunSuite { | ||
| class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach { | ||
|
|
||
| private var initialSession: SparkSession = _ | ||
| override def afterEach(): Unit = { | ||
| // This suite should not interfere with the other test suites. | ||
| SparkSession.getActiveSession.foreach(_.stop()) | ||
| SparkSession.clearActiveSession() | ||
| SparkSession.getDefaultSession.foreach(_.stop()) | ||
| SparkSession.clearDefaultSession() | ||
| } | ||
|
|
||
| private lazy val sparkContext: SparkContext = { | ||
| initialSession = SparkSession.builder() | ||
| test("create with config options and propagate them to SparkContext and SparkSession") { | ||
| val session = SparkSession.builder() | ||
| .master("local") | ||
| .config("spark.ui.enabled", value = false) | ||
| .config("some-config", "v2") | ||
| .getOrCreate() | ||
| initialSession.sparkContext | ||
| } | ||
|
|
||
| test("create with config options and propagate them to SparkContext and SparkSession") { | ||
| // Creating a new session with config - this works by just calling the lazy val | ||
| sparkContext | ||
| assert(initialSession.sparkContext.conf.get("some-config") == "v2") | ||
| assert(initialSession.conf.get("some-config") == "v2") | ||
| SparkSession.clearDefaultSession() | ||
| assert(session.sparkContext.conf.get("some-config") == "v2") | ||
| assert(session.conf.get("some-config") == "v2") | ||
| } | ||
|
|
||
| test("use global default session") { | ||
| val session = SparkSession.builder().getOrCreate() | ||
| val session = SparkSession.builder().master("local").getOrCreate() | ||
| assert(SparkSession.builder().getOrCreate() == session) | ||
| SparkSession.clearDefaultSession() | ||
| } | ||
|
|
||
| test("config options are propagated to existing SparkSession") { | ||
| val session1 = SparkSession.builder().config("spark-config1", "a").getOrCreate() | ||
| val session1 = SparkSession.builder().master("local").config("spark-config1", "a").getOrCreate() | ||
| assert(session1.conf.get("spark-config1") == "a") | ||
| val session2 = SparkSession.builder().config("spark-config1", "b").getOrCreate() | ||
| assert(session1 == session2) | ||
| assert(session1.conf.get("spark-config1") == "b") | ||
| SparkSession.clearDefaultSession() | ||
| } | ||
|
|
||
| test("use session from active thread session and propagate config options") { | ||
| val defaultSession = SparkSession.builder().getOrCreate() | ||
| val defaultSession = SparkSession.builder().master("local").getOrCreate() | ||
| val activeSession = defaultSession.newSession() | ||
| SparkSession.setActiveSession(activeSession) | ||
| val session = SparkSession.builder().config("spark-config2", "a").getOrCreate() | ||
|
|
@@ -73,11 +72,10 @@ class SparkSessionBuilderSuite extends SparkFunSuite { | |
| SparkSession.clearActiveSession() | ||
|
|
||
| assert(SparkSession.builder().getOrCreate() == defaultSession) | ||
| SparkSession.clearDefaultSession() | ||
| } | ||
|
|
||
| test("create a new session if the default session has been stopped") { | ||
| val defaultSession = SparkSession.builder().getOrCreate() | ||
| val defaultSession = SparkSession.builder().master("local").getOrCreate() | ||
| SparkSession.setDefaultSession(defaultSession) | ||
| defaultSession.stop() | ||
| val newSession = SparkSession.builder().master("local").getOrCreate() | ||
|
|
@@ -95,7 +93,6 @@ class SparkSessionBuilderSuite extends SparkFunSuite { | |
| } | ||
|
|
||
| test("create SparkContext first then SparkSession") { | ||
| sparkContext.stop() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. All of them are removed. |
||
| val conf = new SparkConf().setAppName("test").setMaster("local").set("key1", "value1") | ||
| val sparkContext2 = new SparkContext(conf) | ||
| val session = SparkSession.builder().config("key2", "value2").getOrCreate() | ||
|
|
@@ -109,7 +106,6 @@ class SparkSessionBuilderSuite extends SparkFunSuite { | |
| } | ||
|
|
||
| test("create SparkContext first then pass context to SparkSession") { | ||
| sparkContext.stop() | ||
| val conf = new SparkConf().setAppName("test").setMaster("local").set("key1", "value1") | ||
| val newSC = new SparkContext(conf) | ||
| val session = SparkSession.builder().sparkContext(newSC).config("key2", "value2").getOrCreate() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we also stop the session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to update the unit test case because SparkContext requires
spark.master. I'll update like that.