mumrah commented on a change in pull request #10505:
URL: https://github.com/apache/kafka/pull/10505#discussion_r614218074



##########
File path: core/src/test/java/kafka/test/MockController.java
##########
@@ -197,15 +209,73 @@ private MockController(Collection<MockTopic> 
initialTopics) {
 
     @Override
     public CompletableFuture<Map<ConfigResource, ApiError>> 
incrementalAlterConfigs(
-            Map<ConfigResource, Map<String, Map.Entry<AlterConfigOp.OpType, 
String>>> configChanges,
+            Map<ConfigResource, Map<String, Entry<AlterConfigOp.OpType, 
String>>> configChanges,
             boolean validateOnly) {
+        Map<ConfigResource, ApiError> results = new HashMap<>();
+        for (Entry<ConfigResource, Map<String, Entry<AlterConfigOp.OpType, 
String>>> entry :
+                configChanges.entrySet()) {
+            ConfigResource resource = entry.getKey();
+            results.put(resource, incrementalAlterResource(resource, 
entry.getValue(), validateOnly));
+        }
+        CompletableFuture<Map<ConfigResource, ApiError>> future = new 
CompletableFuture<>();
+        future.complete(results);
+        return future;
+    }
+
+    private ApiError incrementalAlterResource(ConfigResource resource,
+            Map<String, Entry<AlterConfigOp.OpType, String>> ops, boolean 
validateOnly) {
+        for (Entry<String, Entry<AlterConfigOp.OpType, String>> entry : 
ops.entrySet()) {
+            AlterConfigOp.OpType opType = entry.getValue().getKey();
+            if (opType != SET && opType != DELETE) {
+                return new ApiError(INVALID_REQUEST, "This mock does not " +
+                    "support the " + opType + " config operation.");
+            }
+        }
+        if (!validateOnly) {
+            for (Entry<String, Entry<AlterConfigOp.OpType, String>> entry : 
ops.entrySet()) {
+                String key = entry.getKey();
+                AlterConfigOp.OpType op = entry.getValue().getKey();
+                String value = entry.getValue().getValue();
+                switch (op) {
+                    case SET:
+                        configs.computeIfAbsent(resource, __ -> new 
HashMap<>()).put(key, value);

Review comment:
       well, i thought a method reference would work here for the hash map, but 
I tried it and it doesn't seem to work. 🤔 




-- 
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:
us...@infra.apache.org


Reply via email to