Skip to content

Commit 5f5dc03

Browse files
authored
YARN-11863. [JDK17] Remove JUnit4 NoExitSecurityManager. (#7986) Contributed by Shilun Fan.
* YARN-11863. [JDK17] Remove JUnit4 NoExitSecurityManager. Signed-off-by: Shilun Fan <[email protected]>
1 parent 3baa288 commit 5f5dc03

File tree

2 files changed

+15
-16
lines changed
  • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity

2 files changed

+15
-16
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ public static void disableSystemExit() {
151151
systemExitDisabled = true;
152152
}
153153

154+
/**
155+
* Enable the use of System.exit for testing.
156+
*/
157+
public static void enableSystemExit() {
158+
systemExitDisabled = false;
159+
}
160+
154161
/**
155162
* Disable the use of {@code Runtime.getRuntime().halt() } for testing.
156163
*/

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.hadoop.test.GenericTestUtils;
3333
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;
3434
import org.apache.hadoop.conf.Configuration;
35+
import org.apache.hadoop.util.ExitUtil;
3536
import org.apache.hadoop.yarn.api.records.Container;
3637
import org.apache.hadoop.yarn.api.records.ContainerExitStatus;
3738
import org.apache.hadoop.yarn.api.records.ContainerId;
@@ -76,11 +77,9 @@
7677
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.SimpleCandidateNodeSet;
7778
import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey;
7879
import org.apache.hadoop.yarn.util.resource.Resources;
79-
import org.junit.jupiter.api.Assumptions;
8080
import org.junit.jupiter.api.BeforeEach;
8181
import org.junit.jupiter.api.Test;
8282
import org.junit.jupiter.api.Timeout;
83-
import org.junit.contrib.java.lang.system.internal.NoExitSecurityManager;
8483
import org.mockito.invocation.InvocationOnMock;
8584
import 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

Comments
 (0)