0
votes

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

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.

2

2 Answers

3
votes

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>

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.

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

0
votes

I found David`s answer very useful but in Sbt you have to use this classifier to make it work:

libraryDependencies += "org.apache.flink" %% "flink-streaming-java" % flinkVersion % "test" classifier "tests",