对 ProcessWindowFunction<IN, OUT, KEY, W> 的 Flink 单元测试 [英] Flink Unit Test over ProcessWindowFunction&lt;IN, OUT, KEY, W&gt;

查看:52
本文介绍了对 ProcessWindowFunction<IN, OUT, KEY, W> 的 Flink 单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为有状态流程功能创建单元测试.我有这样的事情:

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());
    }

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

我在 Flink 页面中发现的所有 Harness 测试都是从 KeyedProcessFunction 扩展而来的,这不是我的情况.谢谢.亲切的问候!

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

推荐答案

通常,这些测试工具期望测试操作符,而不是用户功能.因此,对于 ProcessWindowFunction,您需要首先创建一个合适的窗口操作符以传递给测试工具.

In general these test harnesses expect to be testing an operator, rather than a user function. So in the case of a ProcessWindowFunction, you need to first create an suitable window operator to pass to the test harness.

您可以使用 OneInputStreamOperatorTestHarness 来测试 ProcessWindowFunction,您可以使用包裹在 ProcessWindowFunction 中的 WindowOperator 实例化该代码.恐怕这不是特别直截了当,但我可以向您推荐 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 为例.

You can test a ProcessWindowFunction using a OneInputStreamOperatorTestHarness that you instantiate with a WindowOperator wrapped around your ProcessWindowFunction. I'm afraid this isn't particularly straightforward, but I can refer you to 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 as an example.

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

The session from the Apache Flink training from Ververica that covers testing (https://training.ververica.com/decks/testing) includes more info about how to work with these test harnesses.

这篇关于对 ProcessWindowFunction<IN, OUT, KEY, W> 的 Flink 单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