From 00b426f940384d1dc44851890e0310a3c16171c5 Mon Sep 17 00:00:00 2001 From: Manika Joshi Date: Tue, 21 Jan 2025 23:42:12 -0800 Subject: [PATCH] added test --- .../fs/azurebfs/services/AbfsDfsClient.java | 2 +- .../ITestAzureBlobFileSystemDelegationSAS.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsDfsClient.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsDfsClient.java index 4618a8eb50991..5865ee3f5b6ee 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsDfsClient.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsDfsClient.java @@ -617,7 +617,7 @@ public AbfsClientRenameResult renamePath( if(op.getResult().getStorageErrorCode() .equals(UNAUTHORIZED_BLOB_OVERWRITE.getErrorCode())){ - throw new FileAlreadyExistsException("File already exists." ); + throw new FileAlreadyExistsException("File already exists or request not authorized for blob overwrites."); } // ref: HADOOP-18242. Rename failure occurring due to a rare case of diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemDelegationSAS.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemDelegationSAS.java index 80dda1fa95ed1..80143cdea7d7b 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemDelegationSAS.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemDelegationSAS.java @@ -34,6 +34,7 @@ import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileAlreadyExistsException; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -213,6 +214,23 @@ public void testReadAndWrite() throws Exception { } } + @Test + public void checkExceptionForRenameOverwrites() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + + Path src = new Path("a/b/f1.txt"); + Path dest = new Path("a/b/f2.txt"); + touch(src); + touch(dest); + + try { + fs.rename(src, dest); + } catch (FileAlreadyExistsException e) { + Assertions.assertThat(e) + .isInstanceOf(FileAlreadyExistsException.class); + } + } + @Test // Test rename file and rename folder public void testRename() throws Exception {