Skip to content

Conversation

@empperi
Copy link
Contributor

@empperi empperi commented Jun 11, 2020

Fixes #1

PR bumps the version number to 0.4.1.

Previously typehints in namespaces clj-kafka-x.consumers.simple and clj-kafka-x.producer used implementation classes KafkaConsumer and KafkaProducer. This causes a problem when trying to test application code with fake/mock implementations of those classes. If passing anything else to those functions using the typehints one gets a ClassCastException. One could use Clojure's proxy or similar mechanisms to try to get around this problem but unfortunately the inner implementation of especially KafkaProducer makes mocking them via this manner practically impossible (there are some very nasty ways like JavaAssist but those should be unnecessary).

Because of this very reason in Kafka Client library there are interfaces Consumer and Producer which KafkaConsumer and KafkaProducer implements.

This commit replaces all typehint references to use those two interfaces to allow clean fake/mock implementation usage in tests. This is a non-breaking change and doesn't affect execution or performance characteristics of code in any way when using real KafkaProducer or KafkaConsumer. Typehint safety is also retained since code is referring to very same public methods as before.

After this developers are free to use whatever methods they find necessary to provide mock/fake implementations. They can use ready made MockConsumer and MockProducer or write their own for example with proxy or reify.

empperi added 2 commits June 11, 2020 17:49
Previously typehints in namespaces `clj-kafka-x.consumers.simple` and
`clj-kafka-x.producer` used implementation classes `KafkaConsumer` and
`KafkaProducer`. This causes a problem when trying to test application
code with fake/mock implementations of those classes. If passing
anything else to those functions using the typehints one gets a
`ClassCastException`. One could use Clojure's `proxy` or similar
mechanisms to try to get around this problem but unfortunately the inner
implementation of especially `KafkaProducer` makes mocking them via this
manner practically impossible (there are some very nasty ways like
JavaAssist but those should be unnecessary).

Because of this very reason in Kafka Client library there are
interfaces `Consumer` and `Producer` which `KafkaConsumer` and
`KafkaProducer` implements.

This commit replaces all typehint references to use those two interfaces
to allow clean fake/mock implementation usage in tests. This is a
non-breaking change and doesn't affect execution or performance
characteristics of code in any way when using real `KafkaProducer` or
`KafkaConsumer`. Typehint safety is also retained since code is
referring to very same public methods as before.
@source-c source-c merged commit 3310ce7 into source-c:master Jun 11, 2020
@source-c
Copy link
Owner

Yeah, agree with this. Thank you very much for your contribution.

@empperi
Copy link
Contributor Author

empperi commented Jun 11, 2020

Cheers! Would appreciate a 0.4.1 release relatively soon. I'm currently developing my tests against locally installed jar file but my co-workers won't be too happy about that :D

@source-c
Copy link
Owner

source-c commented Jun 12, 2020

Sorry for a long time to reply. 0.4.1 has been released yesterday - you are welcome to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use interface versions for Producer and Consumer

2 participants