Skip to content

Commit db7486e

Browse files
zhtttylzslfan1989
andauthored
HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part16. (#7922)
* HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part16. Co-authored-by: Shilun Fan <slfan1989@apache.org> Reviewed-by: Shilun Fan <slfan1989@apache.org> Signed-off-by: Shilun Fan <slfan1989@apache.org>
1 parent bc5a5b8 commit db7486e

File tree

50 files changed

+1058
-909
lines changed

Some content is hidden

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

50 files changed

+1058
-909
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/aliasmap/ITestInMemoryAliasMap.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import org.apache.hadoop.hdfs.DFSConfigKeys;
2323
import org.apache.hadoop.hdfs.protocol.Block;
2424
import org.apache.hadoop.hdfs.protocol.ProvidedStorageLocation;
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

29-
import static org.junit.Assert.assertEquals;
30-
import static org.junit.Assert.assertFalse;
31-
import static org.junit.Assert.assertTrue;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertFalse;
31+
import static org.junit.jupiter.api.Assertions.assertTrue;
3232

3333
import java.io.File;
3434
import java.io.IOException;
@@ -46,7 +46,7 @@ public class ITestInMemoryAliasMap {
4646
private File tempDirectory;
4747
private static String bpid = "bpid-0";
4848

49-
@Before
49+
@BeforeEach
5050
public void setUp() throws Exception {
5151
Configuration conf = new Configuration();
5252
File temp = Files.createTempDirectory("seagull").toFile();
@@ -57,7 +57,7 @@ public void setUp() throws Exception {
5757
aliasMap = InMemoryAliasMap.init(conf, bpid);
5858
}
5959

60-
@After
60+
@AfterEach
6161
public void tearDown() throws Exception {
6262
aliasMap.close();
6363
FileUtils.deleteDirectory(tempDirectory);

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/aliasmap/TestSecureAliasMap.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@
3939
import org.apache.hadoop.security.UserGroupInformation;
4040
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
4141
import org.apache.hadoop.test.GenericTestUtils;
42-
import org.junit.After;
43-
import org.junit.AfterClass;
44-
import org.junit.BeforeClass;
45-
import org.junit.Test;
42+
import org.junit.jupiter.api.AfterEach;
43+
import org.junit.jupiter.api.AfterAll;
44+
import org.junit.jupiter.api.BeforeAll;
45+
import org.junit.jupiter.api.Test;
4646

4747
import java.io.File;
4848
import java.io.IOException;
4949
import java.util.Properties;
5050

51-
import static org.junit.Assert.assertEquals;
52-
import static org.junit.Assert.assertNotNull;
53-
import static org.junit.Assert.assertTrue;
51+
import static org.junit.jupiter.api.Assertions.assertEquals;
52+
import static org.junit.jupiter.api.Assertions.assertNotNull;
53+
import static org.junit.jupiter.api.Assertions.assertTrue;
5454

5555
/**
5656
* Test DN & NN communication in secured hdfs with alias map.
@@ -66,7 +66,7 @@ public class TestSecureAliasMap {
6666
private HdfsConfiguration conf;
6767
private FileSystem fs;
6868

69-
@BeforeClass
69+
@BeforeAll
7070
public static void init() throws Exception {
7171
baseDir =
7272
GenericTestUtils.getTestDir(TestSecureAliasMap.class.getSimpleName());
@@ -81,8 +81,8 @@ public static void init() throws Exception {
8181
SecurityUtil.setAuthenticationMethod(
8282
UserGroupInformation.AuthenticationMethod.KERBEROS, baseConf);
8383
UserGroupInformation.setConfiguration(baseConf);
84-
assertTrue("Expected configuration to enable security",
85-
UserGroupInformation.isSecurityEnabled());
84+
assertTrue(UserGroupInformation.isSecurityEnabled(),
85+
"Expected configuration to enable security");
8686

8787
String userName = UserGroupInformation.getLoginUser().getShortUserName();
8888
File keytabFile = new File(baseDir, userName + ".keytab");
@@ -98,7 +98,7 @@ public static void init() throws Exception {
9898
kdc.getRealm(), keytab, keystoresDir, sslConfDir);
9999
}
100100

101-
@AfterClass
101+
@AfterAll
102102
public static void destroy() throws Exception {
103103
if (kdc != null) {
104104
kdc.stop();
@@ -107,7 +107,7 @@ public static void destroy() throws Exception {
107107
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
108108
}
109109

110-
@After
110+
@AfterEach
111111
public void shutdown() throws IOException {
112112
IOUtils.cleanupWithLogger(null, fs);
113113
if (cluster != null) {
@@ -146,10 +146,10 @@ public void testSecureConnectionToAliasMap() throws Exception {
146146
}
147147

148148
String[] bps = providedVolume.getBlockPoolList();
149-
assertEquals("Missing provided volume", 1, bps.length);
149+
assertEquals(1, bps.length, "Missing provided volume");
150150

151151
BlockAliasMap aliasMap = blockManager.getProvidedStorageMap().getAliasMap();
152152
BlockAliasMap.Reader reader = aliasMap.getReader(null, bps[0]);
153-
assertNotNull("Failed to create blockAliasMap reader", reader);
153+
assertNotNull(reader, "Failed to create blockAliasMap reader");
154154
}
155155
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BaseReplicationPolicyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import org.apache.hadoop.net.Node;
3636
import org.apache.hadoop.test.GenericTestUtils;
3737
import org.apache.hadoop.test.PathUtils;
38-
import org.junit.After;
39-
import org.junit.Before;
38+
import org.junit.jupiter.api.AfterEach;
39+
import org.junit.jupiter.api.BeforeEach;
4040
import org.slf4j.event.Level;
4141

4242
abstract public class BaseReplicationPolicyTest {
@@ -69,7 +69,7 @@ void updateHeartbeatWithUsage(DatanodeDescriptor dn,
6969

7070
abstract DatanodeDescriptor[] getDatanodeDescriptors(Configuration conf);
7171

72-
@Before
72+
@BeforeEach
7373
public void setupCluster() throws Exception {
7474
Configuration conf = new HdfsConfiguration();
7575
dataNodes = getDatanodeDescriptors(conf);
@@ -117,7 +117,7 @@ public BlockPlacementPolicy getStriptedPolicy() {
117117
return striptedPolicy;
118118
}
119119

120-
@After
120+
@AfterEach
121121
public void tearDown() throws Exception {
122122
namenode.stop();
123123
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
import org.apache.hadoop.hdfs.server.protocol.StorageReport;
3636
import org.apache.hadoop.hdfs.util.RwLockMode;
3737
import org.apache.hadoop.test.Whitebox;
38-
import org.junit.Assert;
3938

4039
import org.apache.hadoop.util.Preconditions;
4140

41+
import static org.junit.jupiter.api.Assertions.assertNotNull;
42+
4243
public class BlockManagerTestUtil {
4344

4445
static final long SLEEP_TIME = 1000;
@@ -259,7 +260,7 @@ public static void noticeDeadDatanode(NameNode nn, String dnName) {
259260
theDND = dnd;
260261
}
261262
}
262-
Assert.assertNotNull("Could not find DN with name: " + dnName, theDND);
263+
assertNotNull(theDND, "Could not find DN with name: " + dnName);
263264

264265
synchronized (hbm) {
265266
DFSTestUtil.setDatanodeDead(theDND);

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestAvailableSpaceBPPBalanceLocal.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
import org.apache.hadoop.hdfs.server.namenode.NameNode;
2929
import org.apache.hadoop.net.NetworkTopology;
3030
import org.apache.hadoop.test.PathUtils;
31-
import org.junit.Assert;
32-
import org.junit.BeforeClass;
33-
import org.junit.Test;
31+
import org.junit.jupiter.api.BeforeAll;
32+
import org.junit.jupiter.api.Test;
3433

3534
import java.io.File;
3635
import java.util.ArrayList;
3736

3837
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AVAILABLE_SPACE_BLOCK_PLACEMENT_POLICY_BALANCE_LOCAL_NODE_KEY;
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
39+
import static org.junit.jupiter.api.Assertions.assertTrue;
3940

4041
/**
4142
* Tests AvailableSpaceBlockPlacementPolicy with balance local.
@@ -53,7 +54,7 @@ public class TestAvailableSpaceBPPBalanceLocal {
5354
private static NameNode namenode;
5455
private static NetworkTopology cluster;
5556

56-
@BeforeClass
57+
@BeforeAll
5758
public static void setupCluster() throws Exception {
5859
conf = new HdfsConfiguration();
5960
conf.setFloat(
@@ -137,8 +138,8 @@ public void testChooseLocalNode() {
137138
.chooseTarget(FILE, 1, localNode,
138139
new ArrayList<DatanodeStorageInfo>(), false, null, BLOCK_SIZE,
139140
TestBlockStoragePolicy.DEFAULT_STORAGE_POLICY, null);
140-
Assert.assertEquals(1, targets.length);
141-
Assert.assertEquals(localNode, targets[0].getDatanodeDescriptor());
141+
assertEquals(1, targets.length);
142+
assertEquals(localNode, targets[0].getDatanodeDescriptor());
142143
}
143144
}
144145

@@ -154,11 +155,11 @@ public void testChooseLocalNodeWithLocalNodeLoaded() {
154155
new ArrayList<DatanodeStorageInfo>(), false, null, BLOCK_SIZE,
155156
TestBlockStoragePolicy.DEFAULT_STORAGE_POLICY, null);
156157

157-
Assert.assertEquals(1, targets.length);
158+
assertEquals(1, targets.length);
158159
if (localNode == targets[0].getDatanodeDescriptor()) {
159160
numLocalChosen++;
160161
}
161162
}
162-
Assert.assertTrue(numLocalChosen < (CHOOSE_TIMES - numLocalChosen));
163+
assertTrue(numLocalChosen < (CHOOSE_TIMES - numLocalChosen));
163164
}
164165
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestAvailableSpaceBlockPlacementPolicy.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
import org.apache.hadoop.net.NetworkTopology;
3535
import org.apache.hadoop.net.Node;
3636
import org.apache.hadoop.test.PathUtils;
37-
import org.junit.AfterClass;
38-
import org.junit.BeforeClass;
39-
import org.junit.Test;
37+
import org.junit.jupiter.api.AfterAll;
38+
import org.junit.jupiter.api.BeforeAll;
39+
import org.junit.jupiter.api.Test;
4040

41-
import static org.junit.Assert.assertTrue;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
4242

4343
public class TestAvailableSpaceBlockPlacementPolicy {
4444
private final static int numRacks = 4;
@@ -55,7 +55,7 @@ public class TestAvailableSpaceBlockPlacementPolicy {
5555
private static BlockPlacementPolicy placementPolicy;
5656
private static NetworkTopology cluster;
5757

58-
@BeforeClass
58+
@BeforeAll
5959
public static void setupCluster() throws Exception {
6060
conf = new HdfsConfiguration();
6161
conf.setFloat(DFSConfigKeys.
@@ -294,7 +294,7 @@ public void testCompareDataNode() {
294294
tolerateDataNodes[2], false) == -1);
295295
}
296296

297-
@AfterClass
297+
@AfterAll
298298
public static void teardownCluster() {
299299
if (namenode != null) {
300300
namenode.stop();

0 commit comments

Comments
 (0)