|
19 | 19 | package org.apache.hadoop.fs.azurebfs.services;
|
20 | 20 |
|
21 | 21 | import java.io.IOException;
|
22 |
| -import java.lang.reflect.Field; |
23 | 22 | import java.net.ProtocolException;
|
24 | 23 | import java.net.URI;
|
25 | 24 | import java.net.URISyntaxException;
|
|
29 | 28 | import java.util.Random;
|
30 | 29 | import java.util.regex.Pattern;
|
31 | 30 |
|
32 |
| -import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl; |
33 | 31 | import org.assertj.core.api.Assertions;
|
34 | 32 | import org.junit.Assume;
|
35 | 33 | import org.junit.Test;
|
36 | 34 | import org.junit.runner.RunWith;
|
37 | 35 | import org.junit.runners.Parameterized;
|
38 | 36 | import org.mockito.Mockito;
|
39 | 37 |
|
| 38 | +import org.apache.hadoop.conf.Configuration; |
40 | 39 | import org.apache.hadoop.fs.FileSystem;
|
41 | 40 | import org.apache.hadoop.fs.Path;
|
42 | 41 | import org.apache.hadoop.fs.azurebfs.AbfsConfiguration;
|
| 42 | +import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl; |
43 | 43 | import org.apache.hadoop.fs.azurebfs.AbstractAbfsIntegrationTest;
|
44 | 44 | import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem;
|
45 | 45 | import org.apache.hadoop.fs.azurebfs.TestAbfsConfigurationFieldsValidation;
|
|
49 | 49 | import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
|
50 | 50 | import org.apache.hadoop.fs.azurebfs.contracts.services.AppendRequestParameters;
|
51 | 51 | import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider;
|
52 |
| -import org.apache.hadoop.conf.Configuration; |
53 | 52 | import org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys;
|
54 | 53 | import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
|
55 | 54 | import org.apache.hadoop.fs.azurebfs.utils.TracingHeaderFormat;
|
56 | 55 | import org.apache.hadoop.security.ssl.DelegatingSSLSocketFactory;
|
| 56 | +import org.apache.hadoop.test.ReflectionUtils; |
57 | 57 | import org.apache.http.HttpResponse;
|
58 | 58 |
|
59 | 59 | import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
|
@@ -423,50 +423,30 @@ public static AbfsClient getMockAbfsClient(AbfsClient baseAbfsClientInstance,
|
423 | 423 | Mockito.doReturn(baseAbfsClientInstance.getAbfsApacheHttpClient()).when(client).getAbfsApacheHttpClient();
|
424 | 424 |
|
425 | 425 | // override baseurl
|
426 |
| - client = ITestAbfsClient.setAbfsClientField(client, "abfsConfiguration", |
427 |
| - abfsConfig); |
| 426 | + ReflectionUtils.setFinalField(AbfsClient.class, client, "abfsConfiguration", abfsConfig); |
428 | 427 |
|
429 | 428 | // override baseurl
|
430 |
| - client = ITestAbfsClient.setAbfsClientField(client, "baseUrl", |
431 |
| - baseAbfsClientInstance.getBaseUrl()); |
| 429 | + ReflectionUtils.setFinalField(AbfsClient.class, client, "baseUrl", baseAbfsClientInstance.getBaseUrl()); |
432 | 430 |
|
433 | 431 | // override xMsVersion
|
434 |
| - client = ITestAbfsClient.setAbfsClientField(client, "xMsVersion", |
435 |
| - baseAbfsClientInstance.getxMsVersion()); |
| 432 | + ReflectionUtils.setFinalField(AbfsClient.class, client, "xMsVersion", baseAbfsClientInstance.getxMsVersion()); |
436 | 433 |
|
437 | 434 | // override auth provider
|
438 | 435 | if (currentAuthType == AuthType.SharedKey) {
|
439 |
| - client = ITestAbfsClient.setAbfsClientField(client, "sharedKeyCredentials", |
440 |
| - new SharedKeyCredentials( |
| 436 | + ReflectionUtils.setFinalField(AbfsClient.class, client, "sharedKeyCredentials", new SharedKeyCredentials( |
441 | 437 | abfsConfig.getAccountName().substring(0,
|
442 | 438 | abfsConfig.getAccountName().indexOf(DOT)),
|
443 | 439 | abfsConfig.getStorageAccountKey()));
|
444 | 440 | } else {
|
445 |
| - client = ITestAbfsClient.setAbfsClientField(client, "tokenProvider", |
446 |
| - abfsConfig.getTokenProvider()); |
| 441 | + ReflectionUtils.setFinalField(AbfsClient.class, client, "tokenProvider", abfsConfig.getTokenProvider()); |
447 | 442 | }
|
448 | 443 |
|
449 | 444 | // override user agent
|
450 | 445 | String userAgent = "APN/1.0 Azure Blob FS/3.5.0-SNAPSHOT (PrivateBuild "
|
451 | 446 | + "JavaJRE 1.8.0_252; Linux 5.3.0-59-generic/amd64; openssl-1.0; "
|
452 | 447 | + "UNKNOWN/UNKNOWN) MSFT";
|
453 |
| - client = ITestAbfsClient.setAbfsClientField(client, "userAgent", userAgent); |
454 |
| - |
455 |
| - return client; |
456 |
| - } |
| 448 | + ReflectionUtils.setFinalField(AbfsClient.class, client, "userAgent", userAgent); |
457 | 449 |
|
458 |
| - static AbfsClient setAbfsClientField( |
459 |
| - final AbfsClient client, |
460 |
| - final String fieldName, |
461 |
| - Object fieldObject) throws Exception { |
462 |
| - |
463 |
| - Field field = AbfsClient.class.getDeclaredField(fieldName); |
464 |
| - field.setAccessible(true); |
465 |
| - Field modifiersField = Field.class.getDeclaredField("modifiers"); |
466 |
| - modifiersField.setAccessible(true); |
467 |
| - modifiersField.setInt(field, |
468 |
| - field.getModifiers() & ~java.lang.reflect.Modifier.FINAL); |
469 |
| - field.set(client, fieldObject); |
470 | 450 | return client;
|
471 | 451 | }
|
472 | 452 |
|
|
0 commit comments