shuwang21 commented on code in PR #41821:
URL: https://github.com/apache/spark/pull/41821#discussion_r1254646369
##########
resource-managers/yarn/src/test/scala/org/apache/spark/deploy/yarn/ClientDistributedCacheManagerSuite.scala:
##########
@@ -45,6 +45,63 @@ class ClientDistributedCacheManagerSuite extends
SparkFunSuite with MockitoSugar
}
}
+ /*
+ * This this a customized ClientDistributedCacheManager to test statCache.
+ * */
+ class CustomizedClientDistributedCacheManager extends
ClientDistributedCacheManager {
+ override def addResource(fs: FileSystem, conf: Configuration, destPath:
Path,
+ localResources: HashMap[String, LocalResource], resourceType:
LocalResourceType,
+ link: String, statCache: Map[URI, FileStatus], appMasterOnly: Boolean):
Unit = {
+ statCache.getOrElseUpdate(destPath.toUri(), fs.getFileStatus(destPath))
+ }
+
+ /*
+ * This simulates the isPublic method. It will return true if the result is
cached in the
+ * statCache.
+ * */
+ def isPublicResultCached(uri: URI, statCache: Map[URI, FileStatus]):
Boolean = {
+ statCache.get(uri) match {
+ case Some(_) => true
+ case None => false
+ }
+ }
+ }
+
+ test("SPARK-44272: test addResource added FileStatus to statCache and
getVisibility can read" +
+ " from statCache") {
+ val distMgr = new CustomizedClientDistributedCacheManager()
+ val fs = mock[FileSystem]
+ val conf = new Configuration()
+ val destPath = new Path("file:///foo.invalid.com:8080/tmp/testing")
+ val localResources = HashMap[String, LocalResource]()
+ val statCache: Map[URI, FileStatus] = HashMap[URI, FileStatus]()
+ assert(distMgr.isPublicResultCached(destPath.toUri(), statCache) === false)
+ distMgr.addResource(fs, conf, destPath, localResources,
LocalResourceType.FILE, "link",
+ statCache, false)
+ assert(distMgr.isPublicResultCached(destPath.toUri(), statCache) === true)
Review Comment:
Thanks @mridulm. Can you take another look? The current call stack is deep
and each function is complicated. I am using Mock to extract the skeleton. Feel
free to let me know if you have better suggestions. The drawback is, whenever
we need to change the original function, we need to adjust
`when().thenAnswer()` accordingly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]