3232import org .apache .hadoop .test .GenericTestUtils ;
3333import org .apache .hadoop .thirdparty .com .google .common .collect .ImmutableList ;
3434import org .apache .hadoop .conf .Configuration ;
35+ import org .apache .hadoop .util .ExitUtil ;
3536import org .apache .hadoop .yarn .api .records .Container ;
3637import org .apache .hadoop .yarn .api .records .ContainerExitStatus ;
3738import org .apache .hadoop .yarn .api .records .ContainerId ;
7677import org .apache .hadoop .yarn .server .resourcemanager .scheduler .placement .SimpleCandidateNodeSet ;
7778import org .apache .hadoop .yarn .server .scheduler .SchedulerRequestKey ;
7879import org .apache .hadoop .yarn .util .resource .Resources ;
79- import org .junit .jupiter .api .Assumptions ;
8080import org .junit .jupiter .api .BeforeEach ;
8181import org .junit .jupiter .api .Test ;
8282import org .junit .jupiter .api .Timeout ;
83- import org .junit .contrib .java .lang .system .internal .NoExitSecurityManager ;
8483import org .mockito .invocation .InvocationOnMock ;
8584import org .mockito .stubbing .Answer ;
8685
@@ -1104,17 +1103,7 @@ public Boolean answer(InvocationOnMock invocation) throws Exception {
11041103 @ Test
11051104 @ Timeout (value = 30 )
11061105 public void testAsyncScheduleThreadExit () throws Exception {
1107-
1108- // Set no exit security manager to catch System.exit
1109- SecurityManager originalSecurityManager = System .getSecurityManager ();
1110- NoExitSecurityManager noExitSecurityManager =
1111- new NoExitSecurityManager (originalSecurityManager );
1112- try {
1113- System .setSecurityManager (noExitSecurityManager );
1114- } catch (UnsupportedOperationException e ) {
1115- Assumptions .assumeTrue (false ,
1116- "Test is skipped because SecurityManager cannot be set (JEP411)" );
1117- }
1106+ ExitUtil .disableSystemExit ();
11181107
11191108 // init RM & NM
11201109 final MockRM rm = new MockRM (conf );
@@ -1131,11 +1120,14 @@ public void testAsyncScheduleThreadExit() throws Exception {
11311120 cs .setResourceCalculator (null );
11321121
11331122 // wait for RM to be shutdown until timeout
1134- GenericTestUtils .waitFor (noExitSecurityManager :: isCheckExitCalled ,
1123+ GenericTestUtils .waitFor (() -> ExitUtil . getFirstExitException () != null ,
11351124 100 , 5000 );
11361125 } finally {
1137- System .setSecurityManager (originalSecurityManager );
1138- rm .stop ();
1126+ ExitUtil .enableSystemExit ();
1127+ ExitUtil .resetFirstExitException ();
1128+ if (rm != null ) {
1129+ rm .stop ();
1130+ }
11391131 }
11401132 }
11411133
0 commit comments