[Flink Unit Tests] Unit test for Flink streaming codes

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Flink Unit Tests] Unit test for Flink streaming codes

Vijayendra Yadav
Hi Team,

Looking for some help and reference code / material to implement unit tests of possible scenarios in Flink streaming Code that should assert specific cases.

Regards,
Vijay
Reply | Threaded
Open this post in threaded view
|

Re: [Flink Unit Tests] Unit test for Flink streaming codes

Niels Basjes
Does this test in one of my own projects do what you are looking for?



On Fri, 31 Jul 2020, 20:20 Vijayendra Yadav, <[hidden email]> wrote:
Hi Team,

Looking for some help and reference code / material to implement unit tests of possible scenarios in Flink streaming Code that should assert specific cases.

Regards,
Vijay
Reply | Threaded
Open this post in threaded view
|

Re: [Flink Unit Tests] Unit test for Flink streaming codes

Vijayendra Yadav
Thank You Niels. Would you have something for the scala object class.  Say for example if I want to implement a unit test ( not integration test) for below code or similar  :


Regards,
Vijay

On Fri, Jul 31, 2020 at 12:22 PM Niels Basjes <[hidden email]> wrote:
Does this test in one of my own projects do what you are looking for?



On Fri, 31 Jul 2020, 20:20 Vijayendra Yadav, <[hidden email]> wrote:
Hi Team,

Looking for some help and reference code / material to implement unit tests of possible scenarios in Flink streaming Code that should assert specific cases.

Regards,
Vijay
Reply | Threaded
Open this post in threaded view
|

Re: [Flink Unit Tests] Unit test for Flink streaming codes

Niels Basjes
No, I only have Java.

On Fri, 31 Jul 2020, 21:57 Vijayendra Yadav, <[hidden email]> wrote:
Thank You Niels. Would you have something for the scala object class.  Say for example if I want to implement a unit test ( not integration test) for below code or similar  :


Regards,
Vijay

On Fri, Jul 31, 2020 at 12:22 PM Niels Basjes <[hidden email]> wrote:
Does this test in one of my own projects do what you are looking for?



On Fri, 31 Jul 2020, 20:20 Vijayendra Yadav, <[hidden email]> wrote:
Hi Team,

Looking for some help and reference code / material to implement unit tests of possible scenarios in Flink streaming Code that should assert specific cases.

Regards,
Vijay
Reply | Threaded
Open this post in threaded view
|

Re: [Flink Unit Tests] Unit test for Flink streaming codes

Arvid Heise-3
Hi Vijay,

Any unit test of Flink operators is actually an IT case as it involves a large portion of the stack. A real unit test, would be over a factored out logic class.

Similar to Niels, I'd recommend to use simple sources (env.fromElements) and sinks to inject the data and retrieve the data and put the logic under test in the middle. That may be a part of your pipeline or even the whole pipeline.

If you want to have some scala inspiration, have a look at:

On Sat, Aug 1, 2020 at 4:03 PM Niels Basjes <[hidden email]> wrote:
No, I only have Java.

On Fri, 31 Jul 2020, 21:57 Vijayendra Yadav, <[hidden email]> wrote:
Thank You Niels. Would you have something for the scala object class.  Say for example if I want to implement a unit test ( not integration test) for below code or similar  :


Regards,
Vijay

On Fri, Jul 31, 2020 at 12:22 PM Niels Basjes <[hidden email]> wrote:
Does this test in one of my own projects do what you are looking for?



On Fri, 31 Jul 2020, 20:20 Vijayendra Yadav, <[hidden email]> wrote:
Hi Team,

Looking for some help and reference code / material to implement unit tests of possible scenarios in Flink streaming Code that should assert specific cases.

Regards,
Vijay


--

Arvid Heise | Senior Java Developer


Follow us @VervericaData

--

Join Flink Forward - The Apache Flink Conference

Stream Processing | Event Driven | Real Time

--

Ververica GmbH | Invalidenstrasse 115, 10115 Berlin, Germany

--

Ververica GmbH
Registered at Amtsgericht Charlottenburg: HRB 158244 B
Managing Directors: Timothy Alexander Steinert, Yip Park Tung Jason, Ji (Toni) Cheng   
Reply | Threaded
Open this post in threaded view
|

Re: [Flink Unit Tests] Unit test for Flink streaming codes

David Anderson-3
Vijay,

There's a section of the docs that describes some strategies for writing tests of various types, and it includes some Scala examples [1].

There are also some nice examples from Konstantin Knauf in [2], though they are mostly in Java.


Best,
David

On Sun, Aug 2, 2020 at 12:14 PM Arvid Heise <[hidden email]> wrote:
Hi Vijay,

Any unit test of Flink operators is actually an IT case as it involves a large portion of the stack. A real unit test, would be over a factored out logic class.

Similar to Niels, I'd recommend to use simple sources (env.fromElements) and sinks to inject the data and retrieve the data and put the logic under test in the middle. That may be a part of your pipeline or even the whole pipeline.

If you want to have some scala inspiration, have a look at:

On Sat, Aug 1, 2020 at 4:03 PM Niels Basjes <[hidden email]> wrote:
No, I only have Java.

On Fri, 31 Jul 2020, 21:57 Vijayendra Yadav, <[hidden email]> wrote:
Thank You Niels. Would you have something for the scala object class.  Say for example if I want to implement a unit test ( not integration test) for below code or similar  :


Regards,
Vijay

On Fri, Jul 31, 2020 at 12:22 PM Niels Basjes <[hidden email]> wrote:
Does this test in one of my own projects do what you are looking for?



On Fri, 31 Jul 2020, 20:20 Vijayendra Yadav, <[hidden email]> wrote:
Hi Team,

Looking for some help and reference code / material to implement unit tests of possible scenarios in Flink streaming Code that should assert specific cases.

Regards,
Vijay


--

Arvid Heise | Senior Java Developer


Follow us @VervericaData

--

Join Flink Forward - The Apache Flink Conference

Stream Processing | Event Driven | Real Time

--

Ververica GmbH | Invalidenstrasse 115, 10115 Berlin, Germany

--

Ververica GmbH
Registered at Amtsgericht Charlottenburg: HRB 158244 B
Managing Directors: Timothy Alexander Steinert, Yip Park Tung Jason, Ji (Toni) Cheng   
Reply | Threaded
Open this post in threaded view
|

Re: [Flink Unit Tests] Unit test for Flink streaming codes

Vijayendra Yadav
Thank you Arvid, David and Niels for your valuable inputs. One last Question: How do I terminate the flink streaming execution environment after the integration test is completed?

Regards
Vijay

On Sun, Aug 2, 2020 at 12:27 PM David Anderson <[hidden email]> wrote:
Vijay,

There's a section of the docs that describes some strategies for writing tests of various types, and it includes some Scala examples [1].

There are also some nice examples from Konstantin Knauf in [2], though they are mostly in Java.


Best,
David

On Sun, Aug 2, 2020 at 12:14 PM Arvid Heise <[hidden email]> wrote:
Hi Vijay,

Any unit test of Flink operators is actually an IT case as it involves a large portion of the stack. A real unit test, would be over a factored out logic class.

Similar to Niels, I'd recommend to use simple sources (env.fromElements) and sinks to inject the data and retrieve the data and put the logic under test in the middle. That may be a part of your pipeline or even the whole pipeline.

If you want to have some scala inspiration, have a look at:

On Sat, Aug 1, 2020 at 4:03 PM Niels Basjes <[hidden email]> wrote:
No, I only have Java.

On Fri, 31 Jul 2020, 21:57 Vijayendra Yadav, <[hidden email]> wrote:
Thank You Niels. Would you have something for the scala object class.  Say for example if I want to implement a unit test ( not integration test) for below code or similar  :


Regards,
Vijay

On Fri, Jul 31, 2020 at 12:22 PM Niels Basjes <[hidden email]> wrote:
Does this test in one of my own projects do what you are looking for?



On Fri, 31 Jul 2020, 20:20 Vijayendra Yadav, <[hidden email]> wrote:
Hi Team,

Looking for some help and reference code / material to implement unit tests of possible scenarios in Flink streaming Code that should assert specific cases.

Regards,
Vijay


--

Arvid Heise | Senior Java Developer


Follow us @VervericaData

--

Join Flink Forward - The Apache Flink Conference

Stream Processing | Event Driven | Real Time

--

Ververica GmbH | Invalidenstrasse 115, 10115 Berlin, Germany

--

Ververica GmbH
Registered at Amtsgericht Charlottenburg: HRB 158244 B
Managing Directors: Timothy Alexander Steinert, Yip Park Tung Jason, Ji (Toni) Cheng   
Reply | Threaded
Open this post in threaded view
|

Re: [Flink Unit Tests] Unit test for Flink streaming codes

Niels Basjes
Hi,

If you look at the example from my own project you'll see that this is not a problem (if you test it like this).

In some rare testing cases you may run into this problem and for those: have a look at what I did a few weeks ago for testing the PubSub connector:

Here I'm using the fact that the DeserializationSchema interface has a method isEndOfStream that can be used to terminate a stream.

Niels

On Mon, Aug 3, 2020 at 5:24 PM Vijayendra Yadav <[hidden email]> wrote:
Thank you Arvid, David and Niels for your valuable inputs. One last Question: How do I terminate the flink streaming execution environment after the integration test is completed?

Regards
Vijay

On Sun, Aug 2, 2020 at 12:27 PM David Anderson <[hidden email]> wrote:
Vijay,

There's a section of the docs that describes some strategies for writing tests of various types, and it includes some Scala examples [1].

There are also some nice examples from Konstantin Knauf in [2], though they are mostly in Java.


Best,
David

On Sun, Aug 2, 2020 at 12:14 PM Arvid Heise <[hidden email]> wrote:
Hi Vijay,

Any unit test of Flink operators is actually an IT case as it involves a large portion of the stack. A real unit test, would be over a factored out logic class.

Similar to Niels, I'd recommend to use simple sources (env.fromElements) and sinks to inject the data and retrieve the data and put the logic under test in the middle. That may be a part of your pipeline or even the whole pipeline.

If you want to have some scala inspiration, have a look at:

On Sat, Aug 1, 2020 at 4:03 PM Niels Basjes <[hidden email]> wrote:
No, I only have Java.

On Fri, 31 Jul 2020, 21:57 Vijayendra Yadav, <[hidden email]> wrote:
Thank You Niels. Would you have something for the scala object class.  Say for example if I want to implement a unit test ( not integration test) for below code or similar  :


Regards,
Vijay

On Fri, Jul 31, 2020 at 12:22 PM Niels Basjes <[hidden email]> wrote:
Does this test in one of my own projects do what you are looking for?



On Fri, 31 Jul 2020, 20:20 Vijayendra Yadav, <[hidden email]> wrote:
Hi Team,

Looking for some help and reference code / material to implement unit tests of possible scenarios in Flink streaming Code that should assert specific cases.

Regards,
Vijay


--

Arvid Heise | Senior Java Developer


Follow us @VervericaData

--

Join Flink Forward - The Apache Flink Conference

Stream Processing | Event Driven | Real Time

--

Ververica GmbH | Invalidenstrasse 115, 10115 Berlin, Germany

--

Ververica GmbH
Registered at Amtsgericht Charlottenburg: HRB 158244 B
Managing Directors: Timothy Alexander Steinert, Yip Park Tung Jason, Ji (Toni) Cheng   


--
Best regards / Met vriendelijke groeten,

Niels Basjes