Skip to content

Commit 71aa0e4

Browse files
zhtttylzcnaurothslfan1989
authored
HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part2. (#7613)
Co-authored-by: Chris Nauroth <[email protected]> Co-authored-by: Shilun Fan <[email protected]> Reviewed-by: Chris Nauroth <[email protected]> Reviewed-by: Shilun Fan <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent 47d29fd commit 71aa0e4

37 files changed

+744
-694
lines changed

Diff for: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestEnhancedByteBufferAccess.java

+77-70
Large diffs are not rendered by default.

Diff for: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestFcHdfsCreateMkdir.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import org.apache.hadoop.hdfs.HdfsConfiguration;
2828
import org.apache.hadoop.hdfs.MiniDFSCluster;
2929
import org.apache.hadoop.security.UserGroupInformation;
30-
import org.junit.After;
31-
import org.junit.AfterClass;
32-
import org.junit.Before;
33-
import org.junit.BeforeClass;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.AfterAll;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.BeforeAll;
3434

3535
public class TestFcHdfsCreateMkdir extends
3636
FileContextCreateMkdirBaseTest {
@@ -44,7 +44,7 @@ protected FileContextTestHelper createFileContextHelper() {
4444
}
4545

4646

47-
@BeforeClass
47+
@BeforeAll
4848
public static void clusterSetupAtBegining()
4949
throws IOException, LoginException, URISyntaxException {
5050
Configuration conf = new HdfsConfiguration();
@@ -56,21 +56,21 @@ public static void clusterSetupAtBegining()
5656
}
5757

5858

59-
@AfterClass
59+
@AfterAll
6060
public static void ClusterShutdownAtEnd() throws Exception {
6161
if (cluster != null) {
6262
cluster.shutdown();
6363
}
6464
}
6565

6666
@Override
67-
@Before
67+
@BeforeEach
6868
public void setUp() throws Exception {
6969
super.setUp();
7070
}
7171

7272
@Override
73-
@After
73+
@AfterEach
7474
public void tearDown() throws Exception {
7575
super.tearDown();
7676
}

Diff for: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestFcHdfsPermission.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import org.apache.hadoop.hdfs.HdfsConfiguration;
2828
import org.apache.hadoop.hdfs.MiniDFSCluster;
2929
import org.apache.hadoop.security.UserGroupInformation;
30-
import org.junit.After;
31-
import org.junit.AfterClass;
32-
import org.junit.Before;
33-
import org.junit.BeforeClass;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.AfterAll;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.BeforeAll;
3434

3535
public class TestFcHdfsPermission extends FileContextPermissionBase {
3636

@@ -51,7 +51,7 @@ protected FileContext getFileContext() {
5151
return fc;
5252
}
5353

54-
@BeforeClass
54+
@BeforeAll
5555
public static void clusterSetupAtBegining()
5656
throws IOException, LoginException, URISyntaxException {
5757
Configuration conf = new HdfsConfiguration();
@@ -63,21 +63,21 @@ public static void clusterSetupAtBegining()
6363
}
6464

6565

66-
@AfterClass
66+
@AfterAll
6767
public static void ClusterShutdownAtEnd() throws Exception {
6868
if (cluster != null) {
6969
cluster.shutdown();
7070
}
7171
}
7272

7373
@Override
74-
@Before
74+
@BeforeEach
7575
public void setUp() throws Exception {
7676
super.setUp();
7777
}
7878

7979
@Override
80-
@After
80+
@AfterEach
8181
public void tearDown() throws Exception {
8282
super.tearDown();
8383
}

Diff for: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestFcHdfsSetUMask.java

+33-30
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@
3030
import org.apache.hadoop.hdfs.MiniDFSCluster;
3131
import org.apache.hadoop.security.UserGroupInformation;
3232
import static org.apache.hadoop.fs.FileContextTestHelper.*;
33-
import org.junit.After;
34-
import org.junit.AfterClass;
35-
import org.junit.Assert;
36-
import org.junit.Before;
37-
import org.junit.BeforeClass;
38-
import org.junit.Test;
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
34+
import static org.junit.jupiter.api.Assertions.assertFalse;
35+
import static org.junit.jupiter.api.Assertions.assertTrue;
36+
37+
import org.junit.jupiter.api.AfterEach;
38+
import org.junit.jupiter.api.AfterAll;
39+
import org.junit.jupiter.api.BeforeEach;
40+
import org.junit.jupiter.api.BeforeAll;
41+
import org.junit.jupiter.api.Test;
3942

4043
public class TestFcHdfsSetUMask {
4144

@@ -78,7 +81,7 @@ public class TestFcHdfsSetUMask {
7881
private static final FsPermission WIDE_OPEN_TEST_UMASK = FsPermission
7982
.createImmutable((short) (0777 ^ 0777));
8083

81-
@BeforeClass
84+
@BeforeAll
8285
public static void clusterSetupAtBegining()
8386
throws IOException, LoginException, URISyntaxException {
8487
Configuration conf = new HdfsConfiguration();
@@ -91,20 +94,20 @@ public static void clusterSetupAtBegining()
9194
fc.mkdir(defaultWorkingDirectory, FileContext.DEFAULT_PERM, true);
9295
}
9396

94-
@AfterClass
97+
@AfterAll
9598
public static void ClusterShutdownAtEnd() throws Exception {
9699
if (cluster != null) {
97100
cluster.shutdown();
98101
}
99102
}
100103

101-
@Before
104+
@BeforeEach
102105
public void setUp() throws Exception {
103106
fc.setUMask(WIDE_OPEN_TEST_UMASK);
104107
fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
105108
}
106109

107-
@After
110+
@AfterEach
108111
public void tearDown() throws Exception {
109112
fc.delete(fileContextTestHelper.getTestRootPath(fc), true);
110113
}
@@ -165,23 +168,23 @@ public void testCreateRecursiveWithExistingDirMiddle() throws IOException {
165168

166169
@Test
167170
public void testCreateRecursiveWithNonExistingDirClear() throws IOException {
168-
// directory permission inherited from parent so this must match the @Before
171+
// directory permission inherited from parent so this must match the @BeforeEach
169172
// set of umask
170173
testCreateRecursiveWithNonExistingDir(BLANK_TEST_UMASK,
171174
WIDE_OPEN_PERMISSIONS, BLANK_PERMISSIONS);
172175
}
173176

174177
@Test
175178
public void testCreateRecursiveWithNonExistingDirOpen() throws IOException {
176-
// directory permission inherited from parent so this must match the @Before
179+
// directory permission inherited from parent so this must match the @BeforeEach
177180
// set of umask
178181
testCreateRecursiveWithNonExistingDir(WIDE_OPEN_TEST_UMASK,
179182
WIDE_OPEN_PERMISSIONS, WIDE_OPEN_FILE_PERMISSIONS);
180183
}
181184

182185
@Test
183186
public void testCreateRecursiveWithNonExistingDirMiddle() throws IOException {
184-
// directory permission inherited from parent so this must match the @Before
187+
// directory permission inherited from parent so this must match the @BeforeEach
185188
// set of umask
186189
testCreateRecursiveWithNonExistingDir(USER_GROUP_OPEN_TEST_UMASK,
187190
WIDE_OPEN_PERMISSIONS, USER_GROUP_OPEN_FILE_PERMISSIONS);
@@ -193,9 +196,9 @@ public void testMkdirWithExistingDir(FsPermission umask,
193196
Path f = fileContextTestHelper.getTestRootPath(fc, "aDir");
194197
fc.setUMask(umask);
195198
fc.mkdir(f, FileContext.DEFAULT_PERM, true);
196-
Assert.assertTrue(isDir(fc, f));
197-
Assert.assertEquals("permissions on directory are wrong",
198-
expectedPerms, fc.getFileStatus(f).getPermission());
199+
assertTrue(isDir(fc, f));
200+
assertEquals(expectedPerms, fc.getFileStatus(f).getPermission(),
201+
"permissions on directory are wrong");
199202
}
200203

201204
public void testMkdirRecursiveWithNonExistingDir(FsPermission umask,
@@ -204,12 +207,12 @@ public void testMkdirRecursiveWithNonExistingDir(FsPermission umask,
204207
Path f = fileContextTestHelper.getTestRootPath(fc, "NonExistant2/aDir");
205208
fc.setUMask(umask);
206209
fc.mkdir(f, FileContext.DEFAULT_PERM, true);
207-
Assert.assertTrue(isDir(fc, f));
208-
Assert.assertEquals("permissions on directory are wrong",
209-
expectedPerms, fc.getFileStatus(f).getPermission());
210+
assertTrue(isDir(fc, f));
211+
assertEquals(expectedPerms, fc.getFileStatus(f).getPermission(),
212+
"permissions on directory are wrong");
210213
Path fParent = fileContextTestHelper.getTestRootPath(fc, "NonExistant2");
211-
Assert.assertEquals("permissions on parent directory are wrong",
212-
expectedParentPerms, fc.getFileStatus(fParent).getPermission());
214+
assertEquals(expectedParentPerms, fc.getFileStatus(fParent).getPermission(),
215+
"permissions on parent directory are wrong");
213216
}
214217

215218

@@ -218,9 +221,9 @@ public void testCreateRecursiveWithExistingDir(FsPermission umask,
218221
Path f = fileContextTestHelper.getTestRootPath(fc,"foo");
219222
fc.setUMask(umask);
220223
createFile(fc, f);
221-
Assert.assertTrue(isFile(fc, f));
222-
Assert.assertEquals("permissions on file are wrong",
223-
expectedPerms , fc.getFileStatus(f).getPermission());
224+
assertTrue(isFile(fc, f));
225+
assertEquals(expectedPerms, fc.getFileStatus(f).getPermission(),
226+
"permissions on file are wrong");
224227
}
225228

226229

@@ -229,14 +232,14 @@ public void testCreateRecursiveWithNonExistingDir(FsPermission umask,
229232
throws IOException {
230233
Path f = fileContextTestHelper.getTestRootPath(fc,"NonExisting/foo");
231234
Path fParent = fileContextTestHelper.getTestRootPath(fc, "NonExisting");
232-
Assert.assertFalse(exists(fc, fParent));
235+
assertFalse(exists(fc, fParent));
233236
fc.setUMask(umask);
234237
createFile(fc, f);
235-
Assert.assertTrue(isFile(fc, f));
236-
Assert.assertEquals("permissions on file are wrong",
237-
expectedFilePerms, fc.getFileStatus(f).getPermission());
238-
Assert.assertEquals("permissions on parent directory are wrong",
239-
expectedDirPerms, fc.getFileStatus(fParent).getPermission());
238+
assertTrue(isFile(fc, f));
239+
assertEquals(expectedFilePerms, fc.getFileStatus(f).getPermission(),
240+
"permissions on file are wrong");
241+
assertEquals(expectedDirPerms, fc.getFileStatus(fParent).getPermission(),
242+
"permissions on parent directory are wrong");
240243
}
241244

242245
}

0 commit comments

Comments
 (0)