use of com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta in project apex-core by apache.
the class LogicalPlanTest method testAtMostOnceProcessingModeValidation.
@Test
public void testAtMostOnceProcessingModeValidation() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
TestGeneratorInputOperator input2 = dag.addOperator("input2", TestGeneratorInputOperator.class);
GenericTestOperator amoOper = dag.addOperator("amoOper", GenericTestOperator.class);
dag.setOperatorAttribute(amoOper, OperatorContext.PROCESSING_MODE, Operator.ProcessingMode.AT_MOST_ONCE);
dag.addStream("input1.outport", input1.outport, amoOper.inport1);
dag.addStream("input2.outport", input2.outport, amoOper.inport2);
GenericTestOperator outputOper = dag.addOperator("outputOper", GenericTestOperator.class);
dag.setOperatorAttribute(outputOper, OperatorContext.PROCESSING_MODE, Operator.ProcessingMode.AT_LEAST_ONCE);
dag.addStream("aloOper.outport1", amoOper.outport1, outputOper.inport1);
try {
dag.validate();
Assert.fail("Exception expected for " + outputOper);
} catch (ValidationException ve) {
Assert.assertEquals("", ve.getMessage(), "Processing mode outputOper/AT_LEAST_ONCE not valid for source amoOper/AT_MOST_ONCE");
}
dag.setOperatorAttribute(outputOper, OperatorContext.PROCESSING_MODE, null);
dag.validate();
OperatorMeta outputOperOm = dag.getMeta(outputOper);
Assert.assertEquals("" + outputOperOm.getAttributes(), Operator.ProcessingMode.AT_MOST_ONCE, outputOperOm.getValue(OperatorContext.PROCESSING_MODE));
}
use of com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta in project apex-core by apache.
the class LogicalPlanConfigurationTest method simpleAttributeOperatorHelperAssert.
private void simpleAttributeOperatorHelperAssert(Attribute<?> attributeObj, Properties props, Object val, boolean set) {
SimpleTestApplicationWithName app = new SimpleTestApplicationWithName();
LogicalPlanConfiguration dagBuilder = new LogicalPlanConfiguration(new Configuration(false));
dagBuilder.addFromProperties(props, null);
String appPath = app.getClass().getName().replace(".", "/") + ".class";
LogicalPlan dag = new LogicalPlan();
dagBuilder.prepareDAG(dag, app, appPath);
OperatorMeta om1 = dag.getOperatorMeta("operator1");
if (set) {
Assert.assertEquals(val, om1.getValue(attributeObj));
} else {
Assert.assertNotEquals(val, om1.getValue(attributeObj));
}
OperatorMeta om2 = dag.getOperatorMeta("operator2");
if (set) {
Assert.assertEquals(val, om2.getValue(attributeObj));
} else {
Assert.assertNotEquals(val, om2.getValue(attributeObj));
}
OperatorMeta om3 = dag.getOperatorMeta("operator3");
if (set) {
Assert.assertEquals(val, om3.getValue(attributeObj));
} else {
Assert.assertNotEquals(val, om3.getValue(attributeObj));
}
}
use of com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta in project apex-core by apache.
the class LogicalPlanConfigurationTest method testLoadFromPropertiesFile.
@Test
public void testLoadFromPropertiesFile() throws IOException {
Properties props = new Properties();
String resourcePath = "/testTopology.properties";
InputStream is = this.getClass().getResourceAsStream(resourcePath);
if (is == null) {
fail("Could not load " + resourcePath);
}
props.load(is);
LogicalPlanConfiguration pb = new LogicalPlanConfiguration(new Configuration(false)).addFromProperties(props, null);
LogicalPlan dag = new LogicalPlan();
pb.populateDAG(dag);
dag.validate();
assertEquals("number of operator confs", 5, dag.getAllOperators().size());
assertEquals("number of root operators", 1, dag.getRootOperators().size());
StreamMeta s1 = dag.getStream("n1n2");
assertNotNull(s1);
assertTrue("n1n2 locality", DAG.Locality.CONTAINER_LOCAL == s1.getLocality());
OperatorMeta operator3 = dag.getOperatorMeta("operator3");
assertEquals("operator3.classname", GenericTestOperator.class, operator3.getOperator().getClass());
GenericTestOperator doperator3 = (GenericTestOperator) operator3.getOperator();
assertEquals("myStringProperty " + doperator3, "myStringPropertyValueFromTemplate", doperator3.getMyStringProperty());
assertFalse("booleanProperty " + doperator3, doperator3.booleanProperty);
OperatorMeta operator4 = dag.getOperatorMeta("operator4");
GenericTestOperator doperator4 = (GenericTestOperator) operator4.getOperator();
assertEquals("myStringProperty " + doperator4, "overrideOperator4", doperator4.getMyStringProperty());
assertEquals("setterOnlyOperator4 " + doperator4, "setterOnlyOperator4", doperator4.propertySetterOnly);
assertTrue("booleanProperty " + doperator4, doperator4.booleanProperty);
StreamMeta input1 = dag.getStream("inputStream");
assertNotNull(input1);
Assert.assertEquals("input1 source", dag.getOperatorMeta("inputOperator"), input1.getSource().getOperatorMeta());
Set<OperatorMeta> targetNodes = Sets.newHashSet();
for (LogicalPlan.InputPortMeta targetPort : input1.getSinks()) {
targetNodes.add(targetPort.getOperatorMeta());
}
Assert.assertEquals("input1 target ", Sets.newHashSet(dag.getOperatorMeta("operator1"), operator3, operator4), targetNodes);
}
Aggregations