You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/04/06 17:56:22 UTC

[GitHub] [kafka] cmccabe commented on a change in pull request #10465: MINOR: add unit test for ControllerApis#createTopics

cmccabe commented on a change in pull request #10465:
URL: https://github.com/apache/kafka/pull/10465#discussion_r608065053



##########
File path: core/src/test/java/kafka/test/MockController.java
##########
@@ -77,8 +82,28 @@ private MockController(Collection<MockTopic> initialTopics) {
     }
 
     @Override
-    public CompletableFuture<CreateTopicsResponseData> createTopics(CreateTopicsRequestData request) {
-        throw new UnsupportedOperationException();
+    synchronized public CompletableFuture<CreateTopicsResponseData>
+            createTopics(CreateTopicsRequestData request) {
+        CreateTopicsResponseData response = new CreateTopicsResponseData();
+        for (CreatableTopic topic : request.topics()) {
+            if (topics.containsKey(topic.name())) {
+                response.topics().add(new CreatableTopicResult().
+                    setName(topic.name()).
+                    setErrorCode(Errors.TOPIC_ALREADY_EXISTS.code()));
+            } else {
+                long topicId = nextTopicId.getAndAdd(1);
+                Uuid topicUuid = new Uuid(0, topicId);
+                topicNameToId.put(topic.name(), topicUuid);
+                topics.put(topicUuid, new MockTopic(topic.name(), topicUuid));
+                response.topics().add(new CreatableTopicResult().
+                    setName(topic.name()).
+                    setErrorCode(Errors.NONE.code()).
+                    setTopicId(topicUuid));
+                // For a better mock, we might want to return configs, replication

Review comment:
       It wouldn't be useful for the test in this PR since we're trying to test the logic in `ControllerApis.scala`, which doesn't interact with configs or the replication factor.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org