Skip to content

Commit 81146fe

Browse files
slfan1989cnauroth
andauthored
HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part5. (#7357)
Co-authored-by: Chris Nauroth <cnauroth@apache.org> Reviewed-by: Chris Nauroth <cnauroth@apache.org> Signed-off-by: Shilun Fan <slfan1989@apache.org>
1 parent 2550344 commit 81146fe

File tree

77 files changed

+1404
-1300
lines changed

Some content is hidden

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

77 files changed

+1404
-1300
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/UnitTestcaseTimeLimit.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@
1717
*/
1818
package org.apache.hadoop.test;
1919

20-
import org.junit.Rule;
21-
import org.junit.rules.TestRule;
22-
import org.junit.rules.Timeout;
2320

24-
import java.util.concurrent.TimeUnit;
21+
import org.junit.jupiter.api.Timeout;
2522

2623
/**
2724
* Class for test units to extend in order that their individual tests will
2825
* be timed out and fail automatically should they run more than 10 seconds.
2926
* This provides an automatic regression check for tests that begin running
3027
* longer than expected.
3128
*/
29+
@Timeout(10)
3230
public class UnitTestcaseTimeLimit {
3331
public final int timeOutSecs = 10;
34-
35-
@Rule public TestRule globalTimeout =
36-
new Timeout(timeOutSecs, TimeUnit.SECONDS);
3732
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestApplicationClassLoader.java

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

2121
import static org.apache.hadoop.util.ApplicationClassLoader.constructUrlsFromClasspath;
2222
import static org.apache.hadoop.util.ApplicationClassLoader.isSystemClass;
23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertFalse;
25-
import static org.junit.Assert.assertNotNull;
26-
import static org.junit.Assert.assertNull;
27-
import static org.junit.Assert.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
25+
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
import static org.junit.jupiter.api.Assertions.assertNull;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
2828

2929
import java.io.File;
3030
import java.io.FileOutputStream;
@@ -39,16 +39,16 @@
3939
import org.apache.commons.io.IOUtils;
4040
import org.apache.hadoop.fs.FileUtil;
4141
import org.apache.hadoop.test.GenericTestUtils;
42-
import org.junit.Before;
43-
import org.junit.Test;
42+
import org.junit.jupiter.api.BeforeEach;
43+
import org.junit.jupiter.api.Test;
4444

4545
import org.apache.hadoop.thirdparty.com.google.common.base.Splitter;
4646

4747
public class TestApplicationClassLoader {
4848

4949
private static File testDir = GenericTestUtils.getTestDir("appclassloader");
5050

51-
@Before
51+
@BeforeEach
5252
public void setUp() {
5353
FileUtil.fullyDelete(testDir);
5454
testDir.mkdirs();
@@ -57,17 +57,17 @@ public void setUp() {
5757
@Test
5858
public void testConstructUrlsFromClasspath() throws Exception {
5959
File file = new File(testDir, "file");
60-
assertTrue("Create file", file.createNewFile());
60+
assertTrue(file.createNewFile(), "Create file");
6161

6262
File dir = new File(testDir, "dir");
63-
assertTrue("Make dir", dir.mkdir());
63+
assertTrue(dir.mkdir(), "Make dir");
6464

6565
File jarsDir = new File(testDir, "jarsdir");
66-
assertTrue("Make jarsDir", jarsDir.mkdir());
66+
assertTrue(jarsDir.mkdir(), "Make jarsDir");
6767
File nonJarFile = new File(jarsDir, "nonjar");
68-
assertTrue("Create non-jar file", nonJarFile.createNewFile());
68+
assertTrue(nonJarFile.createNewFile(), "Create non-jar file");
6969
File jarFile = new File(jarsDir, "a.jar");
70-
assertTrue("Create jar file", jarFile.createNewFile());
70+
assertTrue(jarFile.createNewFile(), "Create jar file");
7171

7272
File nofile = new File(testDir, "nofile");
7373
// don't create nofile
@@ -130,11 +130,11 @@ public void testGetResource() throws IOException {
130130
ClassLoader appClassloader = new ApplicationClassLoader(
131131
new URL[] { testJar }, currentClassLoader, null);
132132

133-
assertNull("Resource should be null for current classloader",
134-
currentClassLoader.getResourceAsStream("resource.txt"));
133+
assertNull(currentClassLoader.getResourceAsStream("resource.txt"),
134+
"Resource should be null for current classloader");
135135

136136
InputStream in = appClassloader.getResourceAsStream("resource.txt");
137-
assertNotNull("Resource should not be null for app classloader", in);
137+
assertNotNull(in, "Resource should not be null for app classloader");
138138
assertEquals("hello", IOUtils.toString(in, StandardCharsets.UTF_8));
139139
}
140140

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestAsyncDiskService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
*/
1818
package org.apache.hadoop.util;
1919

20-
import org.junit.Test;
21-
import static org.junit.Assert.*;
20+
import org.junit.jupiter.api.Test;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.fail;
2224
import org.slf4j.Logger;
2325
import org.slf4j.LoggerFactory;
2426

@@ -70,8 +72,8 @@ public void testAsyncDiskService() throws Throwable {
7072
} catch (RuntimeException ex) {
7173
e = ex;
7274
}
73-
assertNotNull("Executing a task on a non-existing volume should throw an "
74-
+ "Exception.", e);
75+
assertNotNull(e, "Executing a task on a non-existing volume should throw an "
76+
+ "Exception.");
7577

7678
service.shutdown();
7779
if (!service.awaitTermination(5000)) {

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestAutoCloseableLock.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818
package org.apache.hadoop.util;
1919

20-
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertTrue;
22-
import static org.junit.Assert.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525
/**
2626
* A test class for AutoCloseableLock.
2727
*/

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestBasicDiskValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.apache.hadoop.util;
1919

20-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import org.apache.hadoop.util.DiskChecker.DiskErrorException;
2323

@@ -37,7 +37,7 @@ protected void checkDirs(boolean isDir, String perm, boolean success)
3737

3838
DiskValidatorFactory.getInstance(BasicDiskValidator.NAME).
3939
checkStatus(localDir);
40-
assertTrue("call to checkDir() succeeded.", success);
40+
assertTrue(success, "call to checkDir() succeeded.");
4141
} catch (DiskErrorException e) {
4242
// call to checkDir() succeeded even though it was expected to fail
4343
// if success is false, otherwise throw the exception

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestCacheableIPList.java

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
package org.apache.hadoop.util;
1919

2020
import java.io.IOException;
21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.Assert.*;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2425

2526
public class TestCacheableIPList {
2627

@@ -44,10 +45,8 @@ public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedExc
4445
CacheableIPList cipl = new CacheableIPList(
4546
new FileBasedIPList("ips.txt"),100);
4647

47-
assertFalse("10.113.221.222 is in the list",
48-
cipl.isIn("10.113.221.222"));
49-
assertFalse ("10.222.103.121 is in the list",
50-
cipl.isIn("10.222.103.121"));
48+
assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
49+
assertFalse(cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
5150

5251
TestFileBasedIPList.removeFile("ips.txt");
5352
String[]ips2 = {"10.119.103.112", "10.221.102.0/23",
@@ -56,10 +55,8 @@ public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedExc
5655
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
5756
Thread.sleep(101);
5857

59-
assertTrue("10.113.221.222 is not in the list",
60-
cipl.isIn("10.113.221.222"));
61-
assertTrue ("10.222.103.121 is not in the list",
62-
cipl.isIn("10.222.103.121"));
58+
assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
59+
assertTrue(cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
6360

6461
TestFileBasedIPList.removeFile("ips.txt");
6562
}
@@ -85,21 +82,17 @@ public void testRemovalWithSleepForCacheTimeout() throws IOException, Interrupte
8582
CacheableIPList cipl = new CacheableIPList(
8683
new FileBasedIPList("ips.txt"),100);
8784

88-
assertTrue("10.113.221.222 is not in the list",
89-
cipl.isIn("10.113.221.222"));
90-
assertTrue ("10.222.103.121 is not in the list",
91-
cipl.isIn("10.222.103.121"));
85+
assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
86+
assertTrue(cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
9287

9388
TestFileBasedIPList.removeFile("ips.txt");
9489
String[]ips2 = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"};
9590

9691
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
9792
Thread.sleep(1005);
9893

99-
assertFalse("10.113.221.222 is in the list",
100-
cipl.isIn("10.113.221.222"));
101-
assertFalse ("10.222.103.121 is in the list",
102-
cipl.isIn("10.222.103.121"));
94+
assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
95+
assertFalse(cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
10396

10497
TestFileBasedIPList.removeFile("ips.txt");
10598
}
@@ -124,10 +117,8 @@ public void testAddWithRefresh() throws IOException, InterruptedException {
124117
CacheableIPList cipl = new CacheableIPList(
125118
new FileBasedIPList("ips.txt"),100);
126119

127-
assertFalse("10.113.221.222 is in the list",
128-
cipl.isIn("10.113.221.222"));
129-
assertFalse ("10.222.103.121 is in the list",
130-
cipl.isIn("10.222.103.121"));
120+
assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
121+
assertFalse(cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
131122

132123
TestFileBasedIPList.removeFile("ips.txt");
133124
String[]ips2 = {"10.119.103.112", "10.221.102.0/23",
@@ -136,10 +127,8 @@ public void testAddWithRefresh() throws IOException, InterruptedException {
136127
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
137128
cipl.refresh();
138129

139-
assertTrue("10.113.221.222 is not in the list",
140-
cipl.isIn("10.113.221.222"));
141-
assertTrue ("10.222.103.121 is not in the list",
142-
cipl.isIn("10.222.103.121"));
130+
assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
131+
assertTrue(cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
143132

144133
TestFileBasedIPList.removeFile("ips.txt");
145134
}
@@ -165,21 +154,17 @@ public void testRemovalWithRefresh() throws IOException, InterruptedException {
165154
CacheableIPList cipl = new CacheableIPList(
166155
new FileBasedIPList("ips.txt"),100);
167156

168-
assertTrue("10.113.221.222 is not in the list",
169-
cipl.isIn("10.113.221.222"));
170-
assertTrue ("10.222.103.121 is not in the list",
171-
cipl.isIn("10.222.103.121"));
157+
assertTrue(cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
158+
assertTrue(cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
172159

173160
TestFileBasedIPList.removeFile("ips.txt");
174161
String[]ips2 = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"};
175162

176163
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
177164
cipl.refresh();
178165

179-
assertFalse("10.113.221.222 is in the list",
180-
cipl.isIn("10.113.221.222"));
181-
assertFalse ("10.222.103.121 is in the list",
182-
cipl.isIn("10.222.103.121"));
166+
assertFalse(cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
167+
assertFalse(cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
183168

184169
TestFileBasedIPList.removeFile("ips.txt");
185170
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestChunkedArrayList.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
*/
1818
package org.apache.hadoop.util;
1919

20-
import static org.junit.Assert.*;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2123

2224
import java.util.ArrayList;
2325
import java.util.Iterator;
2426
import java.util.concurrent.TimeUnit;
2527

26-
import org.junit.Assert;
27-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2829

2930
public class TestChunkedArrayList {
3031

@@ -103,41 +104,41 @@ public void testRemovals() throws Exception {
103104
// Iterate through all list elements.
104105
Iterator<Integer> iter = list.iterator();
105106
for (int i = 0; i < NUM_ELEMS; i++) {
106-
Assert.assertTrue(iter.hasNext());
107+
assertTrue(iter.hasNext());
107108
Integer val = iter.next();
108-
Assert.assertEquals(Integer.valueOf(i), val);
109+
assertEquals(Integer.valueOf(i), val);
109110
}
110-
Assert.assertFalse(iter.hasNext());
111-
Assert.assertEquals(NUM_ELEMS, list.size());
111+
assertFalse(iter.hasNext());
112+
assertEquals(NUM_ELEMS, list.size());
112113

113114
// Remove even elements.
114115
iter = list.iterator();
115116
for (int i = 0; i < NUM_ELEMS; i++) {
116-
Assert.assertTrue(iter.hasNext());
117+
assertTrue(iter.hasNext());
117118
Integer val = iter.next();
118-
Assert.assertEquals(Integer.valueOf(i), val);
119+
assertEquals(Integer.valueOf(i), val);
119120
if (i % 2 == 0) {
120121
iter.remove();
121122
}
122123
}
123-
Assert.assertFalse(iter.hasNext());
124-
Assert.assertEquals(NUM_ELEMS / 2, list.size());
124+
assertFalse(iter.hasNext());
125+
assertEquals(NUM_ELEMS / 2, list.size());
125126

126127
// Iterate through all odd list elements.
127128
iter = list.iterator();
128129
for (int i = 0; i < NUM_ELEMS / 2; i++) {
129-
Assert.assertTrue(iter.hasNext());
130+
assertTrue(iter.hasNext());
130131
Integer val = iter.next();
131-
Assert.assertEquals(Integer.valueOf(1 + (2 * i)), val);
132+
assertEquals(Integer.valueOf(1 + (2 * i)), val);
132133
iter.remove();
133134
}
134-
Assert.assertFalse(iter.hasNext());
135+
assertFalse(iter.hasNext());
135136

136137
// Check that list is now empty.
137-
Assert.assertEquals(0, list.size());
138-
Assert.assertTrue(list.isEmpty());
138+
assertEquals(0, list.size());
139+
assertTrue(list.isEmpty());
139140
iter = list.iterator();
140-
Assert.assertFalse(iter.hasNext());
141+
assertFalse(iter.hasNext());
141142
}
142143

143144
@Test
@@ -148,23 +149,23 @@ public void testGet() throws Exception {
148149
list.add(i);
149150
}
150151

151-
Assert.assertEquals(Integer.valueOf(100), list.get(100));
152-
Assert.assertEquals(Integer.valueOf(1000), list.get(1000));
153-
Assert.assertEquals(Integer.valueOf(10000), list.get(10000));
154-
Assert.assertEquals(Integer.valueOf(100000), list.get(100000));
152+
assertEquals(Integer.valueOf(100), list.get(100));
153+
assertEquals(Integer.valueOf(1000), list.get(1000));
154+
assertEquals(Integer.valueOf(10000), list.get(10000));
155+
assertEquals(Integer.valueOf(100000), list.get(100000));
155156

156157
Iterator<Integer> iter = list.iterator();
157158
iter.next();
158159
iter.remove();
159-
Assert.assertEquals(Integer.valueOf(1), list.get(0));
160+
assertEquals(Integer.valueOf(1), list.get(0));
160161

161162
iter = list.iterator();
162163
for (int i = 0; i < 500; i++) {
163164
iter.next();
164165
}
165166
iter.remove();
166167

167-
Assert.assertEquals(Integer.valueOf(502), list.get(500));
168-
Assert.assertEquals(Integer.valueOf(602), list.get(600));
168+
assertEquals(Integer.valueOf(502), list.get(500));
169+
assertEquals(Integer.valueOf(602), list.get(600));
169170
}
170171
}

0 commit comments

Comments
 (0)