Skip to content

Commit 9d10cc2

Browse files
zhtttylzcnauroth
authored andcommitted
HDFS-12431. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-hdfs Part10.
Closes #7841 Signed-off-by: Shilun Fan <[email protected]> Signed-off-by: Chris Nauroth <[email protected]>
1 parent 74bb044 commit 9d10cc2

File tree

67 files changed

+1397
-1366
lines changed

Some content is hidden

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

67 files changed

+1397
-1366
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/BlockReportTestBase.java

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.datanode;
1919

20-
import static org.hamcrest.core.Is.is;
21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertThat;
23-
import static org.junit.Assert.assertTrue;
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
2425
import static org.mockito.ArgumentMatchers.any;
2526
import static org.mockito.ArgumentMatchers.anyString;
2627

@@ -69,10 +70,10 @@
6970
import org.apache.hadoop.test.GenericTestUtils;
7071
import org.apache.hadoop.test.GenericTestUtils.DelayAnswer;
7172
import org.apache.hadoop.util.Time;
72-
import org.junit.After;
73-
import org.junit.Assert;
74-
import org.junit.Before;
75-
import org.junit.Test;
73+
import org.junit.jupiter.api.AfterEach;
74+
import org.junit.jupiter.api.BeforeEach;
75+
import org.junit.jupiter.api.Test;
76+
import org.junit.jupiter.api.Timeout;
7677
import org.mockito.Mockito;
7778
import org.mockito.invocation.InvocationOnMock;
7879
import org.slf4j.event.Level;
@@ -112,14 +113,14 @@ public abstract class BlockReportTestBase {
112113
resetConfiguration();
113114
}
114115

115-
@Before
116+
@BeforeEach
116117
public void startUpCluster() throws IOException {
117118
REPL_FACTOR = 1; //Reset if case a test has modified the value
118119
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(REPL_FACTOR).build();
119120
fs = cluster.getFileSystem();
120121
}
121122

