Search in sources :

Example 1 with CoFlatMapFunction

use of org.apache.flink.streaming.api.functions.co.CoFlatMapFunction in project flink by apache.

the class DataStreamTest method testNaming.

/**
	 * Tests {@link SingleOutputStreamOperator#name(String)} functionality.
	 *
	 * @throws Exception
	 */
@Test
public void testNaming() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<Long> dataStream1 = env.generateSequence(0, 0).name("testSource1").map(new MapFunction<Long, Long>() {

        @Override
        public Long map(Long value) throws Exception {
            return null;
        }
    }).name("testMap");
    DataStream<Long> dataStream2 = env.generateSequence(0, 0).name("testSource2").map(new MapFunction<Long, Long>() {

        @Override
        public Long map(Long value) throws Exception {
            return null;
        }
    }).name("testMap");
    dataStream1.connect(dataStream2).flatMap(new CoFlatMapFunction<Long, Long, Long>() {

        @Override
        public void flatMap1(Long value, Collector<Long> out) throws Exception {
        }

        @Override
        public void flatMap2(Long value, Collector<Long> out) throws Exception {
        }
    }).name("testCoFlatMap").windowAll(GlobalWindows.create()).trigger(PurgingTrigger.of(CountTrigger.of(10))).fold(0L, new FoldFunction<Long, Long>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Long fold(Long accumulator, Long value) throws Exception {
            return null;
        }
    }).name("testWindowFold").print();
    //test functionality through the operator names in the execution plan
    String plan = env.getExecutionPlan();
    assertTrue(plan.contains("testSource1"));
    assertTrue(plan.contains("testSource2"));
    assertTrue(plan.contains("testMap"));
    assertTrue(plan.contains("testMap"));
    assertTrue(plan.contains("testCoFlatMap"));
    assertTrue(plan.contains("testWindowFold"));
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) CoFlatMapFunction(org.apache.flink.streaming.api.functions.co.CoFlatMapFunction) MapFunction(org.apache.flink.api.common.functions.MapFunction) CoMapFunction(org.apache.flink.streaming.api.functions.co.CoMapFunction) FlatMapFunction(org.apache.flink.api.common.functions.FlatMapFunction) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Aggregations

InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)1 FlatMapFunction (org.apache.flink.api.common.functions.FlatMapFunction)1 MapFunction (org.apache.flink.api.common.functions.MapFunction)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 CoFlatMapFunction (org.apache.flink.streaming.api.functions.co.CoFlatMapFunction)1 CoMapFunction (org.apache.flink.streaming.api.functions.co.CoMapFunction)1 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1