17
17
*/
18
18
package org .apache .hadoop .hdfs .server .datanode ;
19
19
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 ;
24
25
import static org .mockito .ArgumentMatchers .any ;
25
26
import static org .mockito .ArgumentMatchers .anyString ;
26
27
69
70
import org .apache .hadoop .test .GenericTestUtils ;
70
71
import org .apache .hadoop .test .GenericTestUtils .DelayAnswer ;
71
72
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 ;
76
77
import org .mockito .Mockito ;
77
78
import org .mockito .invocation .InvocationOnMock ;
78
79
import org .slf4j .event .Level ;
@@ -112,14 +113,14 @@ public abstract class BlockReportTestBase {
112
113
resetConfiguration ();
113
114
}
114
115
115
- @ Before
116
+ @ BeforeEach
116
117
public void startUpCluster () throws IOException {
117
118
REPL_FACTOR = 1 ; //Reset if case a test has modified the value
118
119
cluster = new MiniDFSCluster .Builder (conf ).numDataNodes (REPL_FACTOR ).build ();
119
120
fs = cluster .getFileSystem ();
120
121
}
121
122
122
- @ After
123
+ @ AfterEach
123
124
public void shutDownCluster () throws IOException {
124
125
if (fs != null ) {
125
126
fs .close ();
@@ -209,7 +210,8 @@ protected abstract void sendBlockReports(DatanodeRegistration dnR, String poolId
209
210
*
210
211
* @throws java.io.IOException on an error
211
212
*/
212
- @ Test (timeout =300000 )
213
+ @ Test
214
+ @ Timeout (value = 300 )
213
215
public void blockReport_01 () throws IOException {
214
216
final String METHOD_NAME = GenericTestUtils .getMethodName ();
215
217
Path filePath = new Path ("/" + METHOD_NAME + ".dat" );
@@ -255,8 +257,7 @@ public void blockReport_01() throws IOException {
255
257
256
258
for (int i = 0 ; i < blocksAfterReport .size (); i ++) {
257
259
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" );
260
261
}
261
262
}
262
263
@@ -269,7 +270,8 @@ public void blockReport_01() throws IOException {
269
270
*
270
271
* @throws IOException in case of errors
271
272
*/
272
- @ Test (timeout =300000 )
273
+ @ Test
274
+ @ Timeout (value = 300 )
273
275
public void blockReport_02 () throws IOException {
274
276
final String METHOD_NAME = GenericTestUtils .getMethodName ();
275
277
LOG .info ("Running test " + METHOD_NAME );
@@ -332,10 +334,10 @@ public void blockReport_02() throws IOException {
332
334
333
335
printStats ();
334
336
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" );
339
341
}
340
342
341
343
@@ -346,7 +348,8 @@ public void blockReport_02() throws IOException {
346
348
*
347
349
* @throws IOException in case of an error
348
350
*/
349
- @ Test (timeout =300000 )
351
+ @ Test
352
+ @ Timeout (value = 300 )
350
353
public void blockReport_03 () throws IOException {
351
354
final String METHOD_NAME = GenericTestUtils .getMethodName ();
352
355
Path filePath = new Path ("/" + METHOD_NAME + ".dat" );
@@ -360,10 +363,12 @@ public void blockReport_03() throws IOException {
360
363
sendBlockReports (dnR , poolId , reports );
361
364
printStats ();
362
365
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 );
367
372
}
368
373
369
374
/**
@@ -374,7 +379,8 @@ public void blockReport_03() throws IOException {
374
379
*
375
380
* @throws IOException in case of an error
376
381
*/
377
- @ Test (timeout =300000 )
382
+ @ Test
383
+ @ Timeout (value = 300 )
378
384
public void blockReport_04 () throws IOException {
379
385
final String METHOD_NAME = GenericTestUtils .getMethodName ();
380
386
Path filePath = new Path ("/" + METHOD_NAME + ".dat" );
@@ -396,10 +402,12 @@ public void blockReport_04() throws IOException {
396
402
sendBlockReports (dnR , poolId , reports );
397
403
printStats ();
398
404
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 );
403
411
}
404
412
405
413
/**
@@ -410,7 +418,8 @@ public void blockReport_04() throws IOException {
410
418
*
411
419
* @throws IOException in case of an error
412
420
*/
413
- @ Test (timeout =300000 )
421
+ @ Test
422
+ @ Timeout (value = 300 )
414
423
public void blockReport_06 () throws Exception {
415
424
final String METHOD_NAME = GenericTestUtils .getMethodName ();
416
425
Path filePath = new Path ("/" + METHOD_NAME + ".dat" );
@@ -426,8 +435,8 @@ public void blockReport_06() throws Exception {
426
435
StorageBlockReport [] reports = getBlockReports (dn , poolId , false , false );
427
436
sendBlockReports (dnR , poolId , reports );
428
437
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" );
431
440
}
432
441
433
442
/**
@@ -444,7 +453,8 @@ public void blockReport_06() throws Exception {
444
453
*
445
454
* @throws IOException in case of an error
446
455
*/
447
- @ Test (timeout =300000 )
456
+ @ Test
457
+ @ Timeout (value = 300 )
448
458
public void blockReport_07 () throws Exception {
449
459
final String METHOD_NAME = GenericTestUtils .getMethodName ();
450
460
Path filePath = new Path ("/" + METHOD_NAME + ".dat" );
@@ -462,23 +472,29 @@ public void blockReport_07() throws Exception {
462
472
sendBlockReports (dnR , poolId , reports );
463
473
printStats ();
464
474
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 );
471
484
472
485
reports = getBlockReports (dn , poolId , false , true );
473
486
sendBlockReports (dnR , poolId , reports );
474
487
printStats ();
475
488
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 );
482
498
483
499
printStats ();
484
500
@@ -496,7 +512,8 @@ public void blockReport_07() throws Exception {
496
512
*
497
513
* @throws IOException in case of an error
498
514
*/
499
- @ Test (timeout =300000 )
515
+ @ Test
516
+ @ Timeout (value = 300 )
500
517
public void blockReport_08 () throws IOException {
501
518
final String METHOD_NAME = GenericTestUtils .getMethodName ();
502
519
Path filePath = new Path ("/" + METHOD_NAME + ".dat" );
@@ -524,8 +541,8 @@ public void blockReport_08() throws IOException {
524
541
StorageBlockReport [] reports = getBlockReports (dn , poolId , false , false );
525
542
sendBlockReports (dnR , poolId , reports );
526
543
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" );
529
546
530
547
try {
531
548
bc .join ();
@@ -538,7 +555,8 @@ public void blockReport_08() throws IOException {
538
555
// Similar to BlockReport_08 but corrupts GS and len of the TEMPORARY's
539
556
// replica block. Expect the same behaviour: NN should simply ignore this
540
557
// block
541
- @ Test (timeout =300000 )
558
+ @ Test
559
+ @ Timeout (value = 300 )
542
560
public void blockReport_09 () throws IOException {
543
561
final String METHOD_NAME = GenericTestUtils .getMethodName ();
544
562
Path filePath = new Path ("/" + METHOD_NAME + ".dat" );
@@ -567,8 +585,8 @@ public void blockReport_09() throws IOException {
567
585
StorageBlockReport [] reports = getBlockReports (dn , poolId , true , true );
568
586
sendBlockReports (dnR , poolId , reports );
569
587
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" );
572
590
573
591
try {
574
592
bc .join ();
@@ -587,7 +605,8 @@ public void blockReport_09() throws IOException {
587
605
* corrupt.
588
606
* This is a regression test for HDFS-2791.
589
607
*/
590
- @ Test (timeout =300000 )
608
+ @ Test
609
+ @ Timeout (value = 300 )
591
610
public void testOneReplicaRbwReportArrivesAfterBlockCompleted () throws Exception {
592
611
final CountDownLatch brFinished = new CountDownLatch (1 );
593
612
DelayAnswer delayer = new GenericTestUtils .DelayAnswer (LOG ) {
@@ -658,7 +677,8 @@ protected Object passThrough(InvocationOnMock invocation)
658
677
}
659
678
660
679
// See HDFS-10301
661
- @ Test (timeout = 300000 )
680
+ @ Test
681
+ @ Timeout (value = 300 )
662
682
public void testInterleavedBlockReports ()
663
683
throws IOException , ExecutionException , InterruptedException {
664
684
int numConcurrentBlockReports = 3 ;
@@ -696,7 +716,7 @@ public Void call() throws IOException {
696
716
executorService .shutdown ();
697
717
698
718
// Verify that the storages match before and after the test
699
- Assert . assertArrayEquals (storageInfos , dnDescriptor .getStorageInfos ());
719
+ assertArrayEquals (storageInfos , dnDescriptor .getStorageInfos ());
700
720
}
701
721
702
722
private void waitForTempReplica (Block bl , int DN_N1 ) throws IOException {
@@ -729,8 +749,7 @@ private void waitForTempReplica(Block bl, int DN_N1) throws IOException {
729
749
LOG .debug ("Has been waiting for " + waiting_period + " ms." );
730
750
}
731
751
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" );
734
753
}
735
754
736
755
HdfsServerConstants .ReplicaState state = r .getState ();
@@ -746,8 +765,7 @@ private void waitForTempReplica(Block bl, int DN_N1) throws IOException {
746
765
" is in state " + state .getValue ());
747
766
}
748
767
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" );
751
769
}
752
770
if (LOG .isDebugEnabled ()) {
753
771
LOG .debug ("Replica state after the loop " + state .getValue ());
@@ -910,7 +928,7 @@ public void run() {
910
928
startDNandWait (filePath , true );
911
929
} catch (Exception e ) {
912
930
e .printStackTrace ();
913
- Assert . fail ("Failed to start BlockChecker: " + e );
931
+ fail ("Failed to start BlockChecker: " + e );
914
932
}
915
933
}
916
934
}
0 commit comments