Skip to content

Conversation

@lucasbru
Copy link
Member

@lucasbru lucasbru commented Jan 8, 2026

This commit introduces a TopicCreator interface to abstract topic
creation logic, making the code more modular and testable. The main
changes include:

  • Implemented KRaftTopicCreator for KRaft-based topic creation in Java
    and removed the corresponding logic from DefaultAutoTopicCreationManager
  • Use a mock instance of TopicCreator in AutoTopicCreationManagerTest to
    better test without Mockito's ArgumentCaptor complexity.

This commit introduces a TopicCreator interface to abstract topic creation
logic, making the code more modular and testable. The main changes include:

- Created TopicCreator interface for topic creation abstraction
- Implemented KRaftTopicCreator for KRaft-based topic creation
- Refactored DefaultAutoTopicCreationManager to use TopicCreator instead of
  directly managing NodeToControllerChannelManager
- Simplified envelope handling by moving it into TopicCreator implementation
- Updated AutoTopicCreationManagerTest to use mocked TopicCreator
- Removed obsolete envelope-related test methods
- Use a mock instance of TopicCreator in AutoTopicCreationManagerTest to better test without Mockito's argumentcaptor complexity.
@github-actions github-actions bot added the core Kafka Broker label Jan 8, 2026
@lucasbru lucasbru changed the title MINOR: Refactor topic creation to use TopicCreator abstraction MINOR: Refactor auto topic creation to separate envelope logic Jan 8, 2026
@lucasbru lucasbru requested review from Copilot and mumrah January 8, 2026 20:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors auto topic creation logic by extracting envelope handling into a separate TopicCreator interface and KRaftTopicCreator implementation. The main motivation is to improve modularity and testability by separating concerns between topic creation coordination (in DefaultAutoTopicCreationManager) and the protocol-level details of forwarding requests to the controller.

Key changes:

  • Introduced a new TopicCreator interface with two methods: createTopicWithPrincipal and createTopicWithoutPrincipal that return CompletableFuture<CreateTopicsResponse>
  • Implemented KRaftTopicCreator in Java that encapsulates envelope request building and response parsing logic previously embedded in DefaultAutoTopicCreationManager
  • Refactored DefaultAutoTopicCreationManager to use the TopicCreator interface and simplified response handling using CompletableFuture.whenComplete
  • Replaced complex Mockito-based tests with a custom TestTopicCreator implementation for better control and clarity in testing

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
core/src/main/java/kafka/server/TopicCreator.java New interface defining the contract for topic creation operations
core/src/main/java/kafka/server/KRaftTopicCreator.java KRaft implementation handling envelope requests and response parsing
core/src/test/java/kafka/server/KRaftTopicCreatorTest.java Comprehensive test suite for KRaftTopicCreator covering success, error, and edge cases
core/src/main/scala/kafka/server/AutoTopicCreationManager.scala Refactored to delegate topic creation to TopicCreator and simplified callback handling
core/src/main/scala/kafka/server/BrokerServer.scala Updated to instantiate KRaftTopicCreator and inject it into DefaultAutoTopicCreationManager
core/src/test/scala/unit/kafka/server/AutoTopicCreationManagerTest.scala Replaced Mockito ArgumentCaptor usage with TestTopicCreator for cleaner, more maintainable tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Kafka Broker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant