@@ -28,6 +28,7 @@ import java.util.Locale
28
28
import com .google .common .base .Charsets .UTF_8
29
29
import com .google .common .io .Files
30
30
import org .scalatest .FunSuite
31
+ import org .apache .commons .lang3 .SystemUtils
31
32
32
33
import org .apache .hadoop .conf .Configuration
33
34
import org .apache .hadoop .fs .Path
@@ -233,13 +234,16 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
233
234
assert(new URI (Utils .resolveURIs(before, testWindows)) === new URI (after))
234
235
assert(new URI (Utils .resolveURIs(after, testWindows)) === new URI (after))
235
236
}
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
237
239
assertResolves(" hdfs:/root/spark.jar" , " hdfs:/root/spark.jar" )
238
240
assertResolves(" hdfs:///root/spark.jar#app.jar" , " hdfs:/root/spark.jar#app.jar" )
239
241
assertResolves(" spark.jar" , s " file: $cwd/spark.jar " )
240
242
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 " )
241
244
assertResolves(" C:/path/to/file.txt" , " file:/C:/path/to/file.txt" , testWindows = true )
242
245
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 )
243
247
assertResolves(" file:/C:/path/to/file.txt" , " file:/C:/path/to/file.txt" , testWindows = true )
244
248
assertResolves(" file:///C:/path/to/file.txt" , " file:/C:/path/to/file.txt" , testWindows = true )
245
249
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 {
258
262
assert(resolve(resolve(after)) === after)
259
263
assert(resolve(resolve(resolve(after))) === after)
260
264
}
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
262
267
assertResolves(" jar1,jar2" , s " file: $cwd/jar1,file: $cwd/jar2 " )
263
268
assertResolves(" file:/jar1,file:/jar2" , " file:/jar1,file:/jar2" )
264
269
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 )
269
275
}
270
276
271
277
test(" nonLocalPaths" ) {
@@ -280,6 +286,8 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
280
286
assert(Utils .nonLocalPaths(" local:/spark.jar,file:/smart.jar,family.py" ) === Array .empty)
281
287
assert(Utils .nonLocalPaths(" hdfs:/spark.jar,s3:/smart.jar" ) ===
282
288
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" ))
283
291
assert(Utils .nonLocalPaths(" hdfs:/spark.jar,s3:/smart.jar,local.py,file:/hello/pi.py" ) ===
284
292
Array (" hdfs:/spark.jar" , " s3:/smart.jar" ))
285
293
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 {
293
301
assert(Utils .nonLocalPaths(" local:///C:/some/path.jar" , testWindows = true ) === Array .empty)
294
302
assert(Utils .nonLocalPaths(" hdfs:/a.jar,C:/my.jar,s3:/another.jar" , testWindows = true ) ===
295
303
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" ))
296
309
assert(Utils .nonLocalPaths(" D:/your.jar,hdfs:/a.jar,s3:/another.jar" , testWindows = true ) ===
297
310
Array (" hdfs:/a.jar" , " s3:/another.jar" ))
298
311
assert(Utils .nonLocalPaths(" hdfs:/a.jar,s3:/another.jar,e:/our.jar" , testWindows = true ) ===
@@ -392,7 +405,12 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
392
405
val targetDir = new File (tempDir, " target-dir" )
393
406
Files .write(" some text" , sourceFile, UTF_8 )
394
407
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
+ }
396
414
val conf = new Configuration ()
397
415
val fs = Utils .getHadoopFileSystem(path.toString, conf)
398
416
@@ -412,7 +430,12 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
412
430
val destInnerFile = new File (destInnerDir, sourceFile.getName)
413
431
assert(destInnerFile.isFile())
414
432
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
+ }
416
439
val testFileDir = new File (tempDir, " test-filename" )
417
440
val testFileName = " testFName"
418
441
val testFilefs = Utils .getHadoopFileSystem(filePath.toString, conf)
0 commit comments