FakeBroker
Generated page
Model gemma-mtp, commit ef58254ca7be, 2026-08-16, sources: 6. Edit the code or the hand-written documentation instead.
Diagram
FakeBroker
The FakeBroker is a specialized test fixture designed to speak the protocol well enough to answer requests and, crucially, to decode what the client encoded rather than simply pattern-matching raw bytes FakeBroker.cs:9-15. This ensures that an encoding mistake in the client results in a decode failure within the broker, providing a clear signal of protocol violations FakeBroker.cs:9-15.
ServeAsync
The ServeAsync method implements the core request-response loop FakeBroker.cs:105-168. It reads a 4-byte length prefix, followed by the frame, and extracts the API key, version, and correlation ID FakeBroker.cs:121-134. Based on the apiKey, it dispatches the payload to the appropriate handler:
ApiProduce(1)FakeBroker.cs:137ApiFetch(2)FakeBroker.cs:148ApiMetadata(3)FakeBroker.cs:152
Produce
The Produce method decodes the topic name, partition, and the batch of records FakeBroker.cs:177-197. It handles the AckPolicy to determine if the broker should respond with offsets or remain silent FakeBroker.cs:185-227.
| AckPolicy | Behavior |
|---|---|
None | Returns an empty body and Silent = true FakeBroker.cs:218-222 |
All/Leader | Returns the base offset and the new high watermark FakeBroker.cs:224-226 |
Fetch
The Fetch method performs log traversal by reading records starting from a specific offset FakeBroker.cs:280. It implements the following logic:
- Truncation: It uses
maxBytesto cut the response, which can result in a partial record at the end of the payloadFakeBroker.cs:289-293. - Checksums: It calculates
CRC32Cfor each recordFakeBroker.cs:284. - High Watermark: It includes the current log end offset in the response
FakeBroker.cs:291-292.
Metadata
The Metadata method allows clients to discover the cluster state FakeBroker.cs:297-349. It encodes:
- The number of topics
FakeBroker.cs:299 - Topic names and their partition counts
FakeBroker.cs:304-307 - For each partition: the partition ID, the current log start offset, and the high watermark
FakeBroker.cs:337-345.
Seed
The Seed method allows tests to manually inject records into a specific topic and partition without going through the full Produce request cycle FakeBroker.cs:234-246. This is used to set up specific consumer states for testing FakeBroker.cs:234-246.
Corrupt
To test the robustness of the client's error handling, the Corrupt property can be set to true FakeBroker.cs:36. When enabled, the broker flips a bit in every stored checksum during a Fetch operation, simulating a damaged segment on disk FakeBroker.cs:34-37.
Key files
| File | Lines | What is there |
|---|---|---|
…/Booblik.Tests/FakeBroker.cs | 17-46 | The FakeBroker class definition and its public properties like Corrupt and LastFetch. |
…/Booblik.Tests/FakeBroker.cs | 175-227 | The Produce method implementation. |
…/Booblik.Tests/FakeBroker.cs | 257-295 | The Fetch method implementation. |
…/Booblik.Tests/FakeBroker.cs | 297-349 | The Metadata method implementation. |