Skip to content

Commit 48175c5

Browse files
authored
HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part18. (#7941)
* HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part18. Reviewed-by: Shilun Fan <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent 1e5ae85 commit 48175c5

19 files changed

+258
-262
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
168168
</exclusions>
169169
</dependency>
170170

171-
<dependency>
172-
<groupId>junit</groupId>
173-
<artifactId>junit</artifactId>
174-
<scope>test</scope>
175-
</dependency>
176171
<dependency>
177172
<groupId>org.apache.hadoop</groupId>
178173
<artifactId>hadoop-minikdc</artifactId>

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/TestGenericRefresh.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
package org.apache.hadoop;
2020

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

2424
import org.apache.hadoop.conf.Configuration;
2525
import org.apache.hadoop.fs.FileSystem;
@@ -29,11 +29,11 @@
2929

3030
import org.apache.hadoop.ipc.RefreshRegistry;
3131
import org.apache.hadoop.ipc.RefreshResponse;
32-
import org.junit.Test;
33-
import org.junit.Before;
34-
import org.junit.After;
35-
import org.junit.BeforeClass;
36-
import org.junit.AfterClass;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.AfterEach;
35+
import org.junit.jupiter.api.BeforeAll;
36+
import org.junit.jupiter.api.AfterAll;
3737
import org.mockito.Mockito;
3838

3939
/**
@@ -49,7 +49,7 @@ public class TestGenericRefresh {
4949
private static RefreshHandler firstHandler;
5050
private static RefreshHandler secondHandler;
5151

52-
@BeforeClass
52+
@BeforeAll
5353
public static void setUpBeforeClass() throws Exception {
5454
config = new Configuration();
5555
config.set("hadoop.security.authorization", "true");
@@ -59,14 +59,14 @@ public static void setUpBeforeClass() throws Exception {
5959
cluster.waitActive();
6060
}
6161

62-
@AfterClass
62+
@AfterAll
6363
public static void tearDownBeforeClass() throws Exception {
6464
if (cluster != null) {
6565
cluster.shutdown();
6666
}
6767
}
6868

69-
@Before
69+
@BeforeEach
7070
public void setUp() throws Exception {
7171
// Register Handlers, first one just sends an ok response
7272
firstHandler = Mockito.mock(RefreshHandler.class);
@@ -83,7 +83,7 @@ public void setUp() throws Exception {
8383
RefreshRegistry.defaultRegistry().register("secondHandler", secondHandler);
8484
}
8585

86-
@After
86+
@AfterEach
8787
public void tearDown() throws Exception {
8888
RefreshRegistry.defaultRegistry().unregisterAll("firstHandler");
8989
RefreshRegistry.defaultRegistry().unregisterAll("secondHandler");
@@ -94,7 +94,7 @@ public void testInvalidCommand() throws Exception {
9494
DFSAdmin admin = new DFSAdmin(config);
9595
String [] args = new String[]{"-refresh", "nn"};
9696
int exitCode = admin.run(args);
97-
assertEquals("DFSAdmin should fail due to bad args", -1, exitCode);
97+
assertEquals(-1, exitCode, "DFSAdmin should fail due to bad args");
9898
}
9999

100100
@Test
@@ -103,7 +103,7 @@ public void testInvalidIdentifier() throws Exception {
103103
String [] args = new String[]{"-refresh", "localhost:" +
104104
cluster.getNameNodePort(), "unregisteredIdentity"};
105105
int exitCode = admin.run(args);
106-
assertEquals("DFSAdmin should fail due to no handler registered", -1, exitCode);
106+
assertEquals(-1, exitCode, "DFSAdmin should fail due to no handler registered");
107107
}
108108

109109
@Test
@@ -112,7 +112,7 @@ public void testValidIdentifier() throws Exception {
112112
String[] args = new String[]{"-refresh",
113113
"localhost:" + cluster.getNameNodePort(), "firstHandler"};
114114
int exitCode = admin.run(args);
115-
assertEquals("DFSAdmin should succeed", 0, exitCode);
115+
assertEquals(0, exitCode, "DFSAdmin should succeed");
116116

117117
Mockito.verify(firstHandler).handleRefresh("firstHandler", new String[]{});
118118
// Second handler was never called
@@ -126,11 +126,11 @@ public void testVariableArgs() throws Exception {
126126
String[] args = new String[]{"-refresh", "localhost:" +
127127
cluster.getNameNodePort(), "secondHandler", "one"};
128128
int exitCode = admin.run(args);
129-
assertEquals("DFSAdmin should return 2", 2, exitCode);
129+
assertEquals(2, exitCode, "DFSAdmin should return 2");
130130

131131
exitCode = admin.run(new String[]{"-refresh", "localhost:" +
132132
cluster.getNameNodePort(), "secondHandler", "one", "two"});
133-
assertEquals("DFSAdmin should now return 3", 3, exitCode);
133+
assertEquals(3, exitCode, "DFSAdmin should now return 3");
134134

135135
Mockito.verify(secondHandler).handleRefresh("secondHandler", new String[]{"one"});
136136
Mockito.verify(secondHandler).handleRefresh("secondHandler", new String[]{"one", "two"});
@@ -145,7 +145,7 @@ public void testUnregistration() throws Exception {
145145
String[] args = new String[]{"-refresh", "localhost:" +
146146
cluster.getNameNodePort(), "firstHandler"};
147147
int exitCode = admin.run(args);
148-
assertEquals("DFSAdmin should return -1", -1, exitCode);
148+
assertEquals(-1, exitCode, "DFSAdmin should return -1");
149149
}
150150

151151
@Test

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/TestRefreshCallQueue.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
package org.apache.hadoop;
2020

21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
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.junit.jupiter.api.Assertions.fail;
2525

2626
import java.io.IOException;
2727
import java.net.BindException;
@@ -40,8 +40,8 @@
4040
import org.apache.hadoop.ipc.FairCallQueue;
4141
import org.apache.hadoop.metrics2.MetricsException;
4242
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
43-
import org.junit.After;
44-
import org.junit.Test;
43+
import org.junit.jupiter.api.AfterEach;
44+
import org.junit.jupiter.api.Test;
4545

4646
public class TestRefreshCallQueue {
4747
private MiniDFSCluster cluster;
@@ -77,7 +77,7 @@ private void setUp(Class<?> queueClass) throws IOException {
7777
}
7878
}
7979

80-
@After
80+
@AfterEach
8181
public void tearDown() throws IOException {
8282
if (cluster != null) {
8383
cluster.shutdown();
@@ -115,23 +115,21 @@ public void testRefresh() throws Exception {
115115
mockQueuePuts = 0;
116116
setUp(MockCallQueue.class);
117117

118-
assertTrue("Mock queue should have been constructed",
119-
mockQueueConstructions > 0);
120-
assertTrue("Puts are routed through MockQueue", canPutInMockQueue());
118+
assertTrue(mockQueueConstructions > 0, "Mock queue should have been constructed");
119+
assertTrue(canPutInMockQueue(), "Puts are routed through MockQueue");
121120
int lastMockQueueConstructions = mockQueueConstructions;
122121

123122
// Replace queue with the queue specified in core-site.xml, which would be
124123
// the LinkedBlockingQueue
125124
DFSAdmin admin = new DFSAdmin(config);
126125
String [] args = new String[]{"-refreshCallQueue"};
127126
int exitCode = admin.run(args);
128-
assertEquals("DFSAdmin should return 0", 0, exitCode);
127+
assertEquals(0, exitCode, "DFSAdmin should return 0");
129128

130-
assertEquals("Mock queue should have no additional constructions",
131-
lastMockQueueConstructions, mockQueueConstructions);
129+
assertEquals(lastMockQueueConstructions, mockQueueConstructions,
130+
"Mock queue should have no additional constructions");
132131
try {
133-
assertFalse("Puts are routed through LBQ instead of MockQueue",
134-
canPutInMockQueue());
132+
assertFalse(canPutInMockQueue(), "Puts are routed through LBQ instead of MockQueue");
135133
} catch (IOException ioe) {
136134
fail("Could not put into queue at all");
137135
}
@@ -149,8 +147,9 @@ public void testRefreshCallQueueWithFairCallQueue() throws Exception {
149147
DFSConfigKeys.DFS_NAMENODE_SERVICE_HANDLER_COUNT_DEFAULT);
150148
NameNodeRpcServer rpcServer = (NameNodeRpcServer) cluster.getNameNodeRpc();
151149
// check callqueue size
152-
assertEquals(CommonConfigurationKeys.IPC_SERVER_HANDLER_QUEUE_SIZE_DEFAULT
153-
* serviceHandlerCount, rpcServer.getClientRpcServer().getMaxQueueSize());
150+
assertEquals(
151+
CommonConfigurationKeys.IPC_SERVER_HANDLER_QUEUE_SIZE_DEFAULT * serviceHandlerCount,
152+
rpcServer.getClientRpcServer().getMaxQueueSize());
154153
// Replace queue and update queue size
155154
config.setInt(CommonConfigurationKeys.IPC_SERVER_HANDLER_QUEUE_SIZE_KEY,
156155
150);
@@ -170,8 +169,7 @@ public void testRefreshCallQueueWithFairCallQueue() throws Exception {
170169
DefaultMetricsSystem.setMiniClusterMode(oldValue);
171170
}
172171
// check callQueueSize has changed
173-
assertEquals(150 * serviceHandlerCount, rpcServer.getClientRpcServer()
174-
.getMaxQueueSize());
172+
assertEquals(150 * serviceHandlerCount, rpcServer.getClientRpcServer().getMaxQueueSize());
175173
}
176174

177175
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestAclCLI.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import org.apache.hadoop.fs.FileSystem;
2323
import org.apache.hadoop.hdfs.DFSConfigKeys;
2424
import org.apache.hadoop.hdfs.MiniDFSCluster;
25-
import org.junit.After;
26-
import org.junit.Before;
27-
import org.junit.Test;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2828

2929
public class TestAclCLI extends CLITestHelperDFS {
3030
private MiniDFSCluster cluster = null;
@@ -38,7 +38,7 @@ protected void initConf() {
3838
DFSConfigKeys.DFS_NAMENODE_POSIX_ACL_INHERITANCE_ENABLED_KEY, false);
3939
}
4040

41-
@Before
41+
@BeforeEach
4242
@Override
4343
public void setUp() throws Exception {
4444
super.setUp();
@@ -49,7 +49,7 @@ public void setUp() throws Exception {
4949
username = System.getProperty("user.name");
5050
}
5151

52-
@After
52+
@AfterEach
5353
@Override
5454
public void tearDown() throws Exception {
5555
super.tearDown();

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestAclCLIWithPosixAclInheritance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_POSIX_ACL_INHERITANCE_ENABLED_KEY;
2121

22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

2424
/**
2525
* Test ACL CLI with POSIX ACL inheritance enabled.

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestCacheAdminCLI.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.cli;
2020

21-
import static org.junit.Assert.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
@@ -37,9 +37,9 @@
3737
import org.apache.hadoop.hdfs.MiniDFSCluster;
3838
import org.apache.hadoop.hdfs.tools.CacheAdmin;
3939
import org.apache.hadoop.security.authorize.PolicyProvider;
40-
import org.junit.After;
41-
import org.junit.Before;
42-
import org.junit.Test;
40+
import org.junit.jupiter.api.AfterEach;
41+
import org.junit.jupiter.api.BeforeEach;
42+
import org.junit.jupiter.api.Test;
4343
import org.xml.sax.SAXException;
4444

4545
public class TestCacheAdminCLI extends CLITestHelper {
@@ -51,7 +51,7 @@ public class TestCacheAdminCLI extends CLITestHelper {
5151
protected FileSystem fs = null;
5252
protected String namenode = null;
5353

54-
@Before
54+
@BeforeEach
5555
@Override
5656
public void setUp() throws Exception {
5757
super.setUp();
@@ -68,11 +68,10 @@ public void setUp() throws Exception {
6868
username = System.getProperty("user.name");
6969

7070
fs = dfsCluster.getFileSystem();
71-
assertTrue("Not a HDFS: "+fs.getUri(),
72-
fs instanceof DistributedFileSystem);
71+
assertTrue(fs instanceof DistributedFileSystem, "Not a HDFS: " + fs.getUri());
7372
}
7473

75-
@After
74+
@AfterEach
7675
@Override
7776
public void tearDown() throws Exception {
7877
if (fs != null) {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestCryptoAdminCLI.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.security.NoSuchAlgorithmException;
2424
import java.util.UUID;
2525

26-
import static org.junit.Assert.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
2727

2828
import org.apache.hadoop.cli.util.CLICommand;
2929
import org.apache.hadoop.cli.util.CLICommandCryptoAdmin;
@@ -45,9 +45,9 @@
4545
import org.apache.hadoop.hdfs.tools.CryptoAdmin;
4646
import org.apache.hadoop.security.authorize.PolicyProvider;
4747
import org.apache.hadoop.test.GenericTestUtils;
48-
import org.junit.After;
49-
import org.junit.Before;
50-
import org.junit.Test;
48+
import org.junit.jupiter.api.AfterEach;
49+
import org.junit.jupiter.api.BeforeEach;
50+
import org.junit.jupiter.api.Test;
5151
import org.xml.sax.SAXException;
5252

5353
public class TestCryptoAdminCLI extends CLITestHelperDFS {
@@ -56,7 +56,7 @@ public class TestCryptoAdminCLI extends CLITestHelperDFS {
5656
protected String namenode = null;
5757
private static File tmpDir;
5858

59-
@Before
59+
@BeforeEach
6060
@Override
6161
public void setUp() throws Exception {
6262
super.setUp();
@@ -78,11 +78,11 @@ public void setUp() throws Exception {
7878
username = System.getProperty("user.name");
7979

8080
fs = dfsCluster.getFileSystem();
81-
assertTrue("Not an HDFS: " + fs.getUri(),
82-
fs instanceof DistributedFileSystem);
81+
assertTrue(fs instanceof DistributedFileSystem,
82+
"Not an HDFS: " + fs.getUri());
8383
}
8484

85-
@After
85+
@AfterEach
8686
@Override
8787
public void tearDown() throws Exception {
8888
if (fs != null) {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestDeleteCLI.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.cli;
2020

21-
import static org.junit.Assert.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import org.apache.hadoop.cli.util.CLICommand;
2424
import org.apache.hadoop.cli.util.CommandExecutor.Result;
@@ -27,16 +27,16 @@
2727
import org.apache.hadoop.hdfs.DFSConfigKeys;
2828
import org.apache.hadoop.hdfs.DistributedFileSystem;
2929
import org.apache.hadoop.hdfs.MiniDFSCluster;
30-
import org.junit.After;
31-
import org.junit.Before;
32-
import org.junit.Test;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3333

3434
public class TestDeleteCLI extends CLITestHelperDFS {
3535
protected MiniDFSCluster dfsCluster = null;
3636
protected FileSystem fs = null;
3737
protected String namenode = null;
3838

39-
@Before
39+
@BeforeEach
4040
@Override
4141
public void setUp() throws Exception {
4242
super.setUp();
@@ -49,11 +49,11 @@ public void setUp() throws Exception {
4949
namenode = conf.get(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "file:///");
5050

5151
fs = dfsCluster.getFileSystem();
52-
assertTrue("Not an HDFS: " + fs.getUri(),
53-
fs instanceof DistributedFileSystem);
52+
assertTrue(fs instanceof DistributedFileSystem,
53+
"Not an HDFS: " + fs.getUri());
5454
}
5555

56-
@After
56+
@AfterEach
5757
@Override
5858
public void tearDown() throws Exception {
5959
if (fs != null) {

0 commit comments

Comments
 (0)