32
32
import org .apache .hadoop .test .GenericTestUtils ;
33
33
import org .apache .hadoop .thirdparty .com .google .common .collect .ImmutableList ;
34
34
import org .apache .hadoop .conf .Configuration ;
35
+ import org .apache .hadoop .util .ExitUtil ;
35
36
import org .apache .hadoop .yarn .api .records .Container ;
36
37
import org .apache .hadoop .yarn .api .records .ContainerExitStatus ;
37
38
import org .apache .hadoop .yarn .api .records .ContainerId ;
76
77
import org .apache .hadoop .yarn .server .resourcemanager .scheduler .placement .SimpleCandidateNodeSet ;
77
78
import org .apache .hadoop .yarn .server .scheduler .SchedulerRequestKey ;
78
79
import org .apache .hadoop .yarn .util .resource .Resources ;
79
- import org .junit .jupiter .api .Assumptions ;
80
80
import org .junit .jupiter .api .BeforeEach ;
81
81
import org .junit .jupiter .api .Test ;
82
82
import org .junit .jupiter .api .Timeout ;
83
- import org .junit .contrib .java .lang .system .internal .NoExitSecurityManager ;
84
83
import org .mockito .invocation .InvocationOnMock ;
85
84
import org .mockito .stubbing .Answer ;
86
85
@@ -1104,17 +1103,7 @@ public Boolean answer(InvocationOnMock invocation) throws Exception {
1104
1103
@ Test
1105
1104
@ Timeout (value = 30 )
1106
1105
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 ();
1118
1107
1119
1108
// init RM & NM
1120
1109
final MockRM rm = new MockRM (conf );
@@ -1131,11 +1120,14 @@ public void testAsyncScheduleThreadExit() throws Exception {
1131
1120
cs .setResourceCalculator (null );
1132
1121
1133
1122
// wait for RM to be shutdown until timeout
1134
- GenericTestUtils .waitFor (noExitSecurityManager :: isCheckExitCalled ,
1123
+ GenericTestUtils .waitFor (() -> ExitUtil . getFirstExitException () != null ,
1135
1124
100 , 5000 );
1136
1125
} finally {
1137
- System .setSecurityManager (originalSecurityManager );
1138
- rm .stop ();
1126
+ ExitUtil .enableSystemExit ();
1127
+ ExitUtil .resetFirstExitException ();
1128
+ if (rm != null ) {
1129
+ rm .stop ();
1130
+ }
1139
1131
}
1140
1132
}
1141
1133
0 commit comments