Skip to content

Commit e08bb0b

Browse files
HADOOP-19418. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-nfs. (#7635)
* HADOOP-19418. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-nfs. Co-authored-by: He Xiaoqiao <[email protected]> Reviewed-by: He Xiaoqiao <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent 751468d commit e08bb0b

File tree

13 files changed

+432
-363
lines changed

13 files changed

+432
-363
lines changed

hadoop-hdfs-project/hadoop-hdfs-nfs/pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,36 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
173173
<artifactId>bcprov-jdk18on</artifactId>
174174
<scope>test</scope>
175175
</dependency>
176+
<dependency>
177+
<groupId>org.assertj</groupId>
178+
<artifactId>assertj-core</artifactId>
179+
<scope>test</scope>
180+
</dependency>
181+
<dependency>
182+
<groupId>org.junit.jupiter</groupId>
183+
<artifactId>junit-jupiter-api</artifactId>
184+
<scope>test</scope>
185+
</dependency>
186+
<dependency>
187+
<groupId>org.junit.jupiter</groupId>
188+
<artifactId>junit-jupiter-params</artifactId>
189+
<scope>test</scope>
190+
</dependency>
191+
<dependency>
192+
<groupId>org.junit.jupiter</groupId>
193+
<artifactId>junit-jupiter-engine</artifactId>
194+
<scope>test</scope>
195+
</dependency>
196+
<dependency>
197+
<groupId>org.junit.vintage</groupId>
198+
<artifactId>junit-vintage-engine</artifactId>
199+
<scope>test</scope>
200+
</dependency>
201+
<dependency>
202+
<groupId>org.junit.platform</groupId>
203+
<artifactId>junit-platform-launcher</artifactId>
204+
<scope>test</scope>
205+
</dependency>
176206
</dependencies>
177207

178208
<profiles>

hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/TestMountd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import org.apache.hadoop.hdfs.nfs.nfs3.Nfs3;
3131
import org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3;
3232
import org.apache.hadoop.oncrpc.XDR;
33-
import org.junit.Test;
34-
import static org.junit.Assert.assertTrue;
33+
import org.junit.jupiter.api.Test;
34+
import static org.junit.jupiter.api.Assertions.assertTrue;
3535

3636
public class TestMountd {
3737

hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestClientAccessPrivilege.java

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

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

2222
import java.io.IOException;
2323
import java.net.InetSocketAddress;
@@ -36,11 +36,13 @@
3636
import org.apache.hadoop.oncrpc.security.SecurityHandler;
3737
import org.apache.hadoop.security.authorize.DefaultImpersonationProvider;
3838
import org.apache.hadoop.security.authorize.ProxyUsers;
39-
import org.junit.AfterClass;
40-
import org.junit.Before;
41-
import org.junit.BeforeClass;
42-
import org.junit.Test;
43-
import org.mockito.Mockito;
39+
import org.junit.jupiter.api.AfterAll;
40+
import org.junit.jupiter.api.BeforeEach;
41+
import org.junit.jupiter.api.BeforeAll;
42+
import org.junit.jupiter.api.Test;
43+
import org.junit.jupiter.api.Timeout;
44+
import static org.mockito.Mockito.mock;
45+
import static org.mockito.Mockito.when;
4446

4547
public class TestClientAccessPrivilege {
4648
static MiniDFSCluster cluster = null;
@@ -50,7 +52,7 @@ public class TestClientAccessPrivilege {
5052
static String testdir = "/tmp";
5153
static SecurityHandler securityHandler;
5254

53-
@BeforeClass
55+
@BeforeAll
5456
public static void setup() throws Exception {
5557

5658
String currentUser = System.getProperty("user.name");
@@ -68,26 +70,27 @@ public static void setup() throws Exception {
6870
config.setInt("nfs3.mountd.port", 0);
6971
config.setInt("nfs3.server.port", 0);
7072

71-
securityHandler = Mockito.mock(SecurityHandler.class);
72-
Mockito.when(securityHandler.getUser()).thenReturn(
73+
securityHandler = mock(SecurityHandler.class);
74+
when(securityHandler.getUser()).thenReturn(
7375
System.getProperty("user.name"));
7476
}
7577

76-
@AfterClass
78+
@AfterAll
7779
public static void shutdown() throws Exception {
7880
if (cluster != null) {
7981
cluster.shutdown();
8082
}
8183
}
8284

83-
@Before
85+
@BeforeEach
8486
public void createFiles() throws IllegalArgumentException, IOException {
8587
hdfs.delete(new Path(testdir), true);
8688
hdfs.mkdirs(new Path(testdir));
8789
DFSTestUtil.createFile(hdfs, new Path(testdir + "/f1"), 0, (short) 1, 0);
8890
}
8991

90-
@Test(timeout = 60000)
92+
@Test
93+
@Timeout(value = 60)
9194
public void testClientAccessPrivilegeForRemove() throws Exception {
9295
// Configure ro access for nfs1 service
9396
config.set("dfs.nfs.exports.allowed.hosts", "* ro");
@@ -113,9 +116,8 @@ public void testClientAccessPrivilegeForRemove() throws Exception {
113116
securityHandler, new InetSocketAddress("localhost", 1234));
114117

115118
// Assert on return code
116-
assertEquals("Incorrect return code", Nfs3Status.NFS3ERR_ACCES,
117-
response.getStatus());
118-
119+
assertEquals(Nfs3Status.NFS3ERR_ACCES,
120+
response.getStatus(), "Incorrect return code");
119121
}
120122

121123
}

hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestDFSClientCache.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@
1818
package org.apache.hadoop.hdfs.nfs.nfs3;
1919

2020
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
21-
import static org.hamcrest.core.Is.is;
22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertFalse;
24-
import static org.junit.Assert.assertThat;
25-
import static org.junit.Assert.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.assertj.core.api.Assertions.assertThat;
2625

2726
import java.io.IOException;
2827

2928
import org.apache.hadoop.fs.FileSystem;
3029
import org.apache.hadoop.hdfs.DFSClient;
3130
import org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration;
3231
import org.apache.hadoop.security.UserGroupInformation;
33-
import org.junit.After;
34-
import org.junit.Test;
32+
import org.junit.jupiter.api.AfterEach;
33+
import org.junit.jupiter.api.Test;
3534

3635
public class TestDFSClientCache {
37-
@After
36+
@AfterEach
3837
public void cleanup() {
3938
UserGroupInformation.reset();
4039
}
@@ -58,8 +57,8 @@ public void testEviction() throws IOException {
5857

5958
cache.getDfsClient("test2", namenodeId);
6059
assertTrue(isDfsClientClose(c1));
61-
assertTrue("cache size should be the max size or less",
62-
cache.getClientCache().size() <= MAX_CACHE_SIZE);
60+
assertTrue(cache.getClientCache().size() <= MAX_CACHE_SIZE,
61+
"cache size should be the max size or less");
6362
}
6463

6564
@Test
@@ -79,11 +78,10 @@ public void testGetUserGroupInformationSecure() throws IOException {
7978
UserGroupInformation ugiResult
8079
= cache.getUserGroupInformation(userName, currentUserUgi);
8180

82-
assertThat(ugiResult.getUserName(), is(userName));
83-
assertThat(ugiResult.getRealUser(), is(currentUserUgi));
84-
assertThat(
85-
ugiResult.getAuthenticationMethod(),
86-
is(UserGroupInformation.AuthenticationMethod.PROXY));
81+
assertThat(ugiResult.getUserName()).isEqualTo(userName);
82+
assertThat(ugiResult.getRealUser()).isEqualTo(currentUserUgi);
83+
assertThat(ugiResult.getAuthenticationMethod()).isEqualTo(
84+
UserGroupInformation.AuthenticationMethod.PROXY);
8785
}
8886

8987
@Test
@@ -99,11 +97,10 @@ public void testGetUserGroupInformation() throws IOException {
9997
UserGroupInformation ugiResult
10098
= cache.getUserGroupInformation(userName, currentUserUgi);
10199

102-
assertThat(ugiResult.getUserName(), is(userName));
103-
assertThat(ugiResult.getRealUser(), is(currentUserUgi));
104-
assertThat(
105-
ugiResult.getAuthenticationMethod(),
106-
is(UserGroupInformation.AuthenticationMethod.PROXY));
100+
assertThat(ugiResult.getUserName()).isEqualTo(userName);
101+
assertThat(ugiResult.getRealUser()).isEqualTo(currentUserUgi);
102+
assertThat(ugiResult.getAuthenticationMethod()).isEqualTo(
103+
UserGroupInformation.AuthenticationMethod.PROXY);
107104
}
108105

109106
private static boolean isDfsClientClose(DFSClient c) {

hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestExportsTable.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
*/
1818
package org.apache.hadoop.hdfs.nfs.nfs3;
1919

20-
import static org.junit.Assert.assertTrue;
21-
2220
import java.io.IOException;
2321
import java.nio.file.FileSystemException;
2422

@@ -34,15 +32,13 @@
3432
import org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration;
3533
import org.apache.hadoop.hdfs.nfs.mount.Mountd;
3634
import org.apache.hadoop.hdfs.nfs.mount.RpcProgramMountd;
37-
import org.junit.Rule;
38-
import org.junit.Test;
39-
import org.junit.rules.ExpectedException;
35+
import org.junit.jupiter.api.Test;
36+
37+
import static org.junit.jupiter.api.Assertions.assertThrows;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
4039

4140
public class TestExportsTable {
4241

43-
@Rule
44-
public ExpectedException exception = ExpectedException.none();
45-
4642
@Test
4743
public void testHdfsExportPoint() throws IOException {
4844
NfsConfiguration config = new NfsConfiguration();
@@ -224,13 +220,13 @@ public void testViewFsRootExportPoint() throws IOException {
224220
ConfigUtil.addLink(config, clusterName, "/hdfs2",
225221
hdfs2.makeQualified(base2).toUri());
226222

227-
exception.expect(FileSystemException.class);
228-
exception.
229-
expectMessage("Only HDFS is supported as underlyingFileSystem, "
230-
+ "fs scheme:viewfs");
231-
// Start nfs
232-
final Nfs3 nfsServer = new Nfs3(config);
233-
nfsServer.startServiceInternal(false);
223+
FileSystemException fileSystemException = assertThrows(FileSystemException.class, () -> {
224+
// Start nfs
225+
final Nfs3 nfsServer = new Nfs3(config);
226+
nfsServer.startServiceInternal(false);
227+
});
228+
assertTrue(fileSystemException.getMessage().
229+
contains("Only HDFS is supported as underlyingFileSystem, fs scheme:viewfs"));
234230
} finally {
235231
if (cluster != null) {
236232
cluster.shutdown();
@@ -292,13 +288,14 @@ public void testInvalidFsExport() throws IOException {
292288
config.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY,
293289
FsConstants.LOCAL_FS_URI.toString());
294290

295-
exception.expect(FileSystemException.class);
296-
exception.
297-
expectMessage("Only HDFS is supported as underlyingFileSystem, "
298-
+ "fs scheme:file");
299-
// Start nfs
300-
final Nfs3 nfsServer = new Nfs3(config);
301-
nfsServer.startServiceInternal(false);
291+
FileSystemException fileSystemException =
292+
assertThrows(FileSystemException.class, () -> {
293+
// Start nfs
294+
final Nfs3 nfsServer = new Nfs3(config);
295+
nfsServer.startServiceInternal(false);
296+
});
297+
assertTrue(fileSystemException.getMessage().
298+
contains("Only HDFS is supported as underlyingFileSystem, fs scheme:file"));
302299
} finally {
303300
if (cluster != null) {
304301
cluster.shutdown();

hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestNfs3HttpServer.java

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

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

2222
import java.io.File;
2323
import java.net.URL;
@@ -31,9 +31,9 @@
3131
import org.apache.hadoop.http.HttpConfig;
3232
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
3333
import org.apache.hadoop.test.GenericTestUtils;
34-
import org.junit.AfterClass;
35-
import org.junit.BeforeClass;
36-
import org.junit.Test;
34+
import org.junit.jupiter.api.AfterAll;
35+
import org.junit.jupiter.api.BeforeAll;
36+
import org.junit.jupiter.api.Test;
3737

3838
public class TestNfs3HttpServer {
3939
private static final String BASEDIR =
@@ -43,7 +43,7 @@ public class TestNfs3HttpServer {
4343
private static String keystoresDir;
4444
private static String sslConfDir;
4545

46-
@BeforeClass
46+
@BeforeAll
4747
public static void setUp() throws Exception {
4848
conf.set(DFSConfigKeys.DFS_HTTP_POLICY_KEY,
4949
HttpConfig.Policy.HTTP_AND_HTTPS.name());
@@ -64,7 +64,7 @@ public static void setUp() throws Exception {
6464
cluster.waitActive();
6565
}
6666

67-
@AfterClass
67+
@AfterAll
6868
public static void tearDown() throws Exception {
6969
FileUtil.fullyDelete(new File(BASEDIR));
7070
if (cluster != null) {
@@ -84,11 +84,11 @@ public void testHttpServer() throws Exception {
8484

8585
// Check default servlets.
8686
String pageContents = DFSTestUtil.urlGet(new URL(urlRoot + "/jmx"));
87-
assertTrue("Bad contents: " + pageContents,
88-
pageContents.contains("java.lang:type="));
87+
assertTrue(pageContents.contains("java.lang:type="),
88+
"Bad contents: " + pageContents);
8989
System.out.println("pc:" + pageContents);
9090

9191
int port = infoServer.getSecurePort();
92-
assertTrue("Can't get https port", port > 0);
92+
assertTrue(port > 0, "Can't get https port");
9393
}
9494
}

0 commit comments

Comments
 (0)