Skip to content

Commit b9d2cb9

Browse files
committed
YARN-11262. Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcemanager Part5.
1 parent 126c3d4 commit b9d2cb9

File tree

68 files changed

+1608
-1504
lines changed

Some content is hidden

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

68 files changed

+1608
-1504
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestAMRMTokens.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@
6969
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
7070
import org.apache.hadoop.yarn.util.ConverterUtils;
7171
import 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;
7475
import org.junit.runner.RunWith;
7576
import org.junit.runners.Parameterized;
7677
import 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

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@
6565
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
6666
import org.apache.hadoop.yarn.util.ConverterUtils;
6767
import org.apache.hadoop.yarn.util.Records;
68-
import org.junit.Assert;
69-
import org.junit.Before;
70-
import org.junit.Test;
68+
import org.junit.jupiter.api.Assertions;
69+
import org.junit.jupiter.api.BeforeEach;
70+
import org.junit.jupiter.api.Test;
71+
import org.junit.jupiter.api.Timeout;
7172

7273
import javax.security.sasl.SaslException;
7374
import java.io.IOException;
@@ -79,7 +80,7 @@
7980
import java.util.Timer;
8081
import java.util.TimerTask;
8182

82-
import static org.junit.Assert.fail;
83+
import static org.junit.jupiter.api.Assertions.fail;
8384
import static org.mockito.ArgumentMatchers.any;
8485
import static org.mockito.Mockito.mock;
8586
import static org.mockito.Mockito.when;
@@ -91,7 +92,7 @@ public TestClientToAMTokens(SchedulerType type) throws IOException {
9192
super(type);
9293
}
9394

94-
@Before
95+
@BeforeEach
9596
public void setup() {
9697
conf = getConf();
9798
}
@@ -242,7 +243,7 @@ public RegisterApplicationMasterResponse run() {
242243
try {
243244
response = mockAM.registerAppAttempt();
244245
} catch (Exception e) {
245-
Assert.fail("Exception was not expected");
246+
Assertions.fail("Exception was not expected");
246247
}
247248
return response;
248249
}
@@ -260,14 +261,14 @@ public RegisterApplicationMasterResponse run() {
260261

261262
// ClientToAMToken master key should have been received on register
262263
// application master response.
263-
Assert.assertNotNull(response.getClientToAMTokenMasterKey());
264-
Assert
264+
Assertions.assertNotNull(response.getClientToAMTokenMasterKey());
265+
Assertions
265266
.assertTrue(response.getClientToAMTokenMasterKey().array().length > 0);
266267

267268
// Start the AM with the correct shared-secret.
268269
ApplicationAttemptId appAttemptId =
269270
app.getAppAttempts().keySet().iterator().next();
270-
Assert.assertNotNull(appAttemptId);
271+
Assertions.assertNotNull(appAttemptId);
271272
final CustomAM am =
272273
new CustomAM(appAttemptId, response.getClientToAMTokenMasterKey()
273274
.array());
@@ -285,7 +286,7 @@ public RegisterApplicationMasterResponse run() {
285286
client.ping(null, TestRpcBase.newEmptyRequest());
286287
fail("Access by unauthenticated user should fail!!");
287288
} catch (Exception e) {
288-
Assert.assertFalse(am.pinged);
289+
Assertions.assertFalse(am.pinged);
289290
}
290291

291292
Token<ClientToAMTokenIdentifier> token =
@@ -360,18 +361,18 @@ public Void run() throws Exception {
360361
}
361362
});
362363
} catch (Exception e) {
363-
Assert.assertEquals(RemoteException.class.getName(), e.getClass()
364+
Assertions.assertEquals(RemoteException.class.getName(), e.getClass()
364365
.getName());
365366
e = ((RemoteException)e).unwrapRemoteException();
366-
Assert
367+
Assertions
367368
.assertEquals(SaslException.class
368369
.getCanonicalName(), e.getClass().getCanonicalName());
369-
Assert.assertTrue(e
370+
Assertions.assertTrue(e
370371
.getMessage()
371372
.contains(
372373
"DIGEST-MD5: digest response format violation. "
373374
+ "Mismatched response."));
374-
Assert.assertFalse(am.pinged);
375+
Assertions.assertFalse(am.pinged);
375376
}
376377
}
377378

@@ -395,7 +396,7 @@ public Void run() throws Exception {
395396
CustomProtocol client =
396397
RPC.getProxy(CustomProtocol.class, 1L, am.address, conf);
397398
client.ping(null, TestRpcBase.newEmptyRequest());
398-
Assert.assertTrue(am.pinged);
399+
Assertions.assertTrue(am.pinged);
399400
return null;
400401
}
401402
});
@@ -414,13 +415,14 @@ public Void run() throws Exception {
414415
CustomProtocol client = RPC.getProxy(CustomProtocol.class,
415416
1L, am.address, conf);
416417
client.ping(null, TestRpcBase.newEmptyRequest());
417-
Assert.assertTrue(am.pinged);
418+
Assertions.assertTrue(am.pinged);
418419
return null;
419420
}
420421
});
421422
}
422423

423-
@Test(timeout=20000)
424+
@Test
425+
@Timeout(value = 20)
424426
public void testClientTokenRace() throws Exception {
425427

426428
conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
@@ -472,7 +474,7 @@ public RegisterApplicationMasterResponse run() {
472474
try {
473475
response = mockAM.registerAppAttempt();
474476
} catch (Exception e) {
475-
Assert.fail("Exception was not expected");
477+
Assertions.fail("Exception was not expected");
476478
}
477479
return response;
478480
}
@@ -491,13 +493,13 @@ public RegisterApplicationMasterResponse run() {
491493
// ClientToAMToken master key should have been received on register
492494
// application master response.
493495
final ByteBuffer clientMasterKey = response.getClientToAMTokenMasterKey();
494-
Assert.assertNotNull(clientMasterKey);
495-
Assert.assertTrue(clientMasterKey.array().length > 0);
496+
Assertions.assertNotNull(clientMasterKey);
497+
Assertions.assertTrue(clientMasterKey.array().length > 0);
496498

497499
// Start the AM with the correct shared-secret.
498500
ApplicationAttemptId appAttemptId =
499501
app.getAppAttempts().keySet().iterator().next();
500-
Assert.assertNotNull(appAttemptId);
502+
Assertions.assertNotNull(appAttemptId);
501503
final CustomAM am = new CustomAM(appAttemptId, null);
502504
am.init(conf);
503505
am.start();

0 commit comments

Comments
 (0)