Package org.apache.spark
Class TestUtils
Object
org.apache.spark.TestUtils
Utilities for tests. Included in main codebase since it's used by multiple
 projects.
 
TODO: See if we can move this to the test codebase by specifying test dependencies between projects.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic <E extends Throwable>
 voidassertExceptionMsg(Throwable exception, String msg, boolean ignoreCase, scala.reflect.ClassTag<E> evidence$1) Asserts that exception message contains the message.static voidassertNotSpilled(SparkContext sc, String identifier, scala.Function0<scala.runtime.BoxedUnit> body) Run some code involving jobs submitted to the given context and assert that the jobs did not spill.static voidassertSpilled(SparkContext sc, String identifier, scala.Function0<scala.runtime.BoxedUnit> body) Run some code involving jobs submitted to the given context and assert that the jobs spilled.static voidconfigTestLog4j2(String level) config a log4j2 properties used for testsuitestatic FilecreateCompiledClass(String className, File destDir, String toStringValue, String baseClass, scala.collection.immutable.Seq<URL> classpathUrls, scala.collection.immutable.Seq<String> implementsClasses, String extraCodeBody, scala.Option<String> packageName) static FilecreateCompiledClass(String className, File destDir, SparkTestUtils.JavaSourceFromString sourceFile, scala.collection.immutable.Seq<URL> classpathUrls) static Stringstatic Stringstatic scala.collection.immutable.Seq<URL>static scala.collection.immutable.Seq<String>static Stringstatic scala.Option<String>static URLcreateJar(scala.collection.immutable.Seq<File> files, File jarFile, scala.Option<String> directoryPrefix, scala.Option<String> mainClass) Create a jar file that contains this set of files.static URLcreateJarWithClasses(scala.collection.immutable.Seq<String> classNames, String toStringValue, scala.collection.immutable.Seq<scala.Tuple2<String, String>> classNamesWithBase, scala.collection.immutable.Seq<URL> classpathUrls) Create a jar that defines classes with the given names.static URLcreateJarWithFiles(scala.collection.immutable.Map<String, String> files, File dir) Create a jar file containing multiple files.static StringcreateTempJsonFile(File dir, String prefix, org.json4s.JValue jsonValue) Creates a temp JSON file that contains the input JSON record.static StringcreateTempScriptWithExpectedOutput(File dir, String prefix, String output) Creates a temp bash script that prints the given output.static scala.Option<String>getAbsolutePathFromExecutable(String executable) Get the absolute path from the executable.static inthttpResponseCode(URL url, String method, scala.collection.immutable.Seq<scala.Tuple2<String, String>> headers) Returns the response code from an HTTP(S) URL.static StringhttpResponseMessage(URL url, String method, scala.collection.immutable.Seq<scala.Tuple2<String, String>> headers) Returns the response message from an HTTP(S) URL.static booleanstatic String[]listDirectory(File path) Returns the list of files at 'path' recursively.static Stringstatic JavaFileObject.Kindstatic File[]Lists files recursively.static StringredirectUrl(URL url, String method, scala.collection.immutable.Seq<scala.Tuple2<String, String>> headers) Returns the Location header from an HTTP(S) URL.static booleantestCommandAvailable(String command) Test if a command is available.static <T> TwithHttpConnection(URL url, String method, scala.collection.immutable.Seq<scala.Tuple2<String, String>> headers, scala.Function1<HttpURLConnection, T> fn) static voidwithHttpServer(String resBaseDir, scala.Function1<URL, scala.runtime.BoxedUnit> body) static <L extends SparkListener>
 voidwithListener(SparkContext sc, L listener, scala.Function1<L, scala.runtime.BoxedUnit> body) Runs some code with the given listener installed in the SparkContext.
- 
Constructor Details- 
TestUtilspublic TestUtils()
 
- 
- 
Method Details- 
createJarWithClassespublic static URL createJarWithClasses(scala.collection.immutable.Seq<String> classNames, String toStringValue, scala.collection.immutable.Seq<scala.Tuple2<String, String>> classNamesWithBase, scala.collection.immutable.Seq<URL> classpathUrls) Create a jar that defines classes with the given names.Note: if this is used during class loader tests, class names should be unique in order to avoid interference between tests. - Parameters:
- classNames- (undocumented)
- toStringValue- (undocumented)
- classNamesWithBase- (undocumented)
- classpathUrls- (undocumented)
- Returns:
- (undocumented)
 
- 
createJarWithFilesCreate a jar file containing multiple files. Thefilesmap contains a mapping of file names in the jar file to their contents.- Parameters:
- files- (undocumented)
- dir- (undocumented)
- Returns:
- (undocumented)
 
- 
createJarpublic static URL createJar(scala.collection.immutable.Seq<File> files, File jarFile, scala.Option<String> directoryPrefix, scala.Option<String> mainClass) Create a jar file that contains this set of files. All files will be located in the specified directory or at the root of the jar.- Parameters:
- files- (undocumented)
- jarFile- (undocumented)
- directoryPrefix- (undocumented)
- mainClass- (undocumented)
- Returns:
- (undocumented)
 
- 
assertSpilledpublic static void assertSpilled(SparkContext sc, String identifier, scala.Function0<scala.runtime.BoxedUnit> body) Run some code involving jobs submitted to the given context and assert that the jobs spilled.- Parameters:
- sc- (undocumented)
- identifier- (undocumented)
- body- (undocumented)
 
- 
assertNotSpilledpublic static void assertNotSpilled(SparkContext sc, String identifier, scala.Function0<scala.runtime.BoxedUnit> body) Run some code involving jobs submitted to the given context and assert that the jobs did not spill.- Parameters:
- sc- (undocumented)
- identifier- (undocumented)
- body- (undocumented)
 
- 
assertExceptionMsgpublic static <E extends Throwable> void assertExceptionMsg(Throwable exception, String msg, boolean ignoreCase, scala.reflect.ClassTag<E> evidence$1) Asserts that exception message contains the message. Please note this checks all exceptions in the tree. If a type parameterEis supplied, this will additionally confirm that the exception is a subtype of the exception provided in the type parameter.- Parameters:
- exception- (undocumented)
- msg- (undocumented)
- ignoreCase- (undocumented)
- evidence$1- (undocumented)
 
- 
testCommandAvailableTest if a command is available.- Parameters:
- command- (undocumented)
- Returns:
- (undocumented)
 
- 
minimumPythonSupportedVersion
- 
isPythonVersionAvailablepublic static boolean isPythonVersionAvailable()
- 
getAbsolutePathFromExecutableGet the absolute path from the executable. This implementation was borrowed fromspark/dev/sparktestsupport/shellutils.py.- Parameters:
- executable- (undocumented)
- Returns:
- (undocumented)
 
- 
httpResponseCodepublic static int httpResponseCode(URL url, String method, scala.collection.immutable.Seq<scala.Tuple2<String, String>> headers) Returns the response code from an HTTP(S) URL.- Parameters:
- url- (undocumented)
- method- (undocumented)
- headers- (undocumented)
- Returns:
- (undocumented)
 
- 
redirectUrlpublic static String redirectUrl(URL url, String method, scala.collection.immutable.Seq<scala.Tuple2<String, String>> headers) Returns the Location header from an HTTP(S) URL.- Parameters:
- url- (undocumented)
- method- (undocumented)
- headers- (undocumented)
- Returns:
- (undocumented)
 
- 
httpResponseMessagepublic static String httpResponseMessage(URL url, String method, scala.collection.immutable.Seq<scala.Tuple2<String, String>> headers) Returns the response message from an HTTP(S) URL.- Parameters:
- url- (undocumented)
- method- (undocumented)
- headers- (undocumented)
- Returns:
- (undocumented)
 
- 
withHttpConnectionpublic static <T> T withHttpConnection(URL url, String method, scala.collection.immutable.Seq<scala.Tuple2<String, String>> headers, scala.Function1<HttpURLConnection, T> fn) 
- 
withListenerpublic static <L extends SparkListener> void withListener(SparkContext sc, L listener, scala.Function1<L, scala.runtime.BoxedUnit> body) Runs some code with the given listener installed in the SparkContext. After the code runs, this method will wait until all events posted to the listener bus are processed, and then remove the listener from the bus.- Parameters:
- sc- (undocumented)
- listener- (undocumented)
- body- (undocumented)
 
- 
withHttpServer
- 
configTestLog4j2config a log4j2 properties used for testsuite- Parameters:
- level- (undocumented)
 
- 
recursiveListLists files recursively.- Parameters:
- f- (undocumented)
- Returns:
- (undocumented)
 
- 
listDirectoryReturns the list of files at 'path' recursively. This skips files that are ignored normally by MapReduce.- Parameters:
- path- (undocumented)
- Returns:
- (undocumented)
 
- 
createTempJsonFileCreates a temp JSON file that contains the input JSON record.
- 
createTempScriptWithExpectedOutputCreates a temp bash script that prints the given output.
- 
org$apache$spark$util$SparkTestUtils$$SOURCE
- 
createCompiledClasspublic static File createCompiledClass(String className, File destDir, SparkTestUtils.JavaSourceFromString sourceFile, scala.collection.immutable.Seq<URL> classpathUrls) 
- 
createCompiledClass
- 
createCompiledClass$default$3
- 
createCompiledClass$default$4
- 
createCompiledClass$default$5
- 
createCompiledClass$default$6
- 
createCompiledClass$default$7
- 
createCompiledClass$default$8
 
-