如何利用 Flink 的 TestHarness 类? [英] How to utilize Flink's TestHarness class?

查看:13
本文介绍了如何利用 Flink 的 TestHarness 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试共享状态的 CoFlatMapFunction.通过阅读,我得出结论,我应该使用 TestHarness 类:https://ci.apache.org/projects/flink/flink-docs-stable/dev/stream/testing.html#testing-checkpointing-and-状态处理

I need to test a CoFlatMapFunction that shares state. Through my reading I have come to conclusion I should use the TestHarness class per: https://ci.apache.org/projects/flink/flink-docs-stable/dev/stream/testing.html#testing-checkpointing-and-state-handling

由于它不是公共 api 的一部分,我无法弄清楚如何在不复制和粘贴类本身的情况下导入它.我认为它可能在 flink-test-utils-junit 中,但事实并非如此.

Since it is not apart of the public api, I cannot figure out how to import it without copy and pasting the class itself. I thought it maybe in flink-test-utils-junit, but it was not as well.

推荐答案

您需要将这 3 个依赖项添加到您的项目(或 scala 2.12 的版本,如果这是您使用的 scala 版本):

You'll need to add these 3 dependencies to your project (or the versions for scala 2.12, if that's the version of scala you're using):

<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-test-utils-junit</artifactId>
    <version>${flink.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java_2.11</artifactId>
    <version>${flink.version}</version>
    <scope>test</scope>
    <type>test-jar</type>
</dependency>

<dependency>
    <groupId>org.apache.flink</groupId>
    <!-- with Flink 1.14+, this is flink-runtime -->
    <artifactId>flink-runtime_2.11</artifactId>
    <version>${flink.version}</version>
    <scope>test</scope>
    <type>test-jar</type>
</dependency>

还要注意,从 Flink 1.14 开始,flink-runtime 是 scala-free 的,所以在新版本的 Flink 中,删除_2.11"来自 flink-runtime 依赖.

Note also that since Flink 1.14, the flink-runtime is scala-free, so with newer versions of Flink, remove the "_2.11" from the flink-runtime dependency.

Flink 训练练习 包括使用线束的测试示例,例如 RidesAndFaresUnitTest.

The Flink training exercises include examples of tests that use harnesses, such as RidesAndFaresUnitTest.

这篇关于如何利用 Flink 的 TestHarness 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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