-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-30310] [Core] Resolve missing match case in SparkUncaughtExceptionHandler and added tests #26955
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-30310] [Core] Resolve missing match case in SparkUncaughtExceptionHandler and added tests #26955
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f7c9956
fix missing match case in SparkUncaughtExceptionHandler
tinhto-000 5d671b0
put new line at end of SparkUncaughtExceptionHandlerSuite.scala
tinhto-000 724e254
use string interpolation in log messages
tinhto-000 48abea3
consolidated the thrower classes into one
tinhto-000 c59f93c
add try-catch around the second logError
tinhto-000 b3da69d
modify the try-block to non-oneliner.
tinhto-000 3f9e96f
pull catch statement up one line
tinhto-000 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
156 changes: 156 additions & 0 deletions
156
core/src/test/scala/org/apache/spark/util/SparkUncaughtExceptionHandlerSuite.scala
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 |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.util | ||
|
|
||
| import java.io.File | ||
|
|
||
| import scala.util.Try | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
|
|
||
| class SparkUncaughtExceptionHandlerSuite extends SparkFunSuite { | ||
|
|
||
| private val sparkHome = | ||
| sys.props.getOrElse("spark.test.home", fail("spark.test.home is not set!")) | ||
|
|
||
| // creates a spark-class process that invokes the exception thrower | ||
| // the testcases will detect the process's exit code | ||
| def getThrowerProcess(exceptionThrower: Any, exitOnUncaughtException: Boolean): Process = { | ||
| Utils.executeCommand( | ||
| Seq(s"$sparkHome/bin/spark-class", | ||
| exceptionThrower.getClass.getCanonicalName.dropRight(1), // drops the "$" at the end | ||
| exitOnUncaughtException.toString), | ||
| new File(sparkHome), | ||
| Map("SPARK_TESTING" -> "1", "SPARK_HOME" -> sparkHome)) | ||
| } | ||
|
|
||
| test("SPARK-30310: Test uncaught RuntimeException, exitOnUncaughtException = true") { | ||
|
tinhto-000 marked this conversation as resolved.
Outdated
|
||
| val process = getThrowerProcess(RuntimeExceptionThrower, exitOnUncaughtException = true) | ||
| assert(process.waitFor == SparkExitCode.UNCAUGHT_EXCEPTION) | ||
| } | ||
|
|
||
| test("SPARK-30310: Test uncaught RuntimeException, exitOnUncaughtException = false") { | ||
| val process = getThrowerProcess(RuntimeExceptionThrower, exitOnUncaughtException = false) | ||
| assert(process.waitFor == 0) | ||
| } | ||
|
|
||
| test("SPARK-30310: Test uncaught OutOfMemoryError, exitOnUncaughtException = true") { | ||
| val process = getThrowerProcess(OutOfMemoryErrorThrower, exitOnUncaughtException = true) | ||
| assert(process.waitFor == SparkExitCode.OOM) | ||
| } | ||
|
|
||
| test("SPARK-30310: Test uncaught OutOfMemoryError, exitOnUncaughtException = false") { | ||
| val process = getThrowerProcess(OutOfMemoryErrorThrower, exitOnUncaughtException = false) | ||
| assert(process.waitFor == SparkExitCode.OOM) | ||
| } | ||
|
|
||
| test("SPARK-30310: Test uncaught SparkFatalException, exitOnUncaughtException = true") { | ||
| val process = getThrowerProcess(SparkFatalExceptionThrower, exitOnUncaughtException = true) | ||
| assert(process.waitFor == SparkExitCode.UNCAUGHT_EXCEPTION) | ||
| } | ||
|
|
||
| test("SPARK-30310: Test uncaught SparkFatalException, exitOnUncaughtException = false") { | ||
| val process = getThrowerProcess(SparkFatalExceptionThrower, exitOnUncaughtException = false) | ||
| assert(process.waitFor == 0) | ||
| } | ||
|
|
||
| test("SPARK-30310: Test uncaught SparkFatalException (OOM), exitOnUncaughtException = true") { | ||
| val process = getThrowerProcess(SparkFatalExceptionWithOOMThrower, | ||
| exitOnUncaughtException = true) | ||
| assert(process.waitFor == SparkExitCode.OOM) | ||
| } | ||
|
|
||
| test("SPARK-30310: Test uncaught SparkFatalException (OOM), exitOnUncaughtException = false") { | ||
| val process = getThrowerProcess(SparkFatalExceptionWithOOMThrower, | ||
| exitOnUncaughtException = false) | ||
| assert(process.waitFor == SparkExitCode.OOM) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // a thread that uses SparkUncaughtExceptionHandler, then throws the throwable | ||
| class ThrowableThrowerThread(t: Throwable, | ||
| exitOnUncaughtException: Boolean) extends Thread { | ||
| override def run() { | ||
| Thread.setDefaultUncaughtExceptionHandler( | ||
| new SparkUncaughtExceptionHandler(exitOnUncaughtException)) | ||
| throw t | ||
| } | ||
| } | ||
|
|
||
| // Objects to be invoked by spark-class for different Throwable types | ||
| // that SparkUncaughtExceptionHandler handles. spark-class will exit with | ||
| // exit code dictated by either: | ||
| // - SparkUncaughtExceptionHandler (SparkExitCode) | ||
| // - main() (0, or -1 when args is empty) | ||
|
|
||
| object RuntimeExceptionThrower { | ||
|
tinhto-000 marked this conversation as resolved.
Outdated
|
||
| def main(args: Array[String]): Unit = { | ||
| if (args.length > 0) { | ||
| val t = new ThrowableThrowerThread(new RuntimeException, | ||
| Try(args(0).toBoolean).getOrElse(false)) | ||
| t.start() | ||
| t.join() | ||
| System.exit(0) | ||
| } else { | ||
| System.exit(-1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object OutOfMemoryErrorThrower { | ||
| def main(args: Array[String]): Unit = { | ||
| if (args.length > 0) { | ||
| val t = new ThrowableThrowerThread(new OutOfMemoryError, | ||
| Try(args(0).toBoolean).getOrElse(false)) | ||
| t.start() | ||
| t.join() | ||
| System.exit(0) | ||
| } else { | ||
| System.exit(-1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object SparkFatalExceptionThrower { | ||
| def main(args: Array[String]): Unit = { | ||
| if (args.length > 0) { | ||
| val t = new ThrowableThrowerThread(new SparkFatalException(new RuntimeException), | ||
| Try(args(0).toBoolean).getOrElse(false)) | ||
| t.start() | ||
| t.join() | ||
| System.exit(0) | ||
| } else { | ||
| System.exit(-1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object SparkFatalExceptionWithOOMThrower { | ||
| def main(args: Array[String]): Unit = { | ||
| if (args.length > 0) { | ||
| val t = new ThrowableThrowerThread(new SparkFatalException(new OutOfMemoryError), | ||
| Try(args(0).toBoolean).getOrElse(false)) | ||
| t.start() | ||
| t.join() | ||
| System.exit(0) | ||
| } else { | ||
| System.exit(-1) | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.