|
46 | 46 | import java.io.FileOutputStream; |
47 | 47 | import java.io.FileReader; |
48 | 48 | import java.io.IOException; |
| 49 | +import java.io.InputStreamReader; |
49 | 50 | import java.io.PrintStream; |
50 | 51 | import java.io.PrintWriter; |
51 | 52 | import java.nio.ByteBuffer; |
@@ -1477,6 +1478,76 @@ public void testImmediateKill() throws Exception { |
1477 | 1478 | internalKillTest(false); |
1478 | 1479 | } |
1479 | 1480 |
|
| 1481 | + @Test |
| 1482 | + @Timeout(value = 30) |
| 1483 | + public void testNoBashParentProcess() throws Exception { |
| 1484 | + assumeNotWindows(); |
| 1485 | + containerManager.start(); |
| 1486 | + |
| 1487 | + // Construct the Container-id |
| 1488 | + ApplicationId appId = ApplicationId.newInstance(1, 1); |
| 1489 | + ApplicationAttemptId appAttemptId = |
| 1490 | + ApplicationAttemptId.newInstance(appId, 1); |
| 1491 | + ContainerId cId = ContainerId.newContainerId(appAttemptId, 0); |
| 1492 | + |
| 1493 | + ContainerLaunchContext containerLaunchContext = |
| 1494 | + recordFactory.newRecordInstance(ContainerLaunchContext.class); |
| 1495 | + |
| 1496 | + // set up the rest of the container |
| 1497 | + List<String> commands = Arrays.asList(new String[] {"sleep 30 1>/dev/null 2>/dev/null"}); |
| 1498 | + containerLaunchContext.setCommands(commands); |
| 1499 | + Priority priority = Priority.newInstance(10); |
| 1500 | + long createTime = 1234; |
| 1501 | + Token containerToken = createContainerToken(cId, priority, createTime); |
| 1502 | + |
| 1503 | + StartContainerRequest scRequest = |
| 1504 | + StartContainerRequest.newInstance(containerLaunchContext, |
| 1505 | + containerToken); |
| 1506 | + List<StartContainerRequest> list = new ArrayList<StartContainerRequest>(); |
| 1507 | + list.add(scRequest); |
| 1508 | + StartContainersRequest allRequests = |
| 1509 | + StartContainersRequest.newInstance(list); |
| 1510 | + containerManager.startContainers(allRequests); |
| 1511 | + |
| 1512 | + NMContainerStatus nmContainerStatus = |
| 1513 | + containerManager.getContext().getContainers().get(cId) |
| 1514 | + .getNMContainerStatus(); |
| 1515 | + assertEquals(priority, nmContainerStatus.getPriority()); |
| 1516 | + |
| 1517 | + int timeoutSecs = 0; |
| 1518 | + String pid = containerManager.getContext().getContainerExecutor().getProcessId(cId); |
| 1519 | + while (pid == null && timeoutSecs++ < 20) { |
| 1520 | + Thread.sleep(1000); |
| 1521 | + pid = containerManager.getContext().getContainerExecutor().getProcessId(cId); |
| 1522 | + LOG.info("Waiting for process start-file to be created"); |
| 1523 | + } |
| 1524 | + assertNotNull(pid); |
| 1525 | + |
| 1526 | + Process proc = Runtime.getRuntime().exec(new String[] {"ps", "-o", "command=", pid}); |
| 1527 | + assertEquals(proc.waitFor(), 0); |
| 1528 | + BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); |
| 1529 | + |
| 1530 | + assertEquals(reader.readLine(), "sleep 30"); |
| 1531 | + |
| 1532 | + List<ContainerId> containerIds = new ArrayList<ContainerId>(); |
| 1533 | + containerIds.add(cId); |
| 1534 | + StopContainersRequest stopRequest = |
| 1535 | + StopContainersRequest.newInstance(containerIds); |
| 1536 | + containerManager.stopContainers(stopRequest); |
| 1537 | + |
| 1538 | + BaseContainerManagerTest.waitForContainerState(containerManager, cId, |
| 1539 | + ContainerState.COMPLETE); |
| 1540 | + |
| 1541 | + GetContainerStatusesRequest gcsRequest = |
| 1542 | + GetContainerStatusesRequest.newInstance(containerIds); |
| 1543 | + |
| 1544 | + ContainerStatus containerStatus = |
| 1545 | + containerManager.getContainerStatuses(gcsRequest) |
| 1546 | + .getContainerStatuses().get(0); |
| 1547 | + assertEquals(ContainerExitStatus.KILLED_BY_APPMASTER, |
| 1548 | + containerStatus.getExitStatus()); |
| 1549 | + } |
| 1550 | + |
1480 | 1551 | @SuppressWarnings("rawtypes") |
1481 | 1552 | @Test |
1482 | 1553 | @Timeout(value = 10) |
|
0 commit comments