Search in sources :

Example 1 with EvenOddOutputSelector

use of org.apache.flink.streaming.util.EvenOddOutputSelector in project flink by apache.

the class StreamGraphGeneratorTest method testVirtualTransformations2.

/**
	 * This tests whether virtual Transformations behave correctly.
	 *
	 * Checks whether output selector, partitioning works correctly when applied on a union.
	 */
@Test
public void testVirtualTransformations2() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<Integer> source = env.fromElements(1, 10);
    DataStream<Integer> rebalanceMap = source.rebalance().map(new NoOpIntMap());
    DataStream<Integer> map1 = rebalanceMap.map(new NoOpIntMap());
    DataStream<Integer> map2 = rebalanceMap.map(new NoOpIntMap());
    DataStream<Integer> map3 = rebalanceMap.map(new NoOpIntMap());
    EvenOddOutputSelector selector = new EvenOddOutputSelector();
    SingleOutputStreamOperator<Integer> unionedMap = map1.union(map2).union(map3).broadcast().split(selector).select("foo").map(new NoOpIntMap());
    unionedMap.addSink(new DiscardingSink<Integer>());
    StreamGraph graph = env.getStreamGraph();
    // verify that the properties are correctly set on all input operators
    assertTrue(graph.getStreamNode(map1.getId()).getOutEdges().get(0).getPartitioner() instanceof BroadcastPartitioner);
    assertTrue(graph.getStreamNode(map1.getId()).getOutEdges().get(0).getSelectedNames().get(0).equals("foo"));
    assertTrue(graph.getStreamNode(map1.getId()).getOutputSelectors().contains(selector));
    assertTrue(graph.getStreamNode(map2.getId()).getOutEdges().get(0).getPartitioner() instanceof BroadcastPartitioner);
    assertTrue(graph.getStreamNode(map2.getId()).getOutEdges().get(0).getSelectedNames().get(0).equals("foo"));
    assertTrue(graph.getStreamNode(map2.getId()).getOutputSelectors().contains(selector));
    assertTrue(graph.getStreamNode(map3.getId()).getOutEdges().get(0).getPartitioner() instanceof BroadcastPartitioner);
    assertTrue(graph.getStreamNode(map3.getId()).getOutEdges().get(0).getSelectedNames().get(0).equals("foo"));
    assertTrue(graph.getStreamNode(map3.getId()).getOutputSelectors().contains(selector));
}
Also used : NoOpIntMap(org.apache.flink.streaming.util.NoOpIntMap) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) EvenOddOutputSelector(org.apache.flink.streaming.util.EvenOddOutputSelector) BroadcastPartitioner(org.apache.flink.streaming.runtime.partitioner.BroadcastPartitioner) Test(org.junit.Test)

Aggregations

StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 BroadcastPartitioner (org.apache.flink.streaming.runtime.partitioner.BroadcastPartitioner)1 EvenOddOutputSelector (org.apache.flink.streaming.util.EvenOddOutputSelector)1 NoOpIntMap (org.apache.flink.streaming.util.NoOpIntMap)1 Test (org.junit.Test)1