122-
@After
123+
@AfterEach
123124
public void shutDownCluster() throws IOException {
124125
if (fs != null) {
125126
fs.close();
@@ -209,7 +210,8 @@ protected abstract void sendBlockReports(DatanodeRegistration dnR, String poolId
209210
*
210211
* @throws java.io.IOException on an error
211212
*/
212-
@Test(timeout=300000)
213+
@Test
214+
@Timeout(value = 300)
213215
public void blockReport_01() throws IOException {
214216
final String METHOD_NAME = GenericTestUtils.getMethodName();
215217
Path filePath = new Path("/" + METHOD_NAME + ".dat");
@@ -255,8 +257,7 @@ public void blockReport_01() throws IOException {
255257

256258
for (int i = 0; i < blocksAfterReport.size(); i++) {
257259
ExtendedBlock b = blocksAfterReport.get(i).getBlock();
258-
assertEquals("Length of " + i + "th block is incorrect",
259-
oldLengths[i], b.getNumBytes());
260+
assertEquals(oldLengths[i], b.getNumBytes(), "Length of " + i + "th block is incorrect");
260261
}
261262
}
262263

@@ -269,7 +270,8 @@ public void blockReport_01() throws IOException {
269270
*
270271
* @throws IOException in case of errors
271272
*/
272-
@Test(timeout=300000)
273+
@Test
274+
@Timeout(value = 300)
273275
public void blockReport_02() throws IOException {
274276
final String METHOD_NAME = GenericTestUtils.getMethodName();
275277
LOG.info("Running test " + METHOD_NAME);
@@ -332,10 +334,10 @@ public void blockReport_02() throws IOException {
332334

333335
printStats();
334336

335-
assertEquals("Wrong number of MissingBlocks is found",
336-
blocks2Remove.size(), cluster.getNamesystem().getMissingBlocksCount());
337-
assertEquals("Wrong number of UnderReplicatedBlocks is found",
338-
blocks2Remove.size(), cluster.getNamesystem().getUnderReplicatedBlocks());
337+
assertEquals(blocks2Remove.size(), cluster.getNamesystem().getMissingBlocksCount(),
338+
"Wrong number of MissingBlocks is found");
339+
assertEquals(blocks2Remove.size(), cluster.getNamesystem().getUnderReplicatedBlocks(),
340+
"Wrong number of UnderReplicatedBlocks is found");
339341
}
340342

341343

@@ -346,7 +348,8 @@ public void blockReport_02() throws IOException {
346348
*
347349
* @throws IOException in case of an error
348350
*/
349-
@Test(timeout=300000)
351+
@Test
352+
@Timeout(value = 300)
350353
public void blockReport_03() throws IOException {
351354
final String METHOD_NAME = GenericTestUtils.getMethodName();
352355
Path filePath = new Path("/" + METHOD_NAME + ".dat");
@@ -360,10 +363,12 @@ public void blockReport_03() throws IOException {
360363
sendBlockReports(dnR, poolId, reports);
361364
printStats();
362365

363-
assertThat("Wrong number of corrupt blocks",
364-
cluster.getNamesystem().getCorruptReplicaBlocks(), is(1L));
365-
assertThat("Wrong number of PendingDeletion blocks",
366-
cluster.getNamesystem().getPendingDeletionBlocks(), is(0L));
366+
assertThat(cluster.getNamesystem().getCorruptReplicaBlocks())
367+
.as("Wrong number of corrupt blocks")
368+
.isEqualTo((1L));
369+
assertThat(cluster.getNamesystem().getPendingDeletionBlocks())
370+
.as("Wrong number of PendingDeletion blocks")
371+
.isEqualTo(0L);
367372
}
368373

369374
/**
@@ -374,7 +379,8 @@ public void blockReport_03() throws IOException {
374379
*
375380
* @throws IOException in case of an error
376381
*/
377-
@Test(timeout=300000)
382+
@Test
383+
@Timeout(value = 300)
378384
public void blockReport_04() throws IOException {
379385
final String METHOD_NAME = GenericTestUtils.getMethodName();
380386
Path filePath = new Path("/" + METHOD_NAME + ".dat");
@@ -396,10 +402,12 @@ public void blockReport_04() throws IOException {
396402
sendBlockReports(dnR, poolId, reports);
397403
printStats();
398404

399-
assertThat("Wrong number of corrupt blocks",
400-
cluster.getNamesystem().getCorruptReplicaBlocks(), is(0L));
401-
assertThat("Wrong number of PendingDeletion blocks",
402-
cluster.getNamesystem().getPendingDeletionBlocks(), is(1L));
405+
assertThat(cluster.getNamesystem().getCorruptReplicaBlocks())
406+
.as("Wrong number of corrupt blocks")
407+
.isEqualTo(0L);
408+
assertThat(cluster.getNamesystem().getPendingDeletionBlocks())
409+
.as("Wrong number of PendingDeletion blocks")
410+
.isEqualTo(1L);
403411
}
404412

405413
/**
@@ -410,7 +418,8 @@ public void blockReport_04() throws IOException {
410418
*
411419
* @throws IOException in case of an error
412420
*/
413-
@Test(timeout=300000)
421+
@Test
422+
@Timeout(value = 300)
414423
public void blockReport_06() throws Exception {
415424
final String METHOD_NAME = GenericTestUtils.getMethodName();
416425
Path filePath = new Path("/" + METHOD_NAME + ".dat");
@@ -426,8 +435,8 @@ public void blockReport_06() throws Exception {
426435
StorageBlockReport[] reports = getBlockReports(dn, poolId, false, false);
427436
sendBlockReports(dnR, poolId, reports);
428437
printStats();
429-
assertEquals("Wrong number of PendingReplication Blocks",
430-
0, cluster.getNamesystem().getUnderReplicatedBlocks());
438+
assertEquals(0, cluster.getNamesystem().getUnderReplicatedBlocks(),
439+
"Wrong number of PendingReplication Blocks");
431440
}
432441

433442
/**
@@ -444,7 +453,8 @@ public void blockReport_06() throws Exception {
444453
*
445454
* @throws IOException in case of an error
446455
*/
447-
@Test(timeout=300000)
456+
@Test
457+
@Timeout(value = 300)
448458
public void blockReport_07() throws Exception {
449459
final String METHOD_NAME = GenericTestUtils.getMethodName();
450460
Path filePath = new Path("/" + METHOD_NAME + ".dat");
@@ -462,23 +472,29 @@ public void blockReport_07() throws Exception {
462472
sendBlockReports(dnR, poolId, reports);
463473
printStats();
464474

465-
assertThat("Wrong number of corrupt blocks",
466-
cluster.getNamesystem().getCorruptReplicaBlocks(), is(0L));
467-
assertThat("Wrong number of PendingDeletion blocks",
468-
cluster.getNamesystem().getPendingDeletionBlocks(), is(1L));
469-
assertThat("Wrong number of PendingReplication blocks",
470-
cluster.getNamesystem().getPendingReplicationBlocks(), is(0L));
475+
assertThat(cluster.getNamesystem().getCorruptReplicaBlocks())
476+
.as("Wrong number of corrupt blocks")
477+
.isEqualTo(0L);
478+
assertThat(cluster.getNamesystem().getPendingDeletionBlocks())
479+
.as("Wrong number of PendingDeletion blocks")
480+
.isEqualTo(1L);
481+
assertThat(cluster.getNamesystem().getPendingReplicationBlocks())
482+
.as("Wrong number of PendingReplication blocks")
483+
.isEqualTo(0L);
471484

472485
reports = getBlockReports(dn, poolId, false, true);
473486
sendBlockReports(dnR, poolId, reports);
474487
printStats();
475488

476-
assertThat("Wrong number of corrupt blocks",
477-
cluster.getNamesystem().getCorruptReplicaBlocks(), is(1L));
478-
assertThat("Wrong number of PendingDeletion blocks",
479-
cluster.getNamesystem().getPendingDeletionBlocks(), is(1L));
480-
assertThat("Wrong number of PendingReplication blocks",
481-
cluster.getNamesystem().getPendingReplicationBlocks(), is(0L));
489+
assertThat(cluster.getNamesystem().getCorruptReplicaBlocks())
490+
.as("Wrong number of corrupt blocks")
491+
.isEqualTo(1L);
492+
assertThat(cluster.getNamesystem().getPendingDeletionBlocks())
493+
.as("Wrong number of PendingDeletion blocks")
494+
.isEqualTo(1L);
495+
assertThat(cluster.getNamesystem().getPendingReplicationBlocks())
496+
.as("Wrong number of PendingReplication blocks")
497+
.isEqualTo(0L);
482498

483499
printStats();
484500

@@ -496,7 +512,8 @@ public void blockReport_07() throws Exception {
496512
*
497513
* @throws IOException in case of an error
498514
*/
499-
@Test(timeout=300000)
515+
@Test
516+
@Timeout(value = 300)
500517
public void blockReport_08() throws IOException {
501518
final String METHOD_NAME = GenericTestUtils.getMethodName();
502519
Path filePath = new Path("/" + METHOD_NAME + ".dat");
@@ -524,8 +541,8 @@ public void blockReport_08() throws IOException {
524541
StorageBlockReport[] reports = getBlockReports(dn, poolId, false, false);
525542
sendBlockReports(dnR, poolId, reports);
526543
printStats();
527-
assertEquals("Wrong number of PendingReplication blocks",
528-
blocks.size(), cluster.getNamesystem().getPendingReplicationBlocks());
544+
assertEquals(blocks.size(), cluster.getNamesystem().getPendingReplicationBlocks(),
545+
"Wrong number of PendingReplication blocks");
529546

530547
try {
531548
bc.join();
@@ -538,7 +555,8 @@ public void blockReport_08() throws IOException {
538555
// Similar to BlockReport_08 but corrupts GS and len of the TEMPORARY's
539556
// replica block. Expect the same behaviour: NN should simply ignore this
540557
// block
541-
@Test(timeout=300000)
558+
@Test
559+
@Timeout(value = 300)
542560
public void blockReport_09() throws IOException {
543561
final String METHOD_NAME = GenericTestUtils.getMethodName();
544562
Path filePath = new Path("/" + METHOD_NAME + ".dat");
@@ -567,8 +585,8 @@ public void blockReport_09() throws IOException {
567585
StorageBlockReport[] reports = getBlockReports(dn, poolId, true, true);
568586
sendBlockReports(dnR, poolId, reports);
569587
printStats();
570-
assertEquals("Wrong number of PendingReplication blocks",
571-
2, cluster.getNamesystem().getPendingReplicationBlocks());
588+
assertEquals(2, cluster.getNamesystem().getPendingReplicationBlocks(),
589+
"Wrong number of PendingReplication blocks");
572590

573591
try {
574592
bc.join();
@@ -587,7 +605,8 @@ public void blockReport_09() throws IOException {
587605
* corrupt.
588606
* This is a regression test for HDFS-2791.
589607
*/
590-
@Test(timeout=300000)
608+
@Test
609+
@Timeout(value = 300)
591610
public void testOneReplicaRbwReportArrivesAfterBlockCompleted() throws Exception {
592611
final CountDownLatch brFinished = new CountDownLatch(1);
593612
DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG) {
@@ -658,7 +677,8 @@ protected Object passThrough(InvocationOnMock invocation)
658677
}
659678

660679
// See HDFS-10301
661-
@Test(timeout = 300000)
680+
@Test
681+
@Timeout(value = 300)
662682
public void testInterleavedBlockReports()
663683
throws IOException, ExecutionException, InterruptedException {
664684
int numConcurrentBlockReports = 3;
@@ -696,7 +716,7 @@ public Void call() throws IOException {
696716
executorService.shutdown();
697717

698718
// Verify that the storages match before and after the test
699-
Assert.assertArrayEquals(storageInfos, dnDescriptor.getStorageInfos());
719+
assertArrayEquals(storageInfos, dnDescriptor.getStorageInfos());
700720
}
701721

702722
private void waitForTempReplica(Block bl, int DN_N1) throws IOException {
@@ -729,8 +749,7 @@ private void waitForTempReplica(Block bl, int DN_N1) throws IOException {
729749
LOG.debug("Has been waiting for " + waiting_period + " ms.");
730750
}
731751
if (waiting_period > TIMEOUT)
732-
assertTrue("Was waiting too long to get ReplicaInfo from a datanode",
733-
tooLongWait);
752+
assertTrue(tooLongWait, "Was waiting too long to get ReplicaInfo from a datanode");
734753
}
735754

736755
HdfsServerConstants.ReplicaState state = r.getState();
@@ -746,8 +765,7 @@ private void waitForTempReplica(Block bl, int DN_N1) throws IOException {
746765
" is in state " + state.getValue());
747766
}
748767
if (Time.monotonicNow() - start > TIMEOUT)
749-
assertTrue("Was waiting too long for a replica to become TEMPORARY",
750-
tooLongWait);
768+
assertTrue(tooLongWait, "Was waiting too long for a replica to become TEMPORARY");
751769
}
752770
if(LOG.isDebugEnabled()) {
753771
LOG.debug("Replica state after the loop " + state.getValue());
@@ -910,7 +928,7 @@ public void run() {
910928
startDNandWait(filePath, true);
911929
} catch (Exception e) {
912930
e.printStackTrace();
913-
Assert.fail("Failed to start BlockChecker: " + e);
931+
fail("Failed to start BlockChecker: " + e);
914932
}
915933
}
916934
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/DataNodeTestUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939

4040
import java.util.function.Supplier;
4141

42-
import static org.hamcrest.core.Is.is;
43-
import static org.junit.Assert.assertThat;
42+
import static org.junit.jupiter.api.Assertions.assertEquals;
4443

4544
/**
4645
* DO NOT ADD MOCKITO IMPORTS HERE Or Downstream projects may not
@@ -220,11 +219,12 @@ public static void reconfigureDataNode(DataNode dn, File... newVols)
220219
dnNewDataDirs.append(newVol.getAbsolutePath());
221220
}
222221
try {
223-
assertThat(
222+
assertEquals(
224223
dn.reconfigurePropertyImpl(
225224
DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY,
226225
dnNewDataDirs.toString()),
227-
is(dn.getConf().get(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY)));
226+
dn.getConf().get(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY)
227+
);
228228
} catch (ReconfigurationException e) {
229229
// This can be thrown if reconfiguration tries to use a failed volume.
230230
// We need to swallow the exception, because some of our tests want to

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/InternalDataNodeTestUtils.java

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

1919
package org.apache.hadoop.hdfs.server.datanode;
2020

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
2122
import static org.mockito.Mockito.mock;
2223
import static org.mockito.Mockito.when;
2324

@@ -41,7 +42,6 @@
4142
import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse;
4243
import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat;
4344
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
44-
import org.junit.Assert;
4545
import org.mockito.Mockito;
4646
import org.mockito.invocation.InvocationOnMock;
4747
import org.mockito.stubbing.Answer;
@@ -172,8 +172,8 @@ public DatanodeRegistration answer(InvocationOnMock invocation)
172172
@Override
173173
DatanodeProtocolClientSideTranslatorPB connectToNN(
174174
InetSocketAddress nnAddr) throws IOException {
175-
Assert.assertEquals(nnSocketAddr, nnAddr);
176-
return namenode;
175+
assertEquals(nnSocketAddr, nnAddr);
176+
return namenode;
177177
}
178178
};
179179
// Trigger a heartbeat so that it acknowledges the NN as active.

0 commit comments

Comments
 (0)