|
23 | 23 | import static org.junit.Assert.assertEquals; |
24 | 24 | import static org.junit.Assert.assertNotEquals; |
25 | 25 | import static org.junit.Assert.assertTrue; |
26 | | -import static org.junit.Assert.fail; |
27 | 26 | import static org.mockito.ArgumentMatchers.any; |
28 | 27 | import static org.mockito.ArgumentMatchers.anyBoolean; |
29 | 28 | import static org.mockito.Mockito.doAnswer; |
| 29 | +import static org.mockito.Mockito.doNothing; |
30 | 30 | import static org.mockito.Mockito.doThrow; |
31 | 31 | import static org.mockito.Mockito.mock; |
32 | 32 | import static org.mockito.Mockito.spy; |
@@ -347,7 +347,8 @@ public void testStartLocalizer() throws IOException { |
347 | 347 |
|
348 | 348 | @Test |
349 | 349 | public void testContainerLaunchError() |
350 | | - throws IOException, ContainerExecutionException, URISyntaxException, IllegalAccessException { |
| 350 | + throws IOException, ContainerExecutionException, URISyntaxException, IllegalAccessException, |
| 351 | + NoSuchFieldException { |
351 | 352 |
|
352 | 353 | final String[] expecetedMessage = {"badcommand", "Exit code: 24"}; |
353 | 354 | final String[] executor = { |
@@ -393,15 +394,10 @@ public Object answer(InvocationOnMock invocationOnMock) |
393 | 394 | NodeManager nodeManager = new NodeManager(); |
394 | 395 | NodeManager.NMContext nmContext = |
395 | 396 | nodeManager.createNMContext(null, null, null, false, conf); |
396 | | - try{ |
397 | | - Field LceNmContext = LinuxContainerExecutor.class.getDeclaredField("nmContext"); |
398 | | - LceNmContext.setAccessible(true); |
399 | | - LceNmContext.set(mockExec, nmContext); |
400 | | - }catch(NoSuchFieldException e){ |
401 | | - fail("Could not find the 'nmContext' field in the LinuxContainerExecution class " |
402 | | - + "when attempted to set it using reflection."); |
403 | | - }; |
404 | | - |
| 397 | + Field LceNmContext = LinuxContainerExecutor.class.getDeclaredField("nmContext"); |
| 398 | + LceNmContext.setAccessible(true); |
| 399 | + LceNmContext.set(mockExec, nmContext); |
| 400 | + |
405 | 401 | String appSubmitter = "nobody"; |
406 | 402 | String cmd = String |
407 | 403 | .valueOf(PrivilegedOperation.RunAsUserCommand.LAUNCH_CONTAINER. |
@@ -616,15 +612,30 @@ public void testNoExitCodeFromPrivilegedOperation() throws Exception { |
616 | 612 | LinuxContainerRuntime runtime = new DefaultLinuxContainerRuntime( |
617 | 613 | spyPrivilegedExecutor); |
618 | 614 | runtime.initialize(conf, null); |
619 | | - mockExec = new LinuxContainerExecutor(runtime); |
620 | | - mockExec.setConf(conf); |
621 | 615 | LinuxContainerExecutor lce = new LinuxContainerExecutor(runtime) { |
622 | 616 | @Override |
623 | 617 | protected PrivilegedOperationExecutor getPrivilegedOperationExecutor() { |
624 | 618 | return spyPrivilegedExecutor; |
625 | 619 | } |
626 | 620 | }; |
627 | 621 | lce.setConf(conf); |
| 622 | + |
| 623 | + //set the private nmContext field without initing the LinuxContainerExecutor |
| 624 | + NodeManager nodeManager = new NodeManager(); |
| 625 | + NodeManager.NMContext nmContext = |
| 626 | + nodeManager.createNMContext(null, null, null, false, conf); |
| 627 | + NodeManager.NMContext spyNmContext = spy(nmContext); |
| 628 | + |
| 629 | + //initialize a mock NodeStatusUpdater |
| 630 | + NodeStatusUpdaterImpl nodeStatusUpdater = mock(NodeStatusUpdaterImpl.class); |
| 631 | + nmContext.setNodeStatusUpdater(nodeStatusUpdater); |
| 632 | + //imitate a void method call on the NodeStatusUpdater when setting NM unhealthy. |
| 633 | + doNothing().when(nodeStatusUpdater).reportException(any()); |
| 634 | + |
| 635 | + Field LceNmContext = LinuxContainerExecutor.class.getDeclaredField("nmContext"); |
| 636 | + LceNmContext.setAccessible(true); |
| 637 | + LceNmContext.set(lce, nmContext); |
| 638 | + |
628 | 639 | InetSocketAddress address = InetSocketAddress.createUnresolved( |
629 | 640 | "localhost", 8040); |
630 | 641 | Path nmPrivateCTokensPath= new Path("file:///bin/nmPrivateCTokensPath"); |
@@ -687,6 +698,9 @@ protected PrivilegedOperationExecutor getPrivilegedOperationExecutor() { |
687 | 698 | assertTrue("Unexpected exception " + e, |
688 | 699 | e.getMessage().contains("exit code")); |
689 | 700 | } |
| 701 | + |
| 702 | + //verify that the NM was set unhealthy on PrivilegedOperationException |
| 703 | + verify(nodeStatusUpdater, times(1)).reportException( any() ); |
690 | 704 | } |
691 | 705 |
|
692 | 706 | @Test |
|
0 commit comments