bhattmanish98 commented on code in PR #7364: URL: https://github.com/apache/hadoop/pull/7364#discussion_r1958166104
########## hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemMkDir.java: ########## @@ -167,4 +185,139 @@ public void testMkdirWithExistingFilename() throws Exception { intercept(FileAlreadyExistsException.class, () -> fs.mkdirs(new Path("/testFilePath"))); intercept(FileAlreadyExistsException.class, () -> fs.mkdirs(new Path("/testFilePath/newDir"))); } + + /** + * Tests the idempotency of creating a path with retries by simulating + * a conflict response (HTTP 409) from the Azure Blob File System client. + * The method ensures that the path creation operation retries correctly + * with the proper transaction ID headers, verifying idempotency during + * failure recovery. + * + * @throws Exception if any error occurs during the operation. + */ + @Test + public void createPathRetryIdempotency() throws Exception { + Configuration configuration = new Configuration(getRawConfiguration()); + configuration.set(FS_AZURE_ENABLE_CLIENT_TRANSACTION_ID, "true"); + try (AzureBlobFileSystem fs = getFileSystem(configuration)) { + assumeRecoveryThroughClientTransactionID(fs, true); + AzureBlobFileSystemStore store = Mockito.spy(fs.getAbfsStore()); + AbfsClientHandler clientHandler = Mockito.spy(store.getClientHandler()); + AbfsDfsClient abfsClient = (AbfsDfsClient) Mockito.spy( + clientHandler.getClient()); + fs.getAbfsStore().setClient(abfsClient); + fs.getAbfsStore().setClientHandler(clientHandler); + Mockito.doReturn(abfsClient).when(clientHandler).getIngressClient(); + final Path nonOverwriteFile = new Path( + "/NonOverwriteTest_FileName_" + UUID.randomUUID()); + final List<AbfsHttpHeader> headers = new ArrayList<>(); + TestAbfsClient.mockAbfsOperationCreation(abfsClient, + new MockIntercept<AbfsRestOperation>() { + private int count = 0; + + @Override + public void answer(final AbfsRestOperation mockedObj, + final InvocationOnMock answer) + throws AbfsRestOperationException { + if (count == 0) { + count = 1; + AbfsHttpOperation op = Mockito.mock(AbfsHttpOperation.class); + Mockito.doReturn("PUT").when(op).getMethod(); + Mockito.doReturn("").when(op).getStorageErrorMessage(); Review Comment: Used Constants ########## hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsIntegrationTest.java: ########## @@ -733,4 +734,35 @@ protected void checkFuturesForExceptions(List<Future<?>> futures, int exceptionV } assertEquals(exceptionCaught, exceptionVal); } + + /** + * Assumes that recovery through client transaction ID is enabled. + * Namespace is enabled for the given AzureBlobFileSystem. + * Service type is DFS. + * Assumes that the client transaction ID is enabled in the configuration. + * + * @param fs the AzureBlobFileSystem instance to check + * @throws AzureBlobFileSystemException in case of an error + */ + protected void assumeRecoveryThroughClientTransactionID( + AzureBlobFileSystem fs, boolean isCreate) + throws AzureBlobFileSystemException { + // Assumes that recovery through client transaction ID is enabled. + Assume.assumeTrue(getConfiguration().getIsClientTransactionIdEnabled()); + // Assumes that service type is DFS. + assumeDfsServiceType(); + // Assumes that namespace is enabled for the given AzureBlobFileSystem. + Assume.assumeTrue( + fs.getIsNamespaceEnabled(getTestTracingContext(fs, true))); + if (isCreate) { + // Assume that create client is DFS client. + Assume.assumeTrue( + fs.getAbfsStore().getClientHandler().getIngressClient() + instanceof AbfsDfsClient); + // Assume that append blob is not enabled in DFS client. + Assume.assumeTrue( + StringUtils.isEmpty( + fs.getAbfsStore().getAbfsConfiguration().getAppendBlobDirs())); Review Comment: Made the changes -- 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: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org