Skip to content

[SPARK-25338][Test] Ensure to call super.beforeAll() and super.afterAll() in test cases #22337

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
wants to merge 8 commits into from
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 @@ -53,8 +53,11 @@ class MasterWebUISuite extends SparkFunSuite with BeforeAndAfterAll {
}

override def afterAll() {
masterWebUI.stop()
super.afterAll()
try {
masterWebUI.stop()
} finally {
super.afterAll()
}
}

test("kill application") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ class FlumePollingStreamSuite extends SparkFunSuite with BeforeAndAfterAll with
val utils = new PollingFlumeTestUtils

override def beforeAll(): Unit = {
super.beforeAll()
_sc = new SparkContext(conf)
}

override def afterAll(): Unit = {
if (_sc != null) {
_sc.stop()
_sc = null
try {
if (_sc != null) {
_sc.stop()
_sc = null
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ class KafkaRelationSuite extends QueryTest with SharedSQLContext with KafkaTest
}

override def afterAll(): Unit = {
if (testUtils != null) {
testUtils.teardown()
testUtils = null
try {
if (testUtils != null) {
testUtils.teardown()
testUtils = null
}
} finally {
super.afterAll()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ class KafkaSinkSuite extends StreamTest with SharedSQLContext with KafkaTest {
}

override def afterAll(): Unit = {
if (testUtils != null) {
testUtils.teardown()
testUtils = null
try {
if (testUtils != null) {
testUtils.teardown()
testUtils = null
}
} finally {
super.afterAll()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ class DirectKafkaStreamSuite
private var kafkaTestUtils: KafkaTestUtils = _

override def beforeAll {
super.beforeAll()
kafkaTestUtils = new KafkaTestUtils
kafkaTestUtils.setup()
}

override def afterAll {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
try {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,27 @@ class KafkaRDDSuite extends SparkFunSuite with BeforeAndAfterAll {
private var sc: SparkContext = _

override def beforeAll {
super.beforeAll()
sc = new SparkContext(sparkConf)
kafkaTestUtils = new KafkaTestUtils
kafkaTestUtils.setup()
}

override def afterAll {
if (sc != null) {
sc.stop
sc = null
}

if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
try {
try {
if (sc != null) {
sc.stop
sc = null
}
} finally {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
}
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ class DirectKafkaStreamSuite
private var kafkaTestUtils: KafkaTestUtils = _

override def beforeAll {
super.beforeAll()
kafkaTestUtils = new KafkaTestUtils
kafkaTestUtils.setup()
}

override def afterAll {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
try {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class KafkaClusterSuite extends SparkFunSuite with BeforeAndAfterAll {
private var kafkaTestUtils: KafkaTestUtils = _

override def beforeAll() {
super.beforeAll()
kafkaTestUtils = new KafkaTestUtils
kafkaTestUtils.setup()

Expand All @@ -41,9 +42,13 @@ class KafkaClusterSuite extends SparkFunSuite with BeforeAndAfterAll {
}

override def afterAll() {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
try {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,27 @@ class KafkaRDDSuite extends SparkFunSuite with BeforeAndAfterAll {
private var sc: SparkContext = _

override def beforeAll {
super.beforeAll()
sc = new SparkContext(sparkConf)
kafkaTestUtils = new KafkaTestUtils
kafkaTestUtils.setup()
}

override def afterAll {
if (sc != null) {
sc.stop
sc = null
}

if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
try {
try {
if (sc != null) {
sc.stop
sc = null
}
} finally {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
}
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,26 @@ class KafkaStreamSuite extends SparkFunSuite with Eventually with BeforeAndAfter
private var kafkaTestUtils: KafkaTestUtils = _

override def beforeAll(): Unit = {
super.beforeAll()
kafkaTestUtils = new KafkaTestUtils
kafkaTestUtils.setup()
}

override def afterAll(): Unit = {
if (ssc != null) {
ssc.stop()
ssc = null
}

if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
try {
try {
if (ssc != null) {
ssc.stop()
ssc = null
}
} finally {
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
}
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ReliableKafkaStreamSuite extends SparkFunSuite
private var tempDirectory: File = null

override def beforeAll(): Unit = {
super.beforeAll()
kafkaTestUtils = new KafkaTestUtils
kafkaTestUtils.setup()

Expand All @@ -65,11 +66,15 @@ class ReliableKafkaStreamSuite extends SparkFunSuite
}

override def afterAll(): Unit = {
Utils.deleteRecursively(tempDirectory)
try {
Utils.deleteRecursively(tempDirectory)

if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
if (kafkaTestUtils != null) {
kafkaTestUtils.teardown()
kafkaTestUtils = null
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class KinesisInputDStreamBuilderSuite extends TestSuiteBase with BeforeAndAfterE
.checkpointAppName(checkpointAppName)

override def afterAll(): Unit = {
ssc.stop()
try {
ssc.stop()
} finally {
super.afterAll()
}
}

test("should raise an exception if the StreamingContext is missing") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,21 @@ abstract class KinesisStreamTests(aggregateTestData: Boolean) extends KinesisFun
}

override def afterAll(): Unit = {
if (ssc != null) {
ssc.stop()
}
if (sc != null) {
sc.stop()
}
if (testUtils != null) {
// Delete the Kinesis stream as well as the DynamoDB table generated by
// Kinesis Client Library when consuming the stream
testUtils.deleteStream()
testUtils.deleteDynamoDBTable(appName)
try {
if (ssc != null) {
ssc.stop()
}
if (sc != null) {
sc.stop()
}
if (testUtils != null) {
// Delete the Kinesis stream as well as the DynamoDB table generated by
// Kinesis Client Library when consuming the stream
testUtils.deleteStream()
testUtils.deleteDynamoDBTable(appName)
}
} finally {
super.afterAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private[spark] class KubernetesSuite extends SparkFunSuite
s"${(1024 + memOverheadConstant*1024 + additionalMemory).toInt}Mi"

override def beforeAll(): Unit = {
super.beforeAll()
// The scalatest-maven-plugin gives system properties that are referenced but not set null
// values. We need to remove the null-value properties before initializing the test backend.
val nullValueProperties = System.getProperties.asScala
Expand Down Expand Up @@ -93,7 +94,11 @@ private[spark] class KubernetesSuite extends SparkFunSuite
}

override def afterAll(): Unit = {
testBackend.cleanUp()
try {
testBackend.cleanUp()
} finally {
super.afterAll()
}
}

before {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ class SessionStateSuite extends SparkFunSuite {
}

override def afterAll(): Unit = {
if (activeSession != null) {
activeSession.stop()
activeSession = null
SparkSession.clearActiveSession()
SparkSession.clearDefaultSession()
try {
if (activeSession != null) {
activeSession.stop()
activeSession = null
SparkSession.clearActiveSession()
SparkSession.clearDefaultSession()
}
} finally {
super.afterAll()
}
super.afterAll()
}

test("fork new session and inherit RuntimeConfig options") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ExchangeCoordinatorSuite extends SparkFunSuite with BeforeAndAfterAll {
private var originalInstantiatedSparkSession: Option[SparkSession] = _

override protected def beforeAll(): Unit = {
super.beforeAll()
Copy link
Member

@dongjoon-hyun dongjoon-hyun Sep 7, 2018

Choose a reason for hiding this comment

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

Oh, this one is beforeAll. Did you check beforeAll, too?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. Let me check beforeAll.

originalActiveSparkSession = SparkSession.getActiveSession
originalInstantiatedSparkSession = SparkSession.getDefaultSession

Expand All @@ -39,9 +40,13 @@ class ExchangeCoordinatorSuite extends SparkFunSuite with BeforeAndAfterAll {
}

override protected def afterAll(): Unit = {
// Set these states back.
originalActiveSparkSession.foreach(ctx => SparkSession.setActiveSession(ctx))
originalInstantiatedSparkSession.foreach(ctx => SparkSession.setDefaultSession(ctx))
try {
// Set these states back.
originalActiveSparkSession.foreach(ctx => SparkSession.setActiveSession(ctx))
originalInstantiatedSparkSession.foreach(ctx => SparkSession.setDefaultSession(ctx))
} finally {
super.afterAll()
}
}

private def checkEstimation(
Expand Down
Loading