You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Chang Liu <fl...@gmail.com> on 2018/08/12 23:10:52 UTC

How to do test in Flink?

Dear all,

I have some questions regarding testing in Flink. The more general question is: is there any guideline, template, or best practices that we can follow if we want to test our flink code (more in scala)?

I know there is this page: https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html <https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html> but not so much written there. And I also did not find a more comprehensive documentation of this library: flink-test-utils_2.11.

One detailed question: how do you test this WindowFunction below? The return type is Unit right? We cannot do unit test on like, like how the ReduceFunction was tested in the example link above. Then we only have the option of doing integration testing on it?



Your ideas would be very helpful :) Thanks in advance !

Best regards/祝好,

Chang Liu 刘畅



Re: How to do test in Flink?

Posted by Chang Liu <fl...@gmail.com>.
Hi Hequn,

Thanks fr your reply.

Just to understand, these harness tests and the example your provided is actually having the same concept of the integration test with the example given here (https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html#integration-testing <https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html#integration-testing>) right ?

Harness tests provide more easy to use utils to construct source/sink and the execution environment.

Best regards/祝好,

Chang Liu 刘畅


> On 13 Aug 2018, at 04:01, Hequn Cheng <ch...@gmail.com> wrote:
> 
> Hi Chang,
> 
> There are some harness tests which can be used to test your function. It is also a common way to test function or operator in flink internal tests. Currently, the harness classes mainly include:
> KeyedOneInputStreamOperatorTestHarness
> KeyedTwoInputStreamOperatorTestHarness
> OneInputStreamOperatorTestHarness
> TwoInputStreamOperatorTestHarness
> You can take a look at the source code of these classes. 
> 
> To be more specific, you can take a look at the testSlidingEventTimeWindowsApply[1], in which the RichSumReducer window function has been tested.
> 
> Best, Hequn
> 
> [1] https://github.com/apache/flink/blob/master/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L213 <https://github.com/apache/flink/blob/master/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L213>
> 
> 
> On Mon, Aug 13, 2018 at 7:10 AM, Chang Liu <fluency.03@gmail.com <ma...@gmail.com>> wrote:
> Dear all,
> 
> I have some questions regarding testing in Flink. The more general question is: is there any guideline, template, or best practices that we can follow if we want to test our flink code (more in scala)?
> 
> I know there is this page: https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html <https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html> but not so much written there. And I also did not find a more comprehensive documentation of this library: flink-test-utils_2.11.
> 
> One detailed question: how do you test this WindowFunction below? The return type is Unit right? We cannot do unit test on like, like how the ReduceFunction was tested in the example link above. Then we only have the option of doing integration testing on it?
> <code.png>
> 
> 
> Your ideas would be very helpful :) Thanks in advance !
> 
> Best regards/祝好,
> 
> Chang Liu 刘畅
> 
> 
> 


Re: [External] Re: How to do test in Flink?

Posted by Chang Liu <fl...@gmail.com>.
Thanks Joe!

Best regards/祝好,

Chang Liu 刘畅



On Fri, Aug 24, 2018 at 6:55 PM Joe Malt <jm...@yelp.com> wrote:

