YARN-8759. Copy of resource-types.xml is not deleted if test fails, causes other test failures. Contributed by Antal Bálint Steinbach.
This commit is contained in:
parent
41b3603b5b
commit
5085e5fa9e
@ -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<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 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<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 void testGetResourceInformationWithDiffUnits() throws Exception {
|
||||
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 void testGetResourceInformationWithDiffUnits() throws Exception {
|
||||
for (ResourceInformation resInfo : entry.getValue().getResources()) {
|
||||
Assert.assertEquals(resInfo, actual.get(resInfo.getName()));
|
||||
}
|
||||
dest.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user