InMemory-Testing KafkaRecordBatch #1691
-
Hi I'm trying to test a smallrye kafka application that uses channel which expects a KafkaRecordBatch<K,V>. The application itself is running fine. But how can I test a channel that expects KafkaRecordBatch<K,V> with the InMemorySource-Channels? I've tried to send a List<KafkaRecord<K,V>> but I get a ClassCastException as it is expecting a KafkaRecordBatch<K,V>. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
InMemoryConnector will directly call your channel method. You need to create instances of InMemoryConnector connector;
KafkaCommitHandler commitHandler; // mock
KafkaFailureHandler failureHandler; // mock
ConsumerRecords<K, V> records; ...
InMemorySource<KafkaRecordBatch<K, V>> kafka = connector.source("kafka");
IncomingKafkaRecordBatch<K ,V> batch = new IncomingKafkaRecordBatch<>(records, "kafka", commitHandler, failureHandler, false, false);
kafka.send(batch); Hope this helps |
Beta Was this translation helpful? Give feedback.
InMemoryConnector will directly call your channel method. You need to create instances of
KafkaRecordBatch
and send them to your channel using theInMemorySource
.As it is the in-memory connector, you can mock everything. You can use
IncomingKafkaRecordBatch
usingConsumerRecords
you want to test and mocked commit and failure handlers as such :