Repository navigation
Conversation
Declared topics were already created before anything connects — the convenience constructor passes them to the broker. What was missing is the same guarantee for a topic that appears later, and relying on the broker to create it on demand does not give it: the broker does create the topic, but not in the response to the first metadata request, so a client that assigns partitions right after connecting is left with an empty assignment and every later poll or seek throws. addTopics waits for the creation to complete and fails loudly with the broker's own error, so a spec can add a topic mid-flight and use it immediately. topics() exposes what the environment has, which is what a spec asserts against. Creating topics belongs to the environment, not to whoever consumes it — that is why this lands here rather than in a wait loop inside the Exam tester. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
368e911 to
36cd2c4
Compare
|
Closing: not needed, and adding it would be the wrong shape. The declared path already covers the contract — So the rule stays simple and is the one we document for consumers: declare the topics your specs use when you build the environment. Auto-creation by the broker is not a supported path for specs — it worked on the ZK broker by winning a race, and KRaft does not. |
Topic creation is the environment's job, and the declared case already works:
EmbeddedKafkaSystem("topic-a", "topic-b")passes the topics to the broker, so they exist before anything connects.What was missing is the same guarantee for a topic that shows up later, and leaving it to the broker's on-demand creation does not provide it. Measured on the embedded KRaft broker: the topic is created, but it is absent from the response to the first
partitionsForcall — that call is what triggers the creation. A client that assigns partitions right after connecting therefore keeps an empty assignment, and every laterpollorseekfails with:The embedded ZK broker used to win that race, so specs that never declared their topics worked by accident; on KRaft they die in class initialisation, before a single assertion.
addTopics(vararg String)waits for the creation to finish and fails with the broker's own error if it cannot, so a spec can add a topic mid-flight and use it at once.topics()exposes what the environment holds, which is what a spec asserts against.Verified twice: a test here adds a topic to a running environment and checks both
topics()andAdminClient.listTopics; and downstream in the platform, an ExamKafkaConsumeAndSendTesteron a topic that the environment did not declare fails without this change and passes with it.