Skip to content

Commit 874081e

Browse files
committed
HADOOP-19425. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-azure Part3.
1 parent e103142 commit 874081e

File tree

67 files changed

+2228
-2064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2228
-2064
lines changed

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package org.apache.hadoop.fs.azurebfs;
2020

21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
23+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
24+
2125
import java.io.IOException;
2226
import java.net.URI;
2327
import java.util.Hashtable;
@@ -28,10 +32,8 @@
2832
import java.util.concurrent.ExecutionException;
2933
import java.util.concurrent.Future;
3034

31-
import org.assertj.core.api.Assertions;
32-
import org.junit.After;
33-
import org.junit.Assume;
34-
import org.junit.Before;
35+
import org.junit.jupiter.api.AfterEach;
36+
import org.junit.jupiter.api.BeforeEach;
3537
import org.slf4j.Logger;
3638
import org.slf4j.LoggerFactory;
3739

@@ -73,7 +75,6 @@
7375
import static org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode.FILE_SYSTEM_NOT_FOUND;
7476
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.*;
7577
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
76-
import static org.junit.Assume.assumeTrue;
7778

7879
/**
7980
* Base for AzureBlobFileSystem Integration tests.
@@ -111,8 +112,8 @@ protected AbstractAbfsIntegrationTest() throws Exception {
111112
// check if accountName is set using different config key
112113
accountName = rawConfig.get(FS_AZURE_ABFS_ACCOUNT_NAME);
113114
}
114-
assumeTrue("Not set: " + FS_AZURE_ABFS_ACCOUNT_NAME,
115-
accountName != null && !accountName.isEmpty());
115+
assumeTrue(accountName != null && !accountName.isEmpty(),
116+
"Not set: " + FS_AZURE_ABFS_ACCOUNT_NAME);
116117

117118
final String abfsUrl = this.getFileSystemName() + "@" + this.getAccountName();
118119
URI defaultUri = null;
@@ -188,7 +189,7 @@ public TracingContext getTestTracingContext(AzureBlobFileSystem fs,
188189
FSOperationType.TEST_OP, needsPrimaryReqId, format, null);
189190
}
190191

191-
@Before
192+
@BeforeEach
192193
public void setup() throws Exception {
193194
//Create filesystem first to make sure getWasbFileSystem() can return an existing filesystem.
194195
createFileSystem();
@@ -221,7 +222,7 @@ public void setup() throws Exception {
221222
}
222223
}
223224

224-
@After
225+
@AfterEach
225226
public void teardown() throws Exception {
226227
try {
227228
IOUtils.closeStream(wasb);
@@ -565,23 +566,22 @@ protected AbfsOutputStream createAbfsOutputStreamWithFlushEnabled(
565566
*/
566567
protected long assertAbfsStatistics(AbfsStatistic statistic,
567568
long expectedValue, Map<String, Long> metricMap) {
568-
assertEquals("Mismatch in " + statistic.getStatName(), expectedValue,
569-
(long) metricMap.get(statistic.getStatName()));
569+
assertEquals(expectedValue, (long) metricMap.get(statistic.getStatName()),
570+
"Mismatch in " + statistic.getStatName());
570571
return expectedValue;
571572
}
572573

573574
protected void assumeValidTestConfigPresent(final Configuration conf, final String key) {
574575
String configuredValue = conf.get(accountProperty(key, accountName),
575576
conf.get(key, ""));
576-
Assume.assumeTrue(String.format("Missing Required Test Config: %s.", key),
577-
!configuredValue.isEmpty());
577+
assumeTrue(!configuredValue.isEmpty(),
578+
String.format("Missing Required Test Config: %s.", key));
578579
}
579580

