6969import org .apache .hadoop .yarn .server .utils .BuilderUtils ;
7070import org .apache .hadoop .yarn .util .ConverterUtils ;
7171import org .apache .hadoop .yarn .util .Records ;
72- import org .junit .Assert ;
73- import org .junit .Test ;
72+ import org .junit .jupiter .api .Assertions ;
73+ import org .junit .jupiter .api .Test ;
74+ import org .junit .jupiter .api .Timeout ;
7475import org .junit .runner .RunWith ;
7576import org .junit .runners .Parameterized ;
7677import org .junit .runners .Parameterized .Parameters ;
@@ -139,7 +140,7 @@ public void testTokenExpiry() throws Exception {
139140 LOG .info ("Waiting for AM Launch to happen.." );
140141 Thread .sleep (1000 );
141142 }
142- Assert .assertNotNull (containerManager .containerTokens );
143+ Assertions .assertNotNull (containerManager .containerTokens );
143144
144145 RMAppAttempt attempt = app .getCurrentAppAttempt ();
145146 ApplicationAttemptId applicationAttemptId = attempt .getAppAttemptId ();
@@ -192,7 +193,7 @@ public void testTokenExpiry() throws Exception {
192193 Thread .sleep (100 );
193194 count ++;
194195 }
195- Assert .assertTrue (attempt .getState () == RMAppAttemptState .FINISHED );
196+ Assertions .assertTrue (attempt .getState () == RMAppAttemptState .FINISHED );
196197
197198 // Now simulate trying to allocate. RPC call itself should throw auth
198199 // exception.
@@ -202,13 +203,13 @@ public void testTokenExpiry() throws Exception {
202203 Records .newRecord (AllocateRequest .class );
203204 try {
204205 rmClient .allocate (allocateRequest );
205- Assert .fail ("You got to be kidding me! "
206+ Assertions .fail ("You got to be kidding me! "
206207 + "Using App tokens after app-finish should fail!" );
207208 } catch (Throwable t ) {
208209 LOG .info ("Exception found is " , t );
209210 // The exception will still have the earlier appAttemptId as it picks it
210211 // up from the token.
211- Assert .assertTrue (t .getCause ().getMessage ().contains (
212+ Assertions .assertTrue (t .getCause ().getMessage ().contains (
212213 applicationAttemptId .toString ()
213214 + " not found in AMRMTokenSecretManager." ));
214215 }
@@ -247,7 +248,7 @@ public void testMasterKeyRollOver() throws Exception {
247248 AMRMTokenSecretManager appTokenSecretManager =
248249 rm .getRMContext ().getAMRMTokenSecretManager ();
249250 MasterKeyData oldKey = appTokenSecretManager .getMasterKey ();
250- Assert .assertNotNull (oldKey );
251+ Assertions .assertNotNull (oldKey );
251252 try {
252253 MockNM nm1 = rm .registerNode ("localhost:1234" , 5120 );
253254
@@ -260,7 +261,7 @@ public void testMasterKeyRollOver() throws Exception {
260261 LOG .info ("Waiting for AM Launch to happen.." );
261262 Thread .sleep (1000 );
262263 }
263- Assert .assertNotNull (containerManager .containerTokens );
264+ Assertions .assertNotNull (containerManager .containerTokens );
264265
265266 RMAppAttempt attempt = app .getCurrentAppAttempt ();
266267 ApplicationAttemptId applicationAttemptId = attempt .getAppAttemptId ();
@@ -285,7 +286,7 @@ public void testMasterKeyRollOver() throws Exception {
285286 // One allocate call.
286287 AllocateRequest allocateRequest =
287288 Records .newRecord (AllocateRequest .class );
288- Assert .assertTrue (
289+ Assertions .assertTrue (
289290 rmClient .allocate (allocateRequest ).getAMCommand () == null );
290291
291292 // Wait for enough time and make sure the roll_over happens
@@ -296,14 +297,14 @@ public void testMasterKeyRollOver() throws Exception {
296297 }
297298
298299 MasterKeyData newKey = appTokenSecretManager .getMasterKey ();
299- Assert .assertNotNull (newKey );
300- Assert .assertFalse ("Master key should have changed!" ,
301- oldKey .equals (newKey ));
300+ Assertions .assertNotNull (newKey );
301+ Assertions .assertFalse (
302+ oldKey .equals (newKey ), "Master key should have changed!" );
302303
303304 // Another allocate call with old AMRMToken. Should continue to work.
304305 rpc .stopProxy (rmClient , conf ); // To avoid using cached client
305306 rmClient = createRMClient (rm , conf , rpc , currentUser );
306- Assert
307+ Assertions
307308 .assertTrue (rmClient .allocate (allocateRequest ).getAMCommand () == null );
308309
309310 waitCount = 0 ;
@@ -319,9 +320,9 @@ public void testMasterKeyRollOver() throws Exception {
319320 Thread .sleep (200 );
320321 }
321322 // active the nextMasterKey, and replace the currentMasterKey
322- Assert .assertTrue (appTokenSecretManager .getCurrnetMasterKeyData ().equals (newKey ));
323- Assert .assertTrue (appTokenSecretManager .getMasterKey ().equals (newKey ));
324- Assert .assertTrue (appTokenSecretManager .getNextMasterKeyData () == null );
323+ Assertions .assertTrue (appTokenSecretManager .getCurrnetMasterKeyData ().equals (newKey ));
324+ Assertions .assertTrue (appTokenSecretManager .getMasterKey ().equals (newKey ));
325+ Assertions .assertTrue (appTokenSecretManager .getNextMasterKeyData () == null );
325326
326327 // Create a new Token
327328 Token <AMRMTokenIdentifier > newToken =
@@ -332,7 +333,7 @@ public void testMasterKeyRollOver() throws Exception {
332333 rpc .stopProxy (rmClient , conf ); // To avoid using cached client
333334 rmClient = createRMClient (rm , conf , rpc , currentUser );
334335 allocateRequest = Records .newRecord (AllocateRequest .class );
335- Assert
336+ Assertions
336337 .assertTrue (rmClient .allocate (allocateRequest ).getAMCommand () == null );
337338
338339 // Should not work by using the old AMRMToken.
@@ -341,9 +342,9 @@ public void testMasterKeyRollOver() throws Exception {
341342 currentUser .addToken (amRMToken );
342343 rmClient = createRMClient (rm , conf , rpc , currentUser );
343344 allocateRequest = Records .newRecord (AllocateRequest .class );
344- Assert
345+ Assertions
345346 .assertTrue (rmClient .allocate (allocateRequest ).getAMCommand () == null );
346- Assert .fail ("The old Token should not work" );
347+ Assertions .fail ("The old Token should not work" );
347348 } catch (Exception ex ) {
348349 // expect exception
349350 }
@@ -355,7 +356,8 @@ public void testMasterKeyRollOver() throws Exception {
355356 }
356357 }
357358
358- @ Test (timeout = 20000 )
359+ @ Test
360+ @ Timeout (value = 20 )
359361 public void testAMRMMasterKeysUpdate () throws Exception {
360362 final AtomicReference <AMRMTokenSecretManager > spySecretMgrRef =
361363 new AtomicReference <AMRMTokenSecretManager >();
@@ -387,7 +389,7 @@ protected AMRMTokenSecretManager createAMRMTokenSecretManager(
387389 // Do allocate. Should not update AMRMToken
388390 AllocateResponse response =
389391 am .allocate (Records .newRecord (AllocateRequest .class ));
390- Assert .assertNull (response .getAMRMToken ());
392+ Assertions .assertNull (response .getAMRMToken ());
391393 Token <AMRMTokenIdentifier > oldToken = rm .getRMContext ().getRMApps ()
392394 .get (app .getApplicationId ())
393395 .getRMAppAttempt (am .getApplicationAttemptId ()).getAMRMToken ();
@@ -396,13 +398,13 @@ protected AMRMTokenSecretManager createAMRMTokenSecretManager(
396398 // Do allocate again. the AM should get the latest AMRMToken
397399 rm .getRMContext ().getAMRMTokenSecretManager ().rollMasterKey ();
398400 response = am .allocate (Records .newRecord (AllocateRequest .class ));
399- Assert .assertNotNull (response .getAMRMToken ());
401+ Assertions .assertNotNull (response .getAMRMToken ());
400402
401403 Token <AMRMTokenIdentifier > amrmToken =
402404 ConverterUtils .convertFromYarn (response .getAMRMToken (), new Text (
403405 response .getAMRMToken ().getService ()));
404406
405- Assert .assertEquals (amrmToken .decodeIdentifier ().getKeyId (), rm
407+ Assertions .assertEquals (amrmToken .decodeIdentifier ().getKeyId (), rm
406408 .getRMContext ().getAMRMTokenSecretManager ().getMasterKey ().getMasterKey ()
407409 .getKeyId ());
408410
@@ -413,19 +415,19 @@ protected AMRMTokenSecretManager createAMRMTokenSecretManager(
413415 am .getApplicationAttemptId ().toString (), new String [0 ]);
414416 ugi .addTokenIdentifier (oldToken .decodeIdentifier ());
415417 response = am .doAllocateAs (ugi , Records .newRecord (AllocateRequest .class ));
416- Assert .assertNotNull (response .getAMRMToken ());
418+ Assertions .assertNotNull (response .getAMRMToken ());
417419 verify (spySecretMgr , never ()).createAndGetAMRMToken (isA (ApplicationAttemptId .class ));
418420
419421 // Do allocate again with the updated token and verify we do not
420422 // receive a new token to use.
421423 response = am .allocate (Records .newRecord (AllocateRequest .class ));
422- Assert .assertNull (response .getAMRMToken ());
424+ Assertions .assertNull (response .getAMRMToken ());
423425
424426 // Activate the next master key. Since there is new master key generated
425427 // in AMRMTokenSecretManager. The AMRMToken will not get updated for AM
426428 rm .getRMContext ().getAMRMTokenSecretManager ().activateNextMasterKey ();
427429 response = am .allocate (Records .newRecord (AllocateRequest .class ));
428- Assert .assertNull (response .getAMRMToken ());
430+ Assertions .assertNull (response .getAMRMToken ());
429431 rm .stop ();
430432 }
431433
0 commit comments