Skip to content

Commit 0379aeb

Browse files
sumangala-patkisteveloughran
authored andcommitted
HADOOP-17873. ABFS: Fix transient failures in ITestAbfsStreamStatistics and ITestAbfsRestOperationException (#3341)
Addresses transient failures in the following test classes: * ITestAbfsStreamStatistics: Uses a filesystem level static instance to record read/write statistics, which also tracks these operations in other tests running in parallel. Marked for sequential-only run to avoid transient failure * ITestAbfsRestOperationException: The use of a static member to track retry count causes transient failures when two tests of this class happen to run together. Switch to non-static variable for assertions on retry count closes #3341 Contributed by Sumangala Patki Change-Id: Ied4dec35c81e94efe5f999acae4bb8fde278202e
1 parent a68671e commit 0379aeb

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
@@ -555,6 +555,7 @@
555555
<exclude>**/azurebfs/ITestAzureBlobFileSystemListStatus.java</exclude>
556556
<exclude>**/azurebfs/extensions/ITestAbfsDelegationTokens.java</exclude>
557557
<exclude>**/azurebfs/ITestSmallWriteOptimization.java</exclude>
558+
<exclude>**/azurebfs/ITestAbfsStreamStatistics*.java</exclude>
558559
<exclude>**/azurebfs/services/ITestReadBufferManager.java</exclude>
559560
</excludes>
560561

@@ -597,6 +598,7 @@
597598
<include>**/azurebfs/extensions/ITestAbfsDelegationTokens.java</include>
598599
<include>**/azurebfs/ITestSmallWriteOptimization.java</include>
599600
<include>**/azurebfs/services/ITestReadBufferManager.java</include>
601+
<include>**/azurebfs/ITestAbfsStreamStatistics*.java</include>
600602
</includes>
601603
</configuration>
602604
</execution>

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.thirdparty.com.google.common.annotations.VisibleForTesting;
2526
import org.apache.hadoop.thirdparty.com.google.common.base.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
@@ -1223,4 +1223,9 @@ public ListenableFuture<?> submit(Runnable runnable) {
12231223
public <V> void addCallback(ListenableFuture<V> future, FutureCallback<V> callback) {
12241224
Futures.addCallback(future, callback, executorService);
12251225
}
1226+
1227+
@VisibleForTesting
1228+
protected AccessTokenProvider getTokenProvider() {
1229+
return tokenProvider;
1230+
}
12261231
}

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,9 +37,11 @@
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.AbfsOutputStream;
4243
import org.apache.hadoop.fs.azurebfs.services.AuthType;
44+
import org.apache.hadoop.fs.azurebfs.services.TestAbfsClient;
4345
import org.apache.hadoop.fs.azure.AzureNativeFileSystemStore;
4446
import org.apache.hadoop.fs.azure.NativeAzureFileSystem;
4547
import org.apache.hadoop.fs.azure.metrics.AzureFileSystemInstrumentation;
@@ -239,6 +241,9 @@ public Hashtable<String, String> call() throws Exception {
239241
}
240242
}
241243

244+
public AccessTokenProvider getAccessTokenProvider(final AzureBlobFileSystem fs) {
245+
return TestAbfsClient.getAccessTokenProvider(fs.getAbfsStore().getClient());
246+
}
242247

243248
public void loadConfiguredFileSystem() throws Exception {
244249
// 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
@@ -111,18 +111,21 @@ public void testWithDifferentCustomTokenFetchRetry(int numOfRetries) throws Exce
111111
final AzureBlobFileSystem fs1 =
112112
(AzureBlobFileSystem) FileSystem.newInstance(fs.getUri(),
113113
config);
114-
RetryTestTokenProvider.ResetStatusToFirstTokenFetch();
114+
RetryTestTokenProvider retryTestTokenProvider
115+
= RetryTestTokenProvider.getCurrentRetryTestProviderInstance(
116+
getAccessTokenProvider(fs1));
117+
retryTestTokenProvider.resetStatusToFirstTokenFetch();
115118

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

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

128131
@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)