27
27
import org .apache .hadoop .fs .azurebfs .contracts .exceptions .AbfsRestOperationException ;
28
28
import org .apache .hadoop .fs .azurebfs .contracts .services .AzureServiceErrorCode ;
29
29
import org .apache .hadoop .fs .azurebfs .oauth2 .RetryTestTokenProvider ;
30
- import org .apache .hadoop .fs .FileStatus ;
31
30
import org .apache .hadoop .fs .FileSystem ;
32
31
import org .apache .hadoop .fs .Path ;
33
32
@@ -55,7 +54,7 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
55
54
Path nonExistedFilePath1 = new Path ("nonExistedPath1" );
56
55
Path nonExistedFilePath2 = new Path ("nonExistedPath2" );
57
56
try {
58
- FileStatus fileStatus = fs .getFileStatus (nonExistedFilePath1 );
57
+ fs .getFileStatus (nonExistedFilePath1 );
59
58
} catch (Exception ex ) {
60
59
String errorMessage = ex .getLocalizedMessage ();
61
60
String [] errorFields = errorMessage .split ("," );
@@ -92,7 +91,7 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
92
91
// verify its format
93
92
String errorMessage = ex .getLocalizedMessage ();
94
93
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.
96
95
Assertions .assertThat (errorFields )
97
96
.describedAs ("Number of Fields in exception message are not as expected" )
98
97
.hasSize (7 );
@@ -144,32 +143,33 @@ public void testWithDifferentCustomTokenFetchRetry(int numOfRetries) throws Exce
144
143
145
144
Configuration config = new Configuration (this .getRawConfiguration ());
146
145
String accountName = config .get ("fs.azure.abfs.account.name" );
147
- // Setup to configure custom token provider
146
+ // Setup to configure custom token provider.
148
147
config .set ("fs.azure.account.auth.type." + accountName , "Custom" );
149
148
config .set ("fs.azure.account.oauth.provider.type." + accountName , "org.apache.hadoop.fs"
150
149
+ ".azurebfs.oauth2.RetryTestTokenProvider" );
151
150
config .set ("fs.azure.custom.token.fetch.retry.count" , Integer .toString (numOfRetries ));
152
151
// Stop filesystem creation as it will lead to calls to store.
153
152
config .set ("fs.azure.createRemoteFileSystemDuringInitialization" , "false" );
154
153
155
- final AzureBlobFileSystem fs1 =
154
+ try ( final AzureBlobFileSystem fs1 =
156
155
(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
+ }
173
173
}
174
174
175
175
@ Test
@@ -188,8 +188,10 @@ public void testAuthFailException() throws Exception {
188
188
189
189
final AzureBlobFileSystem fs = getFileSystem (config );
190
190
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
+ });
193
195
} catch (AbfsRestOperationException e ) {
194
196
String errorDesc = "Should throw RestOp exception on AAD failure" ;
195
197
Assertions .assertThat (e .getStatusCode ())
0 commit comments