580581
protected void assumeValidAuthConfigsPresent() {
581582
final AuthType currentAuthType = getAuthType();
582-
Assume.assumeFalse(
583-
"SAS Based Authentication Not Allowed For Integration Tests",
584-
currentAuthType == AuthType.SAS);
583+
assumeFalse(currentAuthType == AuthType.SAS,
584+
"SAS Based Authentication Not Allowed For Integration Tests");
585585
if (currentAuthType == AuthType.SharedKey) {
586586
assumeValidTestConfigPresent(getRawConfiguration(), FS_AZURE_ACCOUNT_KEY);
587587
} else {
@@ -612,7 +612,7 @@ public AbfsServiceType getIngressServiceType() {
612612
* @param path path to create. Can be relative or absolute.
613613
*/
614614
protected void createAzCopyFolder(Path path) throws Exception {
615-
Assume.assumeTrue(getAbfsServiceType() == AbfsServiceType.BLOB);
615+
assumeTrue(getAbfsServiceType() == AbfsServiceType.BLOB);
616616
assumeValidTestConfigPresent(getRawConfiguration(), FS_AZURE_TEST_FIXED_SAS_TOKEN);
617617
String sasToken = getRawConfiguration().get(FS_AZURE_TEST_FIXED_SAS_TOKEN);
618618
AzcopyToolHelper azcopyHelper = AzcopyToolHelper.getInstance(sasToken);
@@ -624,7 +624,7 @@ protected void createAzCopyFolder(Path path) throws Exception {
624624
* @param path path to create. Can be relative or absolute.
625625
*/
626626
protected void createAzCopyFile(Path path) throws Exception {
627-
Assume.assumeTrue(getAbfsServiceType() == AbfsServiceType.BLOB);
627+
assumeTrue(getAbfsServiceType() == AbfsServiceType.BLOB);
628628
assumeValidTestConfigPresent(getRawConfiguration(), FS_AZURE_TEST_FIXED_SAS_TOKEN);
629629
String sasToken = getRawConfiguration().get(FS_AZURE_TEST_FIXED_SAS_TOKEN);
630630
AzcopyToolHelper azcopyHelper = AzcopyToolHelper.getInstance(sasToken);
@@ -642,17 +642,17 @@ private String getAzcopyAbsolutePath(Path path) throws IOException {
642642
* Otherwise, the test will be skipped.
643643
*/
644644
protected void assumeBlobServiceType() {
645-
Assume.assumeTrue("Blob service type is required for this test",
646-
getAbfsServiceType() == AbfsServiceType.BLOB);
645+
assumeTrue(getAbfsServiceType() == AbfsServiceType.BLOB,
646+
"Blob service type is required for this test");
647647
}
648648

649649
/**
650650
* Utility method to assume that the test is running against a DFS service.
651651
* Otherwise, the test will be skipped.
652652
*/
653653
protected void assumeDfsServiceType() {
654-
Assume.assumeTrue("DFS service type is required for this test",
655-
getAbfsServiceType() == AbfsServiceType.DFS);
654+
assumeTrue(getAbfsServiceType() == AbfsServiceType.DFS,
655+
"DFS service type is required for this test");
656656
}
657657

658658
/**
@@ -670,7 +670,7 @@ protected void assumeHnsEnabled() throws IOException {
670670
* @throws IOException if an error occurs while checking the account type.
671671
*/
672672
protected void assumeHnsEnabled(String errorMessage) throws IOException {
673-
Assume.assumeTrue(errorMessage, getIsNamespaceEnabled(getFileSystem()));
673+
assumeTrue(getIsNamespaceEnabled(getFileSystem()), errorMessage);
674674
}
675675

676676
/**
@@ -688,7 +688,7 @@ protected void assumeHnsDisabled() throws IOException {
688688
* @throws IOException if an error occurs while checking the account type.
689689
*/
690690
protected void assumeHnsDisabled(String message) throws IOException {
691-
Assume.assumeFalse(message, getIsNamespaceEnabled(getFileSystem()));
691+
assumeFalse(getIsNamespaceEnabled(getFileSystem()), message);
692692
}
693693

694694
/**
@@ -699,7 +699,7 @@ protected void assumeHnsDisabled(String message) throws IOException {
699699
protected void assertPathDns(Path path) {
700700
String expectedDns = getAbfsServiceType() == AbfsServiceType.BLOB
701701
? ABFS_BLOB_DOMAIN_NAME : ABFS_DFS_DOMAIN_NAME;
702-
Assertions.assertThat(path.toString())
702+
assertThat(path.toString())
703703
.describedAs("Path does not contain expected DNS")
704704
.contains(expectedDns);
705705
}
@@ -745,19 +745,23 @@ protected void checkFuturesForExceptions(List<Future<?>> futures, int exceptionV
745745
protected void assumeRecoveryThroughClientTransactionID(boolean isCreate)
746746
throws IOException {
747747
// Assumes that recovery through client transaction ID is enabled.
748-
Assume.assumeTrue("Recovery through client transaction ID is not enabled",
749-
getConfiguration().getIsClientTransactionIdEnabled());
748+
assumeTrue(getConfiguration().getIsClientTransactionIdEnabled(),
749+
"Recovery through client transaction ID is not enabled");
750750
// Assumes that service type is DFS.
751751
assumeDfsServiceType();
752752
// Assumes that namespace is enabled for the given AzureBlobFileSystem.
753753
assumeHnsEnabled();
754754
if (isCreate) {
755755
// Assume that create client is DFS client.
756-
Assume.assumeTrue("Ingress service type is not DFS",
757-
AbfsServiceType.DFS.equals(getIngressServiceType()));
756+
assumeTrue(AbfsServiceType.DFS.equals(getIngressServiceType()),
757+
"Ingress service type is not DFS");
758758
// Assume that append blob is not enabled in DFS client.
759-
Assume.assumeFalse("Append blob is enabled in DFS client",
760-
isAppendBlobEnabled());
759+
assumeFalse(isAppendBlobEnabled(),
760+
"Append blob is enabled in DFS client");
761761
}
762762
}
763+
764+
protected void assumeNotNull(Object objects) {
765+
assumeTrue(objects != null);
766+
}
763767
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@
1818

1919
package org.apache.hadoop.fs.azurebfs;
2020

21+
import org.junit.jupiter.api.Timeout;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
2324

2425
import org.apache.hadoop.conf.Configuration;
2526
import org.apache.hadoop.fs.azure.integration.AzureTestConstants;
2627

28+
import static org.apache.hadoop.fs.azure.integration.AzureTestConstants.SCALE_TEST_TIMEOUT_MILLIS;
2729
import static org.apache.hadoop.fs.azure.integration.AzureTestUtils.assumeScaleTestsEnabled;
2830

2931
/**
3032
* Integration tests at bigger scale; configurable as to
3133
* size, off by default.
3234
*/
35+
@Timeout(SCALE_TEST_TIMEOUT_MILLIS)
3336
public class AbstractAbfsScaleTest extends AbstractAbfsIntegrationTest {
3437

3538
protected static final Logger LOG =
@@ -39,11 +42,6 @@ public AbstractAbfsScaleTest() throws Exception {
3942
super();
4043
}
4144

42-
@Override
43-
protected int getTestTimeoutMillis() {
44-
return AzureTestConstants.SCALE_TEST_TIMEOUT_MILLIS;
45-
}
46-
4745
@Override
4846
public void setup() throws Exception {
4947
super.setup();

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

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
import java.io.IOException;
2121

22-
import org.junit.Assert;
23-
import org.junit.Before;
24-
import org.junit.BeforeClass;
25-
import org.junit.Rule;
26-
import org.junit.rules.TestName;
27-
import org.junit.rules.Timeout;
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.junit.jupiter.api.Timeout;
26+
import org.junit.jupiter.api.extension.RegisterExtension;
2827
import org.slf4j.Logger;
2928
import org.slf4j.LoggerFactory;
3029

30+
import org.apache.hadoop.test.TestName;
3131
import org.apache.hadoop.fs.FSDataInputStream;
3232
import org.apache.hadoop.fs.Path;
3333

@@ -37,35 +37,30 @@
3737
* Base class for any ABFS test with timeouts & named threads.
3838
* This class does not attempt to bind to Azure.
3939
*/
40-
public class AbstractAbfsTestWithTimeout extends Assert {
40+
@Timeout(TEST_TIMEOUT)
41+
public class AbstractAbfsTestWithTimeout extends Assertions {
4142
private static final Logger LOG =
4243
LoggerFactory.getLogger(AbstractAbfsTestWithTimeout.class);
4344

4445
/**
4546
* The name of the current method.
4647
*/
47-
@Rule
48-
public TestName methodName = new TestName();
49-
/**
50-
* Set the timeout for every test.
51-
* This is driven by the value returned by {@link #getTestTimeoutMillis()}.
52-
*/
53-
@Rule
54-
public Timeout testTimeout = new Timeout(getTestTimeoutMillis());
48+
@RegisterExtension
49+
protected TestName methodName = new TestName();
5550

5651
/**
5752
* Name the junit thread for the class. This will overridden
5853
* before the individual test methods are run.
5954
*/
60-
@BeforeClass
55+
@BeforeAll
6156
public static void nameTestThread() {
6257
Thread.currentThread().setName("JUnit");
6358
}
6459

6560
/**
6661
* Name the thread to the current test method.
6762
*/
68-
@Before
63+
@BeforeEach
6964
public void nameThread() {
7065
Thread.currentThread().setName("JUnit-" + methodName.getMethodName());
7166
}
@@ -110,15 +105,15 @@ protected boolean validateContent(AzureBlobFileSystem fs, Path path,
110105

111106
while (valueOfContentAtPos != -1 && pos < lenOfOriginalByteArray) {
112107
if (originalByteArray[pos] != valueOfContentAtPos) {
113-
assertEquals("Mismatch in content validation at position {}", pos,
114-
originalByteArray[pos], valueOfContentAtPos);
108+
assertEquals(originalByteArray[pos], valueOfContentAtPos,
109+
"Mismatch in content validation at position " + pos);
115110
return false;
116111
}
117112
valueOfContentAtPos = (byte) in.read();
118113
pos++;
119114
}
120115
if (valueOfContentAtPos != -1) {
121-
assertEquals("Expected end of file", -1, valueOfContentAtPos);
116+
assertEquals(-1, valueOfContentAtPos, "Expected end of file");
122117
return false;
123118
}
124119
return true;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.azurebfs;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.apache.hadoop.security.alias.CredentialProviderFactory;
2424
import org.apache.hadoop.conf.Configuration;
@@ -35,7 +35,7 @@ public void testIncompatibleCredentialProviderIsExcluded() throws Exception {
3535
rawConfig.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
3636
"jceks://abfs@[email protected]/tmp/a.jceks,jceks://file/tmp/secret.jceks");
3737
try (AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.get(rawConfig)) {
38-
assertNotNull("filesystem", fs);
38+
assertNotNull(fs, "filesystem");
3939
String providers = fs.getConf().get(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH);
4040
assertEquals("jceks://file/tmp/secret.jceks", providers);
4141
}

0 commit comments

Comments
 (0)