Search in sources :

Example 1 with ValidationTestOperator

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"));
}
Also used : GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) Operator(com.datatorrent.api.Operator) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) PTOperator(com.datatorrent.stram.plan.physical.PTOperator) ValidationTestOperator(com.datatorrent.stram.plan.logical.LogicalPlanTest.ValidationTestOperator) SchemaTestOperator(com.datatorrent.stram.plan.SchemaTestOperator) BaseOperator(com.datatorrent.common.util.BaseOperator) ValidationTestOperator(com.datatorrent.stram.plan.logical.LogicalPlanTest.ValidationTestOperator) Configuration(org.apache.hadoop.conf.Configuration) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) Integer2String(com.datatorrent.api.StringCodec.Integer2String) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with ValidationTestOperator

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"));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ValidationTestOperator(com.datatorrent.stram.plan.logical.LogicalPlanTest.ValidationTestOperator) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) Test(org.junit.Test)

Aggregations

GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)2 ValidationTestOperator (com.datatorrent.stram.plan.logical.LogicalPlanTest.ValidationTestOperator)2 Configuration (org.apache.hadoop.conf.Configuration)2 Test (org.junit.Test)2 Operator (com.datatorrent.api.Operator)1 Integer2String (com.datatorrent.api.StringCodec.Integer2String)1 BaseOperator (com.datatorrent.common.util.BaseOperator)1 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)1 SchemaTestOperator (com.datatorrent.stram.plan.SchemaTestOperator)1 PTOperator (com.datatorrent.stram.plan.physical.PTOperator)1 Properties (java.util.Properties)1