Skip to content

Commit 6e3c5a2

Browse files
author
Andrew Or
committed
[Test] Better exception message from SparkSubmitSuite
Before: ``` Exception in thread "main" java.lang.Exception: Could not load user defined classes inside of executors at org.apache.spark.deploy.JarCreationTest$.main(SparkSubmitSuite.scala:471) at org.apache.spark.deploy.JarCreationTest.main(SparkSubmitSuite.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ``` After: ``` Exception in thread "main" java.lang.Exception: Could not load user class from jar: java.lang.UnsupportedClassVersionError: SparkSubmitClassA : Unsupported major.minor version 51.0 java.lang.ClassLoader.defineClass1(Native Method) java.lang.ClassLoader.defineClass(ClassLoader.java:643) ... at org.apache.spark.deploy.JarCreationTest$.main(SparkSubmitSuite.scala:472) at org.apache.spark.deploy.JarCreationTest.main(SparkSubmitSuite.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ``` Author: Andrew Or <[email protected]> Closes #3212 from andrewor14/submit-suite-message and squashes the following commits: 7779248 [Andrew Or] Format exception 8fe6719 [Andrew Or] Better exception message from failed test
1 parent 36ddeb7 commit 6e3c5a2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

core/src/test/scala/org/apache/spark/deploy/SparkSubmitSuite.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import java.io._
2121

2222
import scala.collection.mutable.ArrayBuffer
2323

24-
import org.apache.spark.{SparkConf, SparkContext, SparkEnv, SparkException, TestUtils}
24+
import org.apache.spark._
2525
import org.apache.spark.deploy.SparkSubmit._
2626
import org.apache.spark.util.Utils
2727
import org.scalatest.FunSuite
@@ -451,24 +451,25 @@ class SparkSubmitSuite extends FunSuite with Matchers {
451451
}
452452
}
453453

454-
object JarCreationTest {
454+
object JarCreationTest extends Logging {
455455
def main(args: Array[String]) {
456456
Utils.configTestLog4j("INFO")
457457
val conf = new SparkConf()
458458
val sc = new SparkContext(conf)
459459
val result = sc.makeRDD(1 to 100, 10).mapPartitions { x =>
460-
var foundClasses = false
460+
var exception: String = null
461461
try {
462462
Class.forName("SparkSubmitClassA", true, Thread.currentThread().getContextClassLoader)
463463
Class.forName("SparkSubmitClassA", true, Thread.currentThread().getContextClassLoader)
464-
foundClasses = true
465464
} catch {
466-
case _: Throwable => // catch all
465+
case t: Throwable =>
466+
exception = t + "\n" + t.getStackTraceString
467+
exception = exception.replaceAll("\n", "\n\t")
467468
}
468-
Seq(foundClasses).iterator
469+
Option(exception).toSeq.iterator
469470
}.collect()
470-
if (result.contains(false)) {
471-
throw new Exception("Could not load user defined classes inside of executors")
471+
if (result.nonEmpty) {
472+
throw new Exception("Could not load user class from jar:\n" + result(0))
472473
}
473474
}
474475
}

0 commit comments

Comments
 (0)