From 5085e5fa9e8c7e489a8518e8541c12b14f3651df Mon Sep 17 00:00:00 2001 From: Sunil G Date: Wed, 17 Oct 2018 16:05:08 +0530 Subject: [PATCH] =?UTF-8?q?YARN-8759.=20Copy=20of=20resource-types.xml=20i?= =?UTF-8?q?s=20not=20deleted=20if=20test=20fails,=20causes=20other=20test?= =?UTF-8?q?=20failures.=20Contributed=20by=20Antal=20B=C3=A1lint=20Steinba?= =?UTF-8?q?ch.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yarn/util/resource/TestResourceUtils.java | 51 ++++++++----------- .../resourcemanager/TestClientRMService.java | 17 ++++--- 2 files changed, 32 insertions(+), 36 deletions(-) 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 9b48017707..c96982df77 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 @@ */ public class TestResourceUtils { + private File nodeResourcesFile; + private File resourceTypesFile; + static class ResourceFileInformation { String filename; int resourceCount; @@ -75,12 +78,11 @@ public void setup() { @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 void testGetResourceTypesConfigs() throws Exception { 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 void testGetResourceTypesConfigs() throws Exception { res.containsKey(resourceName)); Assert.assertEquals(entry.getValue(), res.get(resourceName).getUnits()); } - dest.delete(); } } @@ -161,20 +162,17 @@ public void testGetResourceTypesConfigErrors() throws Exception { "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 void testInitializeResourcesMapErrors() throws Exception { ResourceUtils.initializeResourcesMap(conf); Assert.fail("resource map initialization should fail"); } catch (Exception e) { - // do nothing + //Test passed } } } @@ -299,11 +297,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 +308,6 @@ public void testGetResourceInformation() throws Exception { for (ResourceInformation resInfo : entry.getValue().getResources()) { Assert.assertEquals(resInfo, actual.get(resInfo.getName())); } - dest.delete(); } } @@ -324,19 +320,16 @@ 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(); - } + //Test passed } } } @@ -401,11 +394,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 +405,6 @@ public void testGetResourceInformationWithDiffUnits() throws Exception { for (ResourceInformation resInfo : entry.getValue().getResources()) { Assert.assertEquals(resInfo, actual.get(resInfo.getName())); } - dest.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 3fe46b1f60..0784d1e500 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.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 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( @@ -2566,9 +2568,12 @@ 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(); } } }