brumi1024 commented on code in PR #6780: URL: https://github.com/apache/hadoop/pull/6780#discussion_r1596811423
########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsResourceCalculator.java: ########## @@ -18,258 +18,138 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources; -import org.apache.commons.io.FileUtils; -import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.util.ControlledClock; -import org.apache.hadoop.yarn.util.ResourceCalculatorProcessTree; -import org.junit.Assert; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.stream.Collectors; + +import org.junit.After; +import org.junit.Before; import org.junit.Test; -import java.io.File; -import java.nio.charset.StandardCharsets; +import org.apache.commons.io.FileUtils; +import org.apache.hadoop.util.CpuTimeTracker; +import org.apache.hadoop.yarn.exceptions.YarnException; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Unit test for CGroupsResourceCalculator. */ public class TestCGroupsResourceCalculator { - private ControlledClock clock = new ControlledClock(); - private CGroupsHandler cGroupsHandler = mock(CGroupsHandler.class); - private String basePath = "/tmp/" + this.getClass().getName(); + private Path root; - public TestCGroupsResourceCalculator() { - when(cGroupsHandler.getRelativePathForCGroup("container_1")) - .thenReturn("/yarn/container_1"); - when(cGroupsHandler.getRelativePathForCGroup("")).thenReturn("/yarn/"); + @Before + public void before() throws IOException { + root = Files.createTempDirectory("TestCGroupsResourceCalculator"); + } + + @After + public void after() throws IOException { + FileUtils.deleteDirectory(root.toFile()); } - @Test(expected = YarnException.class) + @Test(expected = IOException.class) public void testPidNotFound() throws Exception { - CGroupsResourceCalculator calculator = - new CGroupsResourceCalculator( - "1234", ".", cGroupsHandler, clock, 10); + CGroupsResourceCalculator calculator = createCalculator(); calculator.setCGroupFilePaths(); - Assert.assertEquals("Expected exception", null, calculator); } - @Test(expected = YarnException.class) + @Test public void testNoMemoryCGgroupMount() throws Exception { - File procfs = new File(basePath + "/1234"); - Assert.assertTrue("Setup error", procfs.mkdirs()); + writeToFile("proc/41/cgroup", + "7:devices:/yarn/container_1", + "6:cpuacct,cpu:/yarn/container_1", + "5:pids:/yarn/container_1" + ); + + CGroupsResourceCalculator calculator = createCalculator(); try { - FileUtils.writeStringToFile( - new File(procfs, CGroupsResourceCalculator.CGROUP), - "7:devices:/yarn/container_1\n" + - "6:cpuacct,cpu:/yarn/container_1\n" + - "5:pids:/yarn/container_1\n", StandardCharsets.UTF_8); - CGroupsResourceCalculator calculator = - new CGroupsResourceCalculator( - "1234", basePath, - cGroupsHandler, clock, 10); calculator.setCGroupFilePaths(); - Assert.assertEquals("Expected exception", null, calculator); - } finally { - FileUtils.deleteDirectory(new File(basePath)); + fail("No exception was thrown"); + } catch (YarnException e) { + assertEquals("Controller MEMORY not found for 41 pid", e.getMessage()); Review Comment: Nit: it might be a bit more developer friendly to assert a contains(MEMORY) and contains(pid), I wouldn't expect test failures for message wording changes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org