use of com.datatorrent.stram.plan.logical.LogicalPlan in project apex-core by apache.
the class PhysicalPlanTest method testSingleFinalCascadingUnifier.
@Test
public void testSingleFinalCascadingUnifier() {
LogicalPlan dag = new LogicalPlan();
//TestGeneratorInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.class);
PartitioningTestOperator o1 = dag.addOperator("o1", PartitioningTestOperator.class);
o1.partitionKeys = new Integer[] { 0, 1, 2, 3 };
o1.setPartitionCount(3);
dag.setOperatorAttribute(o1, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { new PartitioningTest.PartitionLoadWatch() }));
dag.setOutputPortAttribute(o1.outport1, PortContext.UNIFIER_LIMIT, 2);
dag.setOutputPortAttribute(o1.outport1, PortContext.UNIFIER_SINGLE_FINAL, true);
OperatorMeta o1Meta = dag.getMeta(o1);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
dag.setOperatorAttribute(o2, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(3));
OperatorMeta o2Meta = dag.getMeta(o2);
dag.addStream("o1.outport1", o1.outport1, o2.inport1);
dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, 12);
TestPlanContext ctx = new TestPlanContext();
dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
PhysicalPlan plan = new PhysicalPlan(dag, ctx);
Assert.assertEquals("number of containers", 10, plan.getContainers().size());
List<PTOperator> o1Partitions = plan.getOperators(o1Meta);
Assert.assertEquals("partitions " + o1Meta, 4, o1Partitions.size());
Assert.assertEquals("partitioned map " + o1.partitions, 4, o1.partitions.size());
List<PTOperator> o2Partitions = plan.getOperators(o2Meta);
Assert.assertEquals("partitions " + o1Meta, 3, o2Partitions.size());
for (PTOperator o : o1Partitions) {
Assert.assertEquals("outputs " + o, 1, o.getOutputs().size());
for (PTOutput out : o.getOutputs()) {
Assert.assertEquals("sinks " + out, 1, out.sinks.size());
}
Assert.assertNotNull("container " + o, o.getContainer());
}
List<PTOperator> o1Unifiers = plan.getMergeOperators(o1Meta);
// 2 cascadingUnifiers and one-downstream partition unifier
Assert.assertEquals("o1Unifiers " + o1Meta, 3, o1Unifiers.size());
List<PTOperator> finalUnifiers = new ArrayList<>();
for (PTOperator o : o1Unifiers) {
Assert.assertEquals("inputs " + o, 2, o.getInputs().size());
Assert.assertEquals("outputs " + o, 1, o.getOutputs().size());
List<PTInput> sinks = o.getOutputs().get(0).sinks;
boolean finalUnifier = sinks.size() > 0 ? (sinks.get(0).target.getOperatorMeta() == o2Meta) : false;
if (!finalUnifier) {
for (PTOutput out : o.getOutputs()) {
Assert.assertEquals("sinks " + out, 1, out.sinks.size());
Assert.assertTrue(out.sinks.get(0).target.isUnifier());
}
} else {
for (PTOutput out : o.getOutputs()) {
Assert.assertEquals("sinks " + out, 3, out.sinks.size());
for (PTInput in : out.sinks) {
Assert.assertFalse(in.target.isUnifier());
}
}
finalUnifiers.add(o);
}
Assert.assertNotNull("container " + o, o.getContainer());
}
Assert.assertEquals("o1 final unifiers", 1, finalUnifiers.size());
for (int i = 0; i < 4; i++) {
PTContainer container = plan.getContainers().get(i);
Assert.assertEquals("number operators " + container, 1, container.getOperators().size());
Assert.assertTrue(o1Partitions.contains(container.getOperators().get(0)));
}
for (int i = 4; i < 7; i++) {
PTContainer container = plan.getContainers().get(i);
Assert.assertEquals("number operators " + container, 1, container.getOperators().size());
Assert.assertTrue(o1Unifiers.contains(container.getOperators().get(0)));
}
for (int i = 7; i < 10; i++) {
PTContainer container = plan.getContainers().get(i);
Assert.assertEquals("number operators " + container, 1, container.getOperators().size());
Assert.assertTrue(o2Partitions.contains(container.getOperators().get(0)));
}
PTOperator p1 = o1Partitions.get(0);
StatsListener l = p1.statsListeners.get(0);
Assert.assertTrue("stats handlers " + p1.statsListeners, l instanceof PartitioningTest.PartitionLoadWatch);
PartitioningTest.PartitionLoadWatch.put(p1, 1);
plan.onStatusUpdate(p1);
Assert.assertEquals("partition scaling triggered", 1, ctx.events.size());
o1.partitionKeys = new Integer[] { 0, 1, 2, 3, 4 };
ctx.events.remove(0).run();
o1Partitions = plan.getOperators(o1Meta);
Assert.assertEquals("partitions " + o1Meta, 5, o1Partitions.size());
Assert.assertEquals("partitioned map " + o1.partitions, 5, o1.partitions.size());
o1Unifiers = plan.getMergeOperators(o1Meta);
// 3(l1)x2(l2)
Assert.assertEquals("o1Unifiers " + o1Meta, 4, o1Unifiers.size());
for (PTOperator o : o1Unifiers) {
Assert.assertNotNull("container null: " + o, o.getContainer());
}
}
use of com.datatorrent.stram.plan.logical.LogicalPlan in project apex-core by apache.
the class PhysicalPlanTest method testParallelPartitioning.
@Test
public void testParallelPartitioning() {
LogicalPlan dag = new LogicalPlan();
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
dag.setOperatorAttribute(o2, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
dag.addStream("o1Output1", o1.outport1, o2.inport1, o3.inport1).setLocality(null);
dag.addStream("o2Output1", o2.outport1, o3.inport2).setLocality(Locality.CONTAINER_LOCAL);
dag.setInputPortAttribute(o3.inport2, PortContext.PARTITION_PARALLEL, true);
// parallel partition two downstream operators
PartitioningTestOperator o3_1 = dag.addOperator("o3_1", PartitioningTestOperator.class);
o3_1.fixedCapacity = false;
dag.setInputPortAttribute(o3_1.inport1, PortContext.PARTITION_PARALLEL, true);
OperatorMeta o3_1Meta = dag.getMeta(o3_1);
GenericTestOperator o3_2 = dag.addOperator("o3_2", GenericTestOperator.class);
dag.setInputPortAttribute(o3_2.inport1, PortContext.PARTITION_PARALLEL, true);
OperatorMeta o3_2Meta = dag.getMeta(o3_2);
dag.addStream("o3outport1", o3.outport1, o3_1.inport1, o3_2.inport1).setLocality(Locality.CONTAINER_LOCAL);
// join within parallel partition
GenericTestOperator o4 = dag.addOperator("o4", GenericTestOperator.class);
dag.setInputPortAttribute(o4.inport1, PortContext.PARTITION_PARALLEL, true);
dag.setInputPortAttribute(o4.inport2, PortContext.PARTITION_PARALLEL, true);
OperatorMeta o4Meta = dag.getMeta(o4);
dag.addStream("o3_1.outport1", o3_1.outport1, o4.inport1).setLocality(Locality.CONTAINER_LOCAL);
dag.addStream("o3_2.outport1", o3_2.outport1, o4.inport2).setLocality(Locality.CONTAINER_LOCAL);
// non inline
GenericTestOperator o5single = dag.addOperator("o5single", GenericTestOperator.class);
dag.addStream("o4outport1", o4.outport1, o5single.inport1);
int maxContainers = 4;
dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, maxContainers);
dag.setAttribute(OperatorContext.STORAGE_AGENT, new TestPlanContext());
PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());
Assert.assertEquals("number of containers", 4, plan.getContainers().size());
PTContainer container1 = plan.getContainers().get(0);
Assert.assertEquals("number operators " + container1, 1, container1.getOperators().size());
Assert.assertEquals("operators " + container1, "o1", container1.getOperators().get(0).getOperatorMeta().getName());
for (int i = 1; i < 3; i++) {
PTContainer container2 = plan.getContainers().get(i);
Assert.assertEquals("number operators " + container2, 5, container2.getOperators().size());
Set<String> expectedLogicalNames = Sets.newHashSet("o2", "o3", o3_1Meta.getName(), o3_2Meta.getName(), o4Meta.getName());
Set<String> actualLogicalNames = Sets.newHashSet();
for (PTOperator p : container2.getOperators()) {
actualLogicalNames.add(p.getOperatorMeta().getName());
}
Assert.assertEquals("operator names " + container2, expectedLogicalNames, actualLogicalNames);
}
List<OperatorMeta> inlineOperators = Lists.newArrayList(dag.getMeta(o2), o3_1Meta, o3_2Meta);
for (OperatorMeta ow : inlineOperators) {
List<PTOperator> partitionedInstances = plan.getOperators(ow);
Assert.assertEquals("" + partitionedInstances, 2, partitionedInstances.size());
for (PTOperator p : partitionedInstances) {
Assert.assertEquals("outputs " + p, 1, p.getOutputs().size());
Assert.assertTrue("downstream inline " + p.getOutputs().get(0), p.getOutputs().get(0).isDownStreamInline());
}
}
// container 4: Unifier for o4 & O5
PTContainer container4 = plan.getContainers().get(3);
PTOperator ptOperatorO5 = plan.getOperators(dag.getMeta(o5single)).get(0);
PTOperator unifier = ptOperatorO5.upstreamMerge.values().iterator().next();
Assert.assertEquals("number operators " + container4, 2, container4.getOperators().size());
Assert.assertEquals("operators " + container4, o4Meta.getMeta(o4.outport1).getUnifierMeta(), unifier.getOperatorMeta());
Assert.assertEquals("unifier inputs" + unifier.getInputs(), 2, unifier.getInputs().size());
Assert.assertEquals("unifier outputs" + unifier.getOutputs(), 1, unifier.getOutputs().size());
OperatorMeta o5Meta = dag.getMeta(o5single);
Assert.assertEquals("operators " + container4, o5Meta, ptOperatorO5.getOperatorMeta());
List<PTOperator> o5Instances = plan.getOperators(o5Meta);
Assert.assertEquals("" + o5Instances, 1, o5Instances.size());
Assert.assertEquals("inputs" + ptOperatorO5.getInputs(), 1, ptOperatorO5.getInputs().size());
Assert.assertEquals("inputs" + ptOperatorO5.getInputs(), unifier, ptOperatorO5.getInputs().get(0).source.source);
// verify partitioner was called for parallel partition
Assert.assertNotNull("partitioner called " + o3_1, o3_1.partitions);
for (PTOperator p : plan.getOperators(o3_1Meta)) {
Assert.assertEquals("inputs " + p, 1, p.getInputs().size());
for (PTInput pti : p.getInputs()) {
Assert.assertNull("partition keys " + pti, pti.partitions);
}
}
}
use of com.datatorrent.stram.plan.logical.LogicalPlan in project apex-core by apache.
the class PhysicalPlanTest method testNumberOfUnifiersWithEvenPartitions.
@Test
public void testNumberOfUnifiersWithEvenPartitions() {
LogicalPlan dag = new LogicalPlan();
dag.setAttribute(OperatorContext.STORAGE_AGENT, new StramTestSupport.MemoryStorageAgent());
GenericTestOperator node1 = dag.addOperator("node1", GenericTestOperator.class);
GenericTestOperator node2 = dag.addOperator("node2", GenericTestOperator.class);
dag.addStream("node1.outport1", node1.outport1, node2.inport1);
dag.setOperatorAttribute(node1, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(8));
dag.setOutputPortAttribute(node1.outport1, PortContext.UNIFIER_LIMIT, 4);
PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());
List<PTContainer> containers = plan.getContainers();
int unifierCount = 0;
int totalOperators = 0;
for (PTContainer container : containers) {
List<PTOperator> operators = container.getOperators();
for (PTOperator operator : operators) {
totalOperators++;
if (operator.isUnifier()) {
unifierCount++;
}
}
}
Assert.assertEquals("Number of operators", 12, totalOperators);
Assert.assertEquals("Number of unifiers", 3, unifierCount);
}
use of com.datatorrent.stram.plan.logical.LogicalPlan in project apex-core by apache.
the class PhysicalPlanTest method testNumberOfUnifiers.
@Test
public void testNumberOfUnifiers() {
LogicalPlan dag = new LogicalPlan();
dag.setAttribute(OperatorContext.STORAGE_AGENT, new StramTestSupport.MemoryStorageAgent());
GenericTestOperator node1 = dag.addOperator("node1", GenericTestOperator.class);
GenericTestOperator node2 = dag.addOperator("node2", GenericTestOperator.class);
dag.addStream("node1.outport1", node1.outport1, node2.inport1);
dag.setOperatorAttribute(node1, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(5));
dag.setOutputPortAttribute(node1.outport1, PortContext.UNIFIER_LIMIT, 3);
PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());
List<PTContainer> containers = plan.getContainers();
int unifierCount = 0;
int totalOperators = 0;
for (PTContainer container : containers) {
List<PTOperator> operators = container.getOperators();
for (PTOperator operator : operators) {
totalOperators++;
if (operator.isUnifier()) {
unifierCount++;
}
}
}
Assert.assertEquals("Number of operators", 8, totalOperators);
Assert.assertEquals("Number of unifiers", 2, unifierCount);
}
use of com.datatorrent.stram.plan.logical.LogicalPlan in project apex-core by apache.
the class PhysicalPlanTest method testMxNPartitionForSlidingWindow.
@Test
public void testMxNPartitionForSlidingWindow() {
LogicalPlan dag = new LogicalPlan();
dag.setAttribute(OperatorContext.STORAGE_AGENT, new StramTestSupport.MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
dag.setOperatorAttribute(o1, OperatorContext.APPLICATION_WINDOW_COUNT, 4);
dag.setOperatorAttribute(o1, OperatorContext.SLIDE_BY_WINDOW_COUNT, 2);
dag.setOperatorAttribute(o1, OperatorContext.PARTITIONER, new StatelessPartitioner<>(2));
dag.getOperatorMeta("o1").getMeta(o1.outport1).getUnifierMeta().getAttributes().put(OperatorContext.MEMORY_MB, 1024);
dag.setOperatorAttribute(o2, OperatorContext.PARTITIONER, new StatelessPartitioner<>(2));
dag.setOperatorAttribute(o2, OperatorContext.SLIDE_BY_WINDOW_COUNT, 2);
dag.setOperatorAttribute(o2, OperatorContext.APPLICATION_WINDOW_COUNT, 4);
dag.addStream("o1.outport1", o1.outport1, o2.inport1);
dag.addStream("o2.outport1", o2.outport1, o3.inport1);
PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());
Assert.assertEquals("number of containers", 9, plan.getContainers().size());
}
Aggregations