Unit testing KS with Avro

702 views
Skip to first unread message

Branden Makana

unread,
Sep 12, 2017, 6:56:40 PM9/12/17
to Confluent Platform
Hello,

I'm trying to write unit tests for my kafka-streams application that uses Avro. I've been successful with unit testing using the MockedStreams library and JSON, but now I'm moving to using Avro and having trouble. 

I know about MockSchemaRegistryClient, and from this thread: https://groups.google.com/forum/#!msg/confluent-platform/Qwp9xhtzDaI/LgtDkd0aAgAJ it seems like it should be easy to plug in, but I'm running 3.3.0 and I notice the SpecificAvroSerde now has the constructor that takes a SchemaRegistryClient as package private, so the linked example no longer is doable. 

How can I unit test kafka streams, with avro serialization, but with a mocked schema registry? 

Michael Noll

unread,
Sep 13, 2017, 5:59:47 AM9/13/17
to confluent...@googlegroups.com
To confirm: You want to do unit testing, not integration testing, right?

Because we do have working end-to-end examples of how to do integration testing with Kafka's Streams API, Confluent Schema Registry, and Avro.

e.g. for CP 3.3.0:




--
You received this message because you are subscribed to the Google Groups "Confluent Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to confluent-platform+unsub...@googlegroups.com.
To post to this group, send email to confluent-platform@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/confluent-platform/6c49c167-911d-42ac-a38d-3cbb212a8995%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Branden Makana

unread,
Sep 13, 2017, 10:54:09 AM9/13/17
to confluent...@googlegroups.com
Yes, unit testing not integration.
You received this message because you are subscribed to a topic in the Google Groups "Confluent Platform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/confluent-platform/ZsIaS5x516U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to confluent-platf...@googlegroups.com.
To post to this group, send email to confluent...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/confluent-platform/CAA4zQx%2BPK2NK7Fao55Qy9jtK91_cTaZP%3DqG0BjTt_aQk5cfyLA%40mail.gmail.com.

Branden Makana

unread,
Sep 14, 2017, 1:58:07 PM9/14/17
to Confluent Platform
I'm kind of getting the impression that no one unit tests with the Avro serializers, at least not lately, given the lack of anything in ze Googles. 

I can always mock out, replace, or otherwise ignore the avro serializers for a unit test (after all, I'm not unit testing them) but it's pretty annoying to have to do that only when the serialization is Avro (versus say, JSON). 

Peter Figliozzi

unread,
Jul 4, 2018, 10:13:06 PM7/4/18
to Confluent Platform
Did you ever find a good solution for unit testing streams topologies with MockedStreams and Avro?  I've been pointing it at my dev Schema Registry. 

Peter Figliozzi

unread,
Jul 4, 2018, 10:35:32 PM7/4/18
to Confluent Platform
Aside: found that when using MockedStreams, I have to make and pass my own Properties to get it to work with Avro:

val props = new Properties
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG,
      Serdes.String().getClass.getName)
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG,
      "io.confluent.kafka.streams.serdes.avro.GenericAvroSerde")
    props.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,

Then, pass this when building your MockedStreams:

val mstream = MockedStreams()
      .withTopology(getTopology)
      .config(props)
      ...

This doesn't answer OP's question (I have a real SchemaRegistry running), but I wasted a few hours before figuring the Properties riddle out... hopefully this helps someone.

Branden Makana

unread,
Jul 5, 2018, 4:47:53 PM7/5/18
to Confluent Platform
Hi Peter,

No, I was not able to test without a schema registry; I instead just did what you did, and used a local development copy. 
Reply all
Reply to author
Forward
0 new messages