booblik
Wiki

clients/dotnet/Booblik.Tests

Generated page

Model gemma-mtp, commit ef58254ca7be, 2026-08-16, sources: 6. Edit the code or the hand-written documentation instead.

What this module is responsible for

(Documentation for the Booblik.Tests module, covering the testing infrastructure and validation logic for the Booblik client.)

Diagram

FakeBroker

The mock broker implementation used to simulate network responses, protocol framing, and broker-side errors. It implements a TcpListener to handle real network communication on a loopback address FakeBroker.cs:57-169. The broker's behavior can be configured via:

PropertyTypePurpose
CorruptboolFlips a bit in stored checksums to simulate damaged segments FakeBroker.cs:36
RefuseWithCodeSets the error code for the next response FakeBroker.cs:60

The broker maintains state for _produced records FakeBroker.cs:26 and tracks the LastFetch metadata FakeBroker.cs:41-46.

More: FakeBroker

Connection

Validation of the low-level transport, including byte-for-byte payload integrity, protocol error handling, and metadata routing. Tests ensure that ARecordArrivesByteForByte preserves all byte values including nulls ConnectionTests.cs:17-31, and that ATruncatedResponseIsAProtocolError correctly identifies malformed frames ConnectionTests.cs:100-103. It also validates that MetadataAndKeyRouting correctly interacts with the partitioner ConnectionTests.cs:68-79.

More: Connection

Consumer

Testing of the consumer lifecycle, including record ordering, high watermark behavior, max bytes truncation, and checksum validation. The consumer is tested against "golden vectors" for CRC32C checksums ConsumerTests.cs:38-47. Key behaviors tested include:

  • RecordsComeBackInOrder: Verifies position and high watermark updates ConsumerTests.cs:60-75.
  • TruncatedTailIsDroppedAndRefetched: Ensures MaxBytes cuts on byte boundaries do not corrupt data ConsumerTests.cs:100-113.
  • RecordLargerThanMaxBytesIsReported: Validates RecordExceedsMaxBytesException when a single record exceeds the buffer ConsumerTests.cs:136-150.

Producer

Verification of batching logic, linger windows, partition accumulation, and asynchronous error propagation. The producer is tested to ensure NoRecordsAreLostAcrossLingerWindows by simulating timing-sensitive interleaving ProducerTests.cs:17-51. Other verified behaviors include:

  • PartitionsAccumulateSeparately: Ensures batches are partitioned by their target ProducerTests.cs:73-95.
  • DisposeFlushesWhatIsQueued: Verifies that DisposeAsync triggers a final flush of pending records ProducerTests.cs:97-117.
  • ABrokerFailureReachesEveryWaitingCaller: Ensures all tasks in a batch receive the BrokerException ProducerTests.cs:141-157.

Partitioner

Validation of the FNV-1a hashing algorithm and partition assignment against golden vectors. The tests ensure MatchesTheGoldenVectors by comparing results against a known-good implementation PartitionerTests.cs:20-39. It specifically validates that HighBytesAreUnsigned to prevent errors common in signed-integer ports PartitionerTests.cs:47-51.

Key files

FileLinesWhat is there
…/Booblik.Tests/Booblik.Tests.csproj13-17Test dependencies including xUnit and Coverlet
…/Booblik.Tests/ConnectionTests.cs17-31Byte-for-byte payload integrity test
…/Booblik.Tests/ConsumerTests.cs38-47CRC32C checksum validation against golden vectors
…/Booblik.Tests/FakeBroker.cs175-227The Produce method implementation for the mock broker
…/Booblik.Tests/PartitionerTests.cs20-39FNV-1a golden vector validation
…/Booblik.Tests/ProducerTests.cs17-51Linger window and record loss regression test

Behaviour that does not surprise

  • Producer.SendAsync returns Producer.OffsetUnknown when AckPolicy.None is used, rather than waiting for a broker response ProducerTests.cs:132-134.
  • Consumer.PollAsync will throw a RecordExceedsMaxBytesException if a single record is larger than the configured MaxBytes, preventing an infinite retry loop ConsumerTests.cs:145-150.
  • FakeBroker uses a lock on _gate to ensure thread-safe access to the _produced dictionary and _nextOffset FakeBroker.cs:25-28.

On this page