Java Code Examples for com.datatorrent.stram.plan.logical.LogicalPlan#getMeta()

The following examples show how to use com.datatorrent.stram.plan.logical.LogicalPlan#getMeta() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericOperatorPropertyCodecTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericOperatorPropertyCodec()
{
  LogicalPlan dag = new LogicalPlan();
  Map<Class<?>, Class<? extends StringCodec<?>>> codecs = new HashMap<>();
  codecs.put(GenericOperatorProperty.class, GenericOperatorProperty.GenericOperatorPropertyStringCodec.class);
  dag.setAttribute(com.datatorrent.api.Context.DAGContext.STRING_CODECS, codecs);
  dag.setAttribute(com.datatorrent.api.Context.OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());

  GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
  OperatorMeta o1Meta = dag.getMeta(o1);

  TestPlanContext ctx = new TestPlanContext();
  PhysicalPlan plan = new PhysicalPlan(dag, ctx);
  ctx.deploy.clear();
  ctx.undeploy.clear();

  PlanModifier pm = new PlanModifier(plan);
  try {
    pm.setOperatorProperty(o1Meta.getName(), "genericOperatorProperty", "xyz");
    Assert.fail("validation error expected"); // cannot set properties on an operator that is already deployed.
  } catch (javax.validation.ValidationException e) {
    Assert.assertTrue(e.getMessage().contains(o1Meta.toString()));
  }

  GenericTestOperator newOperator = new GenericTestOperator();
  pm.addOperator("newOperator", newOperator);
  pm.setOperatorProperty("newOperator", "genericOperatorProperty", "xyz");
  Assert.assertEquals("", "xyz", newOperator.getGenericOperatorProperty().obtainString());
}
 
Example 2
Source File: PhysicalPlanTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Test
public void testStaticPartitioning()
{
  LogicalPlan dag = new LogicalPlan();
  dag.setAttribute(OperatorContext.STORAGE_AGENT, new StramTestSupport.MemoryStorageAgent());

  TestGeneratorInputOperator node0 = dag.addOperator("node0", TestGeneratorInputOperator.class);
  GenericTestOperator node1 = dag.addOperator("node1", GenericTestOperator.class);
  PartitioningTestOperator partitioned = dag.addOperator("partitioned", PartitioningTestOperator.class);
  partitioned.setPartitionCount(partitioned.partitionKeys.length);
  GenericTestOperator singleton1 = dag.addOperator("singleton1", GenericTestOperator.class);
  GenericTestOperator singleton2 = dag.addOperator("singleton2", GenericTestOperator.class);

  dag.addStream("n0.inport1", node0.outport, node1.inport1);
  dag.addStream("n1.outport1", node1.outport1, partitioned.inport1, partitioned.inportWithCodec);
  dag.addStream("mergeStream", partitioned.outport1, singleton1.inport1, singleton2.inport1);

  dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, 2);

  OperatorMeta partitionedMeta = dag.getMeta(partitioned);

  dag.validate();

  PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());

  Assert.assertEquals("number of containers", 2, plan.getContainers().size());
  Assert.assertNotNull("partition map", partitioned.partitions);
  Assert.assertEquals("partition map " + partitioned.partitions, 3, partitioned.partitions.size());

  List<PTOperator> n2Instances = plan.getOperators(partitionedMeta);
  Assert.assertEquals("partition instances " + n2Instances, partitioned.partitionKeys.length, n2Instances.size());
  for (int i = 0; i < n2Instances.size(); i++) {
    PTOperator po = n2Instances.get(i);
    Map<String, PTInput> inputsMap = new HashMap<>();
    for (PTInput input: po.getInputs()) {
      inputsMap.put(input.portName, input);
      Assert.assertEquals("partitions " + input, Sets.newHashSet(partitioned.partitionKeys[i]), input.partitions.partitions);
      //Assert.assertEquals("codec " + input.logicalStream, PartitioningTestStreamCodec.class, input.logicalStream.getCodecClass());
    }
    Assert.assertEquals("number inputs " + inputsMap, Sets.newHashSet(PartitioningTestOperator.IPORT1, PartitioningTestOperator.INPORT_WITH_CODEC), inputsMap.keySet());
  }

  Collection<PTOperator> unifiers = plan.getMergeOperators(partitionedMeta);
  Assert.assertEquals("number unifiers " + partitionedMeta, 0, unifiers.size());
}
 
Example 3
Source File: PhysicalPlanTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Test
public void testDefaultPartitioning()
{
  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.inport2, node2.inport1);

  int initialPartitionCount = 5;
  OperatorMeta node2Decl = dag.getMeta(node2);
  node2Decl.getAttributes().put(OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(initialPartitionCount));

  PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());

  List<PTOperator> n2Instances = plan.getOperators(node2Decl);
  Assert.assertEquals("partition instances " + n2Instances, initialPartitionCount, n2Instances.size());

  List<Integer> assignedPartitionKeys = Lists.newArrayList();

  for (int i = 0; i < n2Instances.size(); i++) {
    PTOperator n2Partition = n2Instances.get(i);
    Assert.assertNotNull("partition keys null: " + n2Partition, n2Partition.getPartitionKeys());
    Map<InputPort<?>, PartitionKeys> pkeys = n2Partition.getPartitionKeys();
    Assert.assertEquals("partition keys size: " + pkeys, 1, pkeys.size()); // one port partitioned
    InputPort<?> expectedPort = node2.inport2;
    Assert.assertEquals("partition port: " + pkeys, expectedPort, pkeys.keySet().iterator().next());

    Assert.assertEquals("partition mask: " + pkeys, "111", Integer.toBinaryString(pkeys.get(expectedPort).mask));
    Set<Integer> pks = pkeys.get(expectedPort).partitions;
    Assert.assertTrue("number partition keys: " + pkeys, pks.size() == 1 || pks.size() == 2);
    assignedPartitionKeys.addAll(pks);
  }

  int expectedMask = Integer.parseInt("111", 2);
  Assert.assertEquals("assigned partitions ", expectedMask + 1, assignedPartitionKeys.size());
  for (int i = 0; i <= expectedMask; i++) {
    Assert.assertTrue("" + assignedPartitionKeys, assignedPartitionKeys.contains(i));
  }

}
 
Example 4
Source File: PhysicalPlanTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Test
public void testRepartitioningScaleUp()
{
  LogicalPlan dag = new LogicalPlan();

  GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
  GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
  GenericTestOperator mergeNode = dag.addOperator("mergeNode", GenericTestOperator.class);

  dag.addStream("o1.outport1", o1.outport1, o2.inport1, o2.inport2);
  dag.addStream("mergeStream", o2.outport1, mergeNode.inport1);

  OperatorMeta o2Meta = dag.getMeta(o2);
  o2Meta.getAttributes().put(OperatorContext.STATS_LISTENERS,
      Lists.newArrayList((StatsListener)new PartitionLoadWatch(0, 5)));
  o2Meta.getAttributes().put(OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(1));

  TestPlanContext ctx = new TestPlanContext();
  dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
  PhysicalPlan plan = new PhysicalPlan(dag, ctx);

  Assert.assertEquals("number of operators", 3, plan.getAllOperators().size());
  Assert.assertEquals("number of save requests", 3, ctx.backupRequests);

  List<PTOperator> o2Partitions = plan.getOperators(o2Meta);
  Assert.assertEquals("partition count " + o2Meta, 1, o2Partitions.size());

  PTOperator o2p1 = o2Partitions.get(0);
  Assert.assertEquals("stats handlers " + o2p1, 1, o2p1.statsListeners.size());
  StatsListener sl = o2p1.statsListeners.get(0);
  Assert.assertTrue("stats handlers " + o2p1.statsListeners, sl instanceof PartitionLoadWatch);
  ((PartitionLoadWatch)sl).evalIntervalMillis = -1; // no delay

  setThroughput(o2p1, 10);
  plan.onStatusUpdate(o2p1);
  Assert.assertEquals("partitioning triggered", 1, ctx.events.size());
  ctx.backupRequests = 0;
  ctx.events.remove(0).run();

  o2Partitions = plan.getOperators(o2Meta);
  Assert.assertEquals("partition count " + o2Partitions, 2, o2Partitions.size());
  o2p1 = o2Partitions.get(0);
  Assert.assertEquals("sinks " + o2p1.getOutputs(), 1, o2p1.getOutputs().size());
  PTOperator o2p2 = o2Partitions.get(1);
  Assert.assertEquals("sinks " + o2p2.getOutputs(), 1, o2p2.getOutputs().size());

  Set<PTOperator> expUndeploy = Sets.newHashSet(plan.getOperators(dag.getMeta(mergeNode)));
  expUndeploy.add(o2p1);

  expUndeploy.addAll(plan.getOperators(dag.getMeta(mergeNode)).get(0).upstreamMerge.values());

  // verify load update generates expected events per configuration

  setThroughput(o2p1, 0);
  plan.onStatusUpdate(o2p1);
  Assert.assertEquals("load min", 0, ctx.events.size());

  setThroughput(o2p1, 3);
  plan.onStatusUpdate(o2p1);
  Assert.assertEquals("load within range", 0, ctx.events.size());

  setThroughput(o2p1, 10);
  plan.onStatusUpdate(o2p1);
  Assert.assertEquals("load exceeds max", 1, ctx.events.size());

  ctx.backupRequests = 0;
  ctx.events.remove(0).run();

  Assert.assertEquals("new partitions", 3, plan.getOperators(o2Meta).size());
  Assert.assertTrue("", plan.getOperators(o2Meta).contains(o2p2));

  for (PTOperator partition : plan.getOperators(o2Meta)) {
    Assert.assertNotNull("container null " + partition, partition.getContainer());
    Assert.assertEquals("outputs " + partition, 1, partition.getOutputs().size());
    Assert.assertEquals("downstream operators " + partition.getOutputs().get(0).sinks, 1, partition.getOutputs().get(0).sinks.size());
  }
  Assert.assertEquals("" + ctx.undeploy, expUndeploy, ctx.undeploy);

  Set<PTOperator> expDeploy = Sets.newHashSet(plan.getOperators(dag.getMeta(mergeNode)));
  expDeploy.addAll(plan.getOperators(o2Meta));
  expDeploy.remove(o2p2);

  expDeploy.addAll(plan.getOperators(dag.getMeta(mergeNode)).get(0).upstreamMerge.values());

  Assert.assertEquals("" + ctx.deploy, expDeploy, ctx.deploy);
  Assert.assertEquals("Count of storage requests", 2, ctx.backupRequests);

  // partitioning skipped on insufficient head room
  o2p1 = plan.getOperators(o2Meta).get(0);
  plan.setAvailableResources(0);
  setThroughput(o2p1, 10);
  plan.onStatusUpdate(o2p1);
  Assert.assertEquals("not repartitioned", 1, ctx.events.size());
  ctx.events.remove(0).run();
  Assert.assertEquals("partition count unchanged", 3, plan.getOperators(o2Meta).size());

}
 
Example 5
Source File: PhysicalPlanTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
/**
 * Test partitioning of an input operator (no input port).
 * Cover aspects that are not part of generic operator test.
 * Test scaling from one to multiple partitions with unifier when one partition remains unmodified.
 */
@Test
public void testInputOperatorPartitioning()
{
  LogicalPlan dag = new LogicalPlan();
  final TestInputOperator<Object> o1 = dag.addOperator("o1", new TestInputOperator<>());
  GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
  dag.addStream("o1.outport1", o1.output, o2.inport1);

  OperatorMeta o1Meta = dag.getMeta(o1);
  dag.setOperatorAttribute(o1, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[]{new PartitioningTest.PartitionLoadWatch()}));
  TestPartitioner<TestInputOperator<Object>> partitioner = new TestPartitioner<>();
  dag.setOperatorAttribute(o1, OperatorContext.PARTITIONER, partitioner);

  TestPlanContext ctx = new TestPlanContext();
  dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
  PhysicalPlan plan = new PhysicalPlan(dag, ctx);
  Assert.assertEquals("number of containers", 2, plan.getContainers().size());

  List<PTOperator> o1Partitions = plan.getOperators(o1Meta);
  Assert.assertEquals("partitions " + o1Partitions, 1, o1Partitions.size());
  PTOperator o1p1 = o1Partitions.get(0);

  // verify load update generates expected events per configuration
  Assert.assertEquals("stats handlers " + o1p1, 1, o1p1.statsListeners.size());
  StatsListener l = o1p1.statsListeners.get(0);
  Assert.assertTrue("stats handlers " + o1p1.statsListeners, l instanceof PartitioningTest.PartitionLoadWatch);

  PartitioningTest.PartitionLoadWatch.put(o1p1, 1);
  plan.onStatusUpdate(o1p1);
  Assert.assertEquals("scale up triggered", 1, ctx.events.size());
  // add another partition, keep existing as is
  partitioner.extraPartitions.add(new DefaultPartition<>(o1));
  Runnable r = ctx.events.remove(0);
  r.run();
  partitioner.extraPartitions.clear();

  o1Partitions = plan.getOperators(o1Meta);
  Assert.assertEquals("operators after scale up", 2, o1Partitions.size());
  Assert.assertEquals("first partition unmodified", o1p1, o1Partitions.get(0));
  Assert.assertEquals("single output", 1, o1p1.getOutputs().size());
  Assert.assertEquals("output to unifier", 1, o1p1.getOutputs().get(0).sinks.size());

  Set<PTOperator> expUndeploy = Sets.newHashSet(plan.getOperators(dag.getMeta(o2)));
  Set<PTOperator> expDeploy = Sets.newHashSet(o1Partitions.get(1));
  expDeploy.addAll(plan.getMergeOperators(dag.getMeta(o1)));
  expDeploy.addAll(expUndeploy);
  expDeploy.add(o1p1.getOutputs().get(0).sinks.get(0).target);

  Assert.assertEquals("undeploy", expUndeploy, ctx.undeploy);
  Assert.assertEquals("deploy", expDeploy, ctx.deploy);

  for (PTOperator p : o1Partitions) {
    Assert.assertEquals("activation window id " + p, Checkpoint.INITIAL_CHECKPOINT, p.recoveryCheckpoint);
    Assert.assertEquals("checkpoints " + p + " " + p.checkpoints, Lists.newArrayList(), p.checkpoints);
    PartitioningTest.PartitionLoadWatch.put(p, -1);
    plan.onStatusUpdate(p);
  }
  ctx.events.remove(0).run();
  Assert.assertEquals("operators after scale down", 1, plan.getOperators(o1Meta).size());
}
 
Example 6
Source File: PhysicalPlanTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
/**
 * Test unifier gets removed when number partitions drops to 1.
 */
@Test
public void testRepartitioningScaleDownSinglePartition()
{
  LogicalPlan dag = new LogicalPlan();

  TestInputOperator<?> o1 = dag.addOperator("o1", TestInputOperator.class);
  GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);

  dag.addStream("o1.outport1", o1.output, o2.inport1);
  OperatorMeta o1Meta = dag.getMeta(o1);
  dag.setOperatorAttribute(o1, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
  dag.setOperatorAttribute(o1, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[]{new PartitioningTest.PartitionLoadWatch()}));

  TestPlanContext ctx = new TestPlanContext();
  dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
  PhysicalPlan plan = new PhysicalPlan(dag, ctx);

  List<PTOperator> o1Partitions = plan.getOperators(o1Meta);
  Assert.assertEquals("partitions " + o1Partitions, 2, o1Partitions.size());
  PTOperator o1p1 = o1Partitions.get(0);
  PTOperator p1Doper = o1p1.getOutputs().get(0).sinks.get(0).target;
  Assert.assertSame("", p1Doper.getOperatorMeta(), o1Meta.getMeta(o1.output).getUnifierMeta());
  Assert.assertTrue("unifier ", p1Doper.isUnifier());
  Assert.assertEquals("Unifiers " + o1Meta, 1, o1p1.getOutputs().get(0).sinks.size());

  Collection<PTOperator> o1Unifiers = new ArrayList<>(plan.getOperators(dag.getMeta(o2)).get(0).upstreamMerge.values());

  StatsListener l = o1p1.statsListeners.get(0);
  Assert.assertTrue("stats handlers " + o1p1.statsListeners, l instanceof PartitioningTest.PartitionLoadWatch);
  PartitioningTest.PartitionLoadWatch.put(o1p1, -1);
  PartitioningTest.PartitionLoadWatch.put(o1Partitions.get(1), -1);

  plan.onStatusUpdate(o1p1);
  plan.onStatusUpdate(o1Partitions.get(1));
  Assert.assertEquals("partition scaling triggered", 1, ctx.events.size());
  ctx.events.remove(0).run();

  List<PTOperator> o1NewPartitions = plan.getOperators(o1Meta);
  Assert.assertEquals("partitions " + o1NewPartitions, 1, o1NewPartitions.size());

  List<PTOperator> o1NewUnifiers = new ArrayList<>(plan.getOperators(dag.getMeta(o2)).get(0).upstreamMerge.values());

  Assert.assertEquals("unifiers " + o1Meta, 0, o1NewUnifiers.size());
  p1Doper = o1p1.getOutputs().get(0).sinks.get(0).target;
  Assert.assertTrue("", p1Doper.getOperatorMeta() == dag.getMeta(o2));
  Assert.assertFalse("unifier ", p1Doper.isUnifier());

  Assert.assertTrue("removed unifier from deployment " + ctx.undeploy, ctx.undeploy.containsAll(o1Unifiers));
  Assert.assertFalse("removed unifier from deployment " + ctx.deploy, ctx.deploy.containsAll(o1Unifiers));

  // scale up, ensure unifier is setup at activation checkpoint
  setActivationCheckpoint(o1NewPartitions.get(0), 3);
  PartitioningTest.PartitionLoadWatch.put(o1NewPartitions.get(0), 1);
  plan.onStatusUpdate(o1NewPartitions.get(0));
  Assert.assertEquals("partition scaling triggered", 1, ctx.events.size());
  ctx.events.remove(0).run();

  o1NewUnifiers.addAll(plan.getOperators(dag.getMeta(o2)).get(0).upstreamMerge.values());

  Assert.assertEquals("unifiers " + o1Meta, 1, o1NewUnifiers.size());
  Assert.assertEquals("unifier activation checkpoint " + o1Meta, 3, o1NewUnifiers.get(0).recoveryCheckpoint.windowId);
}
 
Example 7
Source File: PhysicalPlanTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testInline()
{

  LogicalPlan dag = new LogicalPlan();

  GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
  GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
  GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);

  PartitioningTestOperator partOperator = dag.addOperator("partNode", PartitioningTestOperator.class);
  partOperator.partitionKeys = new Integer[] {0,1};
  dag.getMeta(partOperator).getAttributes().put(OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(partOperator.partitionKeys.length));

  dag.addStream("o1_outport1", o1.outport1, o2.inport1, o3.inport1, partOperator.inport1)
          .setLocality(null);

  // same container for o2 and o3
  dag.addStream("o2_outport1", o2.outport1, o3.inport2)
      .setLocality(Locality.CONTAINER_LOCAL);

  dag.addStream("o3_outport1", o3.outport1, partOperator.inport2);

  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", maxContainers, plan.getContainers().size());
  Assert.assertEquals("operators container 0", 1, plan.getContainers().get(0).getOperators().size());

  Assert.assertEquals("operators container 0", 1, plan.getContainers().get(0).getOperators().size());
  Set<OperatorMeta> c2ExpNodes = Sets.newHashSet(dag.getMeta(o2), dag.getMeta(o3));
  Set<OperatorMeta> c2ActNodes = new HashSet<>();
  PTContainer c2 = plan.getContainers().get(1);
  for (PTOperator pNode : c2.getOperators()) {
    c2ActNodes.add(pNode.getOperatorMeta());
  }
  Assert.assertEquals("operators " + c2, c2ExpNodes, c2ActNodes);

  // one container per partition
  OperatorMeta partOperMeta = dag.getMeta(partOperator);
  List<PTOperator> partitions = plan.getOperators(partOperMeta);
  for (PTOperator partition : partitions) {
    Assert.assertEquals("operators container" + partition, 1, partition.getContainer().getOperators().size());
  }

}
 
Example 8
Source File: PhysicalPlanTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
/**
 * Test covering scenario when only new partitions are added during dynamic partitioning and there
 * are no changes to existing partitions and partition mapping
 */
@Test
public void testAugmentedDynamicPartitioning()
{
  LogicalPlan dag = new LogicalPlan();

  TestGeneratorInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.class);
  dag.setOperatorAttribute(o1, OperatorContext.PARTITIONER, new TestAugmentingPartitioner<TestGeneratorInputOperator>(3));
  dag.setOperatorAttribute(o1, OperatorContext.STATS_LISTENERS, Lists.newArrayList((StatsListener)new PartitioningTest.PartitionLoadWatch()));
  OperatorMeta o1Meta = dag.getMeta(o1);

  GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
  OperatorMeta o2Meta = dag.getMeta(o2);

  dag.addStream("o1.outport1", o1.outport, o2.inport1);

  int maxContainers = 10;
  dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, maxContainers);

  TestPlanContext ctx = new TestPlanContext();
  dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);

  PhysicalPlan plan = new PhysicalPlan(dag, ctx);
  Assert.assertEquals("number of containers", 4, plan.getContainers().size());

  List<PTOperator> o1ops = plan.getOperators(o1Meta);
  Assert.assertEquals("number of o1 operators", 3, o1ops.size());

  List<PTOperator> o2ops = plan.getOperators(o2Meta);
  Assert.assertEquals("number of o2 operators", 1, o2ops.size());
  Set<PTOperator> expUndeploy = Sets.newLinkedHashSet();
  expUndeploy.addAll(plan.getOperators(o2Meta));
  expUndeploy.add(plan.getOperators(o2Meta).get(0).upstreamMerge.values().iterator().next());

  for (int i = 0; i < 2; ++i) {
    PartitioningTest.PartitionLoadWatch.put(o1ops.get(i), 1);
    plan.onStatusUpdate(o1ops.get(i));
  }

  ctx.backupRequests = 0;
  ctx.events.remove(0).run();

  Assert.assertEquals("number of containers", 6, plan.getContainers().size());

  Assert.assertEquals("undeployed opertors", expUndeploy, ctx.undeploy);
}
 
Example 9
Source File: PhysicalPlanTest.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Test
public void testSingleFinalUnifierInputOverride()
{
  LogicalPlan dag = new LogicalPlan();

  GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
  dag.setOperatorAttribute(o1, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(3));
  OperatorMeta o1Meta = dag.getMeta(o1);

  GenericTestOperator o2 =  dag.addOperator("o2", GenericTestOperator.class);
  dag.setOperatorAttribute(o2, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
  dag.setInputPortAttribute(o2.inport1, PortContext.UNIFIER_SINGLE_FINAL, true);
  OperatorMeta o2Meta = dag.getMeta(o2);

  dag.addStream("o1.outport1", o1.outport1, o2.inport1);

  dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, 10);

  TestPlanContext ctx = new TestPlanContext();
  dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);

  PhysicalPlan plan = new PhysicalPlan(dag, ctx);
  Assert.assertEquals("number of containers", 6, plan.getContainers().size());

  Assert.assertEquals("o1 merge unifiers", 1, plan.getMergeOperators(o1Meta).size());

  dag.setOutputPortAttribute(o1.outport1, PortContext.UNIFIER_SINGLE_FINAL, false);
  ctx = new TestPlanContext();
  dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
  plan = new PhysicalPlan(dag, ctx);
  Assert.assertEquals("number of containers", 6, plan.getContainers().size());

  Assert.assertEquals("o1 merge unifiers", 1, plan.getMergeOperators(o1Meta).size());

  dag.setOutputPortAttribute(o1.outport1, PortContext.UNIFIER_SINGLE_FINAL, true);
  dag.setInputPortAttribute(o2.inport1, PortContext.UNIFIER_SINGLE_FINAL, false);
  ctx = new TestPlanContext();
  dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
  plan = new PhysicalPlan(dag, ctx);
  Assert.assertEquals("number of containers", 5, plan.getContainers().size());

  Set<String> expectedNames = Sets.newHashSet(o1Meta.getMeta(o1.outport1).getUnifierMeta().getName(), o2Meta.getName());
  for (int i = 3; i < 5; ++i) {
    PTContainer container = plan.getContainers().get(i);
    Assert.assertEquals("o2 container size", 2, container.getOperators().size());

    Set<String> names = Sets.newHashSet();
    for (PTOperator operator : container.getOperators()) {
      names.add(operator.getOperatorMeta().getName());
    }
    Assert.assertEquals("o2 container operators", expectedNames, names);
  }
}