Repository: hadoop Updated Branches: refs/heads/trunk 41b3603b5 -> 5085e5fa9
YARN-8759. Copy of resource-types.xml is not deleted if test fails, causes other test failures. Contributed by Antal Bálint Steinbach. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/5085e5fa Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/5085e5fa Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/5085e5fa Branch: refs/heads/trunk Commit: 5085e5fa9e8c7e489a8518e8541c12b14f3651df Parents: 41b3603 Author: Sunil G <sun...@apache.org> Authored: Wed Oct 17 16:05:08 2018 +0530 Committer: Sunil G <sun...@apache.org> Committed: Wed Oct 17 16:05:08 2018 +0530 ---------------------------------------------------------------------- .../yarn/util/resource/TestResourceUtils.java | 51 ++++++++------------ .../resourcemanager/TestClientRMService.java | 17 ++++--- 2 files changed, 32 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/5085e5fa/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java ---------------------------------------------------------------------- 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 9b48017..c96982d 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,9 @@ import java.util.Map; */ public class TestResourceUtils { + private File nodeResourcesFile; + private File resourceTypesFile; + static class ResourceFileInformation { String filename; int resourceCount; @@ -75,12 +78,11 @@ public class TestResourceUtils { @After public void teardown() { - Configuration conf = new YarnConfiguration(); - File source = new File( - conf.getClassLoader().getResource("resource-types-1.xml").getFile()); - File dest = new File(source.getParent(), "resource-types.xml"); - if (dest.exists()) { - dest.delete(); + if(nodeResourcesFile != null && nodeResourcesFile.exists()) { + nodeResourcesFile.delete(); + } + if(resourceTypesFile != null && resourceTypesFile.exists()) { + resourceTypesFile.delete(); } } @@ -136,8 +138,8 @@ public class TestResourceUtils { File source = new File( conf.getClassLoader().getResource(testInformation.filename) .getFile()); - File dest = new File(source.getParent(), "resource-types.xml"); - FileUtils.copyFile(source, dest); + resourceTypesFile = new File(source.getParent(), "resource-types.xml"); + FileUtils.copyFile(source, resourceTypesFile); res = ResourceUtils.getResourceTypes(); testMemoryAndVcores(res); Assert.assertEquals(testInformation.resourceCount, res.size()); @@ -148,7 +150,6 @@ public class TestResourceUtils { res.containsKey(resourceName)); Assert.assertEquals(entry.getValue(), res.get(resourceName).getUnits()); } - dest.delete(); } } @@ -161,20 +162,17 @@ public class TestResourceUtils { "resource-types-error-4.xml"}; for (String resourceFile : resourceFiles) { ResourceUtils.resetResourceTypes(); - File dest = null; try { File source = new File(conf.getClassLoader().getResource(resourceFile).getFile()); - dest = new File(source.getParent(), "resource-types.xml"); - FileUtils.copyFile(source, dest); + resourceTypesFile = new File(source.getParent(), "resource-types.xml"); + FileUtils.copyFile(source, resourceTypesFile); ResourceUtils.getResourceTypes(); Assert.fail("Expected error with file " + resourceFile); } catch (NullPointerException ne) { throw ne; } catch (Exception e) { - if (dest != null) { - dest.delete(); - } + //Test passed } } } @@ -275,7 +273,7 @@ public class TestResourceUtils { ResourceUtils.initializeResourcesMap(conf); Assert.fail("resource map initialization should fail"); } catch (Exception e) { - // do nothing + //Test passed } } } @@ -299,11 +297,10 @@ public class TestResourceUtils { for (Map.Entry<String, Resource> 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<String, ResourceInformation> actual = ResourceUtils .getNodeResourceInformation(conf); Assert.assertEquals(actual.size(), @@ -311,7 +308,6 @@ public class TestResourceUtils { for (ResourceInformation resInfo : entry.getValue().getResources()) { Assert.assertEquals(resInfo, actual.get(resInfo.getName())); } - dest.delete(); } } @@ -324,19 +320,16 @@ public class TestResourceUtils { 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<String, ResourceInformation> actual = ResourceUtils.getNodeResourceInformation(conf); Assert.fail("Expected error with file " + resourceFile); } catch (NullPointerException ne) { throw ne; } catch (Exception e) { - if (dest != null) { - dest.delete(); - } + //Test passed } } } @@ -401,11 +394,10 @@ public class TestResourceUtils { for (Map.Entry<String, Resource> 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<String, ResourceInformation> actual = ResourceUtils .getNodeResourceInformation(conf); Assert.assertEquals(actual.size(), @@ -413,7 +405,6 @@ public class TestResourceUtils { for (ResourceInformation resInfo : entry.getValue().getResources()) { Assert.assertEquals(resInfo, actual.get(resInfo.getName())); } - dest.delete(); } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/5085e5fa/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java ---------------------------------------------------------------------- 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 3fe46b1..0784d1e 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 @@ -174,6 +174,7 @@ import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; 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; @@ -194,6 +195,7 @@ public class TestClientRMService { 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 { @@ -2492,12 +2494,12 @@ public class TestClientRMService { 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( @@ -2566,9 +2568,12 @@ public class TestClientRMService { rpc.stopProxy(client, conf); rm.close(); + } - if (dest.exists()) { - dest.delete(); + @After + public void tearDown(){ + if (resourceTypesFile != null && resourceTypesFile.exists()) { + resourceTypesFile.delete(); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org