apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tushargosavi <...@git.apache.org>
Subject [GitHub] incubator-apex-core pull request: APEX-103: Add module and dag int...
Date Mon, 07 Dec 2015 08:59:15 GMT
Github user tushargosavi commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-core/pull/148#discussion_r46797695
  
    --- Diff: engine/src/test/java/com/datatorrent/stram/plan/logical/module/ModuleAppTest.java
---
    @@ -0,0 +1,185 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package com.datatorrent.stram.plan.logical.module;
    +
    +import java.io.IOException;
    +import java.util.Random;
    +
    +import javax.validation.ConstraintViolationException;
    +
    +import org.junit.Assert;
    +import org.junit.Test;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import org.apache.hadoop.conf.Configuration;
    +
    +import com.datatorrent.api.DAG;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.DefaultOutputPort;
    +import com.datatorrent.api.InputOperator;
    +import com.datatorrent.api.LocalMode;
    +import com.datatorrent.api.Module;
    +import com.datatorrent.api.StreamingApplication;
    +import com.datatorrent.common.util.BaseOperator;
    +import com.datatorrent.stram.plan.logical.LogicalPlan;
    +import com.datatorrent.stram.plan.logical.LogicalPlanConfiguration;
    +
    +/**
    + * Unit tests for testing Dag expansion with modules and proxy port substitution
    + */
    +public class ModuleAppTest
    +{
    +
    +  /*
    +   * Input Operator - 1
    +   */
    +  public static class DummyInputOperator extends BaseOperator implements InputOperator
    +  {
    +
    +    Random r = new Random();
    +    public transient DefaultOutputPort<Integer> output = new DefaultOutputPort<Integer>();
    +
    +    @Override
    +    public void emitTuples()
    +    {
    +      output.emit(r.nextInt());
    +    }
    +  }
    +
    +  /*
    +   * Input Operator - 1.1
    +   */
    +  public static class DummyOperatorAfterInput extends BaseOperator
    +  {
    +
    +    public transient DefaultInputPort<Integer> input = new DefaultInputPort<Integer>()
    +    {
    +      @Override
    +      public void process(Integer tuple)
    +      {
    +        output.emit(tuple);
    +      }
    +    };
    +    public transient DefaultOutputPort<Integer> output = new DefaultOutputPort<Integer>();
    +  }
    +
    +  /*
    +   * Operator - 2
    +   */
    +  public static class DummyOperator extends BaseOperator
    +  {
    +    int prop;
    +
    +    public transient DefaultInputPort<Integer> input = new DefaultInputPort<Integer>()
    +    {
    +      @Override
    +      public void process(Integer tuple)
    +      {
    +        LOG.debug(tuple.intValue() + " processed");
    +        output.emit(tuple);
    +      }
    +    };
    +    public transient DefaultOutputPort<Integer> output = new DefaultOutputPort<Integer>();
    +  }
    +
    +  /*
    +   * Output Operator - 3
    +   */
    +  public static class DummyOutputOperator extends BaseOperator
    +  {
    +    int prop;
    +
    +    public transient DefaultInputPort<Integer> input = new DefaultInputPort<Integer>()
    +    {
    +      @Override
    +      public void process(Integer tuple)
    +      {
    +        LOG.debug(tuple.intValue() + " processed");
    +      }
    +    };
    +  }
    +
    +  /*
    +   * Module Definition
    +   */
    +  public static class TestModule implements Module
    +  {
    +
    +    public transient ProxyInputPort<Integer> moduleInput = new Module.ProxyInputPort<Integer>();
    +    public transient ProxyOutputPort<Integer> moduleOutput = new Module.ProxyOutputPort<Integer>();
    +
    +    @Override
    +    public void populateDAG(DAG dag, Configuration conf)
    +    {
    +      LOG.debug("Module - PopulateDAG");
    +      DummyOperator dummyOperator = dag.addOperator("DummyOperator", new DummyOperator());
    +      moduleInput.set(dummyOperator.input);
    +      moduleOutput.set(dummyOperator.output);
    +    }
    +  }
    +
    +  public static class Application implements StreamingApplication
    +  {
    +    @Override
    +    public void populateDAG(DAG dag, Configuration conf)
    +    {
    +      LOG.debug("Application - PopulateDAG");
    +      DummyInputOperator dummyInputOperator = dag.addOperator("DummyInputOperator", new
DummyInputOperator());
    +      DummyOperatorAfterInput dummyOperatorAfterInput = dag.addOperator("DummyOperatorAfterInput",
new DummyOperatorAfterInput());
    +      Module m1 = dag.addModule("TestModule1", new TestModule());
    +      Module m2 = dag.addModule("TestModule2", new TestModule());
    +      DummyOutputOperator dummyOutputOperator = dag.addOperator("DummyOutputOperator",
new DummyOutputOperator());
    +      dag.addStream("Operator To Operator", dummyInputOperator.output, dummyOperatorAfterInput.input);
    +      dag.addStream("Operator To Module", dummyOperatorAfterInput.output, ((TestModule)m1).moduleInput);
    +      dag.addStream("Module To Module", ((TestModule)m1).moduleOutput, ((TestModule)m2).moduleInput);
    +      dag.addStream("Module To Operator", ((TestModule)m2).moduleOutput, dummyOutputOperator.input);
    +    }
    +  }
    +
    +  @Test
    +  public void validateTestApplication()
    +  {
    +    Configuration conf = new Configuration(false);
    +    LogicalPlanConfiguration lpc = new LogicalPlanConfiguration(conf);
    +    LogicalPlan dag = new LogicalPlan();
    +    lpc.prepareDAG(dag, new Application(), "TestApp");
    +
    +    Assert.assertEquals(2, dag.getAllModules().size(), 2);
    +    Assert.assertEquals(5, dag.getAllOperators().size());
    +    Assert.assertEquals(4, dag.getAllStreams().size());
    +    dag.validate();
    +  }
    +
    +  @Test
    +  public void runTestApplication() throws IOException, Exception
    --- End diff --
    
    Removed this test


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message