Skip to content

Commit 6bb403d

Browse files
author
Anuj Modi
committed
Addressed Comments
1 parent 2db0bbc commit 6bb403d

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
2828
import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode;
2929
import org.apache.hadoop.fs.azurebfs.oauth2.RetryTestTokenProvider;
30-
import org.apache.hadoop.fs.FileStatus;
3130
import org.apache.hadoop.fs.FileSystem;
3231
import org.apache.hadoop.fs.Path;
3332

@@ -55,7 +54,7 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
5554
Path nonExistedFilePath1 = new Path("nonExistedPath1");
5655
Path nonExistedFilePath2 = new Path("nonExistedPath2");
5756
try {
58-
FileStatus fileStatus = fs.getFileStatus(nonExistedFilePath1);
57+
fs.getFileStatus(nonExistedFilePath1);
5958
} catch (Exception ex) {
6059
String errorMessage = ex.getLocalizedMessage();
6160
String[] errorFields = errorMessage.split(",");
@@ -92,7 +91,7 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
9291
// verify its format
9392
String errorMessage = ex.getLocalizedMessage();
9493
String[] errorFields = errorMessage.split(",");
95-
// Expected Fields are: Message, StatusCode, Method, URL, ActivityId(rId), StorageErrorCode, StorageErrorMessage
94+
// Expected Fields are: Message, StatusCode, Method, URL, ActivityId(rId), StorageErrorCode, StorageErrorMessage.
9695
Assertions.assertThat(errorFields)
9796
.describedAs("Number of Fields in exception message are not as expected")
9897
.hasSize(7);
@@ -144,32 +143,33 @@ public void testWithDifferentCustomTokenFetchRetry(int numOfRetries) throws Exce
144143

145144
Configuration config = new Configuration(this.getRawConfiguration());
146145
String accountName = config.get("fs.azure.abfs.account.name");
147-
// Setup to configure custom token provider
146+
// Setup to configure custom token provider.
148147
config.set("fs.azure.account.auth.type." + accountName, "Custom");
149148
config.set("fs.azure.account.oauth.provider.type." + accountName, "org.apache.hadoop.fs"
150149
+ ".azurebfs.oauth2.RetryTestTokenProvider");
151150
config.set("fs.azure.custom.token.fetch.retry.count", Integer.toString(numOfRetries));
152151
// Stop filesystem creation as it will lead to calls to store.
153152
config.set("fs.azure.createRemoteFileSystemDuringInitialization", "false");
154153

155-
final AzureBlobFileSystem fs1 =
154+
try (final AzureBlobFileSystem fs1 =
156155
(AzureBlobFileSystem) FileSystem.newInstance(fs.getUri(),
157-
config);
158-
RetryTestTokenProvider retryTestTokenProvider
159-
= RetryTestTokenProvider.getCurrentRetryTestProviderInstance(
160-
getAccessTokenProvider(fs1));
161-
retryTestTokenProvider.resetStatusToFirstTokenFetch();
162-
163-
intercept(Exception.class,
164-
()-> {
165-
fs1.getFileStatus(new Path("/"));
166-
});
167-
168-
// Number of retries done should be as configured
169-
Assertions.assertThat(retryTestTokenProvider.getRetryCount())
170-
.describedAs("Number of token fetch retries done does not "
171-
+ "match with fs.azure.custom.token.fetch.retry.count configured")
172-
.isEqualTo(numOfRetries);
156+
config)) {
157+
RetryTestTokenProvider retryTestTokenProvider
158+
= RetryTestTokenProvider.getCurrentRetryTestProviderInstance(
159+
getAccessTokenProvider(fs1));
160+
retryTestTokenProvider.resetStatusToFirstTokenFetch();
161+
162+
intercept(Exception.class,
163+
() -> {
164+
fs1.getFileStatus(new Path("/"));
165+
});
166+
167+
// Number of retries done should be as configured
168+
Assertions.assertThat(retryTestTokenProvider.getRetryCount())
169+
.describedAs("Number of token fetch retries done does not "
170+
+ "match with fs.azure.custom.token.fetch.retry.count configured")
171+
.isEqualTo(numOfRetries);
172+
}
173173
}
174174

175175
@Test
@@ -188,8 +188,10 @@ public void testAuthFailException() throws Exception {
188188

189189
final AzureBlobFileSystem fs = getFileSystem(config);
190190
try {
191-
fs.getFileStatus(new Path("/"));
192-
fail("Should fail at auth token fetch call");
191+
intercept(Exception.class,
192+
() -> {
193+
fs.getFileStatus(new Path("/"));
194+
});
193195
} catch (AbfsRestOperationException e) {
194196
String errorDesc = "Should throw RestOp exception on AAD failure";
195197
Assertions.assertThat(e.getStatusCode())

0 commit comments

Comments
 (0)