3030import static org .apache .hadoop .test .MetricsAsserts .assertCounter ;
3131import static org .apache .hadoop .test .MetricsAsserts .getLongCounter ;
3232import static org .apache .hadoop .test .MetricsAsserts .getMetrics ;
33- import static org .junit .Assert .assertEquals ;
34- import static org .junit .Assert .assertFalse ;
35- import static org .junit .Assert .assertNull ;
36- import static org .junit .Assert .assertNotNull ;
37- import static org .junit .Assert .assertSame ;
38- import static org .junit .Assert .assertTrue ;
39- import static org .junit .Assert .fail ;
33+ import static org .junit .jupiter . api . Assertions .assertEquals ;
34+ import static org .junit .jupiter . api . Assertions .assertFalse ;
35+ import static org .junit .jupiter . api . Assertions .assertNull ;
36+ import static org .junit .jupiter . api . Assertions .assertNotNull ;
37+ import static org .junit .jupiter . api . Assertions .assertSame ;
38+ import static org .junit .jupiter . api . Assertions .assertTrue ;
39+ import static org .junit .jupiter . api . Assertions .fail ;
4040
4141import java .io .File ;
4242import java .io .IOException ;
8787import org .apache .hadoop .test .PathUtils ;
8888import org .apache .hadoop .util .Lists ;
8989import org .apache .hadoop .util .Time ;
90- import org .junit .Before ;
91- import org .junit .After ;
92- import org .junit .Rule ;
93- import org .junit .Test ;
94- import org .junit .rules . TemporaryFolder ;
90+ import org .junit .jupiter . api . BeforeEach ;
91+ import org .junit .jupiter . api . AfterEach ;
92+ import org .junit .jupiter . api . Test ;
93+ import org .junit .jupiter . api . Timeout ;
94+ import org .junit .jupiter . api . io . TempDir ;
9595import org .mockito .ArgumentCaptor ;
9696import org .mockito .Mockito ;
9797import org .mockito .invocation .InvocationOnMock ;
@@ -122,8 +122,9 @@ public class TestBPOfferService {
122122 GenericTestUtils .setLogLevel (DataNode .LOG , Level .TRACE );
123123 }
124124
125- @ Rule
126- public TemporaryFolder baseDir = new TemporaryFolder ();
125+ @ SuppressWarnings ("checkstyle:VisibilityModifier" )
126+ @ TempDir
127+ java .nio .file .Path baseDir ;
127128
128129 private DatanodeProtocolClientSideTranslatorPB mockNN1 ;
129130 private DatanodeProtocolClientSideTranslatorPB mockNN2 ;
@@ -138,7 +139,7 @@ public class TestBPOfferService {
138139 private boolean isSlownode ;
139140 private String mockStorageID ;
140141
141- @ Before
142+ @ BeforeEach
142143 public void setupMocks () throws Exception {
143144 mockNN1 = setupNNMock (0 );
144145 mockNN2 = setupNNMock (1 );
@@ -166,7 +167,7 @@ public void setupMocks() throws Exception {
166167 Mockito .doReturn (dataSetLockManager ).when (mockDn ).getDataSetLockManager ();
167168 }
168169
169- @ After
170+ @ AfterEach
170171 public void checkDataSetLockManager () {
171172 dataSetLockManager .lockLeakCheck ();
172173 // make sure no lock Leak.
@@ -831,9 +832,8 @@ public void testReportBadBlockWhenStandbyNNTimesOut() throws Exception {
831832 .getStorageType ());
832833 Thread .sleep (10000 );
833834 long difference = secondCallTime - firstCallTime ;
834- assertTrue ("Active namenode reportBadBlock processing should be "
835- + "independent of standby namenode reportBadBlock processing " ,
836- difference < 5000 );
835+ assertTrue (difference < 5000 , "Active namenode reportBadBlock processing should be "
836+ + "independent of standby namenode reportBadBlock processing " );
837837 } finally {
838838 bpos .stop ();
839839 bpos .join ();
@@ -871,9 +871,9 @@ public void testTrySendErrorReportWhenStandbyNNTimesOut() throws Exception {
871871 bpos .trySendErrorReport (DatanodeProtocol .INVALID_BLOCK , errorString );
872872 Thread .sleep (10000 );
873873 long difference = secondCallTime - firstCallTime ;
874- assertTrue ("Active namenode trySendErrorReport processing "
874+ assertTrue (difference < 5000 , "Active namenode trySendErrorReport processing "
875875 + "should be independent of standby namenode trySendErrorReport"
876- + " processing " , difference < 5000 );
876+ + " processing " );
877877 } finally {
878878 bpos .stop ();
879879 bpos .join ();
@@ -911,8 +911,8 @@ public void testTrySendErrorReportWhenNNThrowsIOException()
911911 String errorString = "Can't send invalid block " + FAKE_BLOCK ;
912912 bpos .trySendErrorReport (DatanodeProtocol .INVALID_BLOCK , errorString );
913913 GenericTestUtils .waitFor (() -> secondCallTime != 0 , 100 , 20000 );
914- assertTrue ("Active namenode didn't add the report back to the queue "
915- + "when errorReport threw IOException" , secondCallTime != 0 );
914+ assertTrue (secondCallTime != 0 , "Active namenode didn't add the report back to the queue "
915+ + "when errorReport threw IOException" );
916916 } finally {
917917 bpos .stop ();
918918 bpos .join ();
@@ -1025,9 +1025,7 @@ public Boolean get() {
10251025 // Send register command back to Datanode to reRegister().
10261026 // After reRegister IBRs should be cleared.
10271027 datanodeCommands [1 ] = new DatanodeCommand [] { new RegisterCommand () };
1028- assertEquals (
1029- "IBR size before reRegister should be non-0" , 1 , getStandbyIBRSize (
1030- bpos ));
1028+ assertEquals (1 , getStandbyIBRSize (bpos ), "IBR size before reRegister should be non-0" );
10311029 bpos .triggerHeartbeatForTests ();
10321030 GenericTestUtils .waitFor (new Supplier <Boolean >() {
10331031 @ Override
@@ -1082,7 +1080,8 @@ public void testNNHAStateUpdateFromVersionRequest() throws Exception {
10821080
10831081 }
10841082
1085- @ Test (timeout = 30000 )
1083+ @ Test
1084+ @ Timeout (value = 30 )
10861085 public void testRefreshNameNodes () throws Exception {
10871086
10881087 BPOfferService bpos = setupBPOSForNNs (mockDn , mockNN1 , mockNN2 );
@@ -1156,7 +1155,8 @@ public void testRefreshNameNodes() throws Exception {
11561155 }
11571156 }
11581157
1159- @ Test (timeout = 15000 )
1158+ @ Test
1159+ @ Timeout (value = 15 )
11601160 public void testRefreshLeaseId () throws Exception {
11611161 Mockito .when (mockNN1 .sendHeartbeat (
11621162 Mockito .any (DatanodeRegistration .class ),
@@ -1221,7 +1221,8 @@ public Object answer(InvocationOnMock invocation)
12211221 }
12221222 }
12231223
1224- @ Test (timeout = 15000 )
1224+ @ Test
1225+ @ Timeout (value = 15 )
12251226 public void testSetIsSlownode () throws Exception {
12261227 assertEquals (mockDn .isSlownode (), false );
12271228 Mockito .when (mockNN1 .sendHeartbeat (
@@ -1259,10 +1260,11 @@ public void testSetIsSlownode() throws Exception {
12591260 }
12601261 }
12611262
1262- @ Test (timeout = 15000 )
1263+ @ Test
1264+ @ Timeout (value = 15 )
12631265 public void testCommandProcessingThread () throws Exception {
12641266 Configuration conf = new HdfsConfiguration ();
1265- try (MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf , baseDir .getRoot ()).build ()) {
1267+ try (MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf , baseDir .toFile ()).build ()) {
12661268 List <DataNode > datanodes = cluster .getDataNodes ();
12671269 assertEquals (datanodes .size (), 1 );
12681270 DataNode datanode = datanodes .get (0 );
@@ -1273,19 +1275,20 @@ public void testCommandProcessingThread() throws Exception {
12731275 DFSTestUtil .createFile (fs , file , 10240L , (short )1 , 0L );
12741276
12751277 MetricsRecordBuilder mrb = getMetrics (datanode .getMetrics ().name ());
1276- assertTrue ("Process command nums is not expected." ,
1277- getLongCounter ( "NumProcessedCommands" , mrb ) > 0 );
1278+ assertTrue (getLongCounter ( "NumProcessedCommands" , mrb ) > 0 ,
1279+ "Process command nums is not expected." );
12781280 assertEquals (0 , getLongCounter ("SumOfActorCommandQueueLength" , mrb ));
12791281 // Check new metric result about processedCommandsOp.
12801282 // One command send back to DataNode here is #FinalizeCommand.
12811283 assertCounter ("ProcessedCommandsOpNumOps" , 1L , mrb );
12821284 }
12831285 }
12841286
1285- @ Test (timeout = 5000 )
1287+ @ Test
1288+ @ Timeout (value = 5 )
12861289 public void testCommandProcessingThreadExit () throws Exception {
12871290 Configuration conf = new HdfsConfiguration ();
1288- try (MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf , baseDir .getRoot ()).
1291+ try (MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf , baseDir .toFile ()).
12891292 numDataNodes (1 ).build ()) {
12901293 List <DataNode > datanodes = cluster .getDataNodes ();
12911294 DataNode dataNode = datanodes .get (0 );
0 commit comments