Search in sources :

Example 1 with DefaultDelayOperator

use of com.datatorrent.common.util.DefaultDelayOperator in project apex-core by apache.

the class DelayOperatorTest method testInvalidDelayDetection.

@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);
    DefaultDelayOperator opDelay = dag.addOperator("opDelay", DefaultDelayOperator.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, new Stack<OperatorMeta>());
    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", DefaultDelayOperator.class);
    dag.setOperatorAttribute(opDelay, Context.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, new Stack<OperatorMeta>());
    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", DefaultDelayOperator.class);
    dag.addStream("BtoC", opB.outport1, opC.inport1);
    dag.addStream("CtoD", opC.outport1, opD.inport1);
    dag.addStream("CtoDelay", opC.outport2, opDelay.input).setLocality(DAG.Locality.THREAD_LOCAL);
    dag.addStream("DelayToC", opDelay.output, opC.inport2).setLocality(DAG.Locality.THREAD_LOCAL);
    try {
        dag.validate();
        fail("validation should fail");
    } catch (ValidationException e) {
    // expected
    }
}
Also used : ValidationException(javax.validation.ValidationException) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DefaultDelayOperator(com.datatorrent.common.util.DefaultDelayOperator) Test(org.junit.Test)

Example 2 with DefaultDelayOperator

use of com.datatorrent.common.util.DefaultDelayOperator in project apex-core by apache.

the class DelayOperatorTest method testValidationWithMultipleStreamLoops.

@Test
public void testValidationWithMultipleStreamLoops() {
    LogicalPlan dag = StramTestSupport.createDAG(testMeta);
    TestGeneratorInputOperator source = dag.addOperator("A", TestGeneratorInputOperator.class);
    GenericTestOperator op1 = dag.addOperator("Op1", GenericTestOperator.class);
    GenericTestOperator op2 = dag.addOperator("Op2", GenericTestOperator.class);
    DefaultDelayOperator delay = dag.addOperator("Delay", DefaultDelayOperator.class);
    dag.addStream("Source", source.outport, op1.inport1);
    dag.addStream("Stream1", op1.outport1, op2.inport1);
    dag.addStream("Stream2", op1.outport2, op2.inport2);
    dag.addStream("Op to Delay", op2.outport1, delay.input);
    dag.addStream("Delay to Op", delay.output, op1.inport2);
    dag.validate();
}
Also used : GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) DefaultDelayOperator(com.datatorrent.common.util.DefaultDelayOperator) Test(org.junit.Test)

Example 3 with DefaultDelayOperator

use of com.datatorrent.common.util.DefaultDelayOperator in project apex-core by apache.

the class DelayOperatorTest method testValidDelay.

@Test
public void testValidDelay() {
    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);
    DefaultDelayOperator opDelay = dag.addOperator("opDelay", DefaultDelayOperator.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);
    dag.validate();
}
Also used : GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) DefaultDelayOperator(com.datatorrent.common.util.DefaultDelayOperator) Test(org.junit.Test)

Example 4 with DefaultDelayOperator

use of com.datatorrent.common.util.DefaultDelayOperator in project apex-core by apache.

the class CheckpointTest method testUpdateRecoveryCheckpointWithCycle.

@Test
public void testUpdateRecoveryCheckpointWithCycle() throws Exception {
    Clock clock = new SystemClock();
    dag.setAttribute(com.datatorrent.api.Context.OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
    // Simulate a DAG with a loop which has a unifier operator
    TestGeneratorInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.class);
    GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
    GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
    GenericTestOperator o4 = dag.addOperator("o4", GenericTestOperator.class);
    DefaultDelayOperator d = dag.addOperator("d", DefaultDelayOperator.class);
    dag.addStream("o1.output1", o1.outport, o2.inport1);
    dag.addStream("o2.output1", o2.outport1, o3.inport1);
    dag.addStream("o3.output1", o3.outport1, o4.inport1);
    dag.addStream("o4.output1", o4.outport1, d.input);
    dag.addStream("d.output", d.output, o2.inport2);
    dag.setOperatorAttribute(o3, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<Operator>(2));
    dag.validate();
    StreamingContainerManager dnm = new StreamingContainerManager(dag);
    PhysicalPlan plan = dnm.getPhysicalPlan();
    for (PTOperator oper : plan.getAllOperators().values()) {
        Assert.assertEquals("Initial activation windowId" + oper, Checkpoint.INITIAL_CHECKPOINT, oper.getRecoveryCheckpoint());
        Assert.assertEquals("Checkpoints empty" + oper, Collections.emptyList(), oper.checkpoints);
    }
    Checkpoint cp1 = new Checkpoint(1L, 0, 0);
    Checkpoint cp2 = new Checkpoint(2L, 0, 0);
    Map<OperatorMeta, Set<OperatorMeta>> checkpointGroups = dnm.getCheckpointGroups();
    Map<Integer, PTOperator> allOperators = plan.getAllOperators();
    for (PTOperator operator : allOperators.values()) {
        operator.setState(PTOperator.State.ACTIVE);
        operator.checkpoints.add(cp1);
        dnm.updateRecoveryCheckpoints(operator, new UpdateCheckpointsContext(clock, false, checkpointGroups), false);
    }
    List<PTOperator> physicalO1 = plan.getOperators(dag.getOperatorMeta("o1"));
    physicalO1.get(0).checkpoints.add(cp2);
    dnm.updateRecoveryCheckpoints(physicalO1.get(0), new UpdateCheckpointsContext(clock, false, checkpointGroups), false);
    Assert.assertEquals("Recovery checkpoint updated ", physicalO1.get(0).getRecoveryCheckpoint(), cp1);
}
Also used : GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) Operator(com.datatorrent.api.Operator) DefaultDelayOperator(com.datatorrent.common.util.DefaultDelayOperator) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) BaseOperator(com.datatorrent.common.util.BaseOperator) PTOperator(com.datatorrent.stram.plan.physical.PTOperator) InputOperator(com.datatorrent.api.InputOperator) PhysicalPlan(com.datatorrent.stram.plan.physical.PhysicalPlan) Set(java.util.Set) SystemClock(org.apache.hadoop.yarn.util.SystemClock) PTOperator(com.datatorrent.stram.plan.physical.PTOperator) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) Clock(org.apache.hadoop.yarn.util.Clock) SystemClock(org.apache.hadoop.yarn.util.SystemClock) Checkpoint(com.datatorrent.stram.api.Checkpoint) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) MemoryStorageAgent(com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent) DefaultDelayOperator(com.datatorrent.common.util.DefaultDelayOperator) UpdateCheckpointsContext(com.datatorrent.stram.StreamingContainerManager.UpdateCheckpointsContext) Test(org.junit.Test)

Example 5 with DefaultDelayOperator

use of com.datatorrent.common.util.DefaultDelayOperator in project apex-core by apache.

the class DelayOperatorTest method testFibonacciRecovery1.

@Test(timeout = 60000)
public void testFibonacciRecovery1() throws Exception {
    LogicalPlan dag = StramTestSupport.createDAG(testMeta);
    TestGeneratorInputOperator dummyInput = dag.addOperator("DUMMY", TestGeneratorInputOperator.class);
    FailableFibonacciOperator fib = dag.addOperator("FIB", FailableFibonacciOperator.class);
    DefaultDelayOperator opDelay = dag.addOperator("opDelay", DefaultDelayOperator.class);
    fib.failableOperator = new FailableOperator(fib, 3, true);
    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);
    dag.getAttributes().put(LogicalPlan.CHECKPOINT_WINDOW_COUNT, 2);
    dag.getAttributes().put(LogicalPlan.STREAMING_WINDOW_SIZE_MILLIS, 300);
    dag.getAttributes().put(LogicalPlan.HEARTBEAT_INTERVAL_MILLIS, 50);
    final StramLocalCluster localCluster = new StramLocalCluster(dag);
    localCluster.setPerContainerBufferServer(true);
    localCluster.run(new ExitCondition(30, FailableOperator.isFailureSimulated));
    assertFalse(ExitCondition.message, ExitCondition.failed);
    assertTrue(FibonacciOperator.results.size() >= 30);
    assertFibonacci();
}
Also used : TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) DefaultDelayOperator(com.datatorrent.common.util.DefaultDelayOperator) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) Test(org.junit.Test)

Aggregations

DefaultDelayOperator (com.datatorrent.common.util.DefaultDelayOperator)7 Test (org.junit.Test)6 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)5 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)4 StramLocalCluster (com.datatorrent.stram.StramLocalCluster)2 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)2 InputOperator (com.datatorrent.api.InputOperator)1 Operator (com.datatorrent.api.Operator)1 BaseOperator (com.datatorrent.common.util.BaseOperator)1 UpdateCheckpointsContext (com.datatorrent.stram.StreamingContainerManager.UpdateCheckpointsContext)1 Checkpoint (com.datatorrent.stram.api.Checkpoint)1 PTOperator (com.datatorrent.stram.plan.physical.PTOperator)1 PhysicalPlan (com.datatorrent.stram.plan.physical.PhysicalPlan)1 MemoryStorageAgent (com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 ValidationException (javax.validation.ValidationException)1 RandomEventGenerator (org.apache.apex.malhar.lib.testbench.RandomEventGenerator)1 Clock (org.apache.hadoop.yarn.util.Clock)1