Skip to content

Commit

Permalink
[SPARK-25338][TEST] Ensure to call super.beforeAll() and super.afterA…
Browse files Browse the repository at this point in the history
…ll() in test cases

## What changes were proposed in this pull request?

This PR ensures to call `super.afterAll()` in `override afterAll()` method for test suites.

* Some suites did not call `super.afterAll()`
* Some suites may call `super.afterAll()` only under certain condition
* Others never call `super.afterAll()`.

This PR also ensures to call `super.beforeAll()` in `override beforeAll()` for test suites.

## How was this patch tested?

Existing UTs

Closes #22337 from kiszk/SPARK-25338.

Authored-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
  • Loading branch information
kiszk authored and dongjoon-hyun committed Sep 13, 2018
1 parent a7e5aa6 commit f60cd7c
Show file tree
Hide file tree
Showing 33 changed files with 216 additions and 114 deletions.
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()
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

0 comments on commit f60cd7c

Please sign in to comment.