1919package org .apache .hadoop .yarn .server .router .webapp ;
2020
2121import java .io .IOException ;
22+ import java .io .PrintWriter ;
23+ import java .io .StringWriter ;
2224import java .security .Principal ;
2325import java .util .ArrayList ;
2426import java .util .List ;
139141import org .apache .hadoop .yarn .util .Times ;
140142import org .apache .hadoop .yarn .util .YarnVersionInfo ;
141143import org .apache .hadoop .yarn .webapp .BadRequestException ;
144+ import org .apache .hadoop .yarn .webapp .NotFoundException ;
142145import org .apache .hadoop .yarn .webapp .dao .ConfInfo ;
143146import org .apache .hadoop .yarn .webapp .dao .QueueConfigInfo ;
144147import org .apache .hadoop .yarn .webapp .dao .SchedConfUpdateInfo ;
145148import org .apache .hadoop .yarn .webapp .util .WebAppUtils ;
146149import org .junit .jupiter .api .AfterEach ;
147150import org .junit .jupiter .api .BeforeEach ;
151+ import org .junit .jupiter .api .Order ;
148152import org .junit .jupiter .api .Test ;
149153
150154import static org .apache .hadoop .yarn .conf .YarnConfiguration .RM_DELEGATION_KEY_UPDATE_INTERVAL_DEFAULT ;
162166import static org .junit .jupiter .api .Assertions .assertFalse ;
163167import static org .junit .jupiter .api .Assertions .assertNotNull ;
164168import static org .junit .jupiter .api .Assertions .assertNull ;
169+ import static org .junit .jupiter .api .Assertions .assertThrows ;
165170import static org .junit .jupiter .api .Assertions .assertTrue ;
166171import static org .mockito .Mockito .mock ;
167172import static org .mockito .Mockito .when ;
@@ -527,9 +532,11 @@ public void testGetApplicationNotExists() {
527532 @ Test
528533 public void testGetApplicationWrongFormat () {
529534
530- AppInfo response = interceptor .getApp (null , "Application_wrong_id" , null );
531-
532- assertNull (response );
535+ IllegalArgumentException illegalArgumentException =
536+ assertThrows (IllegalArgumentException .class , () -> {
537+ interceptor .getApp (null , "Application_wrong_id" , null );
538+ });
539+ assertTrue (illegalArgumentException .getMessage ().contains ("Invalid ApplicationId prefix: Application_wrong_id." ));
533540 }
534541
535542 /**
@@ -601,6 +608,7 @@ public void testUpdateNodeResource() {
601608 * of SubClusterId. SubClusterId in this case is an integer.
602609 */
603610 @ Test
611+ @ Order (1 )
604612 public void testGetClusterMetrics () {
605613
606614 ClusterMetricsInfo responseGet = interceptor .getClusterMetricsInfo ();
@@ -1363,9 +1371,11 @@ public void testDeleteReservation() throws Exception {
13631371 Response delResponse = interceptor .deleteReservation (deleteRequestInfo , null );
13641372 assertNotNull (delResponse );
13651373
1366- LambdaTestUtils .intercept (Exception .class ,
1367- "reservationId with id: " + reservationId + " not found" ,
1368- () -> interceptor .listReservation (QUEUE_DEDICATED_FULL , applyResId , -1 , -1 , false , null ));
1374+ NotFoundException exception = assertThrows (NotFoundException .class , () -> {
1375+ interceptor .listReservation (QUEUE_DEDICATED_FULL , applyResId , -1 , -1 , false , null );
1376+ });
1377+ String stackTraceAsString = getStackTraceAsString (exception );
1378+ assertTrue (stackTraceAsString .contains ("reservationId with id: " + reservationId + " not found" ));
13691379 }
13701380
13711381 private Response submitReservation (ReservationId reservationId )
@@ -1455,16 +1465,23 @@ public void testCheckUserAccessToQueue() throws Exception {
14551465 HttpServletRequest mockHsr = mockHttpServletRequestByUserName ("non-admin" );
14561466 String errorMsg1 = "User=non-admin doesn't haven access to queue=queue " +
14571467 "so it cannot check ACLs for other users." ;
1458- LambdaTestUtils .intercept (YarnRuntimeException .class , errorMsg1 ,
1459- () -> interceptor .checkUserAccessToQueue ("queue" , "jack" ,
1460- QueueACL .SUBMIT_APPLICATIONS .name (), mockHsr ));
1468+ RuntimeException exception = assertThrows (RuntimeException .class , () -> {
1469+ interceptor .checkUserAccessToQueue ("queue" , "jack" ,
1470+ QueueACL .SUBMIT_APPLICATIONS .name (), mockHsr );
1471+ });
1472+ String stackTraceAsString = getStackTraceAsString (exception );
1473+ assertTrue (stackTraceAsString .contains (errorMsg1 ));
14611474
14621475 // Case 2: request an unknown ACL causes BAD_REQUEST
14631476 HttpServletRequest mockHsr1 = mockHttpServletRequestByUserName ("admin" );
14641477 String errorMsg2 = "Specified queueAclType=XYZ_ACL is not a valid type, " +
14651478 "valid queue acl types={SUBMIT_APPLICATIONS/ADMINISTER_QUEUE}" ;
1466- LambdaTestUtils .intercept (YarnRuntimeException .class , errorMsg2 ,
1467- () -> interceptor .checkUserAccessToQueue ("queue" , "jack" , "XYZ_ACL" , mockHsr1 ));
1479+ RuntimeException exception2 = assertThrows (RuntimeException .class , () -> {
1480+ interceptor .checkUserAccessToQueue ("queue" , "jack" ,
1481+ "XYZ_ACL" , mockHsr1 );
1482+ });
1483+ String stackTraceAsString2 = getStackTraceAsString (exception2 );
1484+ assertTrue (stackTraceAsString2 .contains (errorMsg2 ));
14681485
14691486 // We design a test, admin user has ADMINISTER_QUEUE, SUBMIT_APPLICATIONS permissions,
14701487 // yarn user has SUBMIT_APPLICATIONS permissions, other users have no permissions
@@ -1720,8 +1737,11 @@ public void testPostDelegationTokenExpirationError() throws Exception {
17201737
17211738 // If we don't set the header.
17221739 String errorMsg = "Header 'Hadoop-YARN-RM-Delegation-Token' containing encoded token not found" ;
1723- LambdaTestUtils .intercept (BadRequestException .class , errorMsg ,
1724- () -> interceptor .postDelegationTokenExpiration (request ));
1740+ BadRequestException badRequestException = assertThrows (BadRequestException .class , () -> {
1741+ interceptor .postDelegationTokenExpiration (request );
1742+ });
1743+ String stackTraceAsString = getStackTraceAsString (badRequestException );
1744+ assertTrue (stackTraceAsString .contains (errorMsg ));
17251745 }
17261746
17271747 @ Test
@@ -2272,4 +2292,11 @@ public void testGetClusterInfo() {
22722292 clusterInfo .getHAZookeeperConnectionState ());
22732293 }
22742294 }
2295+
2296+ private String getStackTraceAsString (Exception e ) {
2297+ StringWriter sw = new StringWriter ();
2298+ PrintWriter pw = new PrintWriter (sw );
2299+ e .printStackTrace (pw );
2300+ return sw .toString ();
2301+ }
22752302}
0 commit comments