コード例 #1
0
  @Test
  public void shouldMergePartitionedStatefulAndStatelessRegionsAfterOptimization() {
    final OperatorDef partitionedStateful1 =
        OperatorDefBuilder.newInstance("partitionedStateful1", PartitionedStatefulOperator.class)
            .setExtendingSchema(schema)
            .setPartitionFieldNames(partitionFieldNames)
            .build();

    final OperatorDef partitionedStateful2 =
        OperatorDefBuilder.newInstance("partitionedStateful2", PartitionedStatefulOperator.class)
            .setExtendingSchema(schema)
            .setPartitionFieldNames(partitionFieldNames)
            .build();

    final OperatorDef stateless =
        OperatorDefBuilder.newInstance("stateless", StatelessOperator.class)
            .setExtendingSchema(schema)
            .build();

    final FlowDef flow =
        new FlowDefBuilder()
            .add(partitionedStateful1)
            .add(partitionedStateful2)
            .add(stateless)
            .connect("partitionedStateful1", "stateless")
            .connect("partitionedStateful2", "stateless")
            .build();

    final List<RegionDef> regions = regionDefFormer.createRegions(flow);
    final Map<String, OperatorDef> operators = flow.getOperatorsMap();
    final Collection<Entry<Port, Port>> connections = flow.getConnections();
    flowOptimizer.duplicateStatelessRegions(operators, connections, regions);
    flowOptimizer.mergeRegions(operators, connections, regions);

    assertEquals(2, regions.size());
    final RegionDef region1 = regions.get(0);
    assertEquals(PARTITIONED_STATEFUL, region1.getRegionType());
    assertEquals(
        asList(PartitionedStatefulOperator.class, StatelessOperator.class),
        region1.getOperators().stream().map(OperatorDef::operatorClazz).collect(toList()));
    final RegionDef region2 = regions.get(1);
    assertEquals(PARTITIONED_STATEFUL, region2.getRegionType());
    assertEquals(
        asList(PartitionedStatefulOperator.class, StatelessOperator.class),
        region2.getOperators().stream().map(OperatorDef::operatorClazz).collect(toList()));
  }
コード例 #2
0
  @Test
  public void shouldMergeStatefulAndStatelessRegions() {
    final OperatorDef stateful =
        OperatorDefBuilder.newInstance("stateful", StatefulOperator.class).build();
    final OperatorDef stateless =
        OperatorDefBuilder.newInstance("stateless", StatelessOperator.class).build();

    final FlowDef flow =
        new FlowDefBuilder().add(stateful).add(stateless).connect("stateful", "stateless").build();

    final List<RegionDef> regions = regionDefFormer.createRegions(flow);

    flowOptimizer.mergeRegions(flow.getOperatorsMap(), flow.getConnections(), regions);

    assertEquals(1, regions.size());
    final RegionDef region = regions.get(0);
    assertEquals(STATEFUL, region.getRegionType());
    assertEquals(asList(stateful, stateless), region.getOperators());
  }