Testing @Incoming and @Outgoing / Kafka

1,224 views
Skip to first unread message

Dustin Kut Moy Cheung

unread,
Nov 12, 2019, 4:53:05 PM11/12/19
to Quarkus Development mailing list
Hi,


Is there a way to test @Incoming and @Outgoing in Quarkus without starting a Kafka server
on the side? I'd like to test them in a `@QuarkusTest`.

Sincerely,
Dustin

Alex Soto Bueno

unread,
Nov 12, 2019, 4:55:00 PM11/12/19
to Quarkus Development mailing list
Probably one way would be to not configure the incomings and outcomings in application.properties. Then the in-memory messaging system is used instead of Kafka one.

clement escoffier

unread,
Nov 13, 2019, 2:40:36 AM11/13/19
to Quarkus Development mailing list, dust...@gmail.com
Hello,

You can do several thing:

  1. Prefix your configuration with %dev and %prod and duplicate them in %test to use in memory channels. I’m going to ease that in the near future.
  2. Use Test Container to start a Kafka broker (See https://github.com/quarkusio/quarkus-quickstarts/blob/master/kafka-quickstart/src/test/java/org/acme/quarkus/sample/PriceResourceTest.java as example)

Clement
--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/c6032089-c8df-428a-9c87-f8e6709646b7%40googlegroups.com.

Manyanda Chitimbo

unread,
Nov 13, 2019, 3:11:21 AM11/13/19
to clement....@gmail.com, Quarkus Development mailing list, dust...@gmail.com
Thanks all for your replies, I may add a little note about an issue I was investigating which I think might be related to Option 1. 

We recently had reports of this Kafka mp config not picking up the profile in prod mode - 

David’s configuration patch  - 
https://github.com/quarkusio/quarkus/pull/5387 fixed the issue for me locally. 

A workaround could be to leave the prod configurations un-prefixed (without any profile) and have the dev or test mode prefixed with appropriate profiles. Or go for option 2. till the PR lands. 


--
Manyanda Chitimbo.

Dustin Kut Moy Cheung

unread,
Nov 13, 2019, 3:50:00 PM11/13/19
to Quarkus Development mailing list
Thanks for the suggestion! I added the '%prod' in my application.properties and during unit testing, it defaulted into memory channels.

Then I had an @ApplicationScoped class with @Outgoing in my tests to generate random outgoing messages (Thanks podam for that: https://mtedone.github.io/podam/)
This did the trick and I was able to test my @Incoming method indirectly by making sure the data stored in my @Incoming method was not empty.

Merci Clement pour la suggestion!  :)

On Wednesday, November 13, 2019 at 2:40:36 AM UTC-5, clement escoffier wrote:
Hello,

You can do several thing:

  1. Prefix your configuration with %dev and %prod and duplicate them in %test to use in memory channels. I’m going to ease that in the near future.
  2. Use Test Container to start a Kafka broker (See https://github.com/quarkusio/quarkus-quickstarts/blob/master/kafka-quickstart/src/test/java/org/acme/quarkus/sample/PriceResourceTest.java as example)

Clement
On 12 Nov 2019 at 22:53 +0100, Dustin Kut Moy Cheung <dust...@gmail.com>, wrote:
Hi,


Is there a way to test @Incoming and @Outgoing in Quarkus without starting a Kafka server
on the side? I'd like to test them in a `@QuarkusTest`.

Sincerely,
Dustin

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quark...@googlegroups.com.

Luca Masini

unread,
Nov 13, 2019, 3:53:47 PM11/13/19
to dust...@gmail.com, Quarkus Development mailing list
Hi Dustin, you can create a Bean in src/test/java:
@ApplicationScoped
@Connector(CONNECTOR_NAME)
public class DummyKafkaMessagingProvider implements IncomingConnectorFactory, OutgoingConnectorFactory {
and then use this in tests:
%test.mp.messaging.incoming.ordini.connector=fake-kafka
With this you can simulate Kafka in many ways in your integration tests.

Hope this helps.



To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/274659ad-dc96-44a9-bbad-bb9183568c06%40googlegroups.com.


--
****************************************
http://www.lucamasini.net
http://twitter.com/lmasini
http://www.linkedin.com/pub/luca-masini/7/10/2b9
****************************************

clement escoffier

unread,
Nov 14, 2019, 1:45:38 AM11/14/19
to dust...@gmail.com, luca....@gmail.com, Quarkus Development mailing list
That’s exactly what I want to add to SmallRye Reactive Messaging: an in-memory channel so you can just replace the connector attribute with this one.
It will also expose method to send messages and check the received messages.


Clement

Emmanuel Bernard

unread,
Nov 14, 2019, 5:05:48 AM11/14/19
to clement escoffier, Quarkus Development mailing list, dust...@gmail.com

Hey there,

Can someone make a blog out of that info and add it to the testing guide and Rectrive MP guide. This is useful info.

Emmanuel

Alex Soto Bueno

unread,
Nov 14, 2019, 5:08:45 AM11/14/19
to Quarkus Development mailing list
If there is no rush I can take it.


On Thursday, November 14, 2019 at 11:05:48 AM UTC+1, Emmanuel Bernard wrote:

Hey there,

Can someone make a blog out of that info and add it to the testing guide and Rectrive MP guide. This is useful info.

Emmanuel

On 13 Nov 2019, at 8:40, clement escoffier wrote:

Hello,

You can do several thing:

  1. Prefix your configuration with %dev and %prod and duplicate them in %test to use in memory channels. I’m going to ease that in the near future.
  2. Use Test Container to start a Kafka broker (See https://github.com/quarkusio/quarkus-quickstarts/blob/master/kafka-quickstart/src/test/java/org/acme/quarkus/sample/PriceResourceTest.java as example)

Clement
On 12 Nov 2019 at 22:53 +0100, Dustin Kut Moy Cheung <dust...@gmail.com>, wrote:
Hi,


Is there a way to test @Incoming and @Outgoing in Quarkus without starting a Kafka server
on the side? I'd like to test them in a `@QuarkusTest`.

Sincerely,
Dustin

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quark...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quark...@googlegroups.com.

Emmanuel Bernard

unread,
Nov 14, 2019, 5:19:36 AM11/14/19
to Alex Soto Bueno, Quarkus Development mailing list

Sure

To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/26c79c39-7b5a-49a4-bbcb-affbc233ee70%40googlegroups.com.

Alex Soto Bueno

unread,
Nov 14, 2019, 5:22:50 AM11/14/19
to Quarkus Development mailing list
Great I'll start developing an example (in any case I need this example for my reactive demos) and I'll write a test as well and then write an article about how to test Messaging systems.
Reply all
Reply to author
Forward
0 new messages