-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow checking the entire
ProducerMessage
in the mock producers
This is done by introducing `MessageChecker`, a function which validates an entire `ProducerMessage`, and reimplementing the existing expectation interface on top of that. Since `producerExpectation` was not a public API, the only visible effect of this to users of the mock producers should be slightly different error messages when encoding fails. To better mimic the real producers’ behavior, this also runs partitioning before passing the message to the checker. By default all topics have 32 partitions but this can be configured per-topic in either producer via the embedded `TopicConfig`. (This does not allow mocking unavailable partitions; I don’t see a use case for this which can’t be better handled by unit testing the partitioner.) This may affect existing tests if someone was passing a configuration with a `Partitioner` that would fail on their test messages, but it seems more likely they want to know if this is the case (we did). This is useful for (at least) two reasons, - I would often like to test more than just the message value; services may need to produce to different topics or with specific partitioning schemes. In some cases valuable data may only be in the message key, or I want to test that a header and message body agree. - Since the topic usually also corresponds to the data format, exposing the topic makes it easier to collect messages of different types across different topics which may appear in known quantities but non-deterministic orders. Without the topic this is only possible by trying to content-sniff the format from the value, which leads to weaker and more fragile tests.
- Loading branch information
1 parent
83d633e
commit ab79623
Showing
5 changed files
with
219 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.