booblik

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:

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.

AckPolicyBehavior
NoneReturns an empty body and Silent = true FakeBroker.cs:218-222
All/LeaderReturns 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 maxBytes to cut the response, which can result in a partial record at the end of the payload FakeBroker.cs:289-293.
  • Checksums: It calculates CRC32C for each record FakeBroker.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:

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

FileLinesWhat is there
…/Booblik.Tests/FakeBroker.cs17-46The FakeBroker class definition and its public properties like Corrupt and LastFetch.
…/Booblik.Tests/FakeBroker.cs175-227The Produce method implementation.
…/Booblik.Tests/FakeBroker.cs257-295The Fetch method implementation.
…/Booblik.Tests/FakeBroker.cs297-349The Metadata method implementation.

On this page