You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/12/27 04:14:11 UTC

[GitHub] [spark] HeartSaVioR commented on a change in pull request #26955: [SPARK-30310] [Core] Resolve missing match case in SparkUncaughtExceptionHandler and added tests

HeartSaVioR commented on a change in pull request #26955: [SPARK-30310] [Core] Resolve missing match case in SparkUncaughtExceptionHandler and added tests
URL: https://github.com/apache/spark/pull/26955#discussion_r361577326
 
 

 ##########
 File path: core/src/test/scala/org/apache/spark/util/SparkUncaughtExceptionHandlerSuite.scala
 ##########
 @@ -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") {
 
 Review comment:
   I guess Spark codebase has been dealing with this kind of case via having Seq/Map to construct test matrix, and leverage `foreach` to construct each test. Like:
   
   ```
   Seq(
     ("RuntimeException", RuntimeExceptionThrower, true, SparkExitCode.UNCAUGHT_EXCEPTION),
     ...
   ).foreach { case (excKind, thrower, exitOnUncaughtException, expectedExitCode) =>
     test(s"SPARK-30310: Test uncaught $excKind, exitOnUncaughtException = $exitOnUncaughtException") {
       val process = getThrowerProcess(thrower, exitOnUncaughtException = exitOnUncaughtException)
       assert(process.waitFor == expectedExitCode)
     }
   }
   ```
   
   Having Enumeration makes this even simpler, as `excKind` and `thrower` would be consolidated into one.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org