,java,apache-flink,flink-streaming,flink-cep"/>

首页 > 解决方案 > Flink Unit Test over ProcessWindowFunction

问题描述

How can I create a unit test for a Stateful Process Function. I have something like this:

 private static SingleOutputStreamOperator<Tuple> methodName(KeyedStream<Event, String> stream) {
        return stream.window(TumblingEventTimeWindows.of(Time.minutes(10)))
                .process(new ProcessFunction());
    }

and

ProcessFunction extends ProcessWindowFunction<IN, OUT, KEY, W>

All the Harness tests that I've found in Flink page are extending from KeyedProcessFunction and this is not my case. Thanks. Kind regards!

标签: javaapache-flinkflink-streamingflink-cep

解决方案


通常,这些测试工具期望测试操作员,而不是用户功能。因此,在 a 的情况下ProcessWindowFunction,您需要首先创建一个合适的窗口运算符以传递给测试工具。

您可以ProcessWindowFunction使用OneInputStreamOperatorTestHarness一个WindowOperator包裹在您的ProcessWindowFunction. 恐怕这不是特别简单,但我可以推荐你https://github.com/apache/flink/blob/release-1.11/flink-streaming-java/src/test/java/org/apache /flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L437为例。

Ververica 的 Apache Flink 培训课程涵盖了测试 ( https://training.ververica.com/decks/testing ),其中包含有关如何使用这些测试工具的更多信息。


推荐阅读