Search in sources :

Example 21 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-core by apache.

the class LogicalPlanConfigurationTest method testOperatorLevelProperties.

@Test
public void testOperatorLevelProperties() {
    String appName = "app1";
    final GenericTestOperator operator1 = new GenericTestOperator();
    final GenericTestOperator operator2 = new GenericTestOperator();
    StreamingApplication app = new StreamingApplication() {

        @Override
        public void populateDAG(DAG dag, Configuration conf) {
            dag.addOperator("operator1", operator1);
            dag.addOperator("operator2", operator2);
        }
    };
    Properties props = new Properties();
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".class", app.getClass().getName());
    props.put(StreamingApplication.APEX_PREFIX + "operator.*.myStringProperty", "pv1");
    props.put(StreamingApplication.APEX_PREFIX + "operator.*.booleanProperty", Boolean.TRUE.toString());
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator1.myStringProperty", "apv1");
    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);
    Assert.assertEquals("apv1", operator1.getMyStringProperty());
    Assert.assertEquals("pv1", operator2.getMyStringProperty());
    Assert.assertEquals(true, operator2.isBooleanProperty());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) Integer2String(com.datatorrent.api.StringCodec.Integer2String) StreamingApplication(com.datatorrent.api.StreamingApplication) DAG(com.datatorrent.api.DAG) Properties(java.util.Properties) Test(org.junit.Test)

Example 22 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-core by apache.

the class LogicalPlanConfigurationTest method testAppAnnotationAlias.

@Test
public void testAppAnnotationAlias() {
    StreamingApplication app = new AnnotatedApplication();
    Configuration conf = new Configuration(false);
    conf.addResource(StramClientUtils.DT_SITE_XML_FILE);
    LogicalPlanConfiguration builder = new LogicalPlanConfiguration(conf);
    LogicalPlan dag = new LogicalPlan();
    String appPath = app.getClass().getName().replace(".", "/") + ".class";
    builder.prepareDAG(dag, app, appPath);
    Assert.assertEquals("Application name", "AnnotatedAlias", dag.getAttributes().get(com.datatorrent.api.Context.DAGContext.APPLICATION_NAME));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) StreamingApplication(com.datatorrent.api.StreamingApplication) Integer2String(com.datatorrent.api.StringCodec.Integer2String) Test(org.junit.Test)

Example 23 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-core by apache.

the class LogicalPlanConfigurationTest method testPrepareDAG.

@Test
public void testPrepareDAG() {
    final MutableBoolean appInitialized = new MutableBoolean(false);
    StreamingApplication app = new StreamingApplication() {

        @Override
        public void populateDAG(DAG dag, Configuration conf) {
            Assert.assertEquals("", "hostname:9090", dag.getValue(DAG.GATEWAY_CONNECT_ADDRESS));
            dag.setAttribute(DAG.GATEWAY_CONNECT_ADDRESS, "hostname:9091");
            appInitialized.setValue(true);
        }
    };
    Configuration conf = new Configuration(false);
    conf.addResource(StramClientUtils.DT_SITE_XML_FILE);
    LogicalPlanConfiguration pb = new LogicalPlanConfiguration(conf);
    LogicalPlan dag = new LogicalPlan();
    pb.prepareDAG(dag, app, "testconfig");
    Assert.assertTrue("populateDAG called", appInitialized.booleanValue());
    Assert.assertEquals("populateDAG overrides attribute", "hostname:9091", dag.getValue(DAG.GATEWAY_CONNECT_ADDRESS));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) StreamingApplication(com.datatorrent.api.StreamingApplication) DAG(com.datatorrent.api.DAG) Test(org.junit.Test)

Example 24 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-core by apache.

the class LogicalPlanConfigurationTest method testTestTupleClassAttrSetFromConfig.

@Test
public void testTestTupleClassAttrSetFromConfig() {
    Configuration conf = new Configuration(false);
    conf.set(StreamingApplication.APEX_PREFIX + "operator.o2.port.schemaRequiredPort.attr.TUPLE_CLASS", "com.datatorrent.stram.plan.logical.LogicalPlanConfigurationTest$TestSchema");
    StreamingApplication streamingApplication = new StreamingApplication() {

        @Override
        public void populateDAG(DAG dag, Configuration conf) {
            TestGeneratorInputOperator o1 = dag.addOperator("o1", new TestGeneratorInputOperator());
            SchemaTestOperator o2 = dag.addOperator("o2", new SchemaTestOperator());
            dag.addStream("stream", o1.outport, o2.schemaRequiredPort);
        }
    };
    LogicalPlan dag = new LogicalPlan();
    LogicalPlanConfiguration lpc = new LogicalPlanConfiguration(conf);
    lpc.prepareDAG(dag, streamingApplication, "app");
    dag.validate();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) SchemaTestOperator(com.datatorrent.stram.plan.SchemaTestOperator) StreamingApplication(com.datatorrent.api.StreamingApplication) DAG(com.datatorrent.api.DAG) Test(org.junit.Test)

Example 25 with StreamingApplication

use of com.datatorrent.api.StreamingApplication in project apex-malhar by apache.

the class KeyedWindowedOperatorBenchmarkAppTest method test.

@Test
public void test() throws Exception {
    Configuration conf = new Configuration(false);
    LocalMode lma = LocalMode.newInstance();
    DAG dag = lma.getDAG();
    super.populateDAG(dag, conf);
    StreamingApplication app = new StreamingApplication() {

        @Override
        public void populateDAG(DAG dag, Configuration conf) {
        }
    };
    lma.prepareDAG(app, conf);
    // Create local cluster
    final LocalMode.Controller lc = lma.getController();
    lc.run(3000000);
    lc.shutdown();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) DAG(com.datatorrent.api.DAG) StreamingApplication(com.datatorrent.api.StreamingApplication) Test(org.junit.Test)

Aggregations

StreamingApplication (com.datatorrent.api.StreamingApplication)29 Configuration (org.apache.hadoop.conf.Configuration)28 Test (org.junit.Test)23 DAG (com.datatorrent.api.DAG)21 LocalMode (com.datatorrent.api.LocalMode)11 Properties (java.util.Properties)10 Integer2String (com.datatorrent.api.StringCodec.Integer2String)8 AttributeMap (com.datatorrent.api.Attribute.AttributeMap)3 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Attribute (com.datatorrent.api.Attribute)2 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)2 OutputPortMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OutputPortMeta)2 StreamMeta (com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta)2 LogicalPlanConfiguration (com.datatorrent.stram.plan.logical.LogicalPlanConfiguration)2 File (java.io.File)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AppHandle (org.apache.apex.api.Launcher.AppHandle)2 StreamingAppFactory (org.apache.apex.engine.util.StreamingAppFactory)2