Skip to content

Commit b5cbca3

Browse files
slfan1989cnauroth
andauthored
HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part2. (#7347)
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 f900339 commit b5cbca3

File tree

89 files changed

+1433
-1218
lines changed

Some content is hidden

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

89 files changed

+1433
-1218
lines changed

hadoop-common-project/hadoop-common/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,26 @@
381381
<artifactId>lz4-java</artifactId>
382382
<scope>provided</scope>
383383
</dependency>
384+
<dependency>
385+
<groupId>org.junit.jupiter</groupId>
386+
<artifactId>junit-jupiter-api</artifactId>
387+
<scope>test</scope>
388+
</dependency>
389+
<dependency>
390+
<groupId>org.junit.jupiter</groupId>
391+
<artifactId>junit-jupiter-engine</artifactId>
392+
<scope>test</scope>
393+
</dependency>
394+
<dependency>
395+
<groupId>org.junit.jupiter</groupId>
396+
<artifactId>junit-jupiter-params</artifactId>
397+
<scope>test</scope>
398+
</dependency>
399+
<dependency>
400+
<groupId>org.junit.platform</groupId>
401+
<artifactId>junit-platform-launcher</artifactId>
402+
<scope>test</scope>
403+
</dependency>
384404
</dependencies>
385405

386406
<build>

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestAfsCheckPath.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import org.apache.hadoop.fs.Options.ChecksumOpt;
2828
import org.apache.hadoop.security.AccessControlException;
2929
import org.apache.hadoop.util.Progressable;
30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
31+
32+
import static org.junit.jupiter.api.Assertions.assertThrows;
3133

3234
public class TestAfsCheckPath {
3335

@@ -56,11 +58,13 @@ public void testCheckPathWithTheSameNonDefaultPort()
5658
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
5759
}
5860

59-
@Test(expected=InvalidPathException.class)
61+
@Test
6062
public void testCheckPathWithDifferentPorts() throws URISyntaxException {
61-
URI uri = new URI("dummy://dummy-host:" + DEFAULT_PORT);
62-
AbstractFileSystem afs = new DummyFileSystem(uri);
63-
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
63+
assertThrows(InvalidPathException.class, () -> {
64+
URI uri = new URI("dummy://dummy-host:" + DEFAULT_PORT);
65+
AbstractFileSystem afs = new DummyFileSystem(uri);
66+
afs.checkPath(new Path("dummy://dummy-host:" + OTHER_PORT));
67+
});
6468
}
6569

6670
private static class DummyFileSystem extends AbstractFileSystem {

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestAvroFSInput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import org.apache.hadoop.conf.Configuration;
2525
import org.apache.hadoop.test.GenericTestUtils;
2626

27-
import org.junit.Test;
28-
import static org.junit.Assert.*;
27+
import org.junit.jupiter.api.Test;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
2929

3030
public class TestAvroFSInput {
3131

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestBlockLocation.java

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

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

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.Timeout;
2526

2627
public class TestBlockLocation {
2728

@@ -70,7 +71,8 @@ private static void checkBlockLocation(final BlockLocation loc,
7071
/**
7172
* Call all the constructors and verify the delegation is working properly
7273
*/
73-
@Test(timeout = 5000)
74+
@Test
75+
@Timeout(value = 5)
7476
public void testBlockLocationConstructors() throws Exception {
7577
//
7678
BlockLocation loc;
@@ -91,7 +93,8 @@ public void testBlockLocationConstructors() throws Exception {
9193
/**
9294
* Call each of the setters and verify
9395
*/
94-
@Test(timeout = 5000)
96+
@Test
97+
@Timeout(value = 5)
9598
public void testBlockLocationSetters() throws Exception {
9699
BlockLocation loc;
97100
loc = new BlockLocation();

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestChecksumFileSystem.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,22 @@
2626
import static org.apache.hadoop.fs.FileSystemTestHelper.*;
2727
import org.apache.hadoop.conf.Configuration;
2828
import org.apache.hadoop.test.GenericTestUtils;
29-
import org.junit.*;
30-
import static org.junit.Assert.*;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
31+
32+
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.assertFalse;
34+
import static org.junit.jupiter.api.Assertions.assertNotNull;
35+
import static org.junit.jupiter.api.Assertions.assertTrue;
36+
import static org.junit.jupiter.api.Assertions.fail;
3137

3238
public class TestChecksumFileSystem {
3339
static final String TEST_ROOT_DIR =
3440
GenericTestUtils.getTempPath("work-dir/localfs");
3541

3642
static LocalFileSystem localFs;
3743

38-
@Before
44+
@BeforeEach
3945
public void resetLocalFs() throws Exception {
4046
localFs = FileSystem.getLocal(new Configuration());
4147
localFs.setVerifyChecksum(true);
@@ -77,25 +83,25 @@ public void testVerifyChecksum() throws Exception {
7783
readFile(localFs, testPath, 1025);
7884

7985
localFs.delete(localFs.getChecksumFile(testPath), true);
80-
assertTrue("checksum deleted", !localFs.exists(localFs.getChecksumFile(testPath)));
86+
assertTrue(!localFs.exists(localFs.getChecksumFile(testPath)), "checksum deleted");
8187

8288
//copying the wrong checksum file
8389
FileUtil.copy(localFs, localFs.getChecksumFile(testPath11), localFs,
8490
localFs.getChecksumFile(testPath),false,true,localFs.getConf());
85-
assertTrue("checksum exists", localFs.exists(localFs.getChecksumFile(testPath)));
91+
assertTrue(localFs.exists(localFs.getChecksumFile(testPath)), "checksum exists");
8692

8793
boolean errorRead = false;
8894
try {
8995
readFile(localFs, testPath, 1024);
9096
}catch(ChecksumException ie) {
9197
errorRead = true;
9298
}
93-
assertTrue("error reading", errorRead);
99+
assertTrue(errorRead, "error reading");
94100

95101
//now setting verify false, the read should succeed
96102
localFs.setVerifyChecksum(false);
97103
String str = readFile(localFs, testPath, 1024).toString();
98-
assertTrue("read", "testing".equals(str));
104+
assertTrue("testing".equals(str), "read");
99105
}
100106

101107
@Test
@@ -153,7 +159,7 @@ public void testTruncatedChecksum() throws Exception {
153159
// telling it not to verify checksums, should avoid issue.
154160
localFs.setVerifyChecksum(false);
155161
String str = readFile(localFs, testPath, 1024).toString();
156-
assertTrue("read", "testing truncation".equals(str));
162+
assertTrue("testing truncation".equals(str), "read");
157163
}
158164

159165
@Test
@@ -164,13 +170,11 @@ public void testStreamType() throws Exception {
164170

165171
localFs.setVerifyChecksum(true);
166172
in = localFs.open(testPath);
167-
assertTrue("stream is input checker",
168-
in.getWrappedStream() instanceof FSInputChecker);
173+
assertTrue(in.getWrappedStream() instanceof FSInputChecker, "stream is input checker");
169174

170175
localFs.setVerifyChecksum(false);
171176
in = localFs.open(testPath);
172-
assertFalse("stream is not input checker",
173-
in.getWrappedStream() instanceof FSInputChecker);
177+
assertFalse(in.getWrappedStream() instanceof FSInputChecker, "stream is not input checker");
174178
}
175179

176180
@Test
@@ -200,7 +204,7 @@ public void testCorruptedChecksum() throws Exception {
200204
} catch (ChecksumException ce) {
201205
e = ce;
202206
} finally {
203-
assertNotNull("got checksum error", e);
207+
assertNotNull(e, "got checksum error");
204208
}
205209

206210
localFs.setVerifyChecksum(false);

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestCommandFormat.java

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

20-
21-
import static org.junit.Assert.*;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
2221

2322
import java.util.ArrayList;
2423
import java.util.Arrays;
@@ -30,8 +29,8 @@
3029
import org.apache.hadoop.fs.shell.CommandFormat.NotEnoughArgumentsException;
3130
import org.apache.hadoop.fs.shell.CommandFormat.TooManyArgumentsException;
3231
import org.apache.hadoop.fs.shell.CommandFormat.UnknownOptionException;
33-
import org.junit.Before;
34-
import org.junit.Test;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
3534

3635
/**
3736
* This class tests the command line parsing
@@ -41,7 +40,7 @@ public class TestCommandFormat {
4140
private static List<String> expectedArgs;
4241
private static Set<String> expectedOpts;
4342

44-
@Before
43+
@BeforeEach
4544
public void setUp() {
4645
args = new ArrayList<>();
4746
expectedOpts = new HashSet<>();

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestContentSummary.java

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

20-
import static org.junit.Assert.*;
21-
import static org.mockito.Mockito.*;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.mockito.Mockito.inOrder;
22+
import static org.mockito.Mockito.mock;
23+
import static org.mockito.Mockito.when;
2224

2325
import java.io.DataInput;
2426
import java.io.DataOutput;
2527
import java.io.IOException;
2628

27-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
2830
import org.mockito.InOrder;
2931

3032
public class TestContentSummary {
@@ -33,12 +35,12 @@ public class TestContentSummary {
3335
@Test
3436
public void testConstructorEmpty() {
3537
ContentSummary contentSummary = new ContentSummary.Builder().build();
36-
assertEquals("getLength", 0, contentSummary.getLength());
37-
assertEquals("getFileCount", 0, contentSummary.getFileCount());
38-
assertEquals("getDirectoryCount", 0, contentSummary.getDirectoryCount());
39-
assertEquals("getQuota", -1, contentSummary.getQuota());
40-
assertEquals("getSpaceConsumed", 0, contentSummary.getSpaceConsumed());
41-
assertEquals("getSpaceQuota", -1, contentSummary.getSpaceQuota());
38+
assertEquals(0, contentSummary.getLength(), "getLength");
39+
assertEquals(0, contentSummary.getFileCount(), "getFileCount");
40+
assertEquals(0, contentSummary.getDirectoryCount(), "getDirectoryCount");
41+
assertEquals(-1, contentSummary.getQuota(), "getQuota");
42+
assertEquals(0, contentSummary.getSpaceConsumed(), "getSpaceConsumed");
43+
assertEquals(-1, contentSummary.getSpaceQuota(), "getSpaceQuota");
4244
}
4345

4446
// check the full constructor with quota information
@@ -54,14 +56,13 @@ public void testConstructorWithQuota() {
5456
ContentSummary contentSummary = new ContentSummary.Builder().length(length).
5557
fileCount(fileCount).directoryCount(directoryCount).quota(quota).
5658
spaceConsumed(spaceConsumed).spaceQuota(spaceQuota).build();
57-
assertEquals("getLength", length, contentSummary.getLength());
58-
assertEquals("getFileCount", fileCount, contentSummary.getFileCount());
59-
assertEquals("getDirectoryCount", directoryCount,
60-
contentSummary.getDirectoryCount());
61-
assertEquals("getQuota", quota, contentSummary.getQuota());
62-
assertEquals("getSpaceConsumed", spaceConsumed,
63-
contentSummary.getSpaceConsumed());
64-
assertEquals("getSpaceQuota", spaceQuota, contentSummary.getSpaceQuota());
59+
assertEquals(length, contentSummary.getLength(), "getLength");
60+
assertEquals(fileCount, contentSummary.getFileCount(), "getFileCount");
61+
assertEquals(directoryCount, contentSummary.getDirectoryCount(), "getDirectoryCount");
62+
assertEquals(quota, contentSummary.getQuota(), "getQuota");
63+
assertEquals(spaceConsumed,
64+
contentSummary.getSpaceConsumed(), "getSpaceConsumed");
65+
assertEquals(spaceQuota, contentSummary.getSpaceQuota(), "getSpaceQuota");
6566
}
6667

6768
// check the constructor with quota information
@@ -74,13 +75,13 @@ public void testConstructorNoQuota() {
7475
ContentSummary contentSummary = new ContentSummary.Builder().length(length).
7576
fileCount(fileCount).directoryCount(directoryCount).
7677
spaceConsumed(length).build();
77-
assertEquals("getLength", length, contentSummary.getLength());
78-
assertEquals("getFileCount", fileCount, contentSummary.getFileCount());
79-
assertEquals("getDirectoryCount", directoryCount,
80-
contentSummary.getDirectoryCount());
81-
assertEquals("getQuota", -1, contentSummary.getQuota());
82-
assertEquals("getSpaceConsumed", length, contentSummary.getSpaceConsumed());
83-
assertEquals("getSpaceQuota", -1, contentSummary.getSpaceQuota());
78+
assertEquals(length, contentSummary.getLength(), "getLength");
79+
assertEquals(fileCount, contentSummary.getFileCount(), "getFileCount");
80+
assertEquals(directoryCount,
81+
contentSummary.getDirectoryCount(), "getDirectoryCount");
82+
assertEquals(-1, contentSummary.getQuota(), "getQuota");
83+
assertEquals(length, contentSummary.getSpaceConsumed(), "getSpaceConsumed");
84+
assertEquals(-1, contentSummary.getSpaceQuota(), "getSpaceQuota");
8485
}
8586

8687
// check the write method
@@ -127,14 +128,12 @@ public void testReadFields() throws IOException {
127128
.thenReturn(spaceQuota);
128129

129130
contentSummary.readFields(in);
130-
assertEquals("getLength", length, contentSummary.getLength());
131-
assertEquals("getFileCount", fileCount, contentSummary.getFileCount());
132-
assertEquals("getDirectoryCount", directoryCount,
133-
contentSummary.getDirectoryCount());
134-
assertEquals("getQuota", quota, contentSummary.getQuota());
135-
assertEquals("getSpaceConsumed", spaceConsumed,
136-
contentSummary.getSpaceConsumed());
137-
assertEquals("getSpaceQuota", spaceQuota, contentSummary.getSpaceQuota());
131+
assertEquals(length, contentSummary.getLength(), "getLength");
132+
assertEquals(fileCount, contentSummary.getFileCount(), "getFileCount");
133+
assertEquals(directoryCount, contentSummary.getDirectoryCount(), "getDirectoryCount");
134+
assertEquals(quota, contentSummary.getQuota(), "getQuota");
135+
assertEquals(spaceConsumed, contentSummary.getSpaceConsumed(), "getSpaceConsumed");
136+
assertEquals(spaceQuota, contentSummary.getSpaceQuota(), "getSpaceQuota");
138137
}
139138

140139
// check the header with quotas

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFCachingGetSpaceUsed.java

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

2020
import org.apache.commons.lang3.RandomStringUtils;
2121
import org.apache.hadoop.test.GenericTestUtils;
22-
import org.junit.After;
23-
import org.junit.Before;
24-
import org.junit.Test;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2525

2626
import java.io.File;
2727
import java.io.IOException;
2828
import java.io.RandomAccessFile;
2929

3030

31-
import static org.junit.Assert.assertTrue;
31+
import static org.junit.jupiter.api.Assertions.assertTrue;
3232

3333
/**
3434
* Test to make sure df can run and work.
@@ -37,13 +37,13 @@ public class TestDFCachingGetSpaceUsed {
3737
final static private File DF_DIR = GenericTestUtils.getTestDir("testdfspace");
3838
public static final int FILE_SIZE = 1024;
3939

40-
@Before
40+
@BeforeEach
4141
public void setUp() {
4242
FileUtil.fullyDelete(DF_DIR);
4343
assertTrue(DF_DIR.mkdirs());
4444
}
4545

46-
@After
46+
@AfterEach
4747
public void tearDown() throws IOException {
4848
FileUtil.fullyDelete(DF_DIR);
4949
}

0 commit comments

Comments
 (0)