YARN-8943. Upgrade JUnit from 4 to 5 in hadoop-yarn-api.
Signed-off-by: Takanobu Asanuma <tasanuma@apache.org>
This commit is contained in:
parent
b1120d27ab
commit
c65218ee8e
@ -72,6 +72,27 @@
|
|||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Only required to run tests in an IDE that bundles an older version -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-launcher</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
|
@ -17,27 +17,29 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.yarn.api.records;
|
package org.apache.hadoop.yarn.api.records;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class to test {@link Resource}.
|
* The class to test {@link Resource}.
|
||||||
*/
|
*/
|
||||||
public class TestResource {
|
class TestResource {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCastToIntSafely() {
|
void testCastToIntSafely() {
|
||||||
assertEquals(0, Resource.castToIntSafely(0));
|
assertEquals(0, Resource.castToIntSafely(0));
|
||||||
assertEquals(1, Resource.castToIntSafely(1));
|
assertEquals(1, Resource.castToIntSafely(1));
|
||||||
assertEquals(Integer.MAX_VALUE,
|
assertEquals(Integer.MAX_VALUE,
|
||||||
Resource.castToIntSafely(Integer.MAX_VALUE));
|
Resource.castToIntSafely(Integer.MAX_VALUE));
|
||||||
|
|
||||||
assertEquals("Cast to Integer.MAX_VALUE if the long is greater than "
|
assertEquals(Integer.MAX_VALUE,
|
||||||
+ "Integer.MAX_VALUE", Integer.MAX_VALUE,
|
Resource.castToIntSafely(Integer.MAX_VALUE + 1L),
|
||||||
Resource.castToIntSafely(Integer.MAX_VALUE + 1L));
|
"Cast to Integer.MAX_VALUE if the long is greater than "
|
||||||
assertEquals("Cast to Integer.MAX_VALUE if the long is greater than "
|
+ "Integer.MAX_VALUE");
|
||||||
+ "Integer.MAX_VALUE", Integer.MAX_VALUE,
|
assertEquals(Integer.MAX_VALUE,
|
||||||
Resource.castToIntSafely(Long.MAX_VALUE));
|
Resource.castToIntSafely(Long.MAX_VALUE),
|
||||||
|
"Cast to Integer.MAX_VALUE if the long is greater than "
|
||||||
|
+ "Integer.MAX_VALUE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,19 +17,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.yarn.api.records;
|
package org.apache.hadoop.yarn.api.records;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||||
import org.apache.hadoop.yarn.factories.RecordFactory;
|
import org.apache.hadoop.yarn.factories.RecordFactory;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/** Test for the URL class. */
|
/** Test for the URL class. */
|
||||||
public class TestURL {
|
class TestURL {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConversion() throws Exception {
|
void testConversion() throws Exception {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.set(YarnConfiguration.IPC_RECORD_FACTORY_CLASS,
|
conf.set(YarnConfiguration.IPC_RECORD_FACTORY_CLASS,
|
||||||
RecordFactoryForTest.class.getName());
|
RecordFactoryForTest.class.getName());
|
||||||
|
@ -18,18 +18,18 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.yarn.api.records.timelineservice;
|
package org.apache.hadoop.yarn.api.records.timelineservice;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Various tests for the ApplicationEntity class.
|
* Various tests for the ApplicationEntity class.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TestApplicationEntity {
|
class TestApplicationEntity {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsApplicationEntity() {
|
void testIsApplicationEntity() {
|
||||||
TimelineEntity te = new TimelineEntity();
|
TimelineEntity te = new TimelineEntity();
|
||||||
te.setType(TimelineEntityType.YARN_APPLICATION.toString());
|
te.setType(TimelineEntityType.YARN_APPLICATION.toString());
|
||||||
assertTrue(ApplicationEntity.isApplicationEntity(te));
|
assertTrue(ApplicationEntity.isApplicationEntity(te));
|
||||||
@ -43,7 +43,7 @@ public void testIsApplicationEntity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetApplicationEvent() {
|
void testGetApplicationEvent() {
|
||||||
TimelineEntity te = null;
|
TimelineEntity te = null;
|
||||||
TimelineEvent tEvent = ApplicationEntity.getApplicationEvent(te,
|
TimelineEvent tEvent = ApplicationEntity.getApplicationEvent(te,
|
||||||
"no event");
|
"no event");
|
||||||
|
@ -17,20 +17,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.yarn.api.records.timelineservice;
|
package org.apache.hadoop.yarn.api.records.timelineservice;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric.Type;
|
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric.Type;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestTimelineMetric {
|
class TestTimelineMetric {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTimelineMetricAggregation() {
|
void testTimelineMetricAggregation() {
|
||||||
long ts = System.currentTimeMillis();
|
long ts = System.currentTimeMillis();
|
||||||
// single_value metric add against null metric
|
// single_value metric add against null metric
|
||||||
TimelineMetric m1 = getSingleValueMetric("MEGA_BYTES_MILLIS",
|
TimelineMetric m1 = getSingleValueMetric("MEGA_BYTES_MILLIS",
|
||||||
|
@ -49,17 +49,19 @@
|
|||||||
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.targetNodeAttribute;
|
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.targetNodeAttribute;
|
||||||
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.targetNotIn;
|
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.targetNotIn;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test placement constraint parser.
|
* Class to test placement constraint parser.
|
||||||
*/
|
*/
|
||||||
public class TestPlacementConstraintParser {
|
class TestPlacementConstraintParser {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTargetExpressionParser()
|
void testTargetExpressionParser() throws PlacementConstraintParseException {
|
||||||
throws PlacementConstraintParseException {
|
|
||||||
String expressionStr;
|
String expressionStr;
|
||||||
ConstraintParser parser;
|
ConstraintParser parser;
|
||||||
AbstractConstraint constraint;
|
AbstractConstraint constraint;
|
||||||
@ -70,22 +72,22 @@ public void testTargetExpressionParser()
|
|||||||
expressionStr = "NOTIN, NODE, foo";
|
expressionStr = "NOTIN, NODE, foo";
|
||||||
parser = new TargetConstraintParser(expressionStr);
|
parser = new TargetConstraintParser(expressionStr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof SingleConstraint);
|
assertTrue(constraint instanceof SingleConstraint);
|
||||||
single = (SingleConstraint) constraint;
|
single = (SingleConstraint) constraint;
|
||||||
Assert.assertEquals("node", single.getScope());
|
assertEquals("node", single.getScope());
|
||||||
Assert.assertEquals(0, single.getMinCardinality());
|
assertEquals(0, single.getMinCardinality());
|
||||||
Assert.assertEquals(0, single.getMaxCardinality());
|
assertEquals(0, single.getMaxCardinality());
|
||||||
verifyConstraintToString(expressionStr, constraint);
|
verifyConstraintToString(expressionStr, constraint);
|
||||||
|
|
||||||
// lower cases is also valid
|
// lower cases is also valid
|
||||||
expressionStr = "notin, node, foo";
|
expressionStr = "notin, node, foo";
|
||||||
parser = new TargetConstraintParser(expressionStr);
|
parser = new TargetConstraintParser(expressionStr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof SingleConstraint);
|
assertTrue(constraint instanceof SingleConstraint);
|
||||||
single = (SingleConstraint) constraint;
|
single = (SingleConstraint) constraint;
|
||||||
Assert.assertEquals("node", single.getScope());
|
assertEquals("node", single.getScope());
|
||||||
Assert.assertEquals(0, single.getMinCardinality());
|
assertEquals(0, single.getMinCardinality());
|
||||||
Assert.assertEquals(0, single.getMaxCardinality());
|
assertEquals(0, single.getMaxCardinality());
|
||||||
verifyConstraintToString(expressionStr, constraint);
|
verifyConstraintToString(expressionStr, constraint);
|
||||||
|
|
||||||
// Affinity with single target tag
|
// Affinity with single target tag
|
||||||
@ -93,11 +95,11 @@ public void testTargetExpressionParser()
|
|||||||
expressionStr = "IN, NODE, foo";
|
expressionStr = "IN, NODE, foo";
|
||||||
parser = new TargetConstraintParser(expressionStr);
|
parser = new TargetConstraintParser(expressionStr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof SingleConstraint);
|
assertTrue(constraint instanceof SingleConstraint);
|
||||||
single = (SingleConstraint) constraint;
|
single = (SingleConstraint) constraint;
|
||||||
Assert.assertEquals("node", single.getScope());
|
assertEquals("node", single.getScope());
|
||||||
Assert.assertEquals(1, single.getMinCardinality());
|
assertEquals(1, single.getMinCardinality());
|
||||||
Assert.assertEquals(Integer.MAX_VALUE, single.getMaxCardinality());
|
assertEquals(Integer.MAX_VALUE, single.getMaxCardinality());
|
||||||
verifyConstraintToString(expressionStr, constraint);
|
verifyConstraintToString(expressionStr, constraint);
|
||||||
|
|
||||||
// Anti-affinity with multiple target tags
|
// Anti-affinity with multiple target tags
|
||||||
@ -105,17 +107,17 @@ public void testTargetExpressionParser()
|
|||||||
expressionStr = "NOTIN, NODE, foo, bar, exp";
|
expressionStr = "NOTIN, NODE, foo, bar, exp";
|
||||||
parser = new TargetConstraintParser(expressionStr);
|
parser = new TargetConstraintParser(expressionStr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof SingleConstraint);
|
assertTrue(constraint instanceof SingleConstraint);
|
||||||
single = (SingleConstraint) constraint;
|
single = (SingleConstraint) constraint;
|
||||||
Assert.assertEquals("node", single.getScope());
|
assertEquals("node", single.getScope());
|
||||||
Assert.assertEquals(0, single.getMinCardinality());
|
assertEquals(0, single.getMinCardinality());
|
||||||
Assert.assertEquals(0, single.getMaxCardinality());
|
assertEquals(0, single.getMaxCardinality());
|
||||||
Assert.assertEquals(3, single.getTargetExpressions().size());
|
assertEquals(3, single.getTargetExpressions().size());
|
||||||
Set<TargetExpression> expectedTargetExpressions = Sets.newHashSet(
|
Set<TargetExpression> expectedTargetExpressions = Sets.newHashSet(
|
||||||
PlacementTargets.allocationTag("foo"),
|
PlacementTargets.allocationTag("foo"),
|
||||||
PlacementTargets.allocationTag("bar"),
|
PlacementTargets.allocationTag("bar"),
|
||||||
PlacementTargets.allocationTag("exp"));
|
PlacementTargets.allocationTag("exp"));
|
||||||
Assert.assertTrue(Sets.difference(expectedTargetExpressions,
|
assertTrue(Sets.difference(expectedTargetExpressions,
|
||||||
single.getTargetExpressions()).isEmpty());
|
single.getTargetExpressions()).isEmpty());
|
||||||
verifyConstraintToString(expressionStr, constraint);
|
verifyConstraintToString(expressionStr, constraint);
|
||||||
|
|
||||||
@ -124,13 +126,13 @@ public void testTargetExpressionParser()
|
|||||||
try {
|
try {
|
||||||
parser.parse();
|
parser.parse();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assert.assertTrue(e instanceof PlacementConstraintParseException);
|
assertTrue(e instanceof PlacementConstraintParseException);
|
||||||
Assert.assertTrue(e.getMessage().contains("expecting in or notin"));
|
assertTrue(e.getMessage().contains("expecting in or notin"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCardinalityConstraintParser()
|
void testCardinalityConstraintParser()
|
||||||
throws PlacementConstraintParseException {
|
throws PlacementConstraintParseException {
|
||||||
String expressionExpr;
|
String expressionExpr;
|
||||||
ConstraintParser parser;
|
ConstraintParser parser;
|
||||||
@ -141,34 +143,34 @@ public void testCardinalityConstraintParser()
|
|||||||
expressionExpr = "cardinality, NODE, foo, 0, 1";
|
expressionExpr = "cardinality, NODE, foo, 0, 1";
|
||||||
parser = new CardinalityConstraintParser(expressionExpr);
|
parser = new CardinalityConstraintParser(expressionExpr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof SingleConstraint);
|
assertTrue(constraint instanceof SingleConstraint);
|
||||||
single = (SingleConstraint) constraint;
|
single = (SingleConstraint) constraint;
|
||||||
Assert.assertEquals("node", single.getScope());
|
assertEquals("node", single.getScope());
|
||||||
Assert.assertEquals(0, single.getMinCardinality());
|
assertEquals(0, single.getMinCardinality());
|
||||||
Assert.assertEquals(1, single.getMaxCardinality());
|
assertEquals(1, single.getMaxCardinality());
|
||||||
Assert.assertEquals(1, single.getTargetExpressions().size());
|
assertEquals(1, single.getTargetExpressions().size());
|
||||||
TargetExpression exp =
|
TargetExpression exp =
|
||||||
single.getTargetExpressions().iterator().next();
|
single.getTargetExpressions().iterator().next();
|
||||||
Assert.assertEquals("ALLOCATION_TAG", exp.getTargetType().toString());
|
assertEquals("ALLOCATION_TAG", exp.getTargetType().toString());
|
||||||
Assert.assertEquals(1, exp.getTargetValues().size());
|
assertEquals(1, exp.getTargetValues().size());
|
||||||
Assert.assertEquals("foo", exp.getTargetValues().iterator().next());
|
assertEquals("foo", exp.getTargetValues().iterator().next());
|
||||||
verifyConstraintToString(expressionExpr, constraint);
|
verifyConstraintToString(expressionExpr, constraint);
|
||||||
|
|
||||||
// cardinality,NODE,foo,bar,moo,0,1
|
// cardinality,NODE,foo,bar,moo,0,1
|
||||||
expressionExpr = "cardinality,RACK,foo,bar,moo,0,1";
|
expressionExpr = "cardinality,RACK,foo,bar,moo,0,1";
|
||||||
parser = new CardinalityConstraintParser(expressionExpr);
|
parser = new CardinalityConstraintParser(expressionExpr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof SingleConstraint);
|
assertTrue(constraint instanceof SingleConstraint);
|
||||||
single = (SingleConstraint) constraint;
|
single = (SingleConstraint) constraint;
|
||||||
Assert.assertEquals("rack", single.getScope());
|
assertEquals("rack", single.getScope());
|
||||||
Assert.assertEquals(0, single.getMinCardinality());
|
assertEquals(0, single.getMinCardinality());
|
||||||
Assert.assertEquals(1, single.getMaxCardinality());
|
assertEquals(1, single.getMaxCardinality());
|
||||||
Assert.assertEquals(3, single.getTargetExpressions().size());
|
assertEquals(3, single.getTargetExpressions().size());
|
||||||
Set<TargetExpression> expectedTargetExpressions = Sets.newHashSet(
|
Set<TargetExpression> expectedTargetExpressions = Sets.newHashSet(
|
||||||
PlacementTargets.allocationTag("foo"),
|
PlacementTargets.allocationTag("foo"),
|
||||||
PlacementTargets.allocationTag("bar"),
|
PlacementTargets.allocationTag("bar"),
|
||||||
PlacementTargets.allocationTag("moo"));
|
PlacementTargets.allocationTag("moo"));
|
||||||
Assert.assertTrue(Sets.difference(expectedTargetExpressions,
|
assertTrue(Sets.difference(expectedTargetExpressions,
|
||||||
single.getTargetExpressions()).isEmpty());
|
single.getTargetExpressions()).isEmpty());
|
||||||
verifyConstraintToString(expressionExpr, constraint);
|
verifyConstraintToString(expressionExpr, constraint);
|
||||||
|
|
||||||
@ -177,9 +179,9 @@ public void testCardinalityConstraintParser()
|
|||||||
parser = new CardinalityConstraintParser(
|
parser = new CardinalityConstraintParser(
|
||||||
"cardinality,NOWHERE,foo,bar,moo,0,1");
|
"cardinality,NOWHERE,foo,bar,moo,0,1");
|
||||||
parser.parse();
|
parser.parse();
|
||||||
Assert.fail("Expecting a parsing failure!");
|
fail("Expecting a parsing failure!");
|
||||||
} catch (PlacementConstraintParseException e) {
|
} catch (PlacementConstraintParseException e) {
|
||||||
Assert.assertTrue(e.getMessage()
|
assertTrue(e.getMessage()
|
||||||
.contains("expecting scope to node or rack, but met NOWHERE"));
|
.contains("expecting scope to node or rack, but met NOWHERE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,15 +190,15 @@ public void testCardinalityConstraintParser()
|
|||||||
parser = new CardinalityConstraintParser(
|
parser = new CardinalityConstraintParser(
|
||||||
"cardinality,NODE,0,1");
|
"cardinality,NODE,0,1");
|
||||||
parser.parse();
|
parser.parse();
|
||||||
Assert.fail("Expecting a parsing failure!");
|
fail("Expecting a parsing failure!");
|
||||||
} catch (PlacementConstraintParseException e) {
|
} catch (PlacementConstraintParseException e) {
|
||||||
Assert.assertTrue(e.getMessage()
|
assertTrue(e.getMessage()
|
||||||
.contains("at least 5 elements, but only 4 is given"));
|
.contains("at least 5 elements, but only 4 is given"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAndConstraintParser()
|
void testAndConstraintParser()
|
||||||
throws PlacementConstraintParseException {
|
throws PlacementConstraintParseException {
|
||||||
String expressionExpr;
|
String expressionExpr;
|
||||||
ConstraintParser parser;
|
ConstraintParser parser;
|
||||||
@ -206,33 +208,33 @@ public void testAndConstraintParser()
|
|||||||
expressionExpr = "AND(NOTIN,NODE,foo:NOTIN,NODE,bar)";
|
expressionExpr = "AND(NOTIN,NODE,foo:NOTIN,NODE,bar)";
|
||||||
parser = new ConjunctionConstraintParser(expressionExpr);
|
parser = new ConjunctionConstraintParser(expressionExpr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof And);
|
assertTrue(constraint instanceof And);
|
||||||
and = (And) constraint;
|
and = (And) constraint;
|
||||||
Assert.assertEquals(2, and.getChildren().size());
|
assertEquals(2, and.getChildren().size());
|
||||||
verifyConstraintToString(expressionExpr, constraint);
|
verifyConstraintToString(expressionExpr, constraint);
|
||||||
|
|
||||||
expressionExpr = "AND(NOTIN,NODE,foo:cardinality,NODE,foo,0,1)";
|
expressionExpr = "AND(NOTIN,NODE,foo:cardinality,NODE,foo,0,1)";
|
||||||
parser = new ConjunctionConstraintParser(expressionExpr);
|
parser = new ConjunctionConstraintParser(expressionExpr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof And);
|
assertTrue(constraint instanceof And);
|
||||||
Assert.assertEquals(2, and.getChildren().size());
|
assertEquals(2, and.getChildren().size());
|
||||||
verifyConstraintToString(expressionExpr, constraint);
|
verifyConstraintToString(expressionExpr, constraint);
|
||||||
|
|
||||||
expressionExpr =
|
expressionExpr =
|
||||||
"AND(NOTIN,NODE,foo:AND(NOTIN,NODE,foo:cardinality,NODE,foo,0,1))";
|
"AND(NOTIN,NODE,foo:AND(NOTIN,NODE,foo:cardinality,NODE,foo,0,1))";
|
||||||
parser = new ConjunctionConstraintParser(expressionExpr);
|
parser = new ConjunctionConstraintParser(expressionExpr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof And);
|
assertTrue(constraint instanceof And);
|
||||||
and = (And) constraint;
|
and = (And) constraint;
|
||||||
Assert.assertTrue(and.getChildren().get(0) instanceof SingleConstraint);
|
assertTrue(and.getChildren().get(0) instanceof SingleConstraint);
|
||||||
Assert.assertTrue(and.getChildren().get(1) instanceof And);
|
assertTrue(and.getChildren().get(1) instanceof And);
|
||||||
and = (And) and.getChildren().get(1);
|
and = (And) and.getChildren().get(1);
|
||||||
Assert.assertEquals(2, and.getChildren().size());
|
assertEquals(2, and.getChildren().size());
|
||||||
verifyConstraintToString(expressionExpr, constraint);
|
verifyConstraintToString(expressionExpr, constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrConstraintParser()
|
void testOrConstraintParser()
|
||||||
throws PlacementConstraintParseException {
|
throws PlacementConstraintParseException {
|
||||||
String expressionExpr;
|
String expressionExpr;
|
||||||
ConstraintParser parser;
|
ConstraintParser parser;
|
||||||
@ -242,33 +244,33 @@ public void testOrConstraintParser()
|
|||||||
expressionExpr = "OR(NOTIN,NODE,foo:NOTIN,NODE,bar)";
|
expressionExpr = "OR(NOTIN,NODE,foo:NOTIN,NODE,bar)";
|
||||||
parser = new ConjunctionConstraintParser(expressionExpr);
|
parser = new ConjunctionConstraintParser(expressionExpr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof Or);
|
assertTrue(constraint instanceof Or);
|
||||||
or = (Or) constraint;
|
or = (Or) constraint;
|
||||||
Assert.assertEquals(2, or.getChildren().size());
|
assertEquals(2, or.getChildren().size());
|
||||||
verifyConstraintToString(expressionExpr, constraint);
|
verifyConstraintToString(expressionExpr, constraint);
|
||||||
|
|
||||||
expressionExpr = "OR(NOTIN,NODE,foo:cardinality,NODE,foo,0,1)";
|
expressionExpr = "OR(NOTIN,NODE,foo:cardinality,NODE,foo,0,1)";
|
||||||
parser = new ConjunctionConstraintParser(expressionExpr);
|
parser = new ConjunctionConstraintParser(expressionExpr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof Or);
|
assertTrue(constraint instanceof Or);
|
||||||
Assert.assertEquals(2, or.getChildren().size());
|
assertEquals(2, or.getChildren().size());
|
||||||
verifyConstraintToString(expressionExpr, constraint);
|
verifyConstraintToString(expressionExpr, constraint);
|
||||||
|
|
||||||
expressionExpr =
|
expressionExpr =
|
||||||
"OR(NOTIN,NODE,foo:OR(NOTIN,NODE,foo:cardinality,NODE,foo,0,1))";
|
"OR(NOTIN,NODE,foo:OR(NOTIN,NODE,foo:cardinality,NODE,foo,0,1))";
|
||||||
parser = new ConjunctionConstraintParser(expressionExpr);
|
parser = new ConjunctionConstraintParser(expressionExpr);
|
||||||
constraint = parser.parse();
|
constraint = parser.parse();
|
||||||
Assert.assertTrue(constraint instanceof Or);
|
assertTrue(constraint instanceof Or);
|
||||||
or = (Or) constraint;
|
or = (Or) constraint;
|
||||||
Assert.assertTrue(or.getChildren().get(0) instanceof SingleConstraint);
|
assertTrue(or.getChildren().get(0) instanceof SingleConstraint);
|
||||||
Assert.assertTrue(or.getChildren().get(1) instanceof Or);
|
assertTrue(or.getChildren().get(1) instanceof Or);
|
||||||
or = (Or) or.getChildren().get(1);
|
or = (Or) or.getChildren().get(1);
|
||||||
Assert.assertEquals(2, or.getChildren().size());
|
assertEquals(2, or.getChildren().size());
|
||||||
verifyConstraintToString(expressionExpr, constraint);
|
verifyConstraintToString(expressionExpr, constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleConstraintsTokenizer()
|
void testMultipleConstraintsTokenizer()
|
||||||
throws PlacementConstraintParseException {
|
throws PlacementConstraintParseException {
|
||||||
MultipleConstraintsTokenizer ct;
|
MultipleConstraintsTokenizer ct;
|
||||||
SourceTagsTokenizer st;
|
SourceTagsTokenizer st;
|
||||||
@ -310,9 +312,9 @@ public void testMultipleConstraintsTokenizer()
|
|||||||
st = new SourceTagsTokenizer("A(B)");
|
st = new SourceTagsTokenizer("A(B)");
|
||||||
mp = new TokenizerTester(st, "A", "B");
|
mp = new TokenizerTester(st, "A", "B");
|
||||||
mp.verify();
|
mp.verify();
|
||||||
Assert.fail("Expecting a parsing failure");
|
fail("Expecting a parsing failure");
|
||||||
} catch (PlacementConstraintParseException e) {
|
} catch (PlacementConstraintParseException e) {
|
||||||
Assert.assertTrue(e.getMessage()
|
assertTrue(e.getMessage()
|
||||||
.contains("Value of the expression must be an integer"));
|
.contains("Value of the expression must be an integer"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,15 +336,15 @@ void verify()
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
while (tokenizer.hasMoreElements()) {
|
while (tokenizer.hasMoreElements()) {
|
||||||
String current = tokenizer.nextElement();
|
String current = tokenizer.nextElement();
|
||||||
Assert.assertTrue(i < expectedExtractions.length);
|
assertTrue(i < expectedExtractions.length);
|
||||||
Assert.assertEquals(expectedExtractions[i], current);
|
assertEquals(expectedExtractions[i], current);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParsePlacementSpec()
|
void testParsePlacementSpec()
|
||||||
throws PlacementConstraintParseException {
|
throws PlacementConstraintParseException {
|
||||||
Map<SourceTags, PlacementConstraint> result;
|
Map<SourceTags, PlacementConstraint> result;
|
||||||
PlacementConstraint expectedPc1, expectedPc2;
|
PlacementConstraint expectedPc1, expectedPc2;
|
||||||
@ -352,92 +354,92 @@ public void testParsePlacementSpec()
|
|||||||
// Only Source Tag without constraint
|
// Only Source Tag without constraint
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("foo(3)");
|
.parsePlacementSpec("foo(3)");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
tag1 = result.keySet().iterator().next();
|
tag1 = result.keySet().iterator().next();
|
||||||
Assert.assertEquals("foo", tag1.getTag());
|
assertEquals("foo", tag1.getTag());
|
||||||
Assert.assertEquals(3, tag1.getNumOfAllocations());
|
assertEquals(3, tag1.getNumOfAllocations());
|
||||||
expectedPc1 = null;
|
expectedPc1 = null;
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1);
|
assertEquals(expectedPc1, actualPc1);
|
||||||
|
|
||||||
// A single anti-affinity constraint
|
// A single anti-affinity constraint
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("foo(3),notin,node,foo");
|
.parsePlacementSpec("foo(3),notin,node,foo");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
tag1 = result.keySet().iterator().next();
|
tag1 = result.keySet().iterator().next();
|
||||||
Assert.assertEquals("foo", tag1.getTag());
|
assertEquals("foo", tag1.getTag());
|
||||||
Assert.assertEquals(3, tag1.getNumOfAllocations());
|
assertEquals(3, tag1.getNumOfAllocations());
|
||||||
expectedPc1 = targetNotIn("node", allocationTag("foo")).build();
|
expectedPc1 = targetNotIn("node", allocationTag("foo")).build();
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1);
|
assertEquals(expectedPc1, actualPc1);
|
||||||
|
|
||||||
// Upper case
|
// Upper case
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("foo(3),NOTIN,NODE,foo");
|
.parsePlacementSpec("foo(3),NOTIN,NODE,foo");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
tag1 = result.keySet().iterator().next();
|
tag1 = result.keySet().iterator().next();
|
||||||
Assert.assertEquals("foo", tag1.getTag());
|
assertEquals("foo", tag1.getTag());
|
||||||
Assert.assertEquals(3, tag1.getNumOfAllocations());
|
assertEquals(3, tag1.getNumOfAllocations());
|
||||||
expectedPc1 = targetNotIn("node", allocationTag("foo")).build();
|
expectedPc1 = targetNotIn("node", allocationTag("foo")).build();
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1);
|
assertEquals(expectedPc1, actualPc1);
|
||||||
|
|
||||||
// A single cardinality constraint
|
// A single cardinality constraint
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("foo(10),cardinality,node,foo,bar,0,100");
|
.parsePlacementSpec("foo(10),cardinality,node,foo,bar,0,100");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
tag1 = result.keySet().iterator().next();
|
tag1 = result.keySet().iterator().next();
|
||||||
Assert.assertEquals("foo", tag1.getTag());
|
assertEquals("foo", tag1.getTag());
|
||||||
Assert.assertEquals(10, tag1.getNumOfAllocations());
|
assertEquals(10, tag1.getNumOfAllocations());
|
||||||
TargetExpression[] targetExpressions = new TargetExpression[] {
|
TargetExpression[] targetExpressions = new TargetExpression[] {
|
||||||
PlacementTargets.allocationTag("foo"),
|
PlacementTargets.allocationTag("foo"),
|
||||||
PlacementTargets.allocationTag("bar")};
|
PlacementTargets.allocationTag("bar")};
|
||||||
expectedPc1 = PlacementConstraints.targetCardinality("node", 0,
|
expectedPc1 = PlacementConstraints.targetCardinality("node", 0,
|
||||||
100, targetExpressions).build();
|
100, targetExpressions).build();
|
||||||
Assert.assertEquals(expectedPc1, result.values().iterator().next());
|
assertEquals(expectedPc1, result.values().iterator().next());
|
||||||
|
|
||||||
// Two constraint expressions
|
// Two constraint expressions
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("foo(3),notin,node,foo:bar(2),in,node,foo");
|
.parsePlacementSpec("foo(3),notin,node,foo:bar(2),in,node,foo");
|
||||||
Assert.assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
Iterator<SourceTags> keyIt = result.keySet().iterator();
|
Iterator<SourceTags> keyIt = result.keySet().iterator();
|
||||||
tag1 = keyIt.next();
|
tag1 = keyIt.next();
|
||||||
Assert.assertEquals("foo", tag1.getTag());
|
assertEquals("foo", tag1.getTag());
|
||||||
Assert.assertEquals(3, tag1.getNumOfAllocations());
|
assertEquals(3, tag1.getNumOfAllocations());
|
||||||
tag2 = keyIt.next();
|
tag2 = keyIt.next();
|
||||||
Assert.assertEquals("bar", tag2.getTag());
|
assertEquals("bar", tag2.getTag());
|
||||||
Assert.assertEquals(2, tag2.getNumOfAllocations());
|
assertEquals(2, tag2.getNumOfAllocations());
|
||||||
Iterator<PlacementConstraint> valueIt = result.values().iterator();
|
Iterator<PlacementConstraint> valueIt = result.values().iterator();
|
||||||
expectedPc1 = targetNotIn("node", allocationTag("foo")).build();
|
expectedPc1 = targetNotIn("node", allocationTag("foo")).build();
|
||||||
expectedPc2 = targetIn("node", allocationTag("foo")).build();
|
expectedPc2 = targetIn("node", allocationTag("foo")).build();
|
||||||
Assert.assertEquals(expectedPc1, valueIt.next());
|
assertEquals(expectedPc1, valueIt.next());
|
||||||
Assert.assertEquals(expectedPc2, valueIt.next());
|
assertEquals(expectedPc2, valueIt.next());
|
||||||
|
|
||||||
// And constraint
|
// And constraint
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("foo(1000),and(notin,node,bar:in,node,foo)");
|
.parsePlacementSpec("foo(1000),and(notin,node,bar:in,node,foo)");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
keyIt = result.keySet().iterator();
|
keyIt = result.keySet().iterator();
|
||||||
tag1 = keyIt.next();
|
tag1 = keyIt.next();
|
||||||
Assert.assertEquals("foo", tag1.getTag());
|
assertEquals("foo", tag1.getTag());
|
||||||
Assert.assertEquals(1000, tag1.getNumOfAllocations());
|
assertEquals(1000, tag1.getNumOfAllocations());
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
expectedPc1 = and(targetNotIn("node", allocationTag("bar")),
|
expectedPc1 = and(targetNotIn("node", allocationTag("bar")),
|
||||||
targetIn("node", allocationTag("foo"))).build();
|
targetIn("node", allocationTag("foo"))).build();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1);
|
assertEquals(expectedPc1, actualPc1);
|
||||||
|
|
||||||
// Multiple constraints with nested forms.
|
// Multiple constraints with nested forms.
|
||||||
result = PlacementConstraintParser.parsePlacementSpec(
|
result = PlacementConstraintParser.parsePlacementSpec(
|
||||||
"foo(1000),and(notin,node,bar:or(in,node,foo:in,node,moo))"
|
"foo(1000),and(notin,node,bar:or(in,node,foo:in,node,moo))"
|
||||||
+ ":bar(200),notin,node,foo");
|
+ ":bar(200),notin,node,foo");
|
||||||
Assert.assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
keyIt = result.keySet().iterator();
|
keyIt = result.keySet().iterator();
|
||||||
tag1 = keyIt.next();
|
tag1 = keyIt.next();
|
||||||
tag2 = keyIt.next();
|
tag2 = keyIt.next();
|
||||||
Assert.assertEquals("foo", tag1.getTag());
|
assertEquals("foo", tag1.getTag());
|
||||||
Assert.assertEquals(1000, tag1.getNumOfAllocations());
|
assertEquals(1000, tag1.getNumOfAllocations());
|
||||||
Assert.assertEquals("bar", tag2.getTag());
|
assertEquals("bar", tag2.getTag());
|
||||||
Assert.assertEquals(200, tag2.getNumOfAllocations());
|
assertEquals(200, tag2.getNumOfAllocations());
|
||||||
valueIt = result.values().iterator();
|
valueIt = result.values().iterator();
|
||||||
actualPc1 = valueIt.next();
|
actualPc1 = valueIt.next();
|
||||||
actualPc2 = valueIt.next();
|
actualPc2 = valueIt.next();
|
||||||
@ -445,18 +447,18 @@ public void testParsePlacementSpec()
|
|||||||
expectedPc1 = and(targetNotIn("node", allocationTag("bar")),
|
expectedPc1 = and(targetNotIn("node", allocationTag("bar")),
|
||||||
or(targetIn("node", allocationTag("foo")),
|
or(targetIn("node", allocationTag("foo")),
|
||||||
targetIn("node", allocationTag("moo")))).build();
|
targetIn("node", allocationTag("moo")))).build();
|
||||||
Assert.assertEquals(actualPc1, expectedPc1);
|
assertEquals(actualPc1, expectedPc1);
|
||||||
expectedPc2 = targetNotIn("node", allocationTag("foo")).build();
|
expectedPc2 = targetNotIn("node", allocationTag("foo")).build();
|
||||||
Assert.assertEquals(expectedPc2, actualPc2);
|
assertEquals(expectedPc2, actualPc2);
|
||||||
|
|
||||||
// Failure Cases
|
// Failure Cases
|
||||||
String[] invalidSpecs = {"foo(3", "foo),bar", "foobar", "),java=1.7,1.8"};
|
String[] invalidSpecs = {"foo(3", "foo),bar", "foobar", "),java=1.7,1.8"};
|
||||||
for (String spec : invalidSpecs) {
|
for (String spec : invalidSpecs) {
|
||||||
try {
|
try {
|
||||||
result = PlacementConstraintParser.parsePlacementSpec(spec);
|
result = PlacementConstraintParser.parsePlacementSpec(spec);
|
||||||
Assert.fail("Expected a failure!");
|
fail("Expected a failure!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assert.assertTrue(e instanceof PlacementConstraintParseException);
|
assertTrue(e instanceof PlacementConstraintParseException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -475,13 +477,13 @@ private void verifyConstraintToString(String inputExpr,
|
|||||||
try {
|
try {
|
||||||
PlacementConstraintParser.parseExpression(constrainExpr);
|
PlacementConstraintParser.parseExpression(constrainExpr);
|
||||||
} catch (PlacementConstraintParseException e) {
|
} catch (PlacementConstraintParseException e) {
|
||||||
Assert.fail("The parser is unable to parse the expression: "
|
fail("The parser is unable to parse the expression: "
|
||||||
+ constrainExpr + ", caused by: " + e.getMessage());
|
+ constrainExpr + ", caused by: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNodeAttributeSpec()
|
void testParseNodeAttributeSpec()
|
||||||
throws PlacementConstraintParseException {
|
throws PlacementConstraintParseException {
|
||||||
Map<SourceTags, PlacementConstraint> result;
|
Map<SourceTags, PlacementConstraint> result;
|
||||||
PlacementConstraint.AbstractConstraint expectedPc1, expectedPc2;
|
PlacementConstraint.AbstractConstraint expectedPc1, expectedPc2;
|
||||||
@ -490,33 +492,33 @@ public void testParseNodeAttributeSpec()
|
|||||||
// A single node attribute constraint
|
// A single node attribute constraint
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("xyz(4),rm.yarn.io/foo=true");
|
.parsePlacementSpec("xyz(4),rm.yarn.io/foo=true");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
TargetExpression target = PlacementTargets
|
TargetExpression target = PlacementTargets
|
||||||
.nodeAttribute("rm.yarn.io/foo", "true");
|
.nodeAttribute("rm.yarn.io/foo", "true");
|
||||||
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.EQ, target);
|
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.EQ, target);
|
||||||
|
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
||||||
|
|
||||||
// A single node attribute constraint
|
// A single node attribute constraint
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("xyz(3),rm.yarn.io/foo!=abc");
|
.parsePlacementSpec("xyz(3),rm.yarn.io/foo!=abc");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
target = PlacementTargets
|
target = PlacementTargets
|
||||||
.nodeAttribute("rm.yarn.io/foo", "abc");
|
.nodeAttribute("rm.yarn.io/foo", "abc");
|
||||||
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.NE, target);
|
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.NE, target);
|
||||||
|
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
||||||
|
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
||||||
|
|
||||||
// A single node attribute constraint
|
// A single node attribute constraint
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec(
|
.parsePlacementSpec(
|
||||||
"xyz(1),rm.yarn.io/foo!=abc:zxy(1),rm.yarn.io/bar=true");
|
"xyz(1),rm.yarn.io/foo!=abc:zxy(1),rm.yarn.io/bar=true");
|
||||||
Assert.assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
target = PlacementTargets
|
target = PlacementTargets
|
||||||
.nodeAttribute("rm.yarn.io/foo", "abc");
|
.nodeAttribute("rm.yarn.io/foo", "abc");
|
||||||
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.NE, target);
|
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.NE, target);
|
||||||
@ -527,25 +529,25 @@ public void testParseNodeAttributeSpec()
|
|||||||
Iterator<PlacementConstraint> valueIt = result.values().iterator();
|
Iterator<PlacementConstraint> valueIt = result.values().iterator();
|
||||||
actualPc1 = valueIt.next();
|
actualPc1 = valueIt.next();
|
||||||
actualPc2 = valueIt.next();
|
actualPc2 = valueIt.next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
||||||
Assert.assertEquals(expectedPc2, actualPc2.getConstraintExpr());
|
assertEquals(expectedPc2, actualPc2.getConstraintExpr());
|
||||||
|
|
||||||
// A single node attribute constraint w/o source tags
|
// A single node attribute constraint w/o source tags
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("rm.yarn.io/foo=true");
|
.parsePlacementSpec("rm.yarn.io/foo=true");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
target = PlacementTargets.nodeAttribute("rm.yarn.io/foo", "true");
|
target = PlacementTargets.nodeAttribute("rm.yarn.io/foo", "true");
|
||||||
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.EQ, target);
|
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.EQ, target);
|
||||||
|
|
||||||
SourceTags actualSourceTags = result.keySet().iterator().next();
|
SourceTags actualSourceTags = result.keySet().iterator().next();
|
||||||
Assert.assertTrue(actualSourceTags.isEmpty());
|
assertTrue(actualSourceTags.isEmpty());
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
||||||
|
|
||||||
// Node Attribute Constraint With Multiple Values
|
// Node Attribute Constraint With Multiple Values
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("java=1.7,1.8");
|
.parsePlacementSpec("java=1.7,1.8");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
|
|
||||||
Set<String> constraintEntities = new TreeSet<>();
|
Set<String> constraintEntities = new TreeSet<>();
|
||||||
constraintEntities.add("1.7");
|
constraintEntities.add("1.7");
|
||||||
@ -554,52 +556,52 @@ public void testParseNodeAttributeSpec()
|
|||||||
constraintEntities.toArray(new String[constraintEntities.size()]));
|
constraintEntities.toArray(new String[constraintEntities.size()]));
|
||||||
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.EQ, target);
|
expectedPc1 = targetNodeAttribute("node", NodeAttributeOpCode.EQ, target);
|
||||||
actualSourceTags = result.keySet().iterator().next();
|
actualSourceTags = result.keySet().iterator().next();
|
||||||
Assert.assertTrue(actualSourceTags.isEmpty());
|
assertTrue(actualSourceTags.isEmpty());
|
||||||
actualPc1 = result.values().iterator().next();
|
actualPc1 = result.values().iterator().next();
|
||||||
Assert.assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
assertEquals(expectedPc1, actualPc1.getConstraintExpr());
|
||||||
|
|
||||||
// If source tags is not specified for a node-attribute constraint,
|
// If source tags is not specified for a node-attribute constraint,
|
||||||
// then this expression must be single constraint expression.
|
// then this expression must be single constraint expression.
|
||||||
try {
|
try {
|
||||||
PlacementConstraintParser
|
PlacementConstraintParser
|
||||||
.parsePlacementSpec("rm.yarn.io/foo=true:xyz(1),notin,node,xyz");
|
.parsePlacementSpec("rm.yarn.io/foo=true:xyz(1),notin,node,xyz");
|
||||||
Assert.fail("Expected a failure!");
|
fail("Expected a failure!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assert.assertTrue(e instanceof PlacementConstraintParseException);
|
assertTrue(e instanceof PlacementConstraintParseException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseAllocationTagNameSpace()
|
void testParseAllocationTagNameSpace()
|
||||||
throws PlacementConstraintParseException {
|
throws PlacementConstraintParseException {
|
||||||
Map<SourceTags, PlacementConstraint> result;
|
Map<SourceTags, PlacementConstraint> result;
|
||||||
|
|
||||||
// Constraint with Two Different NameSpaces
|
// Constraint with Two Different NameSpaces
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("foo(2),notin,node,not-self/bar,all/moo");
|
.parsePlacementSpec("foo(2),notin,node,not-self/bar,all/moo");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
Set<TargetExpression> expectedTargetExpressions = Sets.newHashSet(
|
Set<TargetExpression> expectedTargetExpressions = Sets.newHashSet(
|
||||||
PlacementTargets.allocationTagWithNamespace("not-self", "bar"),
|
PlacementTargets.allocationTagWithNamespace("not-self", "bar"),
|
||||||
PlacementTargets.allocationTagWithNamespace("all", "moo"));
|
PlacementTargets.allocationTagWithNamespace("all", "moo"));
|
||||||
AbstractConstraint constraint = result.values().iterator().next().
|
AbstractConstraint constraint = result.values().iterator().next().
|
||||||
getConstraintExpr();
|
getConstraintExpr();
|
||||||
Assert.assertTrue(constraint instanceof SingleConstraint);
|
assertTrue(constraint instanceof SingleConstraint);
|
||||||
SingleConstraint single = (SingleConstraint) constraint;
|
SingleConstraint single = (SingleConstraint) constraint;
|
||||||
Assert.assertEquals(2, single.getTargetExpressions().size());
|
assertEquals(2, single.getTargetExpressions().size());
|
||||||
Assert.assertTrue(Sets.difference(expectedTargetExpressions,
|
assertTrue(Sets.difference(expectedTargetExpressions,
|
||||||
single.getTargetExpressions()).isEmpty());
|
single.getTargetExpressions()).isEmpty());
|
||||||
|
|
||||||
// Constraint With Default NameSpace SELF
|
// Constraint With Default NameSpace SELF
|
||||||
result = PlacementConstraintParser
|
result = PlacementConstraintParser
|
||||||
.parsePlacementSpec("foo(2),notin,node,moo");
|
.parsePlacementSpec("foo(2),notin,node,moo");
|
||||||
Assert.assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
TargetExpression expectedTargetExpression = PlacementTargets.
|
TargetExpression expectedTargetExpression = PlacementTargets.
|
||||||
allocationTagWithNamespace("self", "moo");
|
allocationTagWithNamespace("self", "moo");
|
||||||
constraint = result.values().iterator().next().getConstraintExpr();
|
constraint = result.values().iterator().next().getConstraintExpr();
|
||||||
Assert.assertTrue(constraint instanceof SingleConstraint);
|
assertTrue(constraint instanceof SingleConstraint);
|
||||||
single = (SingleConstraint) constraint;
|
single = (SingleConstraint) constraint;
|
||||||
Assert.assertEquals(1, single.getTargetExpressions().size());
|
assertEquals(1, single.getTargetExpressions().size());
|
||||||
Assert.assertEquals(expectedTargetExpression,
|
assertEquals(expectedTargetExpression,
|
||||||
single.getTargetExpressions().iterator().next());
|
single.getTargetExpressions().iterator().next());
|
||||||
|
|
||||||
// Constraint With Invalid NameSpace
|
// Constraint With Invalid NameSpace
|
||||||
@ -610,8 +612,8 @@ public void testParseAllocationTagNameSpace()
|
|||||||
} catch(PlacementConstraintParseException e) {
|
} catch(PlacementConstraintParseException e) {
|
||||||
caughtException = true;
|
caughtException = true;
|
||||||
}
|
}
|
||||||
Assert.assertTrue("PlacementConstraintParseException is expected",
|
assertTrue(caughtException,
|
||||||
caughtException);
|
"PlacementConstraintParseException is expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.targetNotIn;
|
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.targetNotIn;
|
||||||
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.PlacementTargets.allocationTag;
|
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.PlacementTargets.allocationTag;
|
||||||
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.PlacementTargets.nodeAttribute;
|
import static org.apache.hadoop.yarn.api.resource.PlacementConstraints.PlacementTargets.nodeAttribute;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import org.apache.hadoop.yarn.api.records.AllocationTagNamespaceType;
|
import org.apache.hadoop.yarn.api.records.AllocationTagNamespaceType;
|
||||||
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.AbstractConstraint;
|
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.AbstractConstraint;
|
||||||
@ -34,36 +36,35 @@
|
|||||||
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.SingleConstraint;
|
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.SingleConstraint;
|
||||||
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.TargetExpression;
|
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.TargetExpression;
|
||||||
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.TargetExpression.TargetType;
|
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.TargetExpression.TargetType;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for the various static methods in
|
* Test class for the various static methods in
|
||||||
* {@link org.apache.hadoop.yarn.api.resource.PlacementConstraints}.
|
* {@link org.apache.hadoop.yarn.api.resource.PlacementConstraints}.
|
||||||
*/
|
*/
|
||||||
public class TestPlacementConstraints {
|
class TestPlacementConstraints {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNodeAffinityToTag() {
|
void testNodeAffinityToTag() {
|
||||||
AbstractConstraint constraintExpr =
|
AbstractConstraint constraintExpr =
|
||||||
targetIn(NODE, allocationTag("hbase-m"));
|
targetIn(NODE, allocationTag("hbase-m"));
|
||||||
|
|
||||||
SingleConstraint sConstraint = (SingleConstraint) constraintExpr;
|
SingleConstraint sConstraint = (SingleConstraint) constraintExpr;
|
||||||
Assert.assertEquals(NODE, sConstraint.getScope());
|
assertEquals(NODE, sConstraint.getScope());
|
||||||
Assert.assertEquals(1, sConstraint.getMinCardinality());
|
assertEquals(1, sConstraint.getMinCardinality());
|
||||||
Assert.assertEquals(Integer.MAX_VALUE, sConstraint.getMaxCardinality());
|
assertEquals(Integer.MAX_VALUE, sConstraint.getMaxCardinality());
|
||||||
|
|
||||||
Assert.assertEquals(1, sConstraint.getTargetExpressions().size());
|
assertEquals(1, sConstraint.getTargetExpressions().size());
|
||||||
TargetExpression tExpr =
|
TargetExpression tExpr =
|
||||||
sConstraint.getTargetExpressions().iterator().next();
|
sConstraint.getTargetExpressions().iterator().next();
|
||||||
Assert.assertEquals(AllocationTagNamespaceType.SELF.toString(),
|
assertEquals(AllocationTagNamespaceType.SELF.toString(),
|
||||||
tExpr.getTargetKey());
|
tExpr.getTargetKey());
|
||||||
Assert.assertEquals(TargetType.ALLOCATION_TAG, tExpr.getTargetType());
|
assertEquals(TargetType.ALLOCATION_TAG, tExpr.getTargetType());
|
||||||
Assert.assertEquals(1, tExpr.getTargetValues().size());
|
assertEquals(1, tExpr.getTargetValues().size());
|
||||||
Assert.assertEquals("hbase-m", tExpr.getTargetValues().iterator().next());
|
assertEquals("hbase-m", tExpr.getTargetValues().iterator().next());
|
||||||
|
|
||||||
PlacementConstraint constraint = PlacementConstraints.build(constraintExpr);
|
PlacementConstraint constraint = PlacementConstraints.build(constraintExpr);
|
||||||
Assert.assertNotNull(constraint.getConstraintExpr());
|
assertNotNull(constraint.getConstraintExpr());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -72,17 +73,17 @@ public void testNodeAntiAffinityToAttribute() {
|
|||||||
targetNotIn(NODE, nodeAttribute("java", "1.8"));
|
targetNotIn(NODE, nodeAttribute("java", "1.8"));
|
||||||
|
|
||||||
SingleConstraint sConstraint = (SingleConstraint) constraintExpr;
|
SingleConstraint sConstraint = (SingleConstraint) constraintExpr;
|
||||||
Assert.assertEquals(NODE, sConstraint.getScope());
|
assertEquals(NODE, sConstraint.getScope());
|
||||||
Assert.assertEquals(0, sConstraint.getMinCardinality());
|
assertEquals(0, sConstraint.getMinCardinality());
|
||||||
Assert.assertEquals(0, sConstraint.getMaxCardinality());
|
assertEquals(0, sConstraint.getMaxCardinality());
|
||||||
|
|
||||||
Assert.assertEquals(1, sConstraint.getTargetExpressions().size());
|
assertEquals(1, sConstraint.getTargetExpressions().size());
|
||||||
TargetExpression tExpr =
|
TargetExpression tExpr =
|
||||||
sConstraint.getTargetExpressions().iterator().next();
|
sConstraint.getTargetExpressions().iterator().next();
|
||||||
Assert.assertEquals("java", tExpr.getTargetKey());
|
assertEquals("java", tExpr.getTargetKey());
|
||||||
Assert.assertEquals(TargetType.NODE_ATTRIBUTE, tExpr.getTargetType());
|
assertEquals(TargetType.NODE_ATTRIBUTE, tExpr.getTargetType());
|
||||||
Assert.assertEquals(1, tExpr.getTargetValues().size());
|
assertEquals(1, tExpr.getTargetValues().size());
|
||||||
Assert.assertEquals("1.8", tExpr.getTargetValues().iterator().next());
|
assertEquals("1.8", tExpr.getTargetValues().iterator().next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -93,17 +94,17 @@ public void testAndConstraint() {
|
|||||||
targetCardinality(RACK, 2, 10, allocationTag("zk")));
|
targetCardinality(RACK, 2, 10, allocationTag("zk")));
|
||||||
|
|
||||||
And andExpr = (And) constraintExpr;
|
And andExpr = (And) constraintExpr;
|
||||||
Assert.assertEquals(3, andExpr.getChildren().size());
|
assertEquals(3, andExpr.getChildren().size());
|
||||||
SingleConstraint sConstr = (SingleConstraint) andExpr.getChildren().get(0);
|
SingleConstraint sConstr = (SingleConstraint) andExpr.getChildren().get(0);
|
||||||
TargetExpression tExpr = sConstr.getTargetExpressions().iterator().next();
|
TargetExpression tExpr = sConstr.getTargetExpressions().iterator().next();
|
||||||
Assert.assertEquals("spark", tExpr.getTargetValues().iterator().next());
|
assertEquals("spark", tExpr.getTargetValues().iterator().next());
|
||||||
|
|
||||||
sConstr = (SingleConstraint) andExpr.getChildren().get(1);
|
sConstr = (SingleConstraint) andExpr.getChildren().get(1);
|
||||||
Assert.assertEquals(0, sConstr.getMinCardinality());
|
assertEquals(0, sConstr.getMinCardinality());
|
||||||
Assert.assertEquals(3, sConstr.getMaxCardinality());
|
assertEquals(3, sConstr.getMaxCardinality());
|
||||||
|
|
||||||
sConstr = (SingleConstraint) andExpr.getChildren().get(2);
|
sConstr = (SingleConstraint) andExpr.getChildren().get(2);
|
||||||
Assert.assertEquals(2, sConstr.getMinCardinality());
|
assertEquals(2, sConstr.getMinCardinality());
|
||||||
Assert.assertEquals(10, sConstr.getMaxCardinality());
|
assertEquals(10, sConstr.getMaxCardinality());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,74 +22,77 @@
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
|
import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
|
||||||
import org.apache.hadoop.yarn.api.records.ResourceInformation;
|
import org.apache.hadoop.yarn.api.records.ResourceInformation;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class to verify various resource informations in a given resource.
|
* Test class to verify various resource informations in a given resource.
|
||||||
*/
|
*/
|
||||||
public class TestResourceInformation {
|
class TestResourceInformation {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testName() {
|
void testName() {
|
||||||
String name = "yarn.io/test";
|
String name = "yarn.io/test";
|
||||||
ResourceInformation ri = ResourceInformation.newInstance(name);
|
ResourceInformation ri = ResourceInformation.newInstance(name);
|
||||||
Assert.assertEquals("Resource name incorrect", name, ri.getName());
|
assertEquals(name, ri.getName(), "Resource name incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnits() {
|
void testUnits() {
|
||||||
String name = "yarn.io/test";
|
String name = "yarn.io/test";
|
||||||
String units = "m";
|
String units = "m";
|
||||||
ResourceInformation ri = ResourceInformation.newInstance(name, units);
|
ResourceInformation ri = ResourceInformation.newInstance(name, units);
|
||||||
Assert.assertEquals("Resource name incorrect", name, ri.getName());
|
assertEquals(name, ri.getName(), "Resource name incorrect");
|
||||||
Assert.assertEquals("Resource units incorrect", units, ri.getUnits());
|
assertEquals(units, ri.getUnits(), "Resource units incorrect");
|
||||||
units = "z";
|
units = "z";
|
||||||
try {
|
try {
|
||||||
ResourceInformation.newInstance(name, units).setUnits(units);
|
ResourceInformation.newInstance(name, units).setUnits(units);
|
||||||
Assert.fail(units + "is not a valid unit");
|
fail(units + "is not a valid unit");
|
||||||
} catch (IllegalArgumentException ie) {
|
} catch (IllegalArgumentException ie) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValue() {
|
void testValue() {
|
||||||
String name = "yarn.io/test";
|
String name = "yarn.io/test";
|
||||||
long value = 1L;
|
long value = 1L;
|
||||||
ResourceInformation ri = ResourceInformation.newInstance(name, value);
|
ResourceInformation ri = ResourceInformation.newInstance(name, value);
|
||||||
Assert.assertEquals("Resource name incorrect", name, ri.getName());
|
assertEquals(name, ri.getName(), "Resource name incorrect");
|
||||||
Assert.assertEquals("Resource value incorrect", value, ri.getValue());
|
assertEquals(value, ri.getValue(), "Resource value incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResourceInformation() {
|
void testResourceInformation() {
|
||||||
String name = "yarn.io/test";
|
String name = "yarn.io/test";
|
||||||
long value = 1L;
|
long value = 1L;
|
||||||
String units = "m";
|
String units = "m";
|
||||||
ResourceInformation ri =
|
ResourceInformation ri =
|
||||||
ResourceInformation.newInstance(name, units, value);
|
ResourceInformation.newInstance(name, units, value);
|
||||||
Assert.assertEquals("Resource name incorrect", name, ri.getName());
|
assertEquals(name, ri.getName(), "Resource name incorrect");
|
||||||
Assert.assertEquals("Resource value incorrect", value, ri.getValue());
|
assertEquals(value, ri.getValue(), "Resource value incorrect");
|
||||||
Assert.assertEquals("Resource units incorrect", units, ri.getUnits());
|
assertEquals(units, ri.getUnits(), "Resource units incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsWithTagsAndAttributes() {
|
void testEqualsWithTagsAndAttributes() {
|
||||||
// Same tags but different order
|
// Same tags but different order
|
||||||
ResourceInformation ri01 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri01 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100,
|
ResourceTypes.COUNTABLE, 0, 100,
|
||||||
ImmutableSet.of("A", "B"), null);
|
ImmutableSet.of("A", "B"), null);
|
||||||
ResourceInformation ri02 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri02 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100, ImmutableSet.of("B", "A"), null);
|
ResourceTypes.COUNTABLE, 0, 100, ImmutableSet.of("B", "A"), null);
|
||||||
Assert.assertEquals(ri01, ri02);
|
assertEquals(ri01, ri02);
|
||||||
|
|
||||||
// Different tags
|
// Different tags
|
||||||
ResourceInformation ri11 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri11 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100, null, null);
|
ResourceTypes.COUNTABLE, 0, 100, null, null);
|
||||||
ResourceInformation ri12 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri12 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100, ImmutableSet.of("B", "A"), null);
|
ResourceTypes.COUNTABLE, 0, 100, ImmutableSet.of("B", "A"), null);
|
||||||
Assert.assertNotEquals(ri11, ri12);
|
assertNotEquals(ri11, ri12);
|
||||||
|
|
||||||
// Different attributes
|
// Different attributes
|
||||||
ResourceInformation ri21 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri21 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
@ -98,20 +101,20 @@ public void testEqualsWithTagsAndAttributes() {
|
|||||||
ResourceInformation ri22 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri22 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100, null,
|
ResourceTypes.COUNTABLE, 0, 100, null,
|
||||||
ImmutableMap.of("A", "A1", "B", "B2"));
|
ImmutableMap.of("A", "A1", "B", "B2"));
|
||||||
Assert.assertNotEquals(ri21, ri22);
|
assertNotEquals(ri21, ri22);
|
||||||
|
|
||||||
// No tags or attributes
|
// No tags or attributes
|
||||||
ResourceInformation ri31 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri31 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100, null, null);
|
ResourceTypes.COUNTABLE, 0, 100, null, null);
|
||||||
ResourceInformation ri32 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri32 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100, null, null);
|
ResourceTypes.COUNTABLE, 0, 100, null, null);
|
||||||
Assert.assertEquals(ri31, ri32);
|
assertEquals(ri31, ri32);
|
||||||
|
|
||||||
// Null tags/attributes same as empty ones
|
// Null tags/attributes same as empty ones
|
||||||
ResourceInformation ri41 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri41 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100, ImmutableSet.of(), null);
|
ResourceTypes.COUNTABLE, 0, 100, ImmutableSet.of(), null);
|
||||||
ResourceInformation ri42 = ResourceInformation.newInstance("r1", "M", 100,
|
ResourceInformation ri42 = ResourceInformation.newInstance("r1", "M", 100,
|
||||||
ResourceTypes.COUNTABLE, 0, 100, null, ImmutableMap.of());
|
ResourceTypes.COUNTABLE, 0, 100, null, ImmutableMap.of());
|
||||||
Assert.assertEquals(ri41, ri42);
|
assertEquals(ri41, ri42);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,121 +18,132 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.yarn.util;
|
package org.apache.hadoop.yarn.util;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class to handle all test cases needed to verify basic unit conversion
|
* Test class to handle all test cases needed to verify basic unit conversion
|
||||||
* scenarios.
|
* scenarios.
|
||||||
*/
|
*/
|
||||||
public class TestUnitsConversionUtil {
|
class TestUnitsConversionUtil {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnitsConversion() {
|
void testUnitsConversion() {
|
||||||
int value = 5;
|
int value = 5;
|
||||||
String fromUnit = "";
|
String fromUnit = "";
|
||||||
long test = value;
|
long test = value;
|
||||||
Assert.assertEquals("pico test failed",
|
assertEquals(value * 1000L * 1000L * 1000L * 1000L,
|
||||||
value * 1000L * 1000L * 1000L * 1000L,
|
UnitsConversionUtil.convert(fromUnit, "p", test),
|
||||||
UnitsConversionUtil.convert(fromUnit, "p", test));
|
"pico test failed");
|
||||||
Assert.assertEquals("nano test failed",
|
assertEquals(value * 1000L * 1000L * 1000L,
|
||||||
value * 1000L * 1000L * 1000L,
|
UnitsConversionUtil.convert(fromUnit, "n", test),
|
||||||
UnitsConversionUtil.convert(fromUnit, "n", test));
|
"nano test failed");
|
||||||
Assert
|
assertEquals(value * 1000L * 1000L,
|
||||||
.assertEquals("micro test failed", value * 1000L * 1000L,
|
UnitsConversionUtil.convert(fromUnit, "u", test),
|
||||||
UnitsConversionUtil.convert(fromUnit, "u", test));
|
"micro test failed");
|
||||||
Assert.assertEquals("milli test failed", value * 1000L,
|
assertEquals(value * 1000L,
|
||||||
UnitsConversionUtil.convert(fromUnit, "m", test));
|
UnitsConversionUtil.convert(fromUnit, "m", test),
|
||||||
|
"milli test failed");
|
||||||
|
|
||||||
test = value * 1000L * 1000L * 1000L * 1000L * 1000L;
|
test = value * 1000L * 1000L * 1000L * 1000L * 1000L;
|
||||||
fromUnit = "";
|
fromUnit = "";
|
||||||
Assert.assertEquals("kilo test failed", test / 1000L,
|
assertEquals(test / 1000L,
|
||||||
UnitsConversionUtil.convert(fromUnit, "k", test));
|
UnitsConversionUtil.convert(fromUnit, "k", test),
|
||||||
|
"kilo test failed");
|
||||||
|
|
||||||
Assert
|
assertEquals(test / (1000L * 1000L),
|
||||||
.assertEquals("mega test failed", test / (1000L * 1000L),
|
UnitsConversionUtil.convert(fromUnit, "M", test),
|
||||||
UnitsConversionUtil.convert(fromUnit, "M", test));
|
"mega test failed");
|
||||||
Assert.assertEquals("giga test failed",
|
assertEquals(test / (1000L * 1000L * 1000L),
|
||||||
test / (1000L * 1000L * 1000L),
|
UnitsConversionUtil.convert(fromUnit, "G", test),
|
||||||
UnitsConversionUtil.convert(fromUnit, "G", test));
|
"giga test failed");
|
||||||
Assert.assertEquals("tera test failed",
|
assertEquals(test / (1000L * 1000L * 1000L * 1000L),
|
||||||
test / (1000L * 1000L * 1000L * 1000L),
|
UnitsConversionUtil.convert(fromUnit, "T", test),
|
||||||
UnitsConversionUtil.convert(fromUnit, "T", test));
|
"tera test failed");
|
||||||
Assert.assertEquals("peta test failed",
|
assertEquals(test / (1000L * 1000L * 1000L * 1000L * 1000L),
|
||||||
test / (1000L * 1000L * 1000L * 1000L * 1000L),
|
UnitsConversionUtil.convert(fromUnit, "P", test),
|
||||||
UnitsConversionUtil.convert(fromUnit, "P", test));
|
"peta test failed");
|
||||||
|
|
||||||
Assert.assertEquals("nano to pico test failed", value * 1000L,
|
assertEquals(value * 1000L,
|
||||||
UnitsConversionUtil.convert("n", "p", value));
|
UnitsConversionUtil.convert("n", "p", value),
|
||||||
|
"nano to pico test failed");
|
||||||
|
|
||||||
Assert.assertEquals("mega to giga test failed", value,
|
assertEquals(value,
|
||||||
UnitsConversionUtil.convert("M", "G", value * 1000L));
|
UnitsConversionUtil.convert("M", "G", value * 1000L),
|
||||||
|
"mega to giga test failed");
|
||||||
|
|
||||||
Assert.assertEquals("Mi to Gi test failed", value,
|
assertEquals(value,
|
||||||
UnitsConversionUtil.convert("Mi", "Gi", value * 1024L));
|
UnitsConversionUtil.convert("Mi", "Gi", value * 1024L),
|
||||||
|
"Mi to Gi test failed");
|
||||||
|
|
||||||
Assert.assertEquals("Mi to Ki test failed", value * 1024,
|
assertEquals(value * 1024,
|
||||||
UnitsConversionUtil.convert("Mi", "Ki", value));
|
UnitsConversionUtil.convert("Mi", "Ki", value),
|
||||||
|
"Mi to Ki test failed");
|
||||||
|
|
||||||
Assert.assertEquals("Ki to base units test failed", 5 * 1024,
|
assertEquals(5 * 1024,
|
||||||
UnitsConversionUtil.convert("Ki", "", 5));
|
UnitsConversionUtil.convert("Ki", "", 5),
|
||||||
|
"Ki to base units test failed");
|
||||||
|
|
||||||
Assert.assertEquals("Mi to k test failed", 1073741,
|
assertEquals(1073741,
|
||||||
UnitsConversionUtil.convert("Mi", "k", 1024));
|
UnitsConversionUtil.convert("Mi", "k", 1024),
|
||||||
|
"Mi to k test failed");
|
||||||
|
|
||||||
Assert.assertEquals("M to Mi test failed", 953,
|
assertEquals(953,
|
||||||
UnitsConversionUtil.convert("M", "Mi", 1000));
|
UnitsConversionUtil.convert("M", "Mi", 1000),
|
||||||
|
"M to Mi test failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOverflow() {
|
void testOverflow() {
|
||||||
long test = 5 * 1000L * 1000L * 1000L * 1000L * 1000L;
|
long test = 5 * 1000L * 1000L * 1000L * 1000L * 1000L;
|
||||||
try {
|
try {
|
||||||
UnitsConversionUtil.convert("P", "p", test);
|
UnitsConversionUtil.convert("P", "p", test);
|
||||||
Assert.fail("this operation should result in an overflow");
|
fail("this operation should result in an overflow");
|
||||||
} catch (IllegalArgumentException ie) {
|
} catch (IllegalArgumentException ie) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
UnitsConversionUtil.convert("m", "p", Long.MAX_VALUE - 1);
|
UnitsConversionUtil.convert("m", "p", Long.MAX_VALUE - 1);
|
||||||
Assert.fail("this operation should result in an overflow");
|
fail("this operation should result in an overflow");
|
||||||
} catch (IllegalArgumentException ie) {
|
} catch (IllegalArgumentException ie) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompare() {
|
void testCompare() {
|
||||||
String unitA = "P";
|
String unitA = "P";
|
||||||
long valueA = 1;
|
long valueA = 1;
|
||||||
String unitB = "p";
|
String unitB = "p";
|
||||||
long valueB = 2;
|
long valueB = 2;
|
||||||
Assert.assertEquals(1,
|
assertEquals(1,
|
||||||
UnitsConversionUtil.compare(unitA, valueA, unitB, valueB));
|
UnitsConversionUtil.compare(unitA, valueA, unitB, valueB));
|
||||||
Assert.assertEquals(-1,
|
assertEquals(-1,
|
||||||
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
||||||
Assert.assertEquals(0,
|
assertEquals(0,
|
||||||
UnitsConversionUtil.compare(unitA, valueA, unitA, valueA));
|
UnitsConversionUtil.compare(unitA, valueA, unitA, valueA));
|
||||||
Assert.assertEquals(-1,
|
assertEquals(-1,
|
||||||
UnitsConversionUtil.compare(unitA, valueA, unitA, valueB));
|
UnitsConversionUtil.compare(unitA, valueA, unitA, valueB));
|
||||||
Assert.assertEquals(1,
|
assertEquals(1,
|
||||||
UnitsConversionUtil.compare(unitA, valueB, unitA, valueA));
|
UnitsConversionUtil.compare(unitA, valueB, unitA, valueA));
|
||||||
|
|
||||||
unitB = "T";
|
unitB = "T";
|
||||||
Assert.assertEquals(1,
|
assertEquals(1,
|
||||||
UnitsConversionUtil.compare(unitA, valueA, unitB, valueB));
|
UnitsConversionUtil.compare(unitA, valueA, unitB, valueB));
|
||||||
Assert.assertEquals(-1,
|
assertEquals(-1,
|
||||||
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
||||||
Assert.assertEquals(0,
|
assertEquals(0,
|
||||||
UnitsConversionUtil.compare(unitA, valueA, unitB, 1000L));
|
UnitsConversionUtil.compare(unitA, valueA, unitB, 1000L));
|
||||||
|
|
||||||
unitA = "p";
|
unitA = "p";
|
||||||
unitB = "n";
|
unitB = "n";
|
||||||
Assert.assertEquals(-1,
|
assertEquals(-1,
|
||||||
UnitsConversionUtil.compare(unitA, valueA, unitB, valueB));
|
UnitsConversionUtil.compare(unitA, valueA, unitB, valueB));
|
||||||
Assert.assertEquals(1,
|
assertEquals(1,
|
||||||
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
||||||
Assert.assertEquals(0,
|
assertEquals(0,
|
||||||
UnitsConversionUtil.compare(unitA, 1000L, unitB, valueA));
|
UnitsConversionUtil.compare(unitA, 1000L, unitB, valueA));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user