mridulm commented on code in PR #41821:
URL: https://github.com/apache/spark/pull/41821#discussion_r1257003322


##########
resource-managers/yarn/src/test/scala/org/apache/spark/deploy/yarn/ClientDistributedCacheManagerSuite.scala:
##########
@@ -44,6 +47,76 @@ class ClientDistributedCacheManagerSuite extends 
SparkFunSuite with MockitoSugar
     }
   }
 
+  test("SPARK-44272: test addResource added FileStatus to statCache and 
getVisibility can read" +
+    " from statCache") {
+    val distMgr = mock[ClientDistributedCacheManager]
+    val fs = mock[FileSystem]
+    val conf = new Configuration()
+    val destPath = new Path("file:///foo.invalid.com:8080/tmp/testing")
+    val destURI = destPath.toUri
+    val localResources = HashMap[String, LocalResource]()
+    val statCache: Map[URI, FileStatus] = HashMap[URI, FileStatus]()
+
+    when(distMgr.checkPermissionOfOther(any[FileSystem], any[URI], 
any[FsAction],
+      any[Map[URI, FileStatus]])).thenAnswer((invocation: InvocationOnMock) => 
{
+        val uri = invocation.getArgument[URI](1)
+        val statCache = invocation.getArgument[Map[URI, FileStatus]](3)
+        assert(statCache.contains(uri))
+        true
+      })
+
+    when(distMgr.isPublic(any[Configuration], any[URI], any[Map[URI, 
FileStatus]])).
+      thenAnswer((invocation: InvocationOnMock) => {
+        val uri = invocation.getArgument[URI](1)
+        val statCache = invocation.getArgument[Map[URI, FileStatus]](2)
+        distMgr.checkPermissionOfOther(fs, uri, FsAction.READ, statCache)
+        true
+      })
+
+    when(distMgr.getVisibility(any[Configuration], any[URI], any[Map[URI, 
FileStatus]])).
+      thenAnswer((invocation: InvocationOnMock) => {
+        val uri = invocation.getArgument[URI](1)
+        val statCache = invocation.getArgument[Map[URI, FileStatus]](2)
+        distMgr.isPublic(conf, uri, statCache)
+        LocalResourceVisibility.PRIVATE
+      })
+
+    when(distMgr.addResource(any[FileSystem], any[Configuration], any[Path],
+      any[HashMap[String, LocalResource]], any[LocalResourceType], any[String],
+      any[Map[URI, FileStatus]], any[Boolean])).thenAnswer((invocation: 
InvocationOnMock) => {
+      val destPath = invocation.getArgument[Path](2)
+      val statCache = invocation.getArgument[Map[URI, FileStatus]](6)
+
+      statCache.getOrElseUpdate(destPath.toUri, fs.getFileStatus(destPath))
+      assert(statCache.contains(destURI))
+      distMgr.getVisibility(conf, destPath.toUri(), statCache)
+    })
+
+    distMgr.addResource(fs, conf, destPath, localResources, 
LocalResourceType.FILE, "link",
+      statCache, false)

Review Comment:
   For this test, shouldn't it not be sufficient to mock `getFileStatus` and 
return our own `FileStatus` ?
   This can verify that cache is being used (only one invocation for a path), 
and expected number of invocations (using `verify`) - this will be more robust 
to implementation and/or refactoring changes in this class as it evolves.



-- 
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]

Reply via email to