dongjoon-hyun commented on a change in pull request #35509:
URL: https://github.com/apache/spark/pull/35509#discussion_r806540505



##########
File path: 
resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesUtilsSuite.scala
##########
@@ -65,4 +73,49 @@ class KubernetesUtilsSuite extends SparkFunSuite {
     assert(sparkPodWithNoContainerName.pod.getSpec.getHostname == HOST)
     assert(sparkPodWithNoContainerName.container.getName == null)
   }
+
+  test("SPARK-38201: check uploadFileToHadoopCompatibleFS with different 
delSrc and overwrite") {
+    val uploadFileToHadoopCompatibleFSMethod =
+      PrivateMethod[Unit](Symbol("uploadFileToHadoopCompatibleFS"))
+    withTempDir { srcDir =>
+      val fileName = "test.txt"
+      val srcFile = new File(srcDir, fileName)
+      FileUtils.write(srcFile, "test", Charset.defaultCharset())
+      withTempDir { destDir =>
+        import org.apache.spark.SparkException
+        val src = new Path(srcFile.getAbsolutePath)
+        val dest = new Path(destDir.getAbsolutePath, fileName)
+        val fs = src.getFileSystem(new Configuration())
+        // Scenario 1: delSrc = false and overwrite = true, upload successful
+        KubernetesUtils
+          .invokePrivate(uploadFileToHadoopCompatibleFSMethod(src, dest, fs, 
false, true))
+        val firstUploadTime = fs.getFileStatus(dest).getModificationTime
+        // sleep 1s to ensure that the `ModificationTime` changes.
+        TimeUnit.SECONDS.sleep(1)
+        // Scenario 2: delSrc = false and overwrite = true,
+        // upload succeeded but `ModificationTime` changed
+        KubernetesUtils
+          .invokePrivate(uploadFileToHadoopCompatibleFSMethod(src, dest, fs, 
false, true))
+        val secondUploadTime = fs.getFileStatus(dest).getModificationTime
+        assert(firstUploadTime != secondUploadTime)
+
+        // Scenario 3: delSrc = false and overwrite = false,
+        // upload failed because dest exists
+        val message = intercept[SparkException] {
+          KubernetesUtils
+            .invokePrivate(uploadFileToHadoopCompatibleFSMethod(src, dest, fs, 
false, false))
+        }.getMessage
+        assert(message.contains("Error uploading file"))
+
+        TimeUnit.SECONDS.sleep(1)
+        // Scenario 4: delSrc = true and overwrite = true,
+        // upload succeeded, `ModificationTime` changed and src not exists.
+        KubernetesUtils
+          .invokePrivate(uploadFileToHadoopCompatibleFSMethod(src, dest, fs, 
true, true))
+        val thirdUploadTime = fs.getFileStatus(dest).getModificationTime
+        assert(secondUploadTime != thirdUploadTime)

Review comment:
       ditto. `<` instead of `!=`.




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