Skip to content

Commit 0a6f4cc

Browse files
author
fanshilun
committed
HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part5.
1 parent 872ebda commit 0a6f4cc

File tree

76 files changed

+1150
-1043
lines changed

Some content is hidden

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

76 files changed

+1150
-1043
lines changed

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(
134+
currentClassLoader.getResourceAsStream("resource.txt"), "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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
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.*;
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424

@@ -70,8 +70,8 @@ public void testAsyncDiskService() throws Throwable {
7070
} catch (RuntimeException ex) {
7171
e = ex;
7272
}
73-
assertNotNull("Executing a task on a non-existing volume should throw an "
74-
+ "Exception.", e);
73+
assertNotNull(e, "Executing a task on a non-existing volume should throw an "
74+
+ "Exception.");
7575

7676
service.shutdown();
7777
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: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
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.*;
2424

2525
public class TestCacheableIPList {
2626

@@ -44,10 +44,10 @@ public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedExc
4444
CacheableIPList cipl = new CacheableIPList(
4545
new FileBasedIPList("ips.txt"),100);
4646

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"));
47+
assertFalse(
48+
cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
49+
assertFalse (
50+
cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
5151

5252
TestFileBasedIPList.removeFile("ips.txt");
5353
String[]ips2 = {"10.119.103.112", "10.221.102.0/23",
@@ -56,10 +56,10 @@ public void testAddWithSleepForCacheTimeout() throws IOException, InterruptedExc
5656
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
5757
Thread.sleep(101);
5858

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"));
59+
assertTrue(
60+
cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
61+
assertTrue (
62+
cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
6363

6464
TestFileBasedIPList.removeFile("ips.txt");
6565
}
@@ -85,21 +85,21 @@ public void testRemovalWithSleepForCacheTimeout() throws IOException, Interrupte
8585
CacheableIPList cipl = new CacheableIPList(
8686
new FileBasedIPList("ips.txt"),100);
8787

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"));
88+
assertTrue(
89+
cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
90+
assertTrue (
91+
cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
9292

9393
TestFileBasedIPList.removeFile("ips.txt");
9494
String[]ips2 = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"};
9595

9696
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
9797
Thread.sleep(1005);
9898

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"));
99+
assertFalse(
100+
cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
101+
assertFalse (
102+
cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
103103

104104
TestFileBasedIPList.removeFile("ips.txt");
105105
}
@@ -124,10 +124,10 @@ public void testAddWithRefresh() throws IOException, InterruptedException {
124124
CacheableIPList cipl = new CacheableIPList(
125125
new FileBasedIPList("ips.txt"),100);
126126

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"));
127+
assertFalse(
128+
cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
129+
assertFalse (
130+
cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
131131

132132
TestFileBasedIPList.removeFile("ips.txt");
133133
String[]ips2 = {"10.119.103.112", "10.221.102.0/23",
@@ -136,10 +136,10 @@ public void testAddWithRefresh() throws IOException, InterruptedException {
136136
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
137137
cipl.refresh();
138138

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"));
139+
assertTrue(
140+
cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
141+
assertTrue (
142+
cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
143143

144144
TestFileBasedIPList.removeFile("ips.txt");
145145
}
@@ -165,21 +165,21 @@ public void testRemovalWithRefresh() throws IOException, InterruptedException {
165165
CacheableIPList cipl = new CacheableIPList(
166166
new FileBasedIPList("ips.txt"),100);
167167

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"));
168+
assertTrue(
169+
cipl.isIn("10.113.221.222"), "10.113.221.222 is not in the list");
170+
assertTrue (
171+
cipl.isIn("10.222.103.121"), "10.222.103.121 is not in the list");
172172

173173
TestFileBasedIPList.removeFile("ips.txt");
174174
String[]ips2 = {"10.119.103.112", "10.221.102.0/23", "10.113.221.221"};
175175

176176
TestFileBasedIPList.createFileWithEntries ("ips.txt", ips2);
177177
cipl.refresh();
178178

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"));
179+
assertFalse(
180+
cipl.isIn("10.113.221.222"), "10.113.221.222 is in the list");
181+
assertFalse (
182+
cipl.isIn("10.222.103.121"), "10.222.103.121 is in the list");
183183

184184
TestFileBasedIPList.removeFile("ips.txt");
185185
}

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

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

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

2222
import java.util.ArrayList;
2323
import java.util.Iterator;
2424
import java.util.concurrent.TimeUnit;
2525

26-
import org.junit.Assert;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.Assertions;
27+
import org.junit.jupiter.api.Test;
2828

2929
public class TestChunkedArrayList {
3030

@@ -103,41 +103,41 @@ public void testRemovals() throws Exception {
103103
// Iterate through all list elements.
104104
Iterator<Integer> iter = list.iterator();
105105
for (int i = 0; i < NUM_ELEMS; i++) {
106-
Assert.assertTrue(iter.hasNext());
106+
Assertions.assertTrue(iter.hasNext());
107107
Integer val = iter.next();
108-
Assert.assertEquals(Integer.valueOf(i), val);
108+
Assertions.assertEquals(Integer.valueOf(i), val);
109109
}
110-
Assert.assertFalse(iter.hasNext());
111-
Assert.assertEquals(NUM_ELEMS, list.size());
110+
Assertions.assertFalse(iter.hasNext());
111+
Assertions.assertEquals(NUM_ELEMS, list.size());
112112

113113
// Remove even elements.
114114
iter = list.iterator();
115115
for (int i = 0; i < NUM_ELEMS; i++) {
116-
Assert.assertTrue(iter.hasNext());
116+
Assertions.assertTrue(iter.hasNext());
117117
Integer val = iter.next();
118-
Assert.assertEquals(Integer.valueOf(i), val);
118+
Assertions.assertEquals(Integer.valueOf(i), val);
119119
if (i % 2 == 0) {
120120
iter.remove();
121121
}
122122
}
123-
Assert.assertFalse(iter.hasNext());
124-
Assert.assertEquals(NUM_ELEMS / 2, list.size());
123+
Assertions.assertFalse(iter.hasNext());
124+
Assertions.assertEquals(NUM_ELEMS / 2, list.size());
125125

126126
// Iterate through all odd list elements.
127127
iter = list.iterator();
128128
for (int i = 0; i < NUM_ELEMS / 2; i++) {
129-
Assert.assertTrue(iter.hasNext());
129+
Assertions.assertTrue(iter.hasNext());
130130
Integer val = iter.next();
131-
Assert.assertEquals(Integer.valueOf(1 + (2 * i)), val);
131+
Assertions.assertEquals(Integer.valueOf(1 + (2 * i)), val);
132132
iter.remove();
133133
}
134-
Assert.assertFalse(iter.hasNext());
134+
Assertions.assertFalse(iter.hasNext());
135135

136136
// Check that list is now empty.
137-
Assert.assertEquals(0, list.size());
138-
Assert.assertTrue(list.isEmpty());
137+
Assertions.assertEquals(0, list.size());
138+
Assertions.assertTrue(list.isEmpty());
139139
iter = list.iterator();
140-
Assert.assertFalse(iter.hasNext());
140+
Assertions.assertFalse(iter.hasNext());
141141
}
142142

143143
@Test
@@ -148,23 +148,23 @@ public void testGet() throws Exception {
148148
list.add(i);
149149
}
150150

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));
151+
Assertions.assertEquals(Integer.valueOf(100), list.get(100));
152+
Assertions.assertEquals(Integer.valueOf(1000), list.get(1000));
153+
Assertions.assertEquals(Integer.valueOf(10000), list.get(10000));
154+
Assertions.assertEquals(Integer.valueOf(100000), list.get(100000));
155155

156156
Iterator<Integer> iter = list.iterator();
157157
iter.next();
158158
iter.remove();
159-
Assert.assertEquals(Integer.valueOf(1), list.get(0));
159+
Assertions.assertEquals(Integer.valueOf(1), list.get(0));
160160

161161
iter = list.iterator();
162162
for (int i = 0; i < 500; i++) {
163163
iter.next();
164164
}
165165
iter.remove();
166166

167-
Assert.assertEquals(Integer.valueOf(502), list.get(500));
168-
Assert.assertEquals(Integer.valueOf(602), list.get(600));
167+
Assertions.assertEquals(Integer.valueOf(502), list.get(500));
168+
Assertions.assertEquals(Integer.valueOf(602), list.get(600));
169169
}
170170
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
import org.apache.hadoop.fs.viewfs.ViewFileSystem;
2424

2525
import org.assertj.core.api.Assertions;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.Timeout;
2728

2829
public class TestClassUtil {
2930

30-
@Test(timeout=10000)
31+
@Test
32+
@Timeout(value = 10)
3133
public void testFindContainingJar() {
3234
String containingJar = ClassUtil.findContainingJar(Assertions.class);
3335
Assertions
@@ -45,7 +47,8 @@ public void testFindContainingJar() {
4547
.matches("assertj-core.*[.]jar");
4648
}
4749

48-
@Test(timeout = 10000)
50+
@Test
51+
@Timeout(value = 10)
4952
public void testFindContainingClass() {
5053
String classFileLocation = ClassUtil.findClassLocation(ViewFileSystem.class);
5154
Assertions

0 commit comments

Comments
 (0)