Skip to content

Commit 887cf0e

Browse files
zuotingbingsrowen
authored andcommitted
[SPARK-20936][CORE] Lack of an important case about the test of resolveURI in UtilsSuite, and add it as needed.
## What changes were proposed in this pull request? 1. add `assert(resolve(before) === after)` to check before and after in test of resolveURI. the function `assertResolves(before: String, after: String)` have two params, it means we should check the before value whether equals the after value which we want. e.g. the after value of Utils.resolveURI("hdfs:///root/spark.jar#app.jar").toString should be "hdfs:///root/spark.jar#app.jar" rather than "hdfs:/root/spark.jar#app.jar". we need `assert(resolve(before) === after)` to make it more safe. 2. identify the cases between resolveURI and resolveURIs. 3. delete duplicate cases and some small fix make this suit more clear. ## How was this patch tested? unit tests Author: zuotingbing <[email protected]> Closes #18158 from zuotingbing/spark-UtilsSuite.
1 parent 96e6ba6 commit 887cf0e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

core/src/test/scala/org/apache/spark/util/UtilsSuite.scala

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,17 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
461461
def assertResolves(before: String, after: String): Unit = {
462462
// This should test only single paths
463463
assume(before.split(",").length === 1)
464-
// Repeated invocations of resolveURI should yield the same result
465464
def resolve(uri: String): String = Utils.resolveURI(uri).toString
465+
assert(resolve(before) === after)
466466
assert(resolve(after) === after)
467+
// Repeated invocations of resolveURI should yield the same result
467468
assert(resolve(resolve(after)) === after)
468469
assert(resolve(resolve(resolve(after))) === after)
469-
// Also test resolveURIs with single paths
470-
assert(new URI(Utils.resolveURIs(before)) === new URI(after))
471-
assert(new URI(Utils.resolveURIs(after)) === new URI(after))
472470
}
473471
val rawCwd = System.getProperty("user.dir")
474472
val cwd = if (Utils.isWindows) s"/$rawCwd".replace("\\", "/") else rawCwd
475473
assertResolves("hdfs:/root/spark.jar", "hdfs:/root/spark.jar")
476-
assertResolves("hdfs:///root/spark.jar#app.jar", "hdfs:/root/spark.jar#app.jar")
474+
assertResolves("hdfs:///root/spark.jar#app.jar", "hdfs:///root/spark.jar#app.jar")
477475
assertResolves("spark.jar", s"file:$cwd/spark.jar")
478476
assertResolves("spark.jar#app.jar", s"file:$cwd/spark.jar#app.jar")
479477
assertResolves("path to/file.txt", s"file:$cwd/path%20to/file.txt")
@@ -482,20 +480,19 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
482480
assertResolves("C:\\path to\\file.txt", "file:/C:/path%20to/file.txt")
483481
}
484482
assertResolves("file:/C:/path/to/file.txt", "file:/C:/path/to/file.txt")
485-
assertResolves("file:///C:/path/to/file.txt", "file:/C:/path/to/file.txt")
483+
assertResolves("file:///C:/path/to/file.txt", "file:///C:/path/to/file.txt")
486484
assertResolves("file:/C:/file.txt#alias.txt", "file:/C:/file.txt#alias.txt")
487-
assertResolves("file:foo", s"file:foo")
488-
assertResolves("file:foo:baby", s"file:foo:baby")
485+
assertResolves("file:foo", "file:foo")
486+
assertResolves("file:foo:baby", "file:foo:baby")
489487
}
490488

491489
test("resolveURIs with multiple paths") {
492490
def assertResolves(before: String, after: String): Unit = {
493491
assume(before.split(",").length > 1)
494-
assert(Utils.resolveURIs(before) === after)
495-
assert(Utils.resolveURIs(after) === after)
496-
// Repeated invocations of resolveURIs should yield the same result
497492
def resolve(uri: String): String = Utils.resolveURIs(uri)
493+
assert(resolve(before) === after)
498494
assert(resolve(after) === after)
495+
// Repeated invocations of resolveURIs should yield the same result
499496
assert(resolve(resolve(after)) === after)
500497
assert(resolve(resolve(resolve(after))) === after)
501498
}
@@ -511,6 +508,8 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
511508
s"hdfs:/jar1,file:/jar2,file:$cwd/jar3,file:/C:/pi.py%23py.pi,file:/C:/path%20to/jar4")
512509
}
513510
assertResolves(",jar1,jar2", s"file:$cwd/jar1,file:$cwd/jar2")
511+
// Also test resolveURIs with single paths
512+
assertResolves("hdfs:/root/spark.jar", "hdfs:/root/spark.jar")
514513
}
515514

516515
test("nonLocalPaths") {

0 commit comments

Comments
 (0)