> Hi Chang,
>
> A time-saving tip for finding which library contains a class: go to
> https://search.maven.org/
> and enter fc: followed by the fully-qualified name of the class. You
> should get the library as a search result.
>
> In this case for example, you'd search for
> fc:org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder
>
> Best,
>
> Joe Malt
> Engineering Intern, Stream Processing
> Yelp Inc.
>
> On Fri, Aug 24, 2018 at 4:50 AM, Chang Liu <fl...@gmail.com> wrote:
>
>> No worries, I found it here:
>>
>> <dependency>
>>     <groupId>org.apache.flink</groupId>
>>     <artifactId>flink-runtime_${scala.binary.version}</artifactId>
>>     <version>${flink.version}</version>
>>     <type>test-jar</type>
>>     <scope>test</scope>
>> </dependency>
>>
>>
>> Best regards/祝好,
>>
>> Chang Liu 刘畅
>>
>>
>>
>> On Fri, Aug 24, 2018 at 1:16 PM Chang Liu <fl...@gmail.com> wrote:
>>
>>> Hi Hequn,
>>>
>>> I have added the following dependencies:
>>>
>>> <dependency>
>>>     <groupId>org.apache.flink</groupId>
>>>     <artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
>>>     <version>${flink.version}</version>
>>>     <type>test-jar</type>
>>>     <scope>test</scope>
>>> </dependency>
>>> <dependency>
>>>     <groupId>org.mockito</groupId>
>>>     <artifactId>mockito-core</artifactId>
>>>     <version>2.21.0</version>
>>>     <scope>test</scope>
>>> </dependency>
>>>
>>>
>>> But got the exception:   java.lang.NoClassDefFoundError:
>>> org/apache/flink/runtime/operators/testutils/MockEnvironmentBuilder
>>>
>>> Do you know which library contains this class? Thanks :)
>>>
>>> Best regards/祝好,
>>>
>>> Chang Liu 刘畅
>>> DevOps Engineer
>>> WB TECH / Cyber Crime Prevention Team
>>>
>>> Mobile: +31(0)687859981
>>> Email: fluency.03@gmail.com  &  Chang.Liu2@ing.nl
>>>
>>>
>>>
>>> On Mon, Aug 13, 2018 at 1:42 PM Hequn Cheng <ch...@gmail.com>
>>> wrote:
>>>
>>>> Hi Change,
>>>>
>>>> Try
>>>> <dependency>
>>>> <groupId>org.apache.flink</groupId>
>>>> <artifactId>flink-streaming-java_2.11</artifactId>
>>>> <version>${flink.version}</version>
>>>> <type>test-jar</type>
>>>> <scope>test</scope>
>>>> </dependency>
>>>> .
>>>>
>>>> On Mon, Aug 13, 2018 at 6:42 PM, Chang Liu <fl...@gmail.com>
>>>> wrote:
>>>>
>>>>> And another question: which library should I include in order to use
>>>>> these harnesses? I do have this flink-test-utils_2.11 in my pom, but I
>>>>> cannot find the harnesses.
>>>>>
>>>>> I also have the following in my pom:
>>>>>
>>>>>    - flink-core
>>>>>    - flink-clients_2.11
>>>>>    - flink-scala_2.11
>>>>>    - flink-streaming-java_2.11
>>>>>    - flink-streaming-java_2.11
>>>>>    - flink-connector-kafka-0.11_2.11
>>>>>
>>>>>
>>>>> Best regards/祝好,
>>>>>
>>>>> Chang Liu 刘畅
>>>>>
>>>>>
>>>>> On 13 Aug 2018, at 04:01, Hequn Cheng <ch...@gmail.com> wrote:
>>>>>
>>>>> Hi Chang,
>>>>>
>>>>> There are some harness tests which can be used to test your function.
>>>>> It is also a common way to test function or operator in flink internal
>>>>> tests. Currently, the harness classes mainly include:
>>>>>
>>>>>    - KeyedOneInputStreamOperatorTestHarness
>>>>>    - KeyedTwoInputStreamOperatorTestHarness
>>>>>    - OneInputStreamOperatorTestHarness
>>>>>    - TwoInputStreamOperatorTestHarness
>>>>>
>>>>> You can take a look at the source code of these classes.
>>>>>
>>>>> To be more specific, you can take a look at
>>>>> the testSlidingEventTimeWindowsApply[1], in which the RichSumReducer window
>>>>> function has been tested.
>>>>>
>>>>> Best, Hequn
>>>>>
>>>>> [1]
>>>>> https://github.com/apache/flink/blob/master/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L213
>>>>>
>>>>>
>>>>> On Mon, Aug 13, 2018 at 7:10 AM, Chang Liu <fl...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Dear all,
>>>>>>
>>>>>> I have some questions regarding testing in Flink. The more general
>>>>>> question is: is there any guideline, template, or best practices that we
>>>>>> can follow if we want to test our flink code (more in scala)?
>>>>>>
>>>>>> I know there is this page:
>>>>>> https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html but
>>>>>> not so much written there. And I also did not find a more comprehensive
>>>>>> documentation of this library: flink-test-utils_2.11.
>>>>>>
>>>>>> One detailed question: how do you test this WindowFunction below? The
>>>>>> return type is Unit right? We cannot do unit test on like, like how the
>>>>>> ReduceFunction was tested in the example link above. Then we only have the
>>>>>> option of doing integration testing on it?
>>>>>> <code.png>
>>>>>>
>>>>>>
>>>>>> Your ideas would be very helpful :) Thanks in advance !
>>>>>>
>>>>>> Best regards/祝好,
>>>>>>
>>>>>> Chang Liu 刘畅
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>

