apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davidyan74 <...@git.apache.org>
Subject [GitHub] incubator-apex-core pull request: APEXCORE-60 Iteration support in...
Date Wed, 16 Dec 2015 02:21:02 GMT
Github user davidyan74 commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-core/pull/185#discussion_r47729596
  
    --- Diff: engine/src/test/java/com/datatorrent/stram/plan/logical/LogicalPlanTest.java
---
    @@ -115,6 +115,142 @@ public void testCycleDetection() {
     
       }
     
    +  @Test
    +  public void testInvalidDelayDetection()
    +  {
    +    LogicalPlan dag = new LogicalPlan();
    +
    +    GenericTestOperator opB = dag.addOperator("B", GenericTestOperator.class);
    +    GenericTestOperator opC = dag.addOperator("C", GenericTestOperator.class);
    +    GenericTestOperator opD = dag.addOperator("D", GenericTestOperator.class);
    +    SimpleDelayOperator opDelay = dag.addOperator("opDelay", SimpleDelayOperator.class);
    +
    +    dag.addStream("BtoC", opB.outport1, opC.inport1);
    +    dag.addStream("CtoD", opC.outport1, opD.inport1);
    +    dag.addStream("CtoDelay", opC.outport2, opDelay.input);
    +    dag.addStream("DelayToD", opDelay.output, opD.inport2);
    +
    +    List<List<String>> invalidDelays = new ArrayList<>();
    +    dag.findInvalidDelays(dag.getMeta(opB), invalidDelays);
    +    assertEquals("operator invalid delay", 1, invalidDelays.size());
    +
    +    try {
    +      dag.validate();
    +      fail("validation should fail");
    +    } catch (ValidationException e) {
    +      // expected
    +    }
    +
    +    dag = new LogicalPlan();
    +
    +    opB = dag.addOperator("B", GenericTestOperator.class);
    +    opC = dag.addOperator("C", GenericTestOperator.class);
    +    opD = dag.addOperator("D", GenericTestOperator.class);
    +    opDelay = dag.addOperator("opDelay", SimpleDelayOperator.class);
    +    dag.setAttribute(opDelay, OperatorContext.APPLICATION_WINDOW_COUNT, 2);
    +    dag.addStream("BtoC", opB.outport1, opC.inport1);
    +    dag.addStream("CtoD", opC.outport1, opD.inport1);
    +    dag.addStream("CtoDelay", opC.outport2, opDelay.input);
    +    dag.addStream("DelayToC", opDelay.output, opC.inport2);
    +
    +    invalidDelays = new ArrayList<>();
    +    dag.findInvalidDelays(dag.getMeta(opB), invalidDelays);
    +    assertEquals("operator invalid delay", 1, invalidDelays.size());
    +
    +    try {
    +      dag.validate();
    +      fail("validation should fail");
    +    } catch (ValidationException e) {
    +      // expected
    +    }
    +
    +  }
    +
    +  @Test
    +  public void testIteration()
    +  {
    +    LogicalPlan dag = new LogicalPlan();
    +
    +    TestGeneratorInputOperator opA = dag.addOperator("A", TestGeneratorInputOperator.class);
    +    GenericTestOperator opB = dag.addOperator("B", GenericTestOperator.class);
    +    GenericTestOperator opC = dag.addOperator("C", GenericTestOperator.class);
    +    GenericTestOperator opD = dag.addOperator("D", GenericTestOperator.class);
    +    SimpleDelayOperator opDelay = dag.addOperator("opDelay", SimpleDelayOperator.class);
    +
    +    dag.addStream("AtoB", opA.outport, opB.inport1);
    +    dag.addStream("BtoC", opB.outport1, opC.inport1);
    +    dag.addStream("CtoD", opC.outport1, opD.inport1);
    +    dag.addStream("CtoDelay", opC.outport2, opDelay.input);
    +    dag.addStream("DelayToB", opDelay.output, opB.inport2);
    +
    +    try {
    +      final StramLocalCluster localCluster = new StramLocalCluster(dag);
    +      localCluster.runAsync();
    +      Thread.sleep(10000);
    +      localCluster.shutdown();
    +    } catch (InterruptedException ex) {
    +      // ignore
    +    } catch (Exception ex) {
    +      throw new RuntimeException(ex);
    +    }
    +  }
    +
    +  public static class FibonacciOperator extends BaseOperator
    +  {
    +    public long currentNumber = 1;
    +    private transient long tempNum;
    +    public transient DefaultInputPort<Object> dummyInputPort = new DefaultInputPort<Object>()
    +    {
    +      @Override
    +      public void process(Object tuple)
    +      {
    +      }
    +    };
    +    public transient DefaultInputPort<Long> input = new DefaultInputPort<Long>()
    +    {
    +      @Override
    +      public void process(Long tuple)
    +      {
    +        tempNum = tuple;
    +      }
    +    };
    +    public transient DefaultOutputPort<Long> output = new DefaultOutputPort<>();
    +
    +
    +    @Override
    +    public void endWindow()
    +    {
    +      output.emit(currentNumber);
    +      System.out.println("==============> " + currentNumber);
    +      currentNumber += tempNum;
    +    }
    +  }
    +
    +  @Test
    +  public void testFibonacci()
    +  {
    +    LogicalPlan dag = new LogicalPlan();
    +
    +    TestGeneratorInputOperator dummyInput = dag.addOperator("DUMMY", TestGeneratorInputOperator.class);
    +    FibonacciOperator fib = dag.addOperator("FIB", FibonacciOperator.class);
    +    SimpleDelayOperator opDelay = dag.addOperator("opDelay", SimpleDelayOperator.class);
    +
    +    dag.addStream("dummy_to_operator", dummyInput.outport, fib.dummyInputPort);
    +    dag.addStream("operator_to_delay", fib.output, opDelay.input);
    +    dag.addStream("delay_to_operator", opDelay.output, fib.input);
    +
    +    try {
    +      final StramLocalCluster localCluster = new StramLocalCluster(dag);
    +      localCluster.runAsync();
    +      Thread.sleep(10000);
    --- End diff --
    
    Done. Please review the new test cases


---
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