java - 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!
解决方案
通常,这些测试工具期望测试操作员,而不是用户功能。因此,在 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 ),其中包含有关如何使用这些测试工具的更多信息。
推荐阅读
- php - 如何在MYSQL中取消选择当前年份
- ios - 泛型函数 -> 无法将返回表达式转换为返回类型
- vhdl - 我需要 modelsim 来查看内部变量
- java - Java在if语句中向数组添加东西?
- python - 使用从一个函数到另一个函数的局部变量
- python - 自动填充字段不适用于表单
- c++ - 嵌套for循环(可变分支因子)的递归实现以生成加泰罗尼亚数字
- node.js - Websocket 服务器未与节点服务器同时启动
- python - 使用 Caeser Cipher,但是文本没有按应有的方式返回?
- android - 如何使 PagedList 或 DataSource 中的数据子集无效?