Re: [External] Re: How to do test in Flink?

Posted by Joe Malt <jm...@yelp.com>.
Hi Chang,

A time-saving tip for finding which library contains a class: go to
https://search.maven.org/
and enter fc: followed by the fully-qualified name of the class. You should
get the library as a search result.

In this case for example, you'd search for
fc:org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder

Best,

Joe Malt
Engineering Intern, Stream Processing
Yelp Inc.

On Fri, Aug 24, 2018 at 4:50 AM, Chang Liu <fl...@gmail.com> wrote:

> No worries, I found it here:
>
> <dependency>
>     <groupId>org.apache.flink</groupId>
>     <artifactId>flink-runtime_${scala.binary.version}</artifactId>
>     <version>${flink.version}</version>
>     <type>test-jar</type>
>     <scope>test</scope>
> </dependency>
>
>
> Best regards/祝好,
>
> Chang Liu 刘畅
>
>
>
> On Fri, Aug 24, 2018 at 1:16 PM Chang Liu <fl...@gmail.com> wrote:
>
>> Hi Hequn,
>>
>> I have added the following dependencies:
>>
>> <dependency>
>>     <groupId>org.apache.flink</groupId>
>>     <artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
>>     <version>${flink.version}</version>
>>     <type>test-jar</type>
>>     <scope>test</scope>
>> </dependency>
>> <dependency>
>>     <groupId>org.mockito</groupId>
>>     <artifactId>mockito-core</artifactId>
>>     <version>2.21.0</version>
>>     <scope>test</scope>
>> </dependency>
>>
>>
>> But got the exception:   java.lang.NoClassDefFoundError:
>> org/apache/flink/runtime/operators/testutils/MockEnvironmentBuilder
>>
>> Do you know which library contains this class? Thanks :)
>>
>> Best regards/祝好,
>>
>> Chang Liu 刘畅
>> DevOps Engineer
>> WB TECH / Cyber Crime Prevention Team
>>
>> Mobile: +31(0)687859981
>> Email: fluency.03@gmail.com  &  Chang.Liu2@ing.nl
>>
>>
>>
>> On Mon, Aug 13, 2018 at 1:42 PM Hequn Cheng <ch...@gmail.com> wrote:
>>
>>> Hi Change,
>>>
>>> Try
>>> <dependency>
>>> <groupId>org.apache.flink</groupId>
>>> <artifactId>flink-streaming-java_2.11</artifactId>
>>> <version>${flink.version}</version>
>>> <type>test-jar</type>
>>> <scope>test</scope>
>>> </dependency>
>>> .
>>>
>>> On Mon, Aug 13, 2018 at 6:42 PM, Chang Liu <fl...@gmail.com> wrote:
>>>
>>>> And another question: which library should I include in order to use
>>>> these harnesses? I do have this flink-test-utils_2.11 in my pom, but I
>>>> cannot find the harnesses.
>>>>
>>>> I also have the following in my pom:
>>>>
>>>>    - flink-core
>>>>    - flink-clients_2.11
>>>>    - flink-scala_2.11
>>>>    - flink-streaming-java_2.11
>>>>    - flink-streaming-java_2.11
>>>>    - flink-connector-kafka-0.11_2.11
>>>>
>>>>
>>>> Best regards/祝好,
>>>>
>>>> Chang Liu 刘畅
>>>>
>>>>
>>>> On 13 Aug 2018, at 04:01, Hequn Cheng <ch...@gmail.com> wrote:
>>>>
>>>> Hi Chang,
>>>>
>>>> There are some harness tests which can be used to test your function.
>>>> It is also a common way to test function or operator in flink internal
>>>> tests. Currently, the harness classes mainly include:
>>>>
>>>>    - KeyedOneInputStreamOperatorTestHarness
>>>>    - KeyedTwoInputStreamOperatorTestHarness
>>>>    - OneInputStreamOperatorTestHarness
>>>>    - TwoInputStreamOperatorTestHarness
>>>>
>>>> You can take a look at the source code of these classes.
>>>>
>>>> To be more specific, you can take a look at the
>>>> testSlidingEventTimeWindowsApply[1], in which the RichSumReducer
>>>> window function has been tested.
>>>>
>>>> Best, Hequn
>>>>
>>>> [1] https://github.com/apache/flink/blob/master/flink-
>>>> streaming-java/src/test/java/org/apache/flink/streaming/
>>>> runtime/operators/windowing/WindowOperatorTest.java#L213
>>>>
>>>>
>>>> On Mon, Aug 13, 2018 at 7:10 AM, Chang Liu <fl...@gmail.com>
>>>> wrote:
>>>>
>>>>> Dear all,
>>>>>
>>>>> I have some questions regarding testing in Flink. The more general
>>>>> question is: is there any guideline, template, or best practices that we
>>>>> can follow if we want to test our flink code (more in scala)?
>>>>>
>>>>> I know there is this page: https://ci.apache.org/
>>>>> projects/flink/flink-docs-release-1.6/dev/stream/testing.html but not
>>>>> so much written there. And I also did not find a more comprehensive
>>>>> documentation of this library: flink-test-utils_2.11.
>>>>>
>>>>> One detailed question: how do you test this WindowFunction below? The
>>>>> return type is Unit right? We cannot do unit test on like, like how the
>>>>> ReduceFunction was tested in the example link above. Then we only have the
>>>>> option of doing integration testing on it?
>>>>> <code.png>
>>>>>
>>>>>
>>>>> Your ideas would be very helpful :) Thanks in advance !
>>>>>
>>>>> Best regards/祝好,
>>>>>
>>>>> Chang Liu 刘畅
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>

Re: How to do test in Flink?

Posted by Chang Liu <fl...@gmail.com>.
No worries, I found it here:

<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-runtime_${scala.binary.version}</artifactId>
    <version>${flink.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>


Best regards/祝好,

Chang Liu 刘畅



On Fri, Aug 24, 2018 at 1:16 PM Chang Liu <fl...@gmail.com> wrote:

> Hi Hequn,
>
> I have added the following dependencies:
>
> <dependency>
>     <groupId>org.apache.flink</groupId>
>     <artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
>     <version>${flink.version}</version>
>     <type>test-jar</type>
>     <scope>test</scope>
> </dependency>
> <dependency>
>     <groupId>org.mockito</groupId>
>     <artifactId>mockito-core</artifactId>
>     <version>2.21.0</version>
>     <scope>test</scope>
> </dependency>
>
>
> But got the exception:   java.lang.NoClassDefFoundError:
> org/apache/flink/runtime/operators/testutils/MockEnvironmentBuilder
>
> Do you know which library contains this class? Thanks :)
>
> Best regards/祝好,
>
> Chang Liu 刘畅
> DevOps Engineer
> WB TECH / Cyber Crime Prevention Team
>
> Mobile: +31(0)687859981
> Email: fluency.03@gmail.com  &  Chang.Liu2@ing.nl
>
>
>
> On Mon, Aug 13, 2018 at 1:42 PM Hequn Cheng <ch...@gmail.com> wrote:
>
>> Hi Change,
>>
>> Try
>> <dependency>
>> <groupId>org.apache.flink</groupId>
>> <artifactId>flink-streaming-java_2.11</artifactId>
>> <version>${flink.version}</version>
>> <type>test-jar</type>
>> <scope>test</scope>
>> </dependency>
>> .
>>
>> On Mon, Aug 13, 2018 at 6:42 PM, Chang Liu <fl...@gmail.com> wrote:
>>
>>> And another question: which library should I include in order to use
>>> these harnesses? I do have this flink-test-utils_2.11 in my pom, but I
>>> cannot find the harnesses.
>>>
>>> I also have the following in my pom:
>>>
>>>    - flink-core
>>>    - flink-clients_2.11
>>>    - flink-scala_2.11
>>>    - flink-streaming-java_2.11
>>>    - flink-streaming-java_2.11
>>>    - flink-connector-kafka-0.11_2.11
>>>
>>>
>>> Best regards/祝好,
>>>
>>> Chang Liu 刘畅
>>>
>>>
>>> On 13 Aug 2018, at 04:01, Hequn Cheng <ch...@gmail.com> wrote:
>>>
>>> Hi Chang,
>>>
>>> There are some harness tests which can be used to test your function. It
>>> is also a common way to test function or operator in flink internal tests.
>>> Currently, the harness classes mainly include:
>>>
>>>    - KeyedOneInputStreamOperatorTestHarness
>>>    - KeyedTwoInputStreamOperatorTestHarness
>>>    - OneInputStreamOperatorTestHarness
>>>    - TwoInputStreamOperatorTestHarness
>>>
>>> You can take a look at the source code of these classes.
>>>
>>> To be more specific, you can take a look at
>>> the testSlidingEventTimeWindowsApply[1], in which the RichSumReducer window
>>> function has been tested.
>>>
>>> Best, Hequn
>>>
>>> [1]
>>> https://github.com/apache/flink/blob/master/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L213
>>>
>>>
>>> On Mon, Aug 13, 2018 at 7:10 AM, Chang Liu <fl...@gmail.com> wrote:
>>>
>>>> Dear all,
>>>>
>>>> I have some questions regarding testing in Flink. The more general
>>>> question is: is there any guideline, template, or best practices that we
>>>> can follow if we want to test our flink code (more in scala)?
>>>>
>>>> I know there is this page:
>>>> https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html but
>>>> not so much written there. And I also did not find a more comprehensive
>>>> documentation of this library: flink-test-utils_2.11.
>>>>
>>>> One detailed question: how do you test this WindowFunction below? The
>>>> return type is Unit right? We cannot do unit test on like, like how the
>>>> ReduceFunction was tested in the example link above. Then we only have the
>>>> option of doing integration testing on it?
>>>> <code.png>
>>>>
>>>>
>>>> Your ideas would be very helpful :) Thanks in advance !
>>>>
>>>> Best regards/祝好,
>>>>
>>>> Chang Liu 刘畅
>>>>
>>>>
>>>>
>>>
>>>
>>

Re: How to do test in Flink?

Posted by Chang Liu <fl...@gmail.com>.
Hi Hequn,

I have added the following dependencies:

<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
    <version>${flink.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>2.21.0</version>
    <scope>test</scope>
</dependency>


But got the exception:   java.lang.NoClassDefFoundError:
org/apache/flink/runtime/operators/testutils/MockEnvironmentBuilder

Do you know which library contains this class? Thanks :)

Best regards/祝好,

Chang Liu 刘畅
DevOps Engineer
WB TECH / Cyber Crime Prevention Team

Mobile: +31(0)687859981
Email: fluency.03@gmail.com  &  Chang.Liu2@ing.nl



On Mon, Aug 13, 2018 at 1:42 PM Hequn Cheng <ch...@gmail.com> wrote:

> Hi Change,
>
> Try
> <dependency>
> <groupId>org.apache.flink</groupId>
> <artifactId>flink-streaming-java_2.11</artifactId>
> <version>${flink.version}</version>
> <type>test-jar</type>
> <scope>test</scope>
> </dependency>
> .
>
> On Mon, Aug 13, 2018 at 6:42 PM, Chang Liu <fl...@gmail.com> wrote:
>
>> And another question: which library should I include in order to use
>> these harnesses? I do have this flink-test-utils_2.11 in my pom, but I
>> cannot find the harnesses.
>>
>> I also have the following in my pom:
>>
>>    - flink-core
>>    - flink-clients_2.11
>>    - flink-scala_2.11
>>    - flink-streaming-java_2.11
>>    - flink-streaming-java_2.11
>>    - flink-connector-kafka-0.11_2.11
>>
>>
>> Best regards/祝好,
>>
>> Chang Liu 刘畅
>>
>>
>> On 13 Aug 2018, at 04:01, Hequn Cheng <ch...@gmail.com> wrote:
>>
>> Hi Chang,
>>
>> There are some harness tests which can be used to test your function. It
>> is also a common way to test function or operator in flink internal tests.
>> Currently, the harness classes mainly include:
>>
>>    - KeyedOneInputStreamOperatorTestHarness
>>    - KeyedTwoInputStreamOperatorTestHarness
>>    - OneInputStreamOperatorTestHarness
>>    - TwoInputStreamOperatorTestHarness
>>
>> You can take a look at the source code of these classes.
>>
>> To be more specific, you can take a look at
>> the testSlidingEventTimeWindowsApply[1], in which the RichSumReducer window
>> function has been tested.
>>
>> Best, Hequn
>>
>> [1]
>> https://github.com/apache/flink/blob/master/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L213
>>
>>
>> On Mon, Aug 13, 2018 at 7:10 AM, Chang Liu <fl...@gmail.com> wrote:
>>
>>> Dear all,
>>>
>>> I have some questions regarding testing in Flink. The more general
>>> question is: is there any guideline, template, or best practices that we
>>> can follow if we want to test our flink code (more in scala)?
>>>
>>> I know there is this page:
>>> https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html but
>>> not so much written there. And I also did not find a more comprehensive
>>> documentation of this library: flink-test-utils_2.11.
>>>
>>> One detailed question: how do you test this WindowFunction below? The
>>> return type is Unit right? We cannot do unit test on like, like how the
>>> ReduceFunction was tested in the example link above. Then we only have the
>>> option of doing integration testing on it?
>>> <code.png>
>>>
>>>
>>> Your ideas would be very helpful :) Thanks in advance !
>>>
>>> Best regards/祝好,
>>>
>>> Chang Liu 刘畅
>>>
>>>
>>>
>>
>>
>

Re: How to do test in Flink?

Posted by Hequn Cheng <ch...@gmail.com>.
Hi Change,

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

On Mon, Aug 13, 2018 at 6:42 PM, Chang Liu <fl...@gmail.com> wrote:

> And another question: which library should I include in order to use these
> harnesses? I do have this flink-test-utils_2.11 in my pom, but I cannot
> find the harnesses.
>
> I also have the following in my pom:
>
>    - flink-core
>    - flink-clients_2.11
>    - flink-scala_2.11
>    - flink-streaming-java_2.11
>    - flink-streaming-java_2.11
>    - flink-connector-kafka-0.11_2.11
>
>
> Best regards/祝好,
>
> Chang Liu 刘畅
>
>
> On 13 Aug 2018, at 04:01, Hequn Cheng <ch...@gmail.com> wrote:
>
> Hi Chang,
>
> There are some harness tests which can be used to test your function. It
> is also a common way to test function or operator in flink internal tests.
> Currently, the harness classes mainly include:
>
>    - KeyedOneInputStreamOperatorTestHarness
>    - KeyedTwoInputStreamOperatorTestHarness
>    - OneInputStreamOperatorTestHarness
>    - TwoInputStreamOperatorTestHarness
>
> You can take a look at the source code of these classes.
>
> To be more specific, you can take a look at the
> testSlidingEventTimeWindowsApply[1], in which the RichSumReducer window
> function has been tested.
>
> Best, Hequn
>
> [1] https://github.com/apache/flink/blob/master/flink-
> streaming-java/src/test/java/org/apache/flink/streaming/
> runtime/operators/windowing/WindowOperatorTest.java#L213
>
>
> On Mon, Aug 13, 2018 at 7:10 AM, Chang Liu <fl...@gmail.com> wrote:
>
>> Dear all,
>>
>> I have some questions regarding testing in Flink. The more general
>> question is: is there any guideline, template, or best practices that we
>> can follow if we want to test our flink code (more in scala)?
>>
>> I know there is this page: https://ci.apache.org/pr
>> ojects/flink/flink-docs-release-1.6/dev/stream/testing.html but not so
>> much written there. And I also did not find a more comprehensive
>> documentation of this library: flink-test-utils_2.11.
>>
>> One detailed question: how do you test this WindowFunction below? The
>> return type is Unit right? We cannot do unit test on like, like how the
>> ReduceFunction was tested in the example link above. Then we only have the
>> option of doing integration testing on it?
>> <code.png>
>>
>>
>> Your ideas would be very helpful :) Thanks in advance !
>>
>> Best regards/祝好,
>>
>> Chang Liu 刘畅
>>
>>
>>
>
>

Re: How to do test in Flink?

Posted by Chang Liu <fl...@gmail.com>.
And another question: which library should I include in order to use these harnesses? I do have this flink-test-utils_2.11 in my pom, but I cannot find the harnesses.

I also have the following in my pom:
flink-core
flink-clients_2.11
flink-scala_2.11
flink-streaming-java_2.11
flink-streaming-java_2.11
flink-connector-kafka-0.11_2.11

Best regards/祝好,

Chang Liu 刘畅


> On 13 Aug 2018, at 04:01, Hequn Cheng <ch...@gmail.com> wrote:
> 
> Hi Chang,
> 
> There are some harness tests which can be used to test your function. It is also a common way to test function or operator in flink internal tests. Currently, the harness classes mainly include:
> KeyedOneInputStreamOperatorTestHarness
> KeyedTwoInputStreamOperatorTestHarness
> OneInputStreamOperatorTestHarness
> TwoInputStreamOperatorTestHarness
> You can take a look at the source code of these classes. 
> 
> To be more specific, you can take a look at the testSlidingEventTimeWindowsApply[1], in which the RichSumReducer window function has been tested.
> 
> Best, Hequn
> 
> [1] https://github.com/apache/flink/blob/master/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L213 <https://github.com/apache/flink/blob/master/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L213>
> 
> 
> On Mon, Aug 13, 2018 at 7:10 AM, Chang Liu <fluency.03@gmail.com <ma...@gmail.com>> wrote:
> Dear all,
> 
> I have some questions regarding testing in Flink. The more general question is: is there any guideline, template, or best practices that we can follow if we want to test our flink code (more in scala)?
> 
> I know there is this page: https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html <https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html> but not so much written there. And I also did not find a more comprehensive documentation of this library: flink-test-utils_2.11.
> 
> One detailed question: how do you test this WindowFunction below? The return type is Unit right? We cannot do unit test on like, like how the ReduceFunction was tested in the example link above. Then we only have the option of doing integration testing on it?
> <code.png>
> 
> 
> Your ideas would be very helpful :) Thanks in advance !
> 
> Best regards/祝好,
> 
> Chang Liu 刘畅
> 
> 
> 


Re: How to do test in Flink?

Posted by Hequn Cheng <ch...@gmail.com>.
Hi Chang,

There are some harness tests which can be used to test your function. It is
also a common way to test function or operator in flink internal tests.
Currently, the harness classes mainly include:

   - KeyedOneInputStreamOperatorTestHarness
   - KeyedTwoInputStreamOperatorTestHarness
   - OneInputStreamOperatorTestHarness
   - TwoInputStreamOperatorTestHarness

You can take a look at the source code of these classes.

To be more specific, you can take a look at
the testSlidingEventTimeWindowsApply[1], in which the RichSumReducer window
function has been tested.

Best, Hequn

[1]
https://github.com/apache/flink/blob/master/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorTest.java#L213


On Mon, Aug 13, 2018 at 7:10 AM, Chang Liu <fl...@gmail.com> wrote:

> Dear all,
>
> I have some questions regarding testing in Flink. The more general
> question is: is there any guideline, template, or best practices that we
> can follow if we want to test our flink code (more in scala)?
>
> I know there is this page: https://ci.apache.org/
> projects/flink/flink-docs-release-1.6/dev/stream/testing.html but not so
> much written there. And I also did not find a more comprehensive
> documentation of this library: flink-test-utils_2.11.
>
> One detailed question: how do you test this WindowFunction below? The
> return type is Unit right? We cannot do unit test on like, like how the
> ReduceFunction was tested in the example link above. Then we only have the
> option of doing integration testing on it?
>
>
>
> Your ideas would be very helpful :) Thanks in advance !
>
> Best regards/祝好,
>
> Chang Liu 刘畅
>
>
>

Re: How to do test in Flink?

Posted by Chang Liu <fl...@gmail.com>.
Hi Dawid,

Many Thanks :)

Best regards/祝好,

Chang Liu 刘畅


> On 13 Aug 2018, at 09:21, Dawid Wysakowicz <dw...@apache.org> wrote:
> 
> Hi Chang,
> 
> Just to add to how you could test the function you've posted. The Collector is an interface so you can just implement a stub that will keep the results in e.g. some java collection. Then you can assert this collection. The collector might look like this:
> 
> 
> class ListCollector[T](list: java.util.List[T]) extends Collector[T] {
> 
>   override def collect(record: T): Unit = {
>     list.add(record)
>   }
> 
>   override def close(): Unit = {
>   }
> }
> 
> Best,
> 
> Dawid
> 
> 
> On 13/08/18 01:10, Chang Liu wrote:
>> Dear all,
>> 
>> I have some questions regarding testing in Flink. The more general question is: is there any guideline, template, or best practices that we can follow if we want to test our flink code (more in scala)?
>> 
>> I know there is this page: https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html <https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html> but not so much written there. And I also did not find a more comprehensive documentation of this library: flink-test-utils_2.11.
>> 
>> One detailed question: how do you test this WindowFunction below? The return type is Unit right? We cannot do unit test on like, like how the ReduceFunction was tested in the example link above. Then we only have the option of doing integration testing on it?
>> <code.png>
>> 
>> 
>> Your ideas would be very helpful :) Thanks in advance !
>> 
>> Best regards/祝好,
>> 
>> Chang Liu 刘畅
>> 
>> 
> 


Re: How to do test in Flink?

Posted by Dawid Wysakowicz <dw...@apache.org>.
Hi Chang,

Just to add to how you could test the function you've posted. The
Collector is an interface so you can just implement a stub that will
keep the results in e.g. some java collection. Then you can assert this
collection. The collector might look like this:


    class ListCollector[T](list: java.util.List[T]) extends Collector[T] {

      override def collect(record: T): Unit = {
        list.add(record)
      }

      override def close(): Unit = {
      }
    }

Best,

Dawid


On 13/08/18 01:10, Chang Liu wrote:
> Dear all,
>
> I have some questions regarding testing in Flink. The more general
> question is: is there any guideline, template, or best practices that
> we can follow if we want to test our flink code (more in scala)?
>
> I know there is this
> page: https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html but
> not so much written there. And I also did not find a more
> comprehensive documentation of this library: flink-test-utils_2.11.
>
> One detailed question: how do you test this WindowFunction below? The
> return type is Unit right? We cannot do unit test on like, like how
> the ReduceFunction was tested in the example link above. Then we only
> have the option of doing integration testing on it?
>
>
>
> Your ideas would be very helpful :) Thanks in advance !
>
> Best regards/祝好,
>
> Chang Liu 刘畅
>
>


Re: How to do test in Flink?

Posted by vino yang <ya...@gmail.com>.
Hi Chang,

Regarding the return value type, Scala allows the method to not specify the
return value type, it can be inferred by the compiler, if you specify a
non-Unit type compiler will report an error, if you do not specify an
explicit type, the result of the method may be an error, test pass or not
pass. In this respect it does not have the clarity of Java. But there is no
doubt that its return value will not be adopted by Flink.

Chang Liu <fl...@gmail.com> 于2018年8月13日周一 上午7:11写道:

> Dear all,
>
> I have some questions regarding testing in Flink. The more general
> question is: is there any guideline, template, or best practices that we
> can follow if we want to test our flink code (more in scala)?
>
> I know there is this page:
> https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/testing.html but
> not so much written there. And I also did not find a more comprehensive
> documentation of this library: flink-test-utils_2.11.
>
> One detailed question: how do you test this WindowFunction below? The
> return type is Unit right? We cannot do unit test on like, like how the
> ReduceFunction was tested in the example link above. Then we only have the
> option of doing integration testing on it?
>
>
>
> Your ideas would be very helpful :) Thanks in advance !
>
> Best regards/祝好,
>
> Chang Liu 刘畅
>
>
>