apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (APEXMALHAR-2006) Stream API Design
Date Thu, 19 May 2016 05:57:13 GMT

    [ https://issues.apache.org/jira/browse/APEXMALHAR-2006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15290517#comment-15290517
] 

ASF GitHub Bot commented on APEXMALHAR-2006:
--------------------------------------------

Github user siyuanh commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/261#discussion_r63825863
  
    --- Diff: stream/src/test/java/org/apache/apex/malhar/stream/api/impl/ApexStreamImplTest.java
---
    @@ -0,0 +1,152 @@
    +/**
    + * 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 org.apache.apex.malhar.stream.api.impl;
    +
    +import java.util.Collection;
    +import java.util.Date;
    +import java.util.HashSet;
    +import java.util.Set;
    +
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import com.datatorrent.api.Context;
    +import com.datatorrent.api.DAG;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.DefaultOutputPort;
    +import com.datatorrent.api.Operator;
    +import com.datatorrent.stram.plan.logical.LogicalPlan;
    +
    +/**
    + * Unit test to default implementation of ApexStream interface
    + */
    +public class ApexStreamImplTest
    +{
    +
    +  @Test
    +  public void testAddOperator()
    +  {
    +    LogicalPlan dag = new LogicalPlan();
    +    TestOperator<String, Integer> firstOperator = new TestOperator();
    +    TestOperator<Integer, Date> secondOperator = new TestOperator();
    +    new ApexStreamImpl<String>().addOperator("first", firstOperator, null, firstOperator.output)
    +        .addOperator("second", secondOperator, secondOperator.input, null)
    +        .with(DAG.Locality.THREAD_LOCAL)
    +        .with(Context.OperatorContext.AUTO_RECORD, true)
    +        .with("prop", "TestProp").populateDag(dag);
    +    Assert.assertTrue(dag.getAllOperators().size() == 2);
    +    Set<String> opNames = new HashSet<>();
    +    opNames.add("first");
    +    opNames.add("second");
    +    for (LogicalPlan.OperatorMeta operatorMeta : dag.getAllOperators()) {
    +      Assert.assertTrue(operatorMeta.getOperator() instanceof TestOperator);
    +      Assert.assertTrue(opNames.contains(operatorMeta.getName()));
    +      if (operatorMeta.getName().equals("second")) {
    +        // Assert the Context.OperatorContext.AUTO_RECORD attribute has been set to true
for second operator
    +        Assert.assertTrue(operatorMeta.getAttributes().get(Context.OperatorContext.AUTO_RECORD));
    +        // Assert the prop has been set to TestProp for second operator
    +        Assert.assertEquals("TestProp", ((TestOperator)operatorMeta.getOperator()).prop);
    +      } else {
    +        // Assert the Context.OperatorContext.AUTO_RECORD attribute keeps as default
false for first operator
    +        Assert.assertNull(operatorMeta.getAttributes().get(Context.OperatorContext.AUTO_RECORD));
    +        // Assert the prop has not been set for first operator
    +        Assert.assertNull(((TestOperator)operatorMeta.getOperator()).prop);
    +      }
    +    }
    +
    +    Collection<LogicalPlan.StreamMeta> streams = dag.getAllStreams();
    +    // Assert there is only one stream
    +    Assert.assertTrue(streams.size() == 1);
    +    for (LogicalPlan.StreamMeta stream : streams) {
    +
    +      // Assert the stream is from first operator to second operator
    +      Assert.assertEquals("first", stream.getSource().getOperatorMeta().getName());
    +      Assert.assertTrue(1 == stream.getSinks().size());
    +      Assert.assertEquals("second", stream.getSinks().get(0).getOperatorWrapper().getName());
    +
    +      // Assert the stream is thread local
    +      Assert.assertTrue(stream.getLocality() == DAG.Locality.THREAD_LOCAL);
    +
    +
    +
    +    }
    +
    +  }
    +
    +  /**
    +   * A mock operator
    +   * @param <T>
    +   * @param <O>
    +   */
    +  public static class TestOperator<T, O> implements Operator
    +  {
    +
    +    private String prop = null;
    +
    +    public void setProp(String prop)
    +    {
    +      this.prop = prop;
    +    }
    +
    +    public String getProp()
    +    {
    +      return prop;
    +    }
    +
    +    public final transient InputPort<T> input = new DefaultInputPort<T>()
    +    {
    +
    +      @Override
    +      public void process(T o)
    +      {
    +
    +      }
    +    };
    +
    +    public final transient OutputPort<O> output = new DefaultOutputPort<>();
    +
    +    @Override
    +    public void beginWindow(long l)
    +    {
    +
    +    }
    +
    +    @Override
    +    public void endWindow()
    +    {
    +
    +    }
    +
    +    @Override
    +    public void setup(Context.OperatorContext context)
    +    {
    +
    +    }
    +
    +    @Override
    +    public void teardown()
    +    {
    +
    +    }
    +  }
    +
    +
    --- End diff --
    
    I'll use BaseOperator 


> Stream API Design
> -----------------
>
>                 Key: APEXMALHAR-2006
>                 URL: https://issues.apache.org/jira/browse/APEXMALHAR-2006
>             Project: Apache Apex Malhar
>          Issue Type: Sub-task
>            Reporter: Siyuan Hua
>            Assignee: Siyuan Hua
>             Fix For: 3.4.0
>
>
> Construct DAG in a similar way as Flink/Spark Streaming



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message