Path: redb-route/tests/redb.Route.Tests.Kafka/KafkaConformanceTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Kafka/KafkaConformanceTests.cs ---- using Confluent.Kafka; using Confluent.Kafka.Admin; using redb.Route.Abstractions; using redb.Route.Kafka; using redb.Route.Tests.Conformance; namespace redb.Route.Tests.Kafka; /// /// The Kafka connector against , on (one KRaft /// node at localhost:39092). A "queue" is a topic with one partition, read by the group /// : Kafka keeps the records, so a record is "off the queue" once that group committed /// it, and the stand drains as that group. A failed record is read again with breakOnFirstError=true (Kafka has no /// redelivery count: it is read until it succeeds). Not applicable here, and passing without running: /// the dead letter cases (Kafka has no dead letter queue), the concurrency bound (one poll loop per consumer, no option for /// more), and the start while the broker is down (after the bootstrap the client goes to the address the broker announces, /// past the late port). Runs alone: the restart case breaks the broker for every connection of the suite; it and every other /// case need the stand, so the class runs only in a fault run (run-fault-suite.sh --broker kafka). /// [Trait("Category", "Integration")] [Collection(KafkaBrokerRestartCollection.Name)] public sealed class KafkaConformanceTests : ConnectorConformance { protected override KafkaFaultStand Stand => KafkaFaultStand.Instance; protected override ConnectorTraits Traits { get; } = new() { AckOnReceipt = true, Transactions = true, DeadLetter = false, Concurrency = false, Batch = true, LateBroker = false, }; protected override int BrokerPort => 39092; protected override IComponent CreateComponent() => new KafkaComponent(); protected override async Task CreateQueueAsync(bool deadLetter) => new(await KafkaFaultStand.CreateTopicAsync("conformance"), null); protected override async Task DeleteQueueAsync(ConformanceQueue queue) { using var admin = new AdminClientBuilder(new AdminClientConfig { BootstrapServers = KafkaFaultStand.Brokers }).Build(); try { await admin.DeleteTopicsAsync([queue.Name]); } catch (DeleteTopicsException) { // Gone already, or the broker is still coming back after the restart case: the topic is the test's own. } } protected override string ConsumerUri(ConformanceQueue queue, ConsumerSettings settings) { var uri = $"kafka://{queue.Name}?brokers=localhost:{settings.Port ?? BrokerPort}" + $"&groupId={KafkaFaultStand.GroupOf(queue.Name)}&autoOffsetReset=Earliest"; uri += settings.AckOnReceipt ? "&ackMode=auto" : "&breakOnFirstError=true"; if (settings.BatchSize is { } size) uri += $"&batching=true&maxBatchMessages={size}&pollTimeoutMs={(int)settings.BatchWait.TotalMilliseconds}"; return uri; } protected override string ProducerUri(ConformanceQueue queue, bool transacted) => $"kafka://{queue.Name}?brokers=localhost:{BrokerPort}" + (transacted ? $"&transactionalIdPrefix=conformance-{Guid.NewGuid():N}" : ""); // The data folder of the stand's broker survives a restart: the topic is there as soon as the broker is. protected override Task QueueIsBackAsync(ConformanceQueue queue) => Task.Run(() => { try { using var admin = new AdminClientBuilder(new AdminClientConfig { BootstrapServers = KafkaFaultStand.Brokers }).Build(); var topic = admin.GetMetadata(queue.Name, TimeSpan.FromSeconds(5)).Topics.SingleOrDefault(); return topic is { Error.IsError: false } && topic.Partitions.All(p => p.Leader >= 0); } catch (KafkaException) { return false; } }); }