use of com.datatorrent.stram.plan.logical.LogicalPlanTest.ValidationTestOperator in project apex-core by apache.
the class LogicalPlanConfigurationTest method testOperatorConfigurationLookup.
@Test
public void testOperatorConfigurationLookup() {
Properties props = new Properties();
// match operator by name
props.put(StreamingApplication.APEX_PREFIX + "template.matchId1.matchIdRegExp", ".*operator1.*");
props.put(StreamingApplication.APEX_PREFIX + "template.matchId1.stringProperty2", "stringProperty2Value-matchId1");
props.put(StreamingApplication.APEX_PREFIX + "template.matchId1.nested.property", "nested.propertyValue-matchId1");
// match class name, lower priority
props.put(StreamingApplication.APEX_PREFIX + "template.matchClass1.matchClassNameRegExp", ".*" + ValidationTestOperator.class.getSimpleName());
props.put(StreamingApplication.APEX_PREFIX + "template.matchClass1.stringProperty2", "stringProperty2Value-matchClass1");
// match class name
props.put(StreamingApplication.APEX_PREFIX + "template.t2.matchClassNameRegExp", ".*" + GenericTestOperator.class.getSimpleName());
props.put(StreamingApplication.APEX_PREFIX + "template.t2.myStringProperty", "myStringPropertyValue");
// direct setting
props.put(StreamingApplication.APEX_PREFIX + "operator.operator3.emitFormat", "emitFormatValue");
LogicalPlan dag = new LogicalPlan();
Operator operator1 = dag.addOperator("operator1", new ValidationTestOperator());
Operator operator2 = dag.addOperator("operator2", new ValidationTestOperator());
Operator operator3 = dag.addOperator("operator3", new GenericTestOperator());
LogicalPlanConfiguration pb = new LogicalPlanConfiguration(new Configuration(false));
LOG.debug("calling addFromProperties");
pb.addFromProperties(props, null);
Map<String, String> configProps = pb.getProperties(dag.getMeta(operator1), "appName");
Assert.assertEquals("" + configProps, 2, configProps.size());
Assert.assertEquals("" + configProps, "stringProperty2Value-matchId1", configProps.get("stringProperty2"));
Assert.assertEquals("" + configProps, "nested.propertyValue-matchId1", configProps.get("nested.property"));
configProps = pb.getProperties(dag.getMeta(operator2), "appName");
Assert.assertEquals("" + configProps, 1, configProps.size());
Assert.assertEquals("" + configProps, "stringProperty2Value-matchClass1", configProps.get("stringProperty2"));
configProps = pb.getProperties(dag.getMeta(operator3), "appName");
Assert.assertEquals("" + configProps, 2, configProps.size());
Assert.assertEquals("" + configProps, "myStringPropertyValue", configProps.get("myStringProperty"));
Assert.assertEquals("" + configProps, "emitFormatValue", configProps.get("emitFormat"));
}
use of com.datatorrent.stram.plan.logical.LogicalPlanTest.ValidationTestOperator in project apex-core by apache.
the class LogicalPlanConfigurationTest method testSetOperatorProperties.
@Test
public void testSetOperatorProperties() {
Configuration conf = new Configuration(false);
conf.set(StreamingApplication.APEX_PREFIX + "operator.o1.prop.myStringProperty", "myStringPropertyValue");
conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.prop.stringArrayField", "a,b,c");
conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.prop.mapProperty.key1", "key1Val");
conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.prop.mapProperty(key1.dot)", "key1dotVal");
conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.prop.mapProperty(key2.dot)", "key2dotVal");
LogicalPlan dag = new LogicalPlan();
GenericTestOperator o1 = dag.addOperator("o1", new GenericTestOperator());
ValidationTestOperator o2 = dag.addOperator("o2", new ValidationTestOperator());
LogicalPlanConfiguration pb = new LogicalPlanConfiguration(conf);
pb.setOperatorProperties(dag, "testSetOperatorProperties");
Assert.assertEquals("o1.myStringProperty", "myStringPropertyValue", o1.getMyStringProperty());
Assert.assertArrayEquals("o2.stringArrayField", new String[] { "a", "b", "c" }, o2.getStringArrayField());
Assert.assertEquals("o2.mapProperty.key1", "key1Val", o2.getMapProperty().get("key1"));
Assert.assertEquals("o2.mapProperty(key1.dot)", "key1dotVal", o2.getMapProperty().get("key1.dot"));
Assert.assertEquals("o2.mapProperty(key2.dot)", "key2dotVal", o2.getMapProperty().get("key2.dot"));
}
Aggregations