Skip to content

Commit 90a6f3b

Browse files
HADOOP-19426. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-azure-datalake Part1. (#7652)
* HADOOP-19426. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-azure-datalake Part1. Co-authored-by: Anuj Modi <[email protected]> Reviewed-by: Anuj Modi <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent 7ea3f51 commit 90a6f3b

File tree

8 files changed

+154
-157
lines changed

8 files changed

+154
-157
lines changed

hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestAzureADTokenProvider.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.net.URI;
2424
import java.net.URISyntaxException;
25+
import java.nio.file.Path;
2526

2627
import com.microsoft.azure.datalake.store.oauth2.DeviceCodeTokenProvider;
2728
import com.microsoft.azure.datalake.store.oauth2.MsiTokenProvider;
@@ -44,16 +45,16 @@
4445
.AZURE_AD_TOKEN_PROVIDER_TYPE_KEY;
4546
import static org.apache.hadoop.fs.adl.AdlConfKeys.DEVICE_CODE_CLIENT_APP_ID;
4647
import static org.apache.hadoop.fs.adl.TokenProviderType.*;
47-
import static org.junit.Assert.assertEquals;
48+
import static org.junit.jupiter.api.Assertions.assertEquals;
49+
import static org.junit.jupiter.api.Assertions.assertTrue;
50+
import static org.junit.jupiter.api.Assertions.fail;
4851

4952
import org.apache.hadoop.security.ProviderUtils;
5053
import org.apache.hadoop.security.alias.CredentialProvider;
5154
import org.apache.hadoop.security.alias.CredentialProviderFactory;
5255
import org.apache.hadoop.test.GenericTestUtils;
53-
import org.junit.Assert;
54-
import org.junit.Rule;
55-
import org.junit.Test;
56-
import org.junit.rules.TemporaryFolder;
56+
import org.junit.jupiter.api.Test;
57+
import org.junit.jupiter.api.io.TempDir;
5758

5859
/**
5960
* Test appropriate token provider is loaded as per configuration.
@@ -65,8 +66,8 @@ public class TestAzureADTokenProvider {
6566
private static final String CLIENT_SECRET = "MY_CLIENT_SECRET";
6667
private static final String REFRESH_URL = "http://localhost:8080/refresh";
6768

68-
@Rule
69-
public final TemporaryFolder tempDir = new TemporaryFolder();
69+
@TempDir
70+
private Path tempDir;
7071

7172
@Test
7273
public void testRefreshTokenProvider()
@@ -81,7 +82,7 @@ public void testRefreshTokenProvider()
8182
AdlFileSystem fileSystem = new AdlFileSystem();
8283
fileSystem.initialize(uri, conf);
8384
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
84-
Assert.assertTrue(tokenProvider instanceof RefreshTokenBasedTokenProvider);
85+
assertTrue(tokenProvider instanceof RefreshTokenBasedTokenProvider);
8586
}
8687

8788
@Test
@@ -97,7 +98,7 @@ public void testClientCredTokenProvider()
9798
AdlFileSystem fileSystem = new AdlFileSystem();
9899
fileSystem.initialize(uri, conf);
99100
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
100-
Assert.assertTrue(tokenProvider instanceof ClientCredsTokenProvider);
101+
assertTrue(tokenProvider instanceof ClientCredsTokenProvider);
101102
}
102103

103104
@Test
@@ -110,7 +111,7 @@ public void testMSITokenProvider()
110111
AdlFileSystem fileSystem = new AdlFileSystem();
111112
fileSystem.initialize(uri, conf);
112113
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
113-
Assert.assertTrue(tokenProvider instanceof MsiTokenProvider);
114+
assertTrue(tokenProvider instanceof MsiTokenProvider);
114115
}
115116

116117
@Test
@@ -129,7 +130,7 @@ public void testDeviceCodeTokenProvider()
129130
AdlFileSystem fileSystem = new AdlFileSystem();
130131
fileSystem.initialize(uri, conf);
131132
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
132-
Assert.assertTrue(tokenProvider instanceof DeviceCodeTokenProvider);
133+
assertTrue(tokenProvider instanceof DeviceCodeTokenProvider);
133134
}
134135
}
135136

@@ -145,7 +146,7 @@ public void testCustomCredTokenProvider()
145146
AdlFileSystem fileSystem = new AdlFileSystem();
146147
fileSystem.initialize(uri, conf);
147148
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
148-
Assert.assertTrue(tokenProvider instanceof SdkTokenProviderAdapter);
149+
assertTrue(tokenProvider instanceof SdkTokenProviderAdapter);
149150
}
150151

151152
@Test
@@ -157,7 +158,7 @@ public void testInvalidProviderConfigurationForType()
157158
AdlFileSystem fileSystem = new AdlFileSystem();
158159
try {
159160
fileSystem.initialize(uri, conf);
160-
Assert.fail("Initialization should have failed due no token provider "
161+
fail("Initialization should have failed due no token provider "
161162
+ "configuration");
162163
} catch (IllegalArgumentException e) {
163164
GenericTestUtils.assertExceptionContains(
@@ -179,17 +180,17 @@ public void testInvalidProviderConfigurationForClassPath()
179180
"wrong.classpath.CustomMockTokenProvider");
180181
try {
181182
fileSystem.initialize(uri, conf);
182-
Assert.fail("Initialization should have failed due invalid provider "
183+
fail("Initialization should have failed due invalid provider "
183184
+ "configuration");
184185
} catch (RuntimeException e) {
185-
Assert.assertTrue(
186+
assertTrue(
186187
e.getMessage().contains("wrong.classpath.CustomMockTokenProvider"));
187188
}
188189
}
189190

190191
private CredentialProvider createTempCredProvider(Configuration conf)
191192
throws URISyntaxException, IOException {
192-
final File file = tempDir.newFile("test.jks");
193+
final File file = tempDir.resolve("test.jks").toFile();
193194
final URI jks = ProviderUtils.nestURIForLocalJavaKeyStoreProvider(
194195
file.toURI());
195196
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
@@ -217,7 +218,7 @@ public void testRefreshTokenWithCredentialProvider()
217218
fileSystem.initialize(uri, conf);
218219
RefreshTokenBasedTokenProvider expected =
219220
new RefreshTokenBasedTokenProvider(CLIENT_ID, REFRESH_TOKEN);
220-
Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,
221+
assertTrue(EqualsBuilder.reflectionEquals(expected,
221222
fileSystem.getTokenProvider()));
222223
}
223224

@@ -236,7 +237,7 @@ public void testRefreshTokenWithCredentialProviderFallback()
236237
fileSystem.initialize(uri, conf);
237238
RefreshTokenBasedTokenProvider expected =
238239
new RefreshTokenBasedTokenProvider(CLIENT_ID, REFRESH_TOKEN);
239-
Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,
240+
assertTrue(EqualsBuilder.reflectionEquals(expected,
240241
fileSystem.getTokenProvider()));
241242
}
242243

@@ -263,7 +264,7 @@ public void testClientCredWithCredentialProvider()
263264
fileSystem.initialize(uri, conf);
264265
ClientCredsTokenProvider expected = new ClientCredsTokenProvider(
265266
REFRESH_URL, CLIENT_ID, CLIENT_SECRET);
266-
Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,
267+
assertTrue(EqualsBuilder.reflectionEquals(expected,
267268
fileSystem.getTokenProvider()));
268269
}
269270

@@ -283,7 +284,7 @@ public void testClientCredWithCredentialProviderFallback()
283284
fileSystem.initialize(uri, conf);
284285
ClientCredsTokenProvider expected = new ClientCredsTokenProvider(
285286
REFRESH_URL, CLIENT_ID, CLIENT_SECRET);
286-
Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,
287+
assertTrue(EqualsBuilder.reflectionEquals(expected,
287288
fileSystem.getTokenProvider()));
288289
}
289290

hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestRelativePathFormation.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
import org.apache.hadoop.conf.Configuration;
2222
import org.apache.hadoop.fs.Path;
23-
import org.junit.Assert;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2524

2625
import java.io.IOException;
2726
import java.net.URI;
@@ -31,6 +30,7 @@
3130
.AZURE_AD_TOKEN_PROVIDER_CLASS_KEY;
3231
import static org.apache.hadoop.fs.adl.AdlConfKeys
3332
.AZURE_AD_TOKEN_PROVIDER_TYPE_KEY;
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
3434

3535
/**
3636
* This class verifies path conversion to SDK.
@@ -48,17 +48,17 @@ public void testToRelativePath() throws URISyntaxException, IOException {
4848

4949
fs.initialize(new URI("adl://temp.account.net"), configuration);
5050

51-
Assert.assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr")));
52-
Assert.assertEquals("/usr",
51+
assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr")));
52+
assertEquals("/usr",
5353
fs.toRelativeFilePath(new Path("adl://temp.account.net/usr")));
5454

5555
// When working directory is set.
5656
fs.setWorkingDirectory(new Path("/a/b/"));
57-
Assert.assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr")));
58-
Assert.assertEquals("/a/b/usr", fs.toRelativeFilePath(new Path("usr")));
59-
Assert.assertEquals("/usr",
57+
assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr")));
58+
assertEquals("/a/b/usr", fs.toRelativeFilePath(new Path("usr")));
59+
assertEquals("/usr",
6060
fs.toRelativeFilePath(new Path("adl://temp.account.net/usr")));
61-
Assert.assertEquals("/usr",
61+
assertEquals("/usr",
6262
fs.toRelativeFilePath(new Path("wasb://temp.account.net/usr")));
6363
}
6464

hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestValidateConfiguration.java

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

2121
import org.apache.hadoop.conf.Configuration;
2222
import org.apache.hadoop.test.GenericTestUtils;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
import static org.apache.hadoop.fs.adl.AdlConfKeys.ADL_BLOCK_SIZE;
2626
import static org.apache.hadoop.fs.adl.AdlConfKeys
@@ -57,7 +57,7 @@
5757
.TOKEN_PROVIDER_TYPE_REFRESH_TOKEN;
5858
import static org.apache.hadoop.fs.adl.AdlConfKeys.WRITE_BUFFER_SIZE_KEY;
5959

60-
import static org.junit.Assert.assertEquals;
60+
import static org.junit.jupiter.api.Assertions.assertEquals;
6161

6262
import java.io.File;
6363
import java.io.FileOutputStream;

hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlDifferentSizeWritesLive.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@
2323
import org.apache.hadoop.fs.FSDataOutputStream;
2424
import org.apache.hadoop.fs.FileSystem;
2525
import org.apache.hadoop.fs.Path;
26-
import org.apache.hadoop.fs.adl.common.Parallelized;
27-
import org.junit.Assert;
28-
import org.junit.Before;
29-
import org.junit.BeforeClass;
30-
import org.junit.Test;
31-
import org.junit.runner.RunWith;
32-
import org.junit.runners.Parameterized;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.MethodSource;
3330

3431
import java.io.IOException;
3532
import java.net.URISyntaxException;
@@ -39,19 +36,21 @@
3936
import java.util.UUID;
4037

4138
import static org.apache.hadoop.fs.adl.AdlConfKeys.WRITE_BUFFER_SIZE_KEY;
39+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
40+
import static org.junit.jupiter.api.Assertions.assertTrue;
41+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4242

4343
/**
4444
* Verify data integrity with different data sizes with buffer size.
4545
*/
46-
@RunWith(Parallelized.class)
4746
public class TestAdlDifferentSizeWritesLive {
4847
private static Random rand = new Random();
4948
private int totalSize;
5049
private int chunkSize;
5150

52-
public TestAdlDifferentSizeWritesLive(int totalSize, int chunkSize) {
53-
this.totalSize = totalSize;
54-
this.chunkSize = chunkSize;
51+
public void initTestAdlDifferentSizeWritesLive(int pTotalSize, int pChunkSize) {
52+
this.totalSize = pTotalSize;
53+
this.chunkSize = pChunkSize;
5554
}
5655

5756
public static byte[] getRandomByteArrayData(int size) {
@@ -60,8 +59,6 @@ public static byte[] getRandomByteArrayData(int size) {
6059
return b;
6160
}
6261

63-
@Parameterized.Parameters(name = "{index}: Data Size [{0}] ; Chunk Size "
64-
+ "[{1}]")
6562
public static Collection testDataForIntegrityTest() {
6663
return Arrays.asList(
6764
new Object[][] {{4 * 1024, 1 * 1024}, {4 * 1024, 7 * 1024},
@@ -71,7 +68,7 @@ public static Collection testDataForIntegrityTest() {
7168
{10 * 1024, 8 * 1024}});
7269
}
7370

74-
@BeforeClass
71+
@BeforeAll
7572
public static void cleanUpParent() throws IOException, URISyntaxException {
7673
if (AdlStorageConfiguration.isContractTestEnabled()) {
7774
Path path = new Path("/test/dataIntegrityCheck/");
@@ -80,14 +77,15 @@ public static void cleanUpParent() throws IOException, URISyntaxException {
8077
}
8178
}
8279

83-
@Before
80+
@BeforeEach
8481
public void setup() throws Exception {
85-
org.junit.Assume
86-
.assumeTrue(AdlStorageConfiguration.isContractTestEnabled());
82+
assumeTrue(AdlStorageConfiguration.isContractTestEnabled());
8783
}
8884

89-
@Test
90-
public void testDataIntegrity() throws IOException {
85+
@MethodSource("testDataForIntegrityTest")
86+
@ParameterizedTest(name = "{index}: Data Size [{0}] ; Chunk Size [{1}]")
87+
public void testDataIntegrity(int pTotalSize, int pChunkSize) throws IOException {
88+
initTestAdlDifferentSizeWritesLive(pTotalSize, pChunkSize);
9189
Path path = new Path(
9290
"/test/dataIntegrityCheck/" + UUID.randomUUID().toString());
9391
FileSystem fs = null;
@@ -117,7 +115,7 @@ public void testDataIntegrity() throws IOException {
117115
FSDataInputStream in = fs.open(path);
118116
in.readFully(0, actualData);
119117
in.close();
120-
Assert.assertArrayEquals(expectedData, actualData);
121-
Assert.assertTrue(fs.delete(path, true));
118+
assertArrayEquals(expectedData, actualData);
119+
assertTrue(fs.delete(path, true));
122120
}
123121
}

hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlInternalCreateNonRecursive.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,23 @@
2323
import org.apache.hadoop.fs.FileAlreadyExistsException;
2424
import org.apache.hadoop.fs.FileSystem;
2525
import org.apache.hadoop.fs.Path;
26-
import org.apache.hadoop.fs.adl.common.Parallelized;
2726
import org.apache.hadoop.fs.permission.FsPermission;
28-
import org.junit.Assert;
29-
import org.junit.Assume;
30-
import org.junit.Before;
31-
import org.junit.Test;
32-
import org.junit.runner.RunWith;
33-
import org.junit.runners.Parameterized;
27+
import org.junit.jupiter.params.ParameterizedTest;
28+
import org.junit.jupiter.params.provider.MethodSource;
3429

3530
import java.io.IOException;
3631
import java.io.UnsupportedEncodingException;
3732
import java.util.Arrays;
3833
import java.util.Collection;
3934
import java.util.UUID;
4035

36+
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.fail;
38+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
39+
4140
/**
4241
* Test createNonRecursive API.
4342
*/
44-
@RunWith(Parallelized.class)
4543
public class TestAdlInternalCreateNonRecursive {
4644
private Path inputFileName;
4745
private FsPermission inputPermission;
@@ -51,9 +49,9 @@ public class TestAdlInternalCreateNonRecursive {
5149
private Class<IOException> expectedExceptionType;
5250
private FileSystem adlStore;
5351

54-
public TestAdlInternalCreateNonRecursive(String testScenario, String fileName,
52+
public void initTestAdlInternalCreateNonRecursive(String testScenario, String fileName,
5553
FsPermission permission, boolean override, boolean fileAlreadyExist,
56-
boolean parentAlreadyExist, Class<IOException> exceptionType) {
54+
boolean parentAlreadyExist, Class<IOException> exceptionType) throws Exception {
5755

5856
// Random parent path for each test so that parallel execution does not fail
5957
// other running test.
@@ -64,9 +62,9 @@ public TestAdlInternalCreateNonRecursive(String testScenario, String fileName,
6462
inputOverride = override;
6563
inputParentAlreadyExist = parentAlreadyExist;
6664
expectedExceptionType = exceptionType;
65+
setUp();
6766
}
6867

69-
@Parameterized.Parameters(name = "{0}")
7068
public static Collection adlCreateNonRecursiveTestData()
7169
throws UnsupportedEncodingException {
7270
/*
@@ -92,14 +90,18 @@ public static Collection adlCreateNonRecursiveTestData()
9290
IOException.class }*/});
9391
}
9492

95-
@Before
9693
public void setUp() throws Exception {
97-
Assume.assumeTrue(AdlStorageConfiguration.isContractTestEnabled());
94+
assumeTrue(AdlStorageConfiguration.isContractTestEnabled());
9895
adlStore = AdlStorageConfiguration.createStorageConnector();
9996
}
10097

101-
@Test
102-
public void testCreateNonRecursiveFunctionality() throws IOException {
98+
@MethodSource("adlCreateNonRecursiveTestData")
99+
@ParameterizedTest(name = "{0}")
100+
public void testCreateNonRecursiveFunctionality(String testScenario, String fileName,
101+
FsPermission permission, boolean override, boolean fileAlreadyExist,
102+
boolean parentAlreadyExist, Class<IOException> exceptionType) throws Exception {
103+
initTestAdlInternalCreateNonRecursive(testScenario, fileName, permission,
104+
override, fileAlreadyExist, parentAlreadyExist, exceptionType);
103105
if (inputFileAlreadyExist) {
104106
FileSystem.create(adlStore, inputFileName, inputPermission);
105107
}
@@ -122,12 +124,12 @@ public void testCreateNonRecursiveFunctionality() throws IOException {
122124
throw e;
123125
}
124126

125-
Assert.assertEquals(expectedExceptionType, e.getClass());
127+
assertEquals(expectedExceptionType, e.getClass());
126128
return;
127129
}
128130

129131
if (expectedExceptionType != null) {
130-
Assert.fail("CreateNonRecursive should have failed with exception "
132+
fail("CreateNonRecursive should have failed with exception "
131133
+ expectedExceptionType.getName());
132134
}
133135
}

0 commit comments

Comments
 (0)