YARN-9356. Add more tests to ratio method in TestResourceCalculator. Contributed by Zoltan Siegl
This commit is contained in:
parent
be901f4962
commit
35f093f5b3
@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class TestResourceCalculator {
|
public class TestResourceCalculator {
|
||||||
|
private static final String EXTRA_RESOURCE_NAME = "test";
|
||||||
|
|
||||||
private final ResourceCalculator resourceCalculator;
|
private final ResourceCalculator resourceCalculator;
|
||||||
|
|
||||||
@Parameterized.Parameters(name = "{0}")
|
@Parameterized.Parameters(name = "{0}")
|
||||||
@ -55,7 +57,7 @@ public void setupNoExtraResource() {
|
|||||||
private static void setupExtraResource() {
|
private static void setupExtraResource() {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
|
|
||||||
conf.set(YarnConfiguration.RESOURCE_TYPES, "test");
|
conf.set(YarnConfiguration.RESOURCE_TYPES, EXTRA_RESOURCE_NAME);
|
||||||
ResourceUtils.resetResourceTypes(conf);
|
ResourceUtils.resetResourceTypes(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +99,10 @@ private Resource newResource(long memory, int cpu) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Resource newResource(long memory, int cpu, int test) {
|
private Resource newResource(long memory, int cpu, int extraResource) {
|
||||||
Resource res = newResource(memory, cpu);
|
Resource res = newResource(memory, cpu);
|
||||||
|
|
||||||
res.setResourceValue("test", test);
|
res.setResourceValue(EXTRA_RESOURCE_NAME, extraResource);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -548,4 +550,43 @@ public void testFitsInDiagnosticsCollector() {
|
|||||||
newResource(1, 1)));
|
newResource(1, 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRatioWithNoExtraResource() {
|
||||||
|
//setup
|
||||||
|
Resource resource1 = newResource(1, 1);
|
||||||
|
Resource resource2 = newResource(2, 1);
|
||||||
|
|
||||||
|
//act
|
||||||
|
float ratio = resourceCalculator.ratio(resource1, resource2);
|
||||||
|
|
||||||
|
//assert
|
||||||
|
if (resourceCalculator instanceof DefaultResourceCalculator) {
|
||||||
|
double ratioOfMemories = 0.5;
|
||||||
|
assertEquals(ratioOfMemories, ratio, 0.00001);
|
||||||
|
} else if (resourceCalculator instanceof DominantResourceCalculator) {
|
||||||
|
double ratioOfCPUs = 1.0;
|
||||||
|
assertEquals(ratioOfCPUs, ratio, 0.00001);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRatioWithExtraResource() {
|
||||||
|
//setup
|
||||||
|
setupExtraResource();
|
||||||
|
Resource resource1 = newResource(1, 1, 2);
|
||||||
|
Resource resource2 = newResource(2, 1, 1);
|
||||||
|
|
||||||
|
//act
|
||||||
|
float ratio = resourceCalculator.ratio(resource1, resource2);
|
||||||
|
|
||||||
|
//assert
|
||||||
|
if (resourceCalculator instanceof DefaultResourceCalculator) {
|
||||||
|
double ratioOfMemories = 0.5;
|
||||||
|
assertEquals(ratioOfMemories, ratio, 0.00001);
|
||||||
|
} else if (resourceCalculator instanceof DominantResourceCalculator) {
|
||||||
|
double ratioOfExtraResources = 2.0;
|
||||||
|
assertEquals(ratioOfExtraResources, ratio, 0.00001);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user