Apache Flink 是否放弃了 StreamOperatorTestHarness 类,或者它们是否转移到了不同​​的工件?

OMi*_*lls 1 maven apache-flink flink-streaming

我正在使用 intellij、maven 3 和 flink 1.15.1 编写有状态流作业。我正在尝试为我的自定义 KeyedProcessFunction 编写单元测试,并尝试遵循此处的文档以及添加此处提到的依赖项。我对使用 KeyedOneInputStreamOperatorTestHarness 类感兴趣,但我在任何依赖项中都找不到该类(下面发布的经过编辑的 pom)。我唯一能找到该课程的方法是包含

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-java_2.12</artifactId>
            <version>1.14.5</version>
            <scope>test</scope>
            <type>test-jar</type>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

这是来自以前的版本。Flink >= 1.15.0 现在不需要 scala 依赖库,因此 1.15.1 没有 flink-streaming-java_2.12。

我想要使​​用的类是否被移到其他地方或故意排除?我已经尝试了我所知道的所有 google foo,并且可以在 flink 存储库中找到该类,但在我迄今为止尝试过的任何 flink 依赖项中都找不到该类,除了 <=1.14.5 之外。我是否做错了什么或缺少一些文档?使用 1.14.5 库是我唯一的选择还是有一些我不知道的新型测试实用程序?

没有该类的 Pom 依赖项:

...
        <flink.version>1.15.1</flink.version>
...
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-java</artifactId>
            <version>${flink.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-clients</artifactId>
            <version>${flink.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-java</artifactId>
            <version>${flink.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-connector-kafka</artifactId>
            <version>${flink.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-test-utils</artifactId>
            <version>${flink.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-test-utils-junit</artifactId>
            <version>${flink.version}</version>
            <scope>test</scope>
        </dependency>
...
Run Code Online (Sandbox Code Playgroud)

OMi*_*lls 7

看来我已经弄清楚了,但我的行家知识有限,所以我不确定优点和缺点是什么。我还认为未来版本的 flink 将会改变这一点。好处是我可以使用最新的 flink 版本,而无需包含旧代码。

我添加了这些依赖项用于测试(至少对于 1.15.1):

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

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-java</artifactId>
            <version>${flink.version}</version>
            <scope>test</scope>
            <classifier>tests</classifier>
            <type>test-jar</type>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

我看到了有关工件和分类器标签的 flink 自述文件,我知道我需要的类位于 flink-streaming-java 包中,特别是在其测试部分中。因此,将 flink-streaming-java 的依赖项包含在标签中<classifier>tests</classifier>使得测试类可用。

无论如何,文档中有一个神秘的警告:

当用户应该引入 Flink 测试依赖项时很有用。这主要用于测试工具,可能不是您想要的。

我仍然需要 flink-test-utils 作为它提供的模拟运行器。