@@ -28,6 +28,7 @@ import java.util.Locale
2828import com .google .common .base .Charsets .UTF_8
2929import com .google .common .io .Files
3030import org .scalatest .FunSuite
31+ import org .apache .commons .lang3 .SystemUtils
3132
3233import org .apache .hadoop .conf .Configuration
3334import org .apache .hadoop .fs .Path
@@ -233,13 +234,16 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
233234 assert(new URI (Utils .resolveURIs(before, testWindows)) === new URI (after))
234235 assert(new URI (Utils .resolveURIs(after, testWindows)) === new URI (after))
235236 }
236- val cwd = System .getProperty(" user.dir" )
237+ val rawCwd = System .getProperty(" user.dir" )
238+ val cwd = if (SystemUtils .IS_OS_WINDOWS ) s " / $rawCwd" .replace(" \\ " , " /" ) else rawCwd
237239 assertResolves(" hdfs:/root/spark.jar" , " hdfs:/root/spark.jar" )
238240 assertResolves(" hdfs:///root/spark.jar#app.jar" , " hdfs:/root/spark.jar#app.jar" )
239241 assertResolves(" spark.jar" , s " file: $cwd/spark.jar " )
240242 assertResolves(" spark.jar#app.jar" , s " file: $cwd/spark.jar#app.jar " )
243+ assertResolves(" path to/file.txt" , s " file: $cwd/path%20to/file.txt " )
241244 assertResolves(" C:/path/to/file.txt" , " file:/C:/path/to/file.txt" , testWindows = true )
242245 assertResolves(" C:\\ path\\ to\\ file.txt" , " file:/C:/path/to/file.txt" , testWindows = true )
246+ assertResolves(" C:/path to/file.txt" , " file:/C:/path%20to/file.txt" , testWindows = true )
243247 assertResolves(" file:/C:/path/to/file.txt" , " file:/C:/path/to/file.txt" , testWindows = true )
244248 assertResolves(" file:///C:/path/to/file.txt" , " file:/C:/path/to/file.txt" , testWindows = true )
245249 assertResolves(" file:/C:/file.txt#alias.txt" , " file:/C:/file.txt#alias.txt" , testWindows = true )
@@ -258,14 +262,16 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
258262 assert(resolve(resolve(after)) === after)
259263 assert(resolve(resolve(resolve(after))) === after)
260264 }
261- val cwd = System .getProperty(" user.dir" )
265+ val rawCwd = System .getProperty(" user.dir" )
266+ val cwd = if (SystemUtils .IS_OS_WINDOWS ) s " / $rawCwd" .replace(" \\ " , " /" ) else rawCwd
262267 assertResolves(" jar1,jar2" , s " file: $cwd/jar1,file: $cwd/jar2 " )
263268 assertResolves(" file:/jar1,file:/jar2" , " file:/jar1,file:/jar2" )
264269 assertResolves(" hdfs:/jar1,file:/jar2,jar3" , s " hdfs:/jar1,file:/jar2,file: $cwd/jar3 " )
265- assertResolves(" hdfs:/jar1,file:/jar2,jar3,jar4#jar5" ,
266- s " hdfs:/jar1,file:/jar2,file: $cwd/jar3,file: $cwd/jar4#jar5 " )
267- assertResolves(" hdfs:/jar1,file:/jar2,jar3,C:\\ pi.py#py.pi" ,
268- s " hdfs:/jar1,file:/jar2,file: $cwd/jar3,file:/C:/pi.py#py.pi " , testWindows = true )
270+ assertResolves(" hdfs:/jar1,file:/jar2,jar3,jar4#jar5,path to/jar6" ,
271+ s " hdfs:/jar1,file:/jar2,file: $cwd/jar3,file: $cwd/jar4#jar5,file: $cwd/path%20to/jar6 " )
272+ assertResolves(""" hdfs:/jar1,file:/jar2,jar3,C:\pi.py#py.pi,C:\path to\jar4""" ,
273+ s " hdfs:/jar1,file:/jar2,file: $cwd/jar3,file:/C:/pi.py#py.pi,file:/C:/path%20to/jar4 " ,
274+ testWindows = true )
269275 }
270276
271277 test(" nonLocalPaths" ) {
@@ -280,6 +286,8 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
280286 assert(Utils .nonLocalPaths(" local:/spark.jar,file:/smart.jar,family.py" ) === Array .empty)
281287 assert(Utils .nonLocalPaths(" hdfs:/spark.jar,s3:/smart.jar" ) ===
282288 Array (" hdfs:/spark.jar" , " s3:/smart.jar" ))
289+ assert(Utils .nonLocalPaths(" hdfs:/path to/spark.jar,path to/a.jar,s3:/path to/smart.jar" ) ===
290+ Array (" hdfs:/path to/spark.jar" , " s3:/path to/smart.jar" ))
283291 assert(Utils .nonLocalPaths(" hdfs:/spark.jar,s3:/smart.jar,local.py,file:/hello/pi.py" ) ===
284292 Array (" hdfs:/spark.jar" , " s3:/smart.jar" ))
285293 assert(Utils .nonLocalPaths(" local.py,hdfs:/spark.jar,file:/hello/pi.py,s3:/smart.jar" ) ===
@@ -293,6 +301,11 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
293301 assert(Utils .nonLocalPaths(" local:///C:/some/path.jar" , testWindows = true ) === Array .empty)
294302 assert(Utils .nonLocalPaths(" hdfs:/a.jar,C:/my.jar,s3:/another.jar" , testWindows = true ) ===
295303 Array (" hdfs:/a.jar" , " s3:/another.jar" ))
304+ assert(Utils .nonLocalPaths(
305+ " hdfs:/path to/spark.jar,C:\\ path to\\ a.jar,s3:/path to/smart.jar"
306+ , testWindows = true
307+ ) ===
308+ Array (" hdfs:/path to/spark.jar" , " s3:/path to/smart.jar" ))
296309 assert(Utils .nonLocalPaths(" D:/your.jar,hdfs:/a.jar,s3:/another.jar" , testWindows = true ) ===
297310 Array (" hdfs:/a.jar" , " s3:/another.jar" ))
298311 assert(Utils .nonLocalPaths(" hdfs:/a.jar,s3:/another.jar,e:/our.jar" , testWindows = true ) ===
@@ -392,7 +405,12 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
392405 val targetDir = new File (tempDir, " target-dir" )
393406 Files .write(" some text" , sourceFile, UTF_8 )
394407
395- val path = new Path (" file://" + sourceDir.getAbsolutePath)
408+ val path =
409+ if (SystemUtils .IS_OS_WINDOWS ) {
410+ new Path (" file:/" + sourceDir.getAbsolutePath.replace(" \\ " , " /" ))
411+ } else {
412+ new Path (" file://" + sourceDir.getAbsolutePath)
413+ }
396414 val conf = new Configuration ()
397415 val fs = Utils .getHadoopFileSystem(path.toString, conf)
398416
@@ -412,7 +430,12 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
412430 val destInnerFile = new File (destInnerDir, sourceFile.getName)
413431 assert(destInnerFile.isFile())
414432
415- val filePath = new Path (" file://" + sourceFile.getAbsolutePath)
433+ val filePath =
434+ if (SystemUtils .IS_OS_WINDOWS ) {
435+ new Path (" file:/" + sourceFile.getAbsolutePath.replace(" \\ " , " /" ))
436+ } else {
437+ new Path (" file://" + sourceFile.getAbsolutePath)
438+ }
416439 val testFileDir = new File (tempDir, " test-filename" )
417440 val testFileName = " testFName"
418441 val testFilefs = Utils .getHadoopFileSystem(filePath.toString, conf)
0 commit comments