use of javax.validation.ValidationException in project apex-core by apache.
the class LogicalPlanTest method testPortConnectionValidation.
@Test
public void testPortConnectionValidation() {
TestNonOptionalOutportInputOperator input = dag.addOperator("input1", TestNonOptionalOutportInputOperator.class);
try {
dag.validate();
Assert.fail("should raise port not connected for input1.outputPort1");
} catch (ValidationException e) {
Assert.assertEquals("", "Output port connection required: input1.outport1", e.getMessage());
}
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
dag.addStream("stream1", input.outport1, o1.inport1);
dag.validate();
// required input
dag.addOperator("counter", CounterOperator.class);
try {
dag.validate();
} catch (ValidationException e) {
Assert.assertEquals("", "Input port connection required: counter.countInputPort", e.getMessage());
}
}
use of javax.validation.ValidationException in project apex-core by apache.
the class LogicalPlanTest method testCycleDetection.
@Test
public void testCycleDetection() {
//NodeConf operator1 = b.getOrAddNode("operator1");
GenericTestOperator operator2 = dag.addOperator("operator2", GenericTestOperator.class);
GenericTestOperator operator3 = dag.addOperator("operator3", GenericTestOperator.class);
GenericTestOperator operator4 = dag.addOperator("operator4", GenericTestOperator.class);
//NodeConf operator5 = b.getOrAddNode("operator5");
//NodeConf operator6 = b.getOrAddNode("operator6");
GenericTestOperator operator7 = dag.addOperator("operator7", GenericTestOperator.class);
// strongly connect n2-n3-n4-n2
dag.addStream("n2n3", operator2.outport1, operator3.inport1);
dag.addStream("n3n4", operator3.outport1, operator4.inport1);
dag.addStream("n4n2", operator4.outport1, operator2.inport1);
// self referencing operator cycle
StreamMeta n7n7 = dag.addStream("n7n7", operator7.outport1, operator7.inport1);
try {
n7n7.addSink(operator7.inport1);
fail("cannot add to stream again");
} catch (Exception e) {
// expected, stream can have single input/output only
}
LogicalPlan.ValidationContext vc = new LogicalPlan.ValidationContext();
dag.findStronglyConnected(dag.getMeta(operator7), vc);
assertEquals("operator self reference", 1, vc.invalidCycles.size());
assertEquals("operator self reference", 1, vc.invalidCycles.get(0).size());
assertEquals("operator self reference", dag.getMeta(operator7), vc.invalidCycles.get(0).iterator().next());
// 3 operator cycle
vc = new LogicalPlan.ValidationContext();
dag.findStronglyConnected(dag.getMeta(operator4), vc);
assertEquals("3 operator cycle", 1, vc.invalidCycles.size());
assertEquals("3 operator cycle", 3, vc.invalidCycles.get(0).size());
assertTrue("operator2", vc.invalidCycles.get(0).contains(dag.getMeta(operator2)));
assertTrue("operator3", vc.invalidCycles.get(0).contains(dag.getMeta(operator3)));
assertTrue("operator4", vc.invalidCycles.get(0).contains(dag.getMeta(operator4)));
try {
dag.validate();
fail("validation should fail");
} catch (ValidationException e) {
// expected
}
}
use of javax.validation.ValidationException in project apex-core by apache.
the class LogicalPlanTest method testAffinityRulesDagValidation.
@Test
public void testAffinityRulesDagValidation() {
TestGeneratorInputOperator o1 = dag.addOperator("O1", new TestGeneratorInputOperator());
GenericTestOperator o2 = dag.addOperator("O2", new GenericTestOperator());
GenericTestOperator o3 = dag.addOperator("O3", new GenericTestOperator());
dag.addStream("stream1", o1.outport, o2.inport1).setLocality(Locality.THREAD_LOCAL);
StreamMeta stream2 = dag.addStream("stream2", o2.outport1, o3.inport1).setLocality(Locality.CONTAINER_LOCAL);
AffinityRulesSet ruleSet = new AffinityRulesSet();
// Valid case:
List<AffinityRule> rules = new ArrayList<>();
ruleSet.setAffinityRules(rules);
AffinityRule rule1 = new AffinityRule(Type.AFFINITY, Locality.CONTAINER_LOCAL, false, "O1", "O3");
rules.add(rule1);
dag.setAttribute(DAGContext.AFFINITY_RULES_SET, ruleSet);
dag.validate();
// Locality conflicts with affinity rules case:
AffinityRule rule2 = new AffinityRule(Type.ANTI_AFFINITY, Locality.NODE_LOCAL, false, "O2", "O3");
rules.add(rule2);
try {
dag.validate();
Assert.fail("DAG validation should fail due to conflicting rules");
} catch (ValidationException e) {
Assert.assertEquals("Anti Affinity rule for operators O2 & O3 conflicts with affinity rules or Stream locality", e.getMessage());
}
// Change Stream2 locality to Node to check if validation passes
stream2.setLocality(Locality.RACK_LOCAL);
dag.validate();
// Add anti-affinity rule conflicting with rule1
AffinityRule rule3 = new AffinityRule(Type.ANTI_AFFINITY, Locality.NODE_LOCAL, false, "O1", "O3");
rules.add(rule3);
try {
dag.validate();
Assert.fail("DAG validation should fail due to conflicting rules");
} catch (ValidationException e) {
Assert.assertEquals("Anti Affinity rule for operators O1 & O3 conflicts with affinity rules or Stream locality", e.getMessage());
}
// Change rule1 to Rack local to see if dag validation passes
rules.clear();
rule1.setLocality(Locality.RACK_LOCAL);
rules.add(rule1);
rules.add(rule2);
rules.add(rule3);
dag.validate();
// Add conflicting rules and set relaxLocality for one rule
AffinityRule rule4 = new AffinityRule(Type.ANTI_AFFINITY, Locality.NODE_LOCAL, true, "O1", "O2");
rules.add(rule4);
dag.validate();
// Set conflicting host locality and check if it fails validation
rules.clear();
AffinityRule rule = new AffinityRule(Type.ANTI_AFFINITY, Locality.NODE_LOCAL, false, "O2", "O3");
rules.add(rule);
dag.getMeta(o2).getAttributes().put(OperatorContext.LOCALITY_HOST, "host1");
dag.getMeta(o3).getAttributes().put(OperatorContext.LOCALITY_HOST, "host1");
try {
dag.validate();
Assert.fail("DAG validation should fail due to conflicting host locality");
} catch (ValidationException e) {
Assert.assertEquals("Host Locality for operators: O2(host: host1) & O3(host: host1) conflict with anti-affinity rules", e.getMessage());
}
// Set conflicting affinity and different host locality for node-local
// operators
rules.clear();
rule = new AffinityRule(Type.AFFINITY, Locality.NODE_LOCAL, false, "O2", "O3");
rules.add(rule);
dag.getMeta(o2).getAttributes().put(OperatorContext.LOCALITY_HOST, "host1");
dag.getMeta(o3).getAttributes().put(OperatorContext.LOCALITY_HOST, "host2");
try {
dag.validate();
Assert.fail("DAG validation should fail due to conflicting host locality");
} catch (ValidationException e) {
Assert.assertEquals("Host Locality for operators: O2(host: host1) & O3(host: host2) conflicts with affinity rules", e.getMessage());
}
// Check affinity Thread local validation for non-connected operators
dag.getAttributes().get(DAGContext.AFFINITY_RULES_SET).getAffinityRules().clear();
rule = new AffinityRule(Type.AFFINITY, Locality.THREAD_LOCAL, false, "O1", "O3");
rules.add(rule);
try {
dag.validate();
Assert.fail("DAG validation should fail due to conflicting host locality");
} catch (ValidationException e) {
Assert.assertEquals("Affinity rule specified THREAD_LOCAL affinity for operators O1 & O3 which are not connected by stream", e.getMessage());
}
// Check indirect conflict
dag = new LogicalPlan();
o1 = dag.addOperator("O1", new TestGeneratorInputOperator());
o2 = dag.addOperator("O2", new GenericTestOperator());
o3 = dag.addOperator("O3", new GenericTestOperator());
GenericTestOperator o4 = dag.addOperator("O4", new GenericTestOperator());
GenericTestOperator o5 = dag.addOperator("O5", new GenericTestOperator());
dag.addStream("stream1", o1.outport, o2.inport1, o3.inport1).setLocality(Locality.NODE_LOCAL);
dag.addStream("stream2", o3.outport1, o4.inport1);
dag.addStream("stream3", o2.outport1, o5.inport1);
rules.clear();
// O3 and O5 cannot have NODE_LOCAL anti-affinity now, since they already have NODE_LOCAL affinity
rules.add(new AffinityRule(Type.AFFINITY, Locality.CONTAINER_LOCAL, false, "O1", "O5"));
rules.add(new AffinityRule(Type.ANTI_AFFINITY, Locality.NODE_LOCAL, false, "O3", "O5"));
ruleSet = new AffinityRulesSet();
ruleSet.setAffinityRules(rules);
dag.setAttribute(DAGContext.AFFINITY_RULES_SET, ruleSet);
try {
dag.validate();
Assert.fail("dag validation should fail due to conflicting affinity rules");
} catch (ValidationException e) {
Assert.assertEquals("Anti Affinity rule for operators O3 & O5 conflicts with affinity rules or Stream locality", e.getMessage());
}
}
use of javax.validation.ValidationException in project apex-core by apache.
the class LogicalPlanTest method testOperatorAnnotation.
@Test
public void testOperatorAnnotation() {
TestGeneratorInputOperator input = dag.addOperator("input1", TestGeneratorInputOperator.class);
TestOperatorAnnotationOperator operator = dag.addOperator("operator1", TestOperatorAnnotationOperator.class);
dag.addStream("Connection", input.outport, operator.input1);
dag.setOperatorAttribute(operator, OperatorContext.PARTITIONER, new StatelessPartitioner<TestOperatorAnnotationOperator>(2));
try {
dag.validate();
Assert.fail("should raise operator is not partitionable for operator1");
} catch (ValidationException e) {
Assert.assertEquals("", "Operator " + dag.getMeta(operator).getName() + " provides partitioning capabilities but the annotation on the operator class declares it non partitionable!", e.getMessage());
}
dag.setOperatorAttribute(operator, OperatorContext.PARTITIONER, null);
dag.setInputPortAttribute(operator.input1, PortContext.PARTITION_PARALLEL, true);
try {
dag.validate();
Assert.fail("should raise operator is not partitionable for operator1");
} catch (ValidationException e) {
Assert.assertEquals("", "Operator " + dag.getMeta(operator).getName() + " is not partitionable but PARTITION_PARALLEL attribute is set", e.getMessage());
}
dag.setInputPortAttribute(operator.input1, PortContext.PARTITION_PARALLEL, false);
dag.validate();
dag.removeOperator(operator);
TestOperatorAnnotationOperator2 operator2 = dag.addOperator("operator2", TestOperatorAnnotationOperator2.class);
try {
dag.validate();
Assert.fail("should raise operator is not partitionable for operator2");
} catch (ValidationException e) {
Assert.assertEquals("Operator " + dag.getMeta(operator2).getName() + " provides partitioning capabilities but the annotation on the operator class declares it non partitionable!", e.getMessage());
}
}
use of javax.validation.ValidationException in project apex-core by apache.
the class LogicalPlanTest method testOutputPortAnnotation.
@Test
public void testOutputPortAnnotation() {
TestAnnotationsOperator ta1 = dag.addOperator("testAnnotationsOperator", new TestAnnotationsOperator());
try {
dag.validate();
Assert.fail("should raise: port connection required");
} catch (ValidationException e) {
Assert.assertEquals("", "Output port connection required: testAnnotationsOperator.outport2", e.getMessage());
}
TestOutputOperator o2 = dag.addOperator("sink", new TestOutputOperator());
dag.addStream("s1", ta1.outport2, o2.inport);
dag.validate();
TestAnnotationsOperator2 ta2 = dag.addOperator("multiOutputPorts1", new TestAnnotationsOperator2());
dag.validate();
TestOutputOperator o3 = dag.addOperator("o3", new TestOutputOperator());
dag.addStream("s2", ta2.outport1, o3.inport);
dag.addOperator("multiOutputPorts3", new TestAnnotationsOperator3());
dag.validate();
}
Aggregations