From 37b1b4799db680d4a8bd4cb389e00d044f1e4a37 Mon Sep 17 00:00:00 2001 From: Sneha Vijayarajan Date: Tue, 26 May 2020 15:26:28 -0700 Subject: [PATCH] HADOOP-17054. ABFS: Fix test AbfsClient authentication instance Contributed by Sneha Vijayarajan --- .../fs/azurebfs/services/TestAbfsClient.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java index ce9c0325a4a..0fd65fb0a60 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java @@ -246,21 +246,29 @@ public final class TestAbfsClient { AbfsClient baseAbfsClientInstance, AbfsConfiguration abfsConfig) throws AzureBlobFileSystemException { - AbfsPerfTracker tracker = new AbfsPerfTracker("test", - abfsConfig.getAccountName(), - abfsConfig); + AuthType currentAuthType = abfsConfig.getAuthType( + abfsConfig.getAccountName()); - // Create test AbfsClient - AbfsClient testClient = new AbfsClient( - baseAbfsClientInstance.getBaseUrl(), - new SharedKeyCredentials(abfsConfig.getAccountName().substring(0, - abfsConfig.getAccountName().indexOf(DOT)), - abfsConfig.getStorageAccountKey()), - abfsConfig, - new ExponentialRetryPolicy(abfsConfig.getMaxIoRetries()), - abfsConfig.getTokenProvider(), - tracker); + AbfsPerfTracker tracker = new AbfsPerfTracker("test", + abfsConfig.getAccountName(), + abfsConfig); - return testClient; - } + // Create test AbfsClient + AbfsClient testClient = new AbfsClient( + baseAbfsClientInstance.getBaseUrl(), + (currentAuthType == AuthType.SharedKey + ? new SharedKeyCredentials( + abfsConfig.getAccountName().substring(0, + abfsConfig.getAccountName().indexOf(DOT)), + abfsConfig.getStorageAccountKey()) + : null), + abfsConfig, + new ExponentialRetryPolicy(abfsConfig.getMaxIoRetries()), + (currentAuthType == AuthType.OAuth + ? abfsConfig.getTokenProvider() + : null), + tracker); + + return testClient; + } }