Skip to content

Commit 7bcf853

Browse files
HADOOP-17873. ABFS: Fix transient failures in ITestAbfsStreamStatistics and ITestAbfsRestOperationException (#3699)
Successor for the reverted PR #3341, using the hadoop @VisibleForTesting attribute Contributed by Sumangala Patki
1 parent be4c638 commit 7bcf853

File tree

7 files changed

+51
-13
lines changed

7 files changed

+51
-13
lines changed

hadoop-tools/hadoop-azure/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@
604604
<exclude>**/azurebfs/ITestAzureBlobFileSystemListStatus.java</exclude>
605605
<exclude>**/azurebfs/extensions/ITestAbfsDelegationTokens.java</exclude>
606606
<exclude>**/azurebfs/ITestSmallWriteOptimization.java</exclude>
607+
<exclude>**/azurebfs/ITestAbfsStreamStatistics*.java</exclude>
607608
<exclude>**/azurebfs/services/ITestReadBufferManager.java</exclude>
608609
<exclude>**/azurebfs/commit/*.java</exclude>
609610
</excludes>
@@ -647,6 +648,7 @@
647648
<include>**/azurebfs/extensions/ITestAbfsDelegationTokens.java</include>
648649
<include>**/azurebfs/ITestSmallWriteOptimization.java</include>
649650
<include>**/azurebfs/services/ITestReadBufferManager.java</include>
651+
<include>**/azurebfs/ITestAbfsStreamStatistics*.java</include>
650652
<include>**/azurebfs/commit/*.java</include>
651653
</includes>
652654
</configuration>

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/oauth2/CustomTokenProviderAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.net.URI;
2424

25+
import org.apache.hadoop.classification.VisibleForTesting;
2526
import org.apache.hadoop.util.Preconditions;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
@@ -138,4 +139,9 @@ public String getUserAgentSuffix() {
138139
String suffix = ExtensionHelper.getUserAgentSuffix(adaptee, "");
139140
return suffix != null ? suffix : "";
140141
}
142+
143+
@VisibleForTesting
144+
protected CustomTokenProviderAdaptee getCustomTokenProviderAdaptee() {
145+
return adaptee;
146+
}
141147
}

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,4 +1289,9 @@ public ListenableFuture<?> submit(Runnable runnable) {
12891289
public <V> void addCallback(ListenableFuture<V> future, FutureCallback<V> callback) {
12901290
Futures.addCallback(future, callback, executorService);
12911291
}
1292+
1293+
@VisibleForTesting
1294+
protected AccessTokenProvider getTokenProvider() {
1295+
return tokenProvider;
1296+
}
12921297
}

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsIntegrationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
import org.apache.hadoop.fs.Path;
3838
import org.apache.hadoop.fs.azurebfs.constants.FSOperationType;
3939
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
40+
import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider;
4041
import org.apache.hadoop.fs.azurebfs.security.AbfsDelegationTokenManager;
4142
import org.apache.hadoop.fs.azurebfs.services.AbfsClient;
4243
import org.apache.hadoop.fs.azurebfs.services.AbfsOutputStream;
4344
import org.apache.hadoop.fs.azurebfs.services.AuthType;
45+
import org.apache.hadoop.fs.azurebfs.services.TestAbfsClient;
4446
import org.apache.hadoop.fs.azure.AzureNativeFileSystemStore;
4547
import org.apache.hadoop.fs.azure.NativeAzureFileSystem;
4648
import org.apache.hadoop.fs.azure.metrics.AzureFileSystemInstrumentation;
@@ -251,6 +253,9 @@ public Hashtable<String, String> call() throws Exception {
251253
}
252254
}
253255

256+
public AccessTokenProvider getAccessTokenProvider(final AzureBlobFileSystem fs) {
257+
return TestAbfsClient.getAccessTokenProvider(fs.getAbfsStore().getClient());
258+
}
254259

255260
public void loadConfiguredFileSystem() throws Exception {
256261
// disable auto-creation of filesystem

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAbfsRestOperationException.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,21 @@ public void testWithDifferentCustomTokenFetchRetry(int numOfRetries) throws Exce
112112
final AzureBlobFileSystem fs1 =
113113
(AzureBlobFileSystem) FileSystem.newInstance(fs.getUri(),
114114
config);
115-
RetryTestTokenProvider.ResetStatusToFirstTokenFetch();
115+
RetryTestTokenProvider retryTestTokenProvider
116+
= RetryTestTokenProvider.getCurrentRetryTestProviderInstance(
117+
getAccessTokenProvider(fs1));
118+
retryTestTokenProvider.resetStatusToFirstTokenFetch();
116119

117120
intercept(Exception.class,
118121
()-> {
119122
fs1.getFileStatus(new Path("/"));
120123
});
121124

122125
// Number of retries done should be as configured
123-
Assert.assertTrue(
124-
"Number of token fetch retries (" + RetryTestTokenProvider.reTryCount
125-
+ ") done, does not match with fs.azure.custom.token.fetch.retry.count configured (" + numOfRetries
126-
+ ")", RetryTestTokenProvider.reTryCount == numOfRetries);
126+
Assert.assertEquals(
127+
"Number of token fetch retries done does not match with fs.azure"
128+
+ ".custom.token.fetch.retry.count configured", numOfRetries,
129+
retryTestTokenProvider.getRetryCount());
127130
}
128131

129132
@Test

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/oauth2/RetryTestTokenProvider.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,34 @@
3030
*/
3131
public class RetryTestTokenProvider implements CustomTokenProviderAdaptee {
3232

33-
// Need to track first token fetch otherwise will get counted as a retry too.
34-
private static boolean isThisFirstTokenFetch = true;
35-
public static int reTryCount = 0;
33+
private static final Logger LOG = LoggerFactory.getLogger(
34+
RetryTestTokenProvider.class);
3635

37-
private static final Logger LOG = LoggerFactory
38-
.getLogger(RetryTestTokenProvider.class);
36+
// Need to track first token fetch otherwise will get counted as a retry too.
37+
private boolean isThisFirstTokenFetch = true;
38+
private int retryCount = 0;
3939

4040
@Override
4141
public void initialize(Configuration configuration, String accountName)
4242
throws IOException {
4343

4444
}
4545

46-
public static void ResetStatusToFirstTokenFetch() {
46+
/**
47+
* Clear earlier retry details and reset RetryTestTokenProvider instance to
48+
* state of first access token fetch call.
49+
*/
50+
public void resetStatusToFirstTokenFetch() {
4751
isThisFirstTokenFetch = true;
48-
reTryCount = 0;
52+
retryCount = 0;
4953
}
5054

5155
@Override
5256
public String getAccessToken() throws IOException {
5357
if (isThisFirstTokenFetch) {
5458
isThisFirstTokenFetch = false;
5559
} else {
56-
reTryCount++;
60+
retryCount++;
5761
}
5862

5963
LOG.debug("RetryTestTokenProvider: Throw an exception in fetching tokens");
@@ -64,4 +68,13 @@ public String getAccessToken() throws IOException {
6468
public Date getExpiryTime() {
6569
return new Date();
6670
}
71+
72+
public static RetryTestTokenProvider getCurrentRetryTestProviderInstance(
73+
AccessTokenProvider customTokenProvider) {
74+
return (RetryTestTokenProvider) ((CustomTokenProviderAdapter) customTokenProvider).getCustomTokenProviderAdaptee();
75+
}
76+
77+
public int getRetryCount() {
78+
return retryCount;
79+
}
6780
}

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,8 @@ public static AbfsRestOperation getRestOp(AbfsRestOperationType type,
395395
url,
396396
requestHeaders);
397397
}
398+
399+
public static AccessTokenProvider getAccessTokenProvider(AbfsClient client) {
400+
return client.getTokenProvider();
401+
}
398402
}

0 commit comments

Comments
 (0)