0

I am using Embedded Kafka Broker at Junits, for testing my values pushed to topic.

I get following error logs.

[ERROR]   KafkaConsumerTest>KafkaConsumerTests.shouldNotRetry4XXResponse:256 

expected: <LocKey(orgId=ORG101, locationType=STORE, locationId=S101)> 

but was: <{"orgId":"ORG101","locationType":"STORE","locationId":"S101"}>

I am comparing keys keys

assertEquals(getKey(), record.getKey());

Somehow, the CURLY BRACKETS are being added to the Received Records from Kafka

Any clues how to get this right, thanks !

Aditya Rewari
  • 2,343
  • 2
  • 23
  • 36
  • seems issue with type mismatch. what is your kafka consumer key type? seems you compare different types (you expect `LocKey `), but real message key has either json string or map type. either figure out that you compare the same types, or just compare two jsons – Vasyl Sarzhynskyi Jul 10 '20 at 16:54

2 Answers2

1

I have solved this issue.. the data being published to Kafka was being converted to json before, then published.

that is why the curly braces got appended

Abstraction is such a sin !

Aditya Rewari
  • 2,343
  • 2
  • 23
  • 36
0

I would have preferred if you posted the entire unit test for us to see what exactly is happening prior to the assertion, but the problem is probably in you definition of serializers for the Kafka library. It seems like you defined a string serializer for the key of the message, but you are trying to compare it to an object. Anyway, Check your serializers

Stav Saad
  • 589
  • 1
  • 4
  • 13