Skip to content

Commit 818e3f0

Browse files
authored
HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part12. (#7873)
* HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part12. Reviewed-by: Shilun Fan <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent fcd3eb3 commit 818e3f0

Some content is hidden

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

47 files changed

+877
-917
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddBlock.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.namenode;
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.util.EnumSet;
@@ -33,9 +33,9 @@
3333
import org.apache.hadoop.hdfs.client.HdfsDataOutputStream.SyncFlag;
3434
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
3535
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
36-
import org.junit.After;
37-
import org.junit.Before;
38-
import org.junit.Test;
36+
import org.junit.jupiter.api.AfterEach;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Test;
3939

4040
/**
4141
* Test AddBlockOp is written and read correctly
@@ -47,7 +47,7 @@ public class TestAddBlock {
4747
private MiniDFSCluster cluster;
4848
private Configuration conf;
4949

50-
@Before
50+
@BeforeEach
5151
public void setup() throws IOException {
5252
conf = new Configuration();
5353
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCKSIZE);
@@ -56,7 +56,7 @@ public void setup() throws IOException {
5656
cluster.waitActive();
5757
}
5858

59-
@After
59+
@AfterEach
6060
public void tearDown() {
6161
if (cluster != null) {
6262
cluster.shutdown();
@@ -147,8 +147,7 @@ public void testAddBlockUC() throws Exception {
147147
assertEquals(BLOCKSIZE, fileBlocks[0].getNumBytes());
148148
assertEquals(BlockUCState.COMPLETE, fileBlocks[0].getBlockUCState());
149149
assertEquals(appendContent.length() - 1, fileBlocks[1].getNumBytes());
150-
assertEquals(BlockUCState.UNDER_CONSTRUCTION,
151-
fileBlocks[1].getBlockUCState());
150+
assertEquals(BlockUCState.UNDER_CONSTRUCTION, fileBlocks[1].getBlockUCState());
152151
} finally {
153152
if (out != null) {
154153
out.close();

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddBlockRetry.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
package org.apache.hadoop.hdfs.server.namenode;
2020

2121

22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertNotNull;
24-
import static org.junit.Assert.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2525
import java.io.IOException;
2626
import java.util.EnumSet;
2727

@@ -38,9 +38,9 @@
3838
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
3939
import org.apache.hadoop.hdfs.util.RwLockMode;
4040
import org.apache.hadoop.io.EnumSetWritable;
41-
import org.junit.After;
42-
import org.junit.Before;
43-
import org.junit.Test;
41+
import org.junit.jupiter.api.AfterEach;
42+
import org.junit.jupiter.api.BeforeEach;
43+
import org.junit.jupiter.api.Test;
4444
import org.mockito.Mockito;
4545

4646
/**
@@ -56,7 +56,7 @@ public class TestAddBlockRetry {
5656
private Configuration conf;
5757
private MiniDFSCluster cluster;
5858

59-
@Before
59+
@BeforeEach
6060
public void setUp() throws Exception {
6161
conf = new Configuration();
6262
cluster = new MiniDFSCluster.Builder(conf)
@@ -65,7 +65,7 @@ public void setUp() throws Exception {
6565
cluster.waitActive();
6666
}
6767

68-
@After
68+
@AfterEach
6969
public void tearDown() throws Exception {
7070
if (cluster != null) {
7171
cluster.shutdown();
@@ -105,18 +105,17 @@ public void testRetryAddBlockWhileInChooseTarget() throws Exception {
105105
}
106106
DatanodeStorageInfo targets[] = FSDirWriteFileOp.chooseTargetForNewBlock(
107107
ns.getBlockManager(), src, null, null, null, r);
108-
assertNotNull("Targets must be generated", targets);
108+
assertNotNull(targets, "Targets must be generated");
109109

110110
// run second addBlock()
111111
LOG.info("Starting second addBlock for " + src);
112112
nn.addBlock(src, "clientName", null, null,
113113
HdfsConstants.GRANDFATHER_INODE_ID, null, null);
114-
assertTrue("Penultimate block must be complete",
115-
checkFileProgress(src, false));
114+
assertTrue(checkFileProgress(src, false), "Penultimate block must be complete");
116115
LocatedBlocks lbs = nn.getBlockLocations(src, 0, Long.MAX_VALUE);
117-
assertEquals("Must be one block", 1, lbs.getLocatedBlocks().size());
116+
assertEquals(1, lbs.getLocatedBlocks().size(), "Must be one block");
118117
LocatedBlock lb2 = lbs.get(0);
119-
assertEquals("Wrong replication", REPLICATION, lb2.getLocations().length);
118+
assertEquals(REPLICATION, lb2.getLocations().length, "Wrong replication");
120119

121120
// continue first addBlock()
122121
ns.writeLock(RwLockMode.GLOBAL);
@@ -127,14 +126,14 @@ public void testRetryAddBlockWhileInChooseTarget() throws Exception {
127126
} finally {
128127
ns.writeUnlock(RwLockMode.GLOBAL, "testRetryAddBlockWhileInChooseTarget");
129128
}
130-
assertEquals("Blocks are not equal", lb2.getBlock(), newBlock.getBlock());
129+
assertEquals(lb2.getBlock(), newBlock.getBlock(), "Blocks are not equal");
131130

132131
// check locations
133132
lbs = nn.getBlockLocations(src, 0, Long.MAX_VALUE);
134-
assertEquals("Must be one block", 1, lbs.getLocatedBlocks().size());
133+
assertEquals(1, lbs.getLocatedBlocks().size(), "Must be one block");
135134
LocatedBlock lb1 = lbs.get(0);
136-
assertEquals("Wrong replication", REPLICATION, lb1.getLocations().length);
137-
assertEquals("Blocks are not equal", lb1.getBlock(), lb2.getBlock());
135+
assertEquals(REPLICATION, lb1.getLocations().length, "Wrong replication");
136+
assertEquals(lb1.getBlock(), lb2.getBlock(), "Blocks are not equal");
138137
}
139138

140139
boolean checkFileProgress(String src, boolean checkall) throws IOException {
@@ -165,14 +164,14 @@ public void testAddBlockRetryShouldReturnBlockWithLocations()
165164
LOG.info("Starting first addBlock for " + src);
166165
LocatedBlock lb1 = nameNodeRpc.addBlock(src, "clientName", null, null,
167166
HdfsConstants.GRANDFATHER_INODE_ID, null, null);
168-
assertTrue("Block locations should be present",
169-
lb1.getLocations().length > 0);
167+
assertTrue(lb1.getLocations().length > 0,
168+
"Block locations should be present");
170169

171170
cluster.restartNameNode();
172171
nameNodeRpc = cluster.getNameNodeRpc();
173172
LocatedBlock lb2 = nameNodeRpc.addBlock(src, "clientName", null, null,
174173
HdfsConstants.GRANDFATHER_INODE_ID, null, null);
175-
assertEquals("Blocks are not equal", lb1.getBlock(), lb2.getBlock());
176-
assertTrue("Wrong locations with retry", lb2.getLocations().length > 0);
174+
assertEquals(lb1.getBlock(), lb2.getBlock(), "Blocks are not equal");
175+
assertTrue(lb2.getLocations().length > 0, "Wrong locations with retry");
177176
}
178177
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddOverReplicatedStripedBlocks.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@
3434
import org.apache.hadoop.hdfs.server.datanode.DataNode;
3535
import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset;
3636
import org.apache.hadoop.hdfs.util.RwLockMode;
37-
import org.junit.After;
38-
import org.junit.Assert;
39-
import org.junit.Before;
40-
import org.junit.Ignore;
41-
import org.junit.Rule;
42-
import org.junit.Test;
43-
import org.junit.rules.Timeout;
37+
import org.junit.jupiter.api.AfterEach;
38+
import org.junit.jupiter.api.BeforeEach;
39+
import org.junit.jupiter.api.Disabled;
40+
import org.junit.jupiter.api.Test;
41+
import org.junit.jupiter.api.Timeout;
4442

4543
import java.io.IOException;
4644
import java.util.Arrays;
4745
import java.util.BitSet;
4846
import java.util.List;
4947

50-
import static org.junit.Assert.assertEquals;
51-
import static org.junit.Assert.assertTrue;
48+
import static org.junit.jupiter.api.Assertions.assertEquals;
49+
import static org.junit.jupiter.api.Assertions.assertFalse;
50+
import static org.junit.jupiter.api.Assertions.assertTrue;
5251

52+
@Timeout(300)
5353
public class TestAddOverReplicatedStripedBlocks {
5454

5555
private MiniDFSCluster cluster;
@@ -66,10 +66,7 @@ public class TestAddOverReplicatedStripedBlocks {
6666
private final int blockSize = stripesPerBlock * cellSize;
6767
private final int numDNs = groupSize + 3;
6868

69-
@Rule
70-
public Timeout globalTimeout = new Timeout(300000);
71-
72-
@Before
69+
@BeforeEach
7370
public void setup() throws IOException {
7471
Configuration conf = new Configuration();
7572
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize);
@@ -87,7 +84,7 @@ public void setup() throws IOException {
8784
ecPolicy.getName());
8885
}
8986

90-
@After
87+
@AfterEach
9188
public void tearDown() {
9289
if (cluster != null) {
9390
cluster.shutdown();
@@ -238,15 +235,15 @@ public void testProcessOverReplicatedAndCorruptStripedBlock()
238235
for (byte index : bg.getBlockIndices()) {
239236
set.set(index);
240237
}
241-
Assert.assertFalse(set.get(0));
238+
assertFalse(set.get(0));
242239
for (int i = 1; i < groupSize; i++) {
243240
assertTrue(set.get(i));
244241
}
245242
}
246243

247244
// This test is going to be rewritten in HDFS-10854. Ignoring this test
248245
// temporarily as it fails with the fix for HDFS-10301.
249-
@Ignore
246+
@Disabled
250247
@Test
251248
public void testProcessOverReplicatedAndMissingStripedBlock()
252249
throws Exception {
@@ -295,7 +292,7 @@ public void testProcessOverReplicatedAndMissingStripedBlock()
295292
for (byte index : bg.getBlockIndices()) {
296293
set.set(index);
297294
}
298-
Assert.assertFalse(set.get(groupSize - 1));
295+
assertFalse(set.get(groupSize - 1));
299296
for (int i = 0; i < groupSize - 1; i++) {
300297
assertTrue(set.get(i));
301298
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlockInFBR.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
import org.apache.hadoop.hdfs.server.datanode.DataNode;
3434
import org.apache.hadoop.test.GenericTestUtils;
3535
import org.apache.hadoop.test.Whitebox;
36-
import org.junit.After;
37-
import org.junit.Before;
38-
import org.junit.Rule;
39-
import org.junit.Test;
40-
import org.junit.rules.Timeout;
36+
import org.junit.jupiter.api.AfterEach;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.api.Timeout;
4140
import org.mockito.Mockito;
4241

4342
import java.util.function.Supplier;
4443

4544
import java.io.IOException;
4645

46+
@Timeout(300)
4747
public class TestAddStripedBlockInFBR {
4848
private final ErasureCodingPolicy ecPolicy =
4949
StripedFileTestUtil.getDefaultECPolicy();
@@ -55,10 +55,7 @@ public class TestAddStripedBlockInFBR {
5555
private MiniDFSCluster cluster;
5656
private DistributedFileSystem dfs;
5757

58-
@Rule
59-
public Timeout globalTimeout = new Timeout(300000);
60-
61-
@Before
58+
@BeforeEach
6259
public void setup() throws IOException {
6360
Configuration conf = new HdfsConfiguration();
6461
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(groupSize).build();
@@ -68,7 +65,7 @@ public void setup() throws IOException {
6865
StripedFileTestUtil.getDefaultECPolicy().getName());
6966
}
7067

71-
@After
68+
@AfterEach
7269
public void tearDown() {
7370
if (cluster != null) {
7471
cluster.shutdown();

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlocks.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,23 @@
5151
import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport;
5252
import org.apache.hadoop.hdfs.server.protocol.StorageReceivedDeletedBlocks;
5353
import org.apache.hadoop.io.IOUtils;
54-
import org.junit.After;
55-
import org.junit.Before;
56-
import org.junit.Test;
57-
import org.junit.Rule;
58-
import org.junit.rules.Timeout;
54+
import org.junit.jupiter.api.AfterEach;
55+
import org.junit.jupiter.api.BeforeEach;
56+
import org.junit.jupiter.api.Test;
57+
import org.junit.jupiter.api.Timeout;
5958

6059
import java.io.IOException;
6160
import java.util.ArrayList;
6261
import java.util.List;
6362
import java.util.UUID;
6463

6564
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_DEFAULT;
66-
import static org.junit.Assert.assertEquals;
67-
import static org.junit.Assert.assertFalse;
68-
import static org.junit.Assert.assertTrue;
69-
import static org.junit.Assert.assertArrayEquals;
65+
import static org.junit.jupiter.api.Assertions.assertEquals;
66+
import static org.junit.jupiter.api.Assertions.assertFalse;
67+
import static org.junit.jupiter.api.Assertions.assertTrue;
68+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
7069

70+
@Timeout(300)
7171
public class TestAddStripedBlocks {
7272
private final ErasureCodingPolicy ecPolicy =
7373
StripedFileTestUtil.getDefaultECPolicy();
@@ -80,10 +80,7 @@ public class TestAddStripedBlocks {
8080
private MiniDFSCluster cluster;
8181
private DistributedFileSystem dfs;
8282

83-
@Rule
84-
public Timeout globalTimeout = new Timeout(300000);
85-
86-
@Before
83+
@BeforeEach
8784
public void setup() throws IOException {
8885
HdfsConfiguration conf = new HdfsConfiguration();
8986
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(groupSize).build();
@@ -93,7 +90,7 @@ public void setup() throws IOException {
9390
dfs.getClient().setErasureCodingPolicy("/", ecPolicy.getName());
9491
}
9592

96-
@After
93+
@AfterEach
9794
public void tearDown() {
9895
if (cluster != null) {
9996
cluster.shutdown();
@@ -163,7 +160,8 @@ private static void writeAndFlushStripedOutputStream(
163160
DFSTestUtil.flushInternal(out);
164161
}
165162

166-
@Test (timeout=60000)
163+
@Test
164+
@Timeout(value = 60)
167165
public void testAddStripedBlock() throws Exception {
168166
final Path file = new Path("/file1");
169167
// create an empty file
@@ -485,17 +483,17 @@ public void testStripedFlagInBlockLocation() throws IOException {
485483
out.write("this is a replicated file".getBytes());
486484
}
487485
BlockLocation[] locations = dfs.getFileBlockLocations(replicated, 0, 100);
488-
assertEquals("There should be exactly one Block present",
489-
1, locations.length);
490-
assertFalse("The file is Striped", locations[0].isStriped());
486+
assertEquals(1, locations.length,
487+
"There should be exactly one Block present");
488+
assertFalse(locations[0].isStriped(), "The file is Striped");
491489

492490
Path striped = new Path("/blockLocation/striped");
493491
try (FSDataOutputStream out = dfs.createFile(striped).recursive().build()) {
494492
out.write("this is a striped file".getBytes());
495493
}
496494
locations = dfs.getFileBlockLocations(striped, 0, 100);
497-
assertEquals("There should be exactly one Block present",
498-
1, locations.length);
499-
assertTrue("The file is not Striped", locations[0].isStriped());
495+
assertEquals(1, locations.length,
496+
"There should be exactly one Block present");
497+
assertTrue(locations[0].isStriped(), "The file is not Striped");
500498
}
501499
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogAtDebug.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.hadoop.hdfs.server.namenode;
2020

2121
import org.apache.hadoop.thirdparty.com.google.common.base.Joiner;
22+
import org.junit.jupiter.api.Timeout;
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425
import org.apache.hadoop.conf.Configuration;
@@ -27,9 +28,7 @@
2728
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem.FSNamesystemAuditLogger;
2829
import org.apache.hadoop.test.GenericTestUtils;
2930

30-
import org.junit.Rule;
31-
import org.junit.Test;
32-
import org.junit.rules.Timeout;
31+
import org.junit.jupiter.api.Test;
3332
import org.slf4j.event.Level;
3433

3534
import java.net.Inet4Address;
@@ -44,11 +43,9 @@
4443
/**
4544
* Test that the HDFS Audit logger respects DFS_NAMENODE_AUDIT_LOG_DEBUG_CMDLIST.
4645
*/
46+
@Timeout(300)
4747
public class TestAuditLogAtDebug {
4848
static final Logger LOG = LoggerFactory.getLogger(TestAuditLogAtDebug.class);
49-
50-
@Rule
51-
public Timeout timeout = new Timeout(300000);
5249

5350
private static final String DUMMY_COMMAND_1 = "dummycommand1";
5451
private static final String DUMMY_COMMAND_2 = "dummycommand2";

0 commit comments

Comments
 (0)