Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ public static void disableSystemExit() {
systemExitDisabled = true;
}

/**
* Enable the use of System.exit for testing.
*/
public static void enableSystemExit() {
systemExitDisabled = false;
}

/**
* Disable the use of {@code Runtime.getRuntime().halt() } for testing.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ExitUtil;
import org.apache.hadoop.yarn.api.records.Container;
import org.apache.hadoop.yarn.api.records.ContainerExitStatus;
import org.apache.hadoop.yarn.api.records.ContainerId;
Expand Down Expand Up @@ -76,11 +77,9 @@
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.SimpleCandidateNodeSet;
import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey;
import org.apache.hadoop.yarn.util.resource.Resources;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.contrib.java.lang.system.internal.NoExitSecurityManager;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

Expand Down Expand Up @@ -1104,17 +1103,7 @@ public Boolean answer(InvocationOnMock invocation) throws Exception {
@Test
@Timeout(value = 30)
public void testAsyncScheduleThreadExit() throws Exception {

// Set no exit security manager to catch System.exit
SecurityManager originalSecurityManager = System.getSecurityManager();
NoExitSecurityManager noExitSecurityManager =
new NoExitSecurityManager(originalSecurityManager);
try {
System.setSecurityManager(noExitSecurityManager);
} catch (UnsupportedOperationException e) {
Assumptions.assumeTrue(false,
"Test is skipped because SecurityManager cannot be set (JEP411)");
}
ExitUtil.disableSystemExit();

// init RM & NM
final MockRM rm = new MockRM(conf);
Expand All @@ -1131,11 +1120,14 @@ public void testAsyncScheduleThreadExit() throws Exception {
cs.setResourceCalculator(null);

// wait for RM to be shutdown until timeout
GenericTestUtils.waitFor(noExitSecurityManager::isCheckExitCalled,
GenericTestUtils.waitFor(() -> ExitUtil.getFirstExitException() != null,
100, 5000);
} finally {
System.setSecurityManager(originalSecurityManager);
rm.stop();
ExitUtil.enableSystemExit();
ExitUtil.resetFirstExitException();
if (rm != null) {
rm.stop();
}
}
}

Expand Down