use of com.datatorrent.stram.engine.TestGeneratorInputOperator 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.stram.engine.TestGeneratorInputOperator 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();
}
use of com.datatorrent.stram.engine.TestGeneratorInputOperator in project apex-core by apache.
the class DelayOperatorTest method testCheckpointUpdate.
@Test
public void testCheckpointUpdate() {
LogicalPlan dag = StramTestSupport.createDAG(testMeta);
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<Object> opDelay = dag.addOperator("opDelay", new DefaultDelayOperator<>());
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();
dag.setAttribute(com.datatorrent.api.Context.OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
StreamingContainerManager scm = new StreamingContainerManager(dag);
PhysicalPlan plan = scm.getPhysicalPlan();
// set all operators as active to enable recovery window id update
for (PTOperator oper : plan.getAllOperators().values()) {
oper.setState(PTOperator.State.ACTIVE);
}
Clock clock = new SystemClock();
PTOperator opA1 = plan.getOperators(dag.getMeta(opA)).get(0);
PTOperator opB1 = plan.getOperators(dag.getMeta(opB)).get(0);
PTOperator opC1 = plan.getOperators(dag.getMeta(opC)).get(0);
PTOperator opDelay1 = plan.getOperators(dag.getMeta(opDelay)).get(0);
PTOperator opD1 = plan.getOperators(dag.getMeta(opD)).get(0);
Checkpoint cp3 = new Checkpoint(3L, 0, 0);
Checkpoint cp5 = new Checkpoint(5L, 0, 0);
Checkpoint cp4 = new Checkpoint(4L, 0, 0);
opB1.checkpoints.add(cp3);
opC1.checkpoints.add(cp3);
opC1.checkpoints.add(cp4);
opDelay1.checkpoints.add(cp3);
opDelay1.checkpoints.add(cp5);
opD1.checkpoints.add(cp5);
// construct grouping that would be supplied through LogicalPlan
Set<OperatorMeta> stronglyConnected = Sets.newHashSet(dag.getMeta(opB), dag.getMeta(opC), dag.getMeta(opDelay));
Map<OperatorMeta, Set<OperatorMeta>> groups = new HashMap<>();
for (OperatorMeta om : stronglyConnected) {
groups.put(om, stronglyConnected);
}
UpdateCheckpointsContext ctx = new UpdateCheckpointsContext(clock, false, groups);
scm.updateRecoveryCheckpoints(opB1, ctx, false);
Assert.assertEquals("checkpoint " + opA1, Checkpoint.INITIAL_CHECKPOINT, opA1.getRecoveryCheckpoint());
Assert.assertEquals("checkpoint " + opB1, cp3, opC1.getRecoveryCheckpoint());
Assert.assertEquals("checkpoint " + opC1, cp3, opC1.getRecoveryCheckpoint());
Assert.assertEquals("checkpoint " + opD1, cp5, opD1.getRecoveryCheckpoint());
}
use of com.datatorrent.stram.engine.TestGeneratorInputOperator in project apex-core by apache.
the class DelayOperatorTest method testFibonacci.
@Test(timeout = 60000)
public void testFibonacci() throws Exception {
LogicalPlan dag = new LogicalPlan();
TestGeneratorInputOperator dummyInput = dag.addOperator("DUMMY", TestGeneratorInputOperator.class);
FibonacciOperator fib = dag.addOperator("FIB", FibonacciOperator.class);
DefaultDelayOperator opDelay = dag.addOperator("opDelay", DefaultDelayOperator.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);
new StramLocalCluster(dag).run(new ExitCondition(10, null));
assertFalse(ExitCondition.message, ExitCondition.failed);
assertFibonacci();
}
use of com.datatorrent.stram.engine.TestGeneratorInputOperator in project apex-core by apache.
the class LogicalPlanTest method testExactlyOnceProcessingModeValidation.
@Test
public void testExactlyOnceProcessingModeValidation() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
TestGeneratorInputOperator input2 = dag.addOperator("input2", TestGeneratorInputOperator.class);
GenericTestOperator amoOper = dag.addOperator("amoOper", GenericTestOperator.class);
dag.setOperatorAttribute(amoOper, OperatorContext.PROCESSING_MODE, Operator.ProcessingMode.EXACTLY_ONCE);
dag.addStream("input1.outport", input1.outport, amoOper.inport1);
dag.addStream("input2.outport", input2.outport, amoOper.inport2);
GenericTestOperator outputOper = dag.addOperator("outputOper", GenericTestOperator.class);
dag.addStream("aloOper.outport1", amoOper.outport1, outputOper.inport1);
try {
dag.validate();
Assert.fail("Exception expected for " + outputOper);
} catch (ValidationException ve) {
Assert.assertEquals("", ve.getMessage(), "Processing mode for outputOper should be AT_MOST_ONCE for source amoOper/EXACTLY_ONCE");
}
dag.setOperatorAttribute(outputOper, OperatorContext.PROCESSING_MODE, Operator.ProcessingMode.AT_LEAST_ONCE);
try {
dag.validate();
Assert.fail("Exception expected for " + outputOper);
} catch (ValidationException ve) {
Assert.assertEquals("", ve.getMessage(), "Processing mode outputOper/AT_LEAST_ONCE not valid for source amoOper/EXACTLY_ONCE");
}
// AT_MOST_ONCE is valid
dag.setOperatorAttribute(outputOper, OperatorContext.PROCESSING_MODE, Operator.ProcessingMode.AT_MOST_ONCE);
dag.validate();
}
Aggregations