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
}
}
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();
}
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();
}
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);
}
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();
}
Aggregations