30
30
import static org .apache .hadoop .test .MetricsAsserts .assertCounter ;
31
31
import static org .apache .hadoop .test .MetricsAsserts .getLongCounter ;
32
32
import 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 ;
40
40
41
41
import java .io .File ;
42
42
import java .io .IOException ;
87
87
import org .apache .hadoop .test .PathUtils ;
88
88
import org .apache .hadoop .util .Lists ;
89
89
import 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 ;
95
95
import org .mockito .ArgumentCaptor ;
96
96
import org .mockito .Mockito ;
97
97
import org .mockito .invocation .InvocationOnMock ;
@@ -122,8 +122,9 @@ public class TestBPOfferService {
122
122
GenericTestUtils .setLogLevel (DataNode .LOG , Level .TRACE );
123
123
}
124
124
125
- @ Rule
126
- public TemporaryFolder baseDir = new TemporaryFolder ();
125
+ @ SuppressWarnings ("checkstyle:VisibilityModifier" )
126
+ @ TempDir
127
+ java .nio .file .Path baseDir ;
127
128
128
129
private DatanodeProtocolClientSideTranslatorPB mockNN1 ;
129
130
private DatanodeProtocolClientSideTranslatorPB mockNN2 ;
@@ -138,7 +139,7 @@ public class TestBPOfferService {
138
139
private boolean isSlownode ;
139
140
private String mockStorageID ;
140
141
141
- @ Before
142
+ @ BeforeEach
142
143
public void setupMocks () throws Exception {
143
144
mockNN1 = setupNNMock (0 );
144
145
mockNN2 = setupNNMock (1 );
@@ -166,7 +167,7 @@ public void setupMocks() throws Exception {
166
167
Mockito .doReturn (dataSetLockManager ).when (mockDn ).getDataSetLockManager ();
167
168
}
168
169
169
- @ After
170
+ @ AfterEach
170
171
public void checkDataSetLockManager () {
171
172
dataSetLockManager .lockLeakCheck ();
172
173
// make sure no lock Leak.
@@ -831,9 +832,8 @@ public void testReportBadBlockWhenStandbyNNTimesOut() throws Exception {
831
832
.getStorageType ());
832
833
Thread .sleep (10000 );
833
834
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 " );
837
837
} finally {
838
838
bpos .stop ();
839
839
bpos .join ();
@@ -871,9 +871,9 @@ public void testTrySendErrorReportWhenStandbyNNTimesOut() throws Exception {
871
871
bpos .trySendErrorReport (DatanodeProtocol .INVALID_BLOCK , errorString );
872
872
Thread .sleep (10000 );
873
873
long difference = secondCallTime - firstCallTime ;
874
- assertTrue ("Active namenode trySendErrorReport processing "
874
+ assertTrue (difference < 5000 , "Active namenode trySendErrorReport processing "
875
875
+ "should be independent of standby namenode trySendErrorReport"
876
- + " processing " , difference < 5000 );
876
+ + " processing " );
877
877
} finally {
878
878
bpos .stop ();
879
879
bpos .join ();
@@ -911,8 +911,8 @@ public void testTrySendErrorReportWhenNNThrowsIOException()
911
911
String errorString = "Can't send invalid block " + FAKE_BLOCK ;
912
912
bpos .trySendErrorReport (DatanodeProtocol .INVALID_BLOCK , errorString );
913
913
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" );
916
916
} finally {
917
917
bpos .stop ();
918
918
bpos .join ();
@@ -1025,9 +1025,7 @@ public Boolean get() {
1025
1025
// Send register command back to Datanode to reRegister().
1026
1026
// After reRegister IBRs should be cleared.
1027
1027
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" );
1031
1029
bpos .triggerHeartbeatForTests ();
1032
1030
GenericTestUtils .waitFor (new Supplier <Boolean >() {
1033
1031
@ Override
@@ -1082,7 +1080,8 @@ public void testNNHAStateUpdateFromVersionRequest() throws Exception {
1082
1080
1083
1081
}
1084
1082
1085
- @ Test (timeout = 30000 )
1083
+ @ Test
1084
+ @ Timeout (value = 30 )
1086
1085
public void testRefreshNameNodes () throws Exception {
1087
1086
1088
1087
BPOfferService bpos = setupBPOSForNNs (mockDn , mockNN1 , mockNN2 );
@@ -1156,7 +1155,8 @@ public void testRefreshNameNodes() throws Exception {
1156
1155
}
1157
1156
}
1158
1157
1159
- @ Test (timeout = 15000 )
1158
+ @ Test
1159
+ @ Timeout (value = 15 )
1160
1160
public void testRefreshLeaseId () throws Exception {
1161
1161
Mockito .when (mockNN1 .sendHeartbeat (
1162
1162
Mockito .any (DatanodeRegistration .class ),
@@ -1221,7 +1221,8 @@ public Object answer(InvocationOnMock invocation)
1221
1221
}
1222
1222
}
1223
1223
1224
- @ Test (timeout = 15000 )
1224
+ @ Test
1225
+ @ Timeout (value = 15 )
1225
1226
public void testSetIsSlownode () throws Exception {
1226
1227
assertEquals (mockDn .isSlownode (), false );
1227
1228
Mockito .when (mockNN1 .sendHeartbeat (
@@ -1259,10 +1260,11 @@ public void testSetIsSlownode() throws Exception {
1259
1260
}
1260
1261
}
1261
1262
1262
- @ Test (timeout = 15000 )
1263
+ @ Test
1264
+ @ Timeout (value = 15 )
1263
1265
public void testCommandProcessingThread () throws Exception {
1264
1266
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 ()) {
1266
1268
List <DataNode > datanodes = cluster .getDataNodes ();
1267
1269
assertEquals (datanodes .size (), 1 );
1268
1270
DataNode datanode = datanodes .get (0 );
@@ -1273,19 +1275,20 @@ public void testCommandProcessingThread() throws Exception {
1273
1275
DFSTestUtil .createFile (fs , file , 10240L , (short )1 , 0L );
1274
1276
1275
1277
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." );
1278
1280
assertEquals (0 , getLongCounter ("SumOfActorCommandQueueLength" , mrb ));
1279
1281
// Check new metric result about processedCommandsOp.
1280
1282
// One command send back to DataNode here is #FinalizeCommand.
1281
1283
assertCounter ("ProcessedCommandsOpNumOps" , 1L , mrb );
1282
1284
}
1283
1285
}
1284
1286
1285
- @ Test (timeout = 5000 )
1287
+ @ Test
1288
+ @ Timeout (value = 5 )
1286
1289
public void testCommandProcessingThreadExit () throws Exception {
1287
1290
Configuration conf = new HdfsConfiguration ();
1288
- try (MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf , baseDir .getRoot ()).
1291
+ try (MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf , baseDir .toFile ()).
1289
1292
numDataNodes (1 ).build ()) {
1290
1293
List <DataNode > datanodes = cluster .getDataNodes ();
1291
1294
DataNode dataNode = datanodes .get (0 );
0 commit comments