I have updated the libraries of one project, in particular, I've updated Spring Boot, from version 2.2.6 to 2.3.2.
As mentioned in the migration documentation, this would also mean a change in my Kafka dependencies, going up to Spring Kafka and Kafka 2.5
However, since this change, some of my tests 'randomly' fail, as in, when I execute all of my tests, I encounter this failure in some of them (but not always in the same tests):
java.lang.IllegalStateException: More than one record for topic found
Coming from this particular line:
KafkaTestUtils.getSingleRecord(consumer, topicConfiguration.getTopic(event))
There is no mention in the documentation as to why this is happening, and no other log error message throwing light as to why this is happening. As I haven't changed the logic of my application, am I missing something with the migration?
If I try something like this:
KafkaTestUtils.getRecords(consumer)
.records(topicConfiguration.getTopic(event)).map { it }[0]
To get only the first one, tests that worked previously would fail with an IndexOutOfBoundsException
due to the index.