Skip to content

Commit 9098424

Browse files
committed
HADOOP-19425. Improve Some Code.
1 parent b226480 commit 9098424

27 files changed

+121
-84
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public void testGetAclCallOnHnsConfigAbsence() throws Exception {
8888
AzureBlobFileSystem fs = ((AzureBlobFileSystem) FileSystem.newInstance(
8989
getRawConfiguration()));
9090

91-
AzureBlobFileSystemStore store = Mockito.spy(fs.getAbfsStore());
92-
AbfsClient client = Mockito.spy(fs.getAbfsStore().getClient(AbfsServiceType.DFS));
91+
AzureBlobFileSystemStore store = spy(fs.getAbfsStore());
92+
AbfsClient client = spy(fs.getAbfsStore().getClient(AbfsServiceType.DFS));
9393
doReturn(client).when(store).getClient(AbfsServiceType.DFS);
9494
store.getAbfsConfiguration().setIsNamespaceEnabledAccountForTesting(Trilean.UNKNOWN);
9595

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public void testMkdirExistingDirOverwriteFalse() throws Exception {
7171
assertMkdirs(fs, path); //checks that mkdirs returns true
7272
long timeCreated = fs.getFileStatus(path).getModificationTime();
7373
assertMkdirs(fs, path); //call to existing dir should return success
74-
assertEquals(timeCreated,
75-
fs.getFileStatus(path).getModificationTime(),
74+
assertEquals(timeCreated, fs.getFileStatus(path).getModificationTime(),
7675
"LMT should not be updated for existing dir");
7776
}
7877

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

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,36 @@
4646
import static org.assertj.core.api.Assertions.assertThat;
4747
import static org.junit.jupiter.api.Assumptions.assumeFalse;
4848
import static org.junit.jupiter.api.Assumptions.assumeTrue;
49+
import static org.assertj.core.api.Assertions.assertThat;
50+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
51+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
52+
import static org.junit.jupiter.api.Assertions.assertEquals;
53+
import static org.junit.jupiter.api.Assertions.assertFalse;
54+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
55+
import static org.junit.jupiter.api.Assertions.assertNotNull;
56+
import static org.junit.jupiter.api.Assertions.assertNotSame;
57+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
58+
import static org.junit.jupiter.api.Assertions.assertNull;
59+
import static org.junit.jupiter.api.Assertions.assertSame;
60+
import static org.junit.jupiter.api.Assertions.assertThrows;
61+
import static org.junit.jupiter.api.Assertions.assertTrue;
62+
import static org.junit.jupiter.api.Assertions.fail;
63+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
64+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4965
import static org.mockito.ArgumentMatchers.any;
66+
import static org.mockito.ArgumentMatchers.nullable;
67+
import static org.mockito.Mockito.any;
68+
import static org.mockito.Mockito.anyBoolean;
69+
import static org.mockito.Mockito.anyInt;
70+
import static org.mockito.Mockito.anyLong;
71+
import static org.mockito.Mockito.anyList;
5072
import static org.mockito.Mockito.anyString;
73+
import static org.mockito.Mockito.atMost;
74+
import static org.mockito.Mockito.atLeast;
75+
import static org.mockito.Mockito.atLeastOnce;
76+
import static org.mockito.Mockito.doAnswer;
77+
import static org.mockito.Mockito.doCallRealMethod;
78+
import static org.mockito.Mockito.doNothing;
5179
import static org.mockito.Mockito.doReturn;
5280
import static org.mockito.Mockito.doThrow;
5381
import static org.mockito.Mockito.mock;
@@ -365,17 +393,17 @@ public void testNameSpaceConfig() throws Exception {
365393
AbfsConfiguration abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName");
366394

367395
// Test that the namespace value when config is not set
368-
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount())
396+
assertThat(abfsConfig.getIsNamespaceEnabledAccount())
369397
.describedAs("Namespace enabled should be unknown in case config is not set")
370398
.isEqualTo(Trilean.UNKNOWN);
371399

372400
// In case no namespace config is present, file system init calls getAcl() to determine account type.
373-
Assertions.assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false)))
401+
assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false)))
374402
.describedAs("getIsNamespaceEnabled should return account type based on getAcl() call")
375403
.isEqualTo(abfs.getAbfsClient().getIsNamespaceEnabled());
376404

377405
// In case no namespace config is present, file system init calls getAcl() to determine account type.
378-
Assertions.assertThat(abfs.getAbfsStore().getAbfsConfiguration().getIsNamespaceEnabledAccount())
406+
assertThat(abfs.getAbfsStore().getAbfsConfiguration().getIsNamespaceEnabledAccount())
379407
.describedAs("getIsNamespaceEnabled() should return updated account type based on getAcl() call")
380408
.isNotEqualTo(Trilean.UNKNOWN);
381409

@@ -384,17 +412,17 @@ public void testNameSpaceConfig() throws Exception {
384412
abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName");
385413

386414
// Test that the namespace enabled config is set correctly
387-
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount())
415+
assertThat(abfsConfig.getIsNamespaceEnabledAccount())
388416
.describedAs("Namespace enabled should be true in case config is set to true")
389417
.isEqualTo(Trilean.TRUE);
390418

391419
// In case namespace config is present, same value will be return.
392-
Assertions.assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false)))
420+
assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false)))
393421
.describedAs("getIsNamespaceEnabled() should return true when config is set to true")
394422
.isEqualTo(true);
395423

396424
// In case namespace config is present, same value will be return.
397-
Assertions.assertThat(abfs.getAbfsClient().getIsNamespaceEnabled())
425+
assertThat(abfs.getAbfsClient().getIsNamespaceEnabled())
398426
.describedAs("Client's getIsNamespaceEnabled() should return true when config is set to true")
399427
.isEqualTo(true);
400428

@@ -403,17 +431,17 @@ public void testNameSpaceConfig() throws Exception {
403431
abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName");
404432

405433
// Test that the namespace enabled config is set correctly
406-
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount())
434+
assertThat(abfsConfig.getIsNamespaceEnabledAccount())
407435
.describedAs("Namespace enabled should be false in case config is set to false")
408436
.isEqualTo(Trilean.FALSE);
409437

410438
// In case namespace config is present, same value will be return.
411-
Assertions.assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false)))
439+
assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false)))
412440
.describedAs("getIsNamespaceEnabled() should return false when config is set to false")
413441
.isEqualTo(false);
414442

415443
// In case namespace config is present, same value will be return.
416-
Assertions.assertThat(abfs.getAbfsClient().getIsNamespaceEnabled())
444+
assertThat(abfs.getAbfsClient().getIsNamespaceEnabled())
417445
.describedAs("Client's getIsNamespaceEnabled() should return false when config is set to false")
418446
.isEqualTo(false);
419447
}
@@ -428,15 +456,15 @@ public void testNameSpaceConfig() throws Exception {
428456
@Test
429457
public void testFsInitShouldSetNamespaceConfig() throws Exception {
430458
// Mock the AzureBlobFileSystem and its dependencies
431-
AzureBlobFileSystem mockFileSystem = Mockito.spy((AzureBlobFileSystem)
459+
AzureBlobFileSystem mockFileSystem = spy((AzureBlobFileSystem)
432460
FileSystem.newInstance(getConfigurationWithoutHnsConfig()));
433-
AzureBlobFileSystemStore mockStore = Mockito.spy(mockFileSystem.getAbfsStore());
434-
AbfsClient abfsClient = Mockito.spy(mockStore.getClient());
435-
Mockito.doReturn(abfsClient).when(mockStore).getClient();
436-
Mockito.doReturn(abfsClient).when(mockStore).getClient(any());
461+
AzureBlobFileSystemStore mockStore = spy(mockFileSystem.getAbfsStore());
462+
AbfsClient abfsClient = spy(mockStore.getClient());
463+
doReturn(abfsClient).when(mockStore).getClient();
464+
doReturn(abfsClient).when(mockStore).getClient(any());
437465
abfsClient.getIsNamespaceEnabled();
438466
// Verify that getAclStatus is called once during initialization
439-
Mockito.verify(abfsClient, times(0))
467+
verify(abfsClient, times(0))
440468
.getAclStatus(anyString(), any(TracingContext.class));
441469

442470
mockStore.getAbfsConfiguration().setIsNamespaceEnabledAccountForTesting(Trilean.UNKNOWN);
@@ -445,19 +473,19 @@ public void testFsInitShouldSetNamespaceConfig() throws Exception {
445473
String errorMessage = intercept(InvalidConfigurationValueException.class, () -> {
446474
abfsClient.getIsNamespaceEnabled();
447475
}).getMessage();
448-
Assertions.assertThat(errorMessage)
476+
assertThat(errorMessage)
449477
.describedAs("Client should throw exception when namespace is unknown")
450478
.contains("Failed to determine account type");
451479

452480
// In case of unknown namespace, store's getIsNamespaceEnabled should call getAclStatus
453481
// to determine the namespace status.
454482
mockStore.getIsNamespaceEnabled(getTestTracingContext(mockFileSystem, false));
455-
Mockito.verify(abfsClient, times(1))
483+
verify(abfsClient, times(1))
456484
.getAclStatus(anyString(), any(TracingContext.class));
457485

458486
abfsClient.getIsNamespaceEnabled();
459487
// Verify that client's getNamespaceEnabled will not call getAclStatus again
460-
Mockito.verify(abfsClient, times(1))
488+
verify(abfsClient, times(1))
461489
.getAclStatus(anyString(), any(TracingContext.class));
462490
}
463491

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import static org.mockito.Mockito.anyString;
6060
import static org.mockito.Mockito.doNothing;
6161
import static org.mockito.Mockito.mock;
62+
import static org.assertj.core.api.Assertions.assertThat;
6263

6364
public class TestTracingContext extends AbstractAbfsIntegrationTest {
6465
private static final String[] CLIENT_CORRELATIONID_LIST = {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.hadoop.mapreduce.lib.output.committer.manifest.impl.ManifestStoreOperations;
4040

4141
import static org.apache.hadoop.fs.azurebfs.commit.AbfsCommitTestHelper.prepareTestConfiguration;
42+
import static org.assertj.core.api.Assertions.assertThat;
4243

4344
/**
4445
* Test the Manifest committer stages against ABFS.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import static org.apache.hadoop.fs.CommonPathCapabilities.ETAGS_PRESERVED_IN_RENAME;
4242
import static org.apache.hadoop.fs.azurebfs.commit.AbfsCommitTestHelper.prepareTestConfiguration;
4343
import static org.junit.Assume.assumeTrue;
44+
import static org.assertj.core.api.Assertions.assertThat;
4445

4546
/**
4647
* Test {@link AbfsManifestStoreOperations}.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ private ManifestSuccessData executeStage(
219219
d.close();
220220
}
221221
dumpOutputTree(dest);
222-
assertEquals(0, result, stage
223-
+ "(" + StringUtils.join(", ", args) + ")"
224-
+ " failed");
222+
assertEquals(0, result, stage+ "(" + StringUtils.join(", ", args) + ")"+ " failed");
225223
final ManifestSuccessData successFile = validateSuccessFile(getFileSystem(), dest,
226224
minimumFileCount, "");
227225
final IOStatistics iostats = successFile.getIOStatistics();

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

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import java.io.PrintStream;
2525
import java.net.URI;
2626

27-
import org.junit.AfterClass;
28-
import org.junit.BeforeClass;
29-
import org.junit.Test;
27+
import org.junit.jupiter.api.AfterAll;
28+
import org.junit.jupiter.api.BeforeAll;
29+
import org.junit.jupiter.api.Test;
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
3232

@@ -74,7 +74,7 @@ public class ITestAbfsDelegationTokens extends AbstractAbfsIntegrationTest {
7474
/***
7575
* Set up the clusters.
7676
*/
77-
@BeforeClass
77+
@BeforeAll
7878
public static void setupCluster() throws Exception {
7979
resetUGI();
8080
cluster = new KerberizedAbfsCluster();
@@ -86,7 +86,7 @@ public static void setupCluster() throws Exception {
8686
* Tear down the Cluster.
8787
*/
8888
@SuppressWarnings("ThrowableNotThrown")
89-
@AfterClass
89+
@AfterAll
9090
public static void teardownCluster() throws Exception {
9191
resetUGI();
9292
ServiceOperations.stopQuietly(LOG, cluster);
@@ -176,10 +176,9 @@ public void testTokenManagerBinding() throws Throwable {
176176
@Test
177177
public void testCanonicalization() throws Throwable {
178178
String service = getCanonicalServiceName();
179-
assertNotNull("No canonical service name from filesystem " + getFileSystem(),
180-
service);
181-
assertEquals(getFilesystemURI(), new URI(service),
182-
"canonical URI and service name mismatch");
179+
assertNotNull(
180+
service, "No canonical service name from filesystem " + getFileSystem());
181+
assertEquals(getFilesystemURI(), new URI(service), "canonical URI and service name mismatch");
183182
}
184183

185184
protected URI getFilesystemURI() throws IOException {
@@ -199,8 +198,8 @@ public void testDefaultCanonicalization() throws Throwable {
199198
FileSystem fs = getFileSystem();
200199
clearTokenServiceName();
201200

202-
assertEquals("canonicalServiceName is not the default",
203-
getDefaultServiceName(fs), getCanonicalServiceName());
201+
assertEquals(getDefaultServiceName(fs), getCanonicalServiceName(),
202+
"canonicalServiceName is not the default");
204203
}
205204

206205
protected String getDefaultServiceName(final FileSystem fs) {
@@ -218,8 +217,7 @@ protected void clearTokenServiceName() throws IOException {
218217
public void testRequestToken() throws Throwable {
219218
AzureBlobFileSystem fs = getFileSystem();
220219
Credentials credentials = mkTokens(fs);
221-
assertEquals(1, credentials.numberOfTokens(),
222-
"Number of collected tokens");
220+
assertEquals(1, credentials.numberOfTokens(), "Number of collected tokens");
223221
verifyCredentialsContainsToken(credentials, fs);
224222
}
225223

@@ -231,12 +229,11 @@ public void testRequestTokenDefault() throws Throwable {
231229
clearTokenServiceName();
232230

233231
AzureBlobFileSystem fs = getFileSystem();
234-
assertEquals("canonicalServiceName is not the default",
235-
getDefaultServiceName(fs), fs.getCanonicalServiceName());
232+
assertEquals(getDefaultServiceName(fs), fs.getCanonicalServiceName(),
233+
"canonicalServiceName is not the default");
236234

237235
Credentials credentials = mkTokens(fs);
238-
assertEquals(1,
239-
credentials.numberOfTokens(), "Number of collected tokens");
236+
assertEquals(1, credentials.numberOfTokens(), "Number of collected tokens");
240237
verifyCredentialsContainsToken(credentials,
241238
getDefaultServiceName(fs), getFilesystemURI().toString());
242239
}
@@ -264,16 +261,13 @@ public StubAbfsTokenIdentifier verifyCredentialsContainsToken(
264261
Token<? extends TokenIdentifier> token = credentials.getToken(
265262
new Text(serviceName));
266263

267-
assertEquals(StubAbfsTokenIdentifier.TOKEN_KIND, token.getKind(),
268-
"Token Kind in " + token);
269-
assertEquals("Token Service Kind in " + token,
270-
tokenService, token.getService().toString());
264+
assertEquals(StubAbfsTokenIdentifier.TOKEN_KIND, token.getKind(), "Token Kind in " + token);
265+
assertEquals("Token Service Kind in " + token, tokenService, token.getService().toString());
271266

272267
StubAbfsTokenIdentifier abfsId = (StubAbfsTokenIdentifier)
273268
token.decodeIdentifier();
274269
LOG.info("Created token {}", abfsId);
275-
assertEquals("token URI in " + abfsId,
276-
tokenService, abfsId.getUri().toString());
270+
assertEquals("token URI in " + abfsId, tokenService, abfsId.getUri().toString());
277271
return abfsId;
278272
}
279273

@@ -315,8 +309,8 @@ protected String dtutil(final int expected,
315309
() -> ToolRunner.run(conf, dt, args));
316310
String s = dtUtilContent.toString();
317311
LOG.info("\n{}", s);
318-
assertEquals(expected, r, "Exit code from command dtutil "
319-
+ StringUtils.join(" ", args) + " with output " + s);
312+
assertEquals(expected, r,
313+
"Exit code from command dtutil "+ StringUtils.join(" ", args) + " with output " + s);
320314
return s;
321315
}
322316

@@ -359,8 +353,7 @@ public void testBaseDTLifecycle() throws Throwable {
359353
ClassicDelegationTokenManager.useClassicDTManager(conf);
360354
try (FileSystem fs = FileSystem.newInstance(getFilesystemURI(), conf)) {
361355
Credentials credentials = mkTokens(fs);
362-
assertEquals(1,
363-
credentials.numberOfTokens(), "Number of collected tokens");
356+
assertEquals(1, credentials.numberOfTokens(), "Number of collected tokens");
364357
verifyCredentialsContainsToken(credentials,
365358
fs.getCanonicalServiceName(),
366359
ClassicDelegationTokenManager.UNSET);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
import java.util.Date;
2525

2626
import org.assertj.core.api.Assertions;
27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828
import org.mockito.Mockito;
2929

3030
import org.apache.commons.io.FileUtils;
3131
import org.apache.hadoop.fs.azurebfs.AbstractAbfsTestWithTimeout;
3232

3333
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
34+
import static org.assertj.core.api.Assertions.assertThat;
3435

3536
/**
3637
* Test the refresh logic of workload identity tokens.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import org.assertj.core.api.Assertions;
3333
import org.junit.Assume;
34-
import org.junit.Test;
34+
import org.junit.jupiter.api.Test;
3535
import org.junit.runner.RunWith;
3636
import org.junit.runners.Parameterized;
3737
import org.mockito.Mockito;
@@ -96,6 +96,7 @@
9696
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_NAME;
9797
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_TYPE;
9898
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.TEST_CONFIGURATION_FILE_NAME;
99+
import static org.assertj.core.api.Assertions.assertThat;
99100

100101
/**
101102
* Test useragent of abfs client.

0 commit comments

Comments
 (0)