1717
1818package org .apache .spark .deploy
1919
20- import java .io .{File , OutputStream , PrintStream }
20+ import java .io .{File , OutputStream , PrintWriter , PrintStream }
2121
2222import scala .collection .mutable .ArrayBuffer
2323
@@ -291,7 +291,7 @@ class SparkSubmitSuite extends FunSuite with Matchers {
291291 runSparkSubmit(args)
292292 }
293293
294- test(" spark submit includes jars passed in through --jar " ) {
294+ test(" includes jars passed in through --jars " ) {
295295 val unusedJar = TestUtils .createJarWithClasses(Seq .empty)
296296 val jar1 = TestUtils .createJarWithClasses(Seq (" SparkSubmitClassA" ))
297297 val jar2 = TestUtils .createJarWithClasses(Seq (" SparkSubmitClassB" ))
@@ -305,6 +305,110 @@ class SparkSubmitSuite extends FunSuite with Matchers {
305305 runSparkSubmit(args)
306306 }
307307
308+ test(" resolves command line argument paths correctly" ) {
309+ val jars = " /jar1,/jar2" // --jars
310+ val files = " hdfs:/file1,file2" // --files
311+ val archives = " file:/archive1,archive2" // --archives
312+ val pyFiles = " py-file1,py-file2" // --py-files
313+
314+ // Test jars and files
315+ val clArgs = Seq (
316+ " --master" , " local" ,
317+ " --class" , " org.SomeClass" ,
318+ " --jars" , jars,
319+ " --files" , files,
320+ " thejar.jar" )
321+ val appArgs = new SparkSubmitArguments (clArgs)
322+ val sysProps = SparkSubmit .createLaunchEnv(appArgs)._3
323+ appArgs.jars should be (Utils .resolveURIs(jars))
324+ appArgs.files should be (Utils .resolveURIs(files))
325+ sysProps(" spark.jars" ) should be (Utils .resolveURIs(jars + " ,thejar.jar" ))
326+ sysProps(" spark.files" ) should be (Utils .resolveURIs(files))
327+
328+ // Test files and archives (Yarn)
329+ val clArgs2 = Seq (
330+ " --master" , " yarn-client" ,
331+ " --class" , " org.SomeClass" ,
332+ " --files" , files,
333+ " --archives" , archives,
334+ " thejar.jar"
335+ )
336+ val appArgs2 = new SparkSubmitArguments (clArgs2)
337+ val sysProps2 = SparkSubmit .createLaunchEnv(appArgs2)._3
338+ appArgs2.files should be (Utils .resolveURIs(files))
339+ appArgs2.archives should be (Utils .resolveURIs(archives))
340+ sysProps2(" spark.yarn.dist.files" ) should be (Utils .resolveURIs(files))
341+ sysProps2(" spark.yarn.dist.archives" ) should be (Utils .resolveURIs(archives))
342+
343+ // Test python files
344+ val clArgs3 = Seq (
345+ " --master" , " local" ,
346+ " --py-files" , pyFiles,
347+ " mister.py"
348+ )
349+ val appArgs3 = new SparkSubmitArguments (clArgs3)
350+ val sysProps3 = SparkSubmit .createLaunchEnv(appArgs3)._3
351+ appArgs3.pyFiles should be (Utils .resolveURIs(pyFiles))
352+ sysProps3(" spark.submit.pyFiles" ) should be (
353+ PythonRunner .formatPaths(Utils .resolveURIs(pyFiles)).mkString(" ," ))
354+ }
355+
356+ test(" resolves config paths correctly" ) {
357+ val jars = " /jar1,/jar2" // spark.jars
358+ val files = " hdfs:/file1,file2" // spark.files / spark.yarn.dist.files
359+ val archives = " file:/archive1,archive2" // spark.yarn.dist.archives
360+ val pyFiles = " py-file1,py-file2" // spark.submit.pyFiles
361+
362+ // Test jars and files
363+ val f1 = File .createTempFile(" test-submit-jars-files" , " " )
364+ val writer1 = new PrintWriter (f1)
365+ writer1.println(" spark.jars " + jars)
366+ writer1.println(" spark.files " + files)
367+ writer1.close()
368+ val clArgs = Seq (
369+ " --master" , " local" ,
370+ " --class" , " org.SomeClass" ,
371+ " --properties-file" , f1.getPath,
372+ " thejar.jar"
373+ )
374+ val appArgs = new SparkSubmitArguments (clArgs)
375+ val sysProps = SparkSubmit .createLaunchEnv(appArgs)._3
376+ sysProps(" spark.jars" ) should be (Utils .resolveURIs(jars + " ,thejar.jar" ))
377+ sysProps(" spark.files" ) should be (Utils .resolveURIs(files))
378+
379+ // Test files and archives (Yarn)
380+ val f2 = File .createTempFile(" test-submit-files-archives" , " " )
381+ val writer2 = new PrintWriter (f2)
382+ writer2.println(" spark.yarn.dist.files " + files)
383+ writer2.println(" spark.yarn.dist.archives " + archives)
384+ writer2.close()
385+ val clArgs2 = Seq (
386+ " --master" , " yarn-client" ,
387+ " --class" , " org.SomeClass" ,
388+ " --properties-file" , f2.getPath,
389+ " thejar.jar"
390+ )
391+ val appArgs2 = new SparkSubmitArguments (clArgs2)
392+ val sysProps2 = SparkSubmit .createLaunchEnv(appArgs2)._3
393+ sysProps2(" spark.yarn.dist.files" ) should be (Utils .resolveURIs(files))
394+ sysProps2(" spark.yarn.dist.archives" ) should be (Utils .resolveURIs(archives))
395+
396+ // Test python files
397+ val f3 = File .createTempFile(" test-submit-python-files" , " " )
398+ val writer3 = new PrintWriter (f3)
399+ writer3.println(" spark.submit.pyFiles " + pyFiles)
400+ writer3.close()
401+ val clArgs3 = Seq (
402+ " --master" , " local" ,
403+ " --properties-file" , f3.getPath,
404+ " mister.py"
405+ )
406+ val appArgs3 = new SparkSubmitArguments (clArgs3)
407+ val sysProps3 = SparkSubmit .createLaunchEnv(appArgs3)._3
408+ sysProps3(" spark.submit.pyFiles" ) should be (
409+ PythonRunner .formatPaths(Utils .resolveURIs(pyFiles)).mkString(" ," ))
410+ }
411+
308412 // NOTE: This is an expensive operation in terms of time (10 seconds+). Use sparingly.
309413 def runSparkSubmit (args : Seq [String ]): String = {
310414 val sparkHome = sys.props.getOrElse(" spark.test.home" , fail(" spark.test.home is not set!" ))
0 commit comments