diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java index 9b480177075..d6941ed5b51 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java @@ -39,6 +39,8 @@ */ public class TestResourceUtils { + private File nodeResourcesFile; + static class ResourceFileInformation { String filename; int resourceCount; @@ -82,6 +84,9 @@ public void teardown() { if (dest.exists()) { dest.delete(); } + if(nodeResourcesFile != null && nodeResourcesFile.exists()) { + nodeResourcesFile.delete(); + } } private void testMemoryAndVcores(Map res) { @@ -299,11 +304,10 @@ public void testGetResourceInformation() throws Exception { for (Map.Entry entry : testRun.entrySet()) { String resourceFile = entry.getKey(); ResourceUtils.resetNodeResources(); - File dest; File source = new File( conf.getClassLoader().getResource(resourceFile).getFile()); - dest = new File(source.getParent(), "node-resources.xml"); - FileUtils.copyFile(source, dest); + nodeResourcesFile = new File(source.getParent(), "node-resources.xml"); + FileUtils.copyFile(source, nodeResourcesFile); Map actual = ResourceUtils .getNodeResourceInformation(conf); Assert.assertEquals(actual.size(), @@ -311,7 +315,7 @@ public void testGetResourceInformation() throws Exception { for (ResourceInformation resInfo : entry.getValue().getResources()) { Assert.assertEquals(resInfo, actual.get(resInfo.getName())); } - dest.delete(); + nodeResourcesFile.delete(); } } @@ -324,18 +328,17 @@ public void testGetNodeResourcesConfigErrors() throws Exception { for (String resourceFile : invalidNodeResFiles) { ResourceUtils.resetNodeResources(); - File dest = null; try { File source = new File(conf.getClassLoader().getResource(resourceFile).getFile()); - dest = new File(source.getParent(), "node-resources.xml"); - FileUtils.copyFile(source, dest); + nodeResourcesFile = new File(source.getParent(), "node-resources.xml"); + FileUtils.copyFile(source, nodeResourcesFile); Map actual = ResourceUtils.getNodeResourceInformation(conf); Assert.fail("Expected error with file " + resourceFile); } catch (NullPointerException ne) { throw ne; } catch (Exception e) { - if (dest != null) { - dest.delete(); + if (nodeResourcesFile != null) { + nodeResourcesFile.delete(); } } } @@ -401,11 +404,10 @@ public void testGetResourceInformationWithDiffUnits() throws Exception { for (Map.Entry entry : testRun.entrySet()) { String resourceFile = entry.getKey(); ResourceUtils.resetNodeResources(); - File dest; File source = new File( conf.getClassLoader().getResource(resourceFile).getFile()); - dest = new File(source.getParent(), "node-resources.xml"); - FileUtils.copyFile(source, dest); + nodeResourcesFile = new File(source.getParent(), "node-resources.xml"); + FileUtils.copyFile(source, nodeResourcesFile); Map actual = ResourceUtils .getNodeResourceInformation(conf); Assert.assertEquals(actual.size(), @@ -413,7 +415,7 @@ public void testGetResourceInformationWithDiffUnits() throws Exception { for (ResourceInformation resInfo : entry.getValue().getResources()) { Assert.assertEquals(resInfo, actual.get(resInfo.getName())); } - dest.delete(); + nodeResourcesFile.delete(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java index 6644e44453d..86bcd5005d2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java @@ -163,6 +163,7 @@ import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceUtils; import org.apache.hadoop.yarn.util.resource.Resources; +import org.junit.After; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; @@ -183,6 +184,7 @@ private final static String QUEUE_1 = "Q-1"; private final static String QUEUE_2 = "Q-2"; + private File resourceTypesFile = null; @Test public void testGetDecommissioningClusterNodes() throws Exception { @@ -2252,12 +2254,12 @@ public void handle(Event event) { public void testRegisterNMWithDiffUnits() throws Exception { ResourceUtils.resetResourceTypes(); Configuration yarnConf = new YarnConfiguration(); - String resourceTypesFile = "resource-types-4.xml"; + String resourceTypesFileName = "resource-types-4.xml"; InputStream source = - yarnConf.getClassLoader().getResourceAsStream(resourceTypesFile); - File dest = new File(yarnConf.getClassLoader(). + yarnConf.getClassLoader().getResourceAsStream(resourceTypesFileName); + resourceTypesFile = new File(yarnConf.getClassLoader(). getResource(".").getPath(), "resource-types.xml"); - FileUtils.copyInputStreamToFile(source, dest); + FileUtils.copyInputStreamToFile(source, resourceTypesFile); ResourceUtils.getResourceTypes(); yarnConf.setClass( @@ -2326,9 +2328,13 @@ protected ClientRMService createClientRMService() { rpc.stopProxy(client, conf); rm.close(); + } - if (dest.exists()) { - dest.delete(); + @After + public void tearDown(){ + if (resourceTypesFile != null && resourceTypesFile.exists()) { + resourceTypesFile.delete(); + resourceTypesFile = null; } } }