Search in sources :

Example 1 with ProcessFunction

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

the class DataStreamTest method testKeyedProcessTranslation.

/**
	 * Verify that a {@link KeyedStream#process(ProcessFunction)} call is correctly translated to
	 * an operator.
	 */
@Test
public void testKeyedProcessTranslation() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSource<Long> src = env.generateSequence(0, 0);
    ProcessFunction<Long, Integer> processFunction = new ProcessFunction<Long, Integer>() {

        private static final long serialVersionUID = 1L;

        @Override
        public void processElement(Long value, Context ctx, Collector<Integer> out) throws Exception {
        }

        @Override
        public void onTimer(long timestamp, OnTimerContext ctx, Collector<Integer> out) throws Exception {
        }
    };
    DataStream<Integer> processed = src.keyBy(new IdentityKeySelector<Long>()).process(processFunction);
    processed.addSink(new DiscardingSink<Integer>());
    assertEquals(processFunction, getFunctionForDataStream(processed));
    assertTrue(getOperatorForDataStream(processed) instanceof KeyedProcessOperator);
}
Also used : ProcessFunction(org.apache.flink.streaming.api.functions.ProcessFunction) Collector(org.apache.flink.util.Collector) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) KeyedProcessOperator(org.apache.flink.streaming.api.operators.KeyedProcessOperator) Test(org.junit.Test)

Example 2 with ProcessFunction

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

the class DataStreamTest method testProcessTranslation.

/**
	 * Verify that a {@link DataStream#process(ProcessFunction)} call is correctly translated to
	 * an operator.
	 */
@Test
public void testProcessTranslation() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSource<Long> src = env.generateSequence(0, 0);
    ProcessFunction<Long, Integer> processFunction = new ProcessFunction<Long, Integer>() {

        private static final long serialVersionUID = 1L;

        @Override
        public void processElement(Long value, Context ctx, Collector<Integer> out) throws Exception {
        }

        @Override
        public void onTimer(long timestamp, OnTimerContext ctx, Collector<Integer> out) throws Exception {
        }
    };
    DataStream<Integer> processed = src.process(processFunction);
    processed.addSink(new DiscardingSink<Integer>());
    assertEquals(processFunction, getFunctionForDataStream(processed));
    assertTrue(getOperatorForDataStream(processed) instanceof ProcessOperator);
}
Also used : ProcessFunction(org.apache.flink.streaming.api.functions.ProcessFunction) KeyedProcessOperator(org.apache.flink.streaming.api.operators.KeyedProcessOperator) ProcessOperator(org.apache.flink.streaming.api.operators.ProcessOperator) Collector(org.apache.flink.util.Collector) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Aggregations

StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 ProcessFunction (org.apache.flink.streaming.api.functions.ProcessFunction)2 KeyedProcessOperator (org.apache.flink.streaming.api.operators.KeyedProcessOperator)2 Collector (org.apache.flink.util.Collector)2 Test (org.junit.Test)2 ProcessOperator (org.apache.flink.streaming.api.operators.ProcessOperator)1