Icewind52 commented on code in PR #24247:
URL: https://github.com/apache/kafka/pull/24247#discussion_r4635757493


##########
tools/src/test/java/org/apache/kafka/tools/ConfigCommandTest.java:
##########
@@ -1295,6 +1303,119 @@ public synchronized AlterConfigsResult 
incrementalAlterConfigs(Map<ConfigResourc
         verify(alterResult).all();
     }
 
+    @Test
+    public void shouldAlterClusterMirrorConfig() throws Exception {
+        ConfigCommand.ConfigCommandOptions alterOpts = new 
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server", 
"localhost:9092",
+            "--entity-type", "cluster-mirrors",
+            "--entity-name", "mirror",
+            "--alter",
+            "--delete-config", "a",
+            "--add-config", "b=c"));
+        alterOpts.checkArgs();
+
+        KafkaFutureImpl<Void> alterFuture = new KafkaFutureImpl<>();
+        alterFuture.complete(null);
+        AlterConfigsResult alterResult = mock(AlterConfigsResult.class);
+        when(alterResult.all()).thenReturn(alterFuture);
+
+        Node node = new Node(1, "localhost", 9092);
+        MockAdminClient mockAdminClient = new MockAdminClient(List.of(node), 
node) {
+            @Override
+            public synchronized AlterConfigsResult 
incrementalAlterConfigs(Map<ConfigResource, Collection<AlterConfigOp>> configs, 
AlterConfigsOptions options) {
+                assertEquals(Map.of(new 
ConfigResource(ConfigResource.Type.CLUSTER_MIRROR, "mirror"), List.of(
+                    new AlterConfigOp(new ConfigEntry("a", ""), 
AlterConfigOp.OpType.DELETE),
+                    new AlterConfigOp(new ConfigEntry("b", "c"), 
AlterConfigOp.OpType.SET)
+                )), configs);
+                return alterResult;
+            }
+        };
+        ConfigCommand.alterConfig(mockAdminClient, alterOpts);
+        verify(alterResult).all();
+    }
+
+    @Test
+    public void 
shouldPropagateUnsupportedVersionWhenAlteringClusterMirrorConfig() {
+        ConfigCommand.ConfigCommandOptions alterOpts = new 
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server", 
"localhost:9092",
+            "--entity-type", "cluster-mirrors",
+            "--entity-name", "mirror",
+            "--alter",
+            "--add-config", "b=c"));
+
+        KafkaFutureImpl<Void> alterFuture = new KafkaFutureImpl<>();
+        alterFuture.completeExceptionally(new 
UnsupportedVersionException("Cluster mirror configs are not supported yet."));
+        AlterConfigsResult alterResult = mock(AlterConfigsResult.class);
+        when(alterResult.all()).thenReturn(alterFuture);
+
+        Node node = new Node(1, "localhost", 9092);
+        MockAdminClient mockAdminClient = new MockAdminClient(List.of(node), 
node) {
+            @Override
+            public synchronized AlterConfigsResult 
incrementalAlterConfigs(Map<ConfigResource, Collection<AlterConfigOp>> configs, 
AlterConfigsOptions options) {
+                return alterResult;
+            }
+        };
+        UnsupportedVersionException exception = 
assertThrows(UnsupportedVersionException.class,
+            () -> ConfigCommand.alterConfig(mockAdminClient, alterOpts));
+        assertEquals("Cluster mirror configs are not supported yet.", 
exception.getMessage());
+    }
+
+    @Test
+    public void shouldDescribeClusterMirrorConfig() {
+        ConfigCommand.ConfigCommandOptions describeOpts = new 
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server", 
"localhost:9092",
+            "--entity-type", "cluster-mirrors",
+            "--entity-name", "mirror",
+            "--describe"));
+        describeOpts.checkArgs();
+
+        ConfigResource resource = new 
ConfigResource(ConfigResource.Type.CLUSTER_MIRROR, "mirror");
+        KafkaFutureImpl<Config> future = new KafkaFutureImpl<>();
+        future.complete(new Config(List.of(
+            new ConfigEntry("a", "b", 
ConfigEntry.ConfigSource.DYNAMIC_CLUSTER_MIRROR_CONFIG, false, false, 
List.of(), ConfigEntry.ConfigType.STRING, null),
+            new ConfigEntry("c", "d", ConfigEntry.ConfigSource.DEFAULT_CONFIG, 
false, false, List.of(), ConfigEntry.ConfigType.STRING, null))));
+        DescribeConfigsResult describeResult = 
mock(DescribeConfigsResult.class);
+        when(describeResult.values()).thenReturn(Map.of(resource, future));
+
+        Node node = new Node(1, "localhost", 9092);
+        MockAdminClient mockAdminClient = new MockAdminClient(List.of(node), 
node) {
+            @Override
+            public synchronized DescribeConfigsResult 
describeConfigs(Collection<ConfigResource> resources, DescribeConfigsOptions 
options) {
+                assertEquals(List.of(resource), List.copyOf(resources));
+                return describeResult;
+            }
+        };
+        String output = ToolsTestUtils.captureStandardOut(() -> {
+            try {
+                ConfigCommand.describeConfig(mockAdminClient, describeOpts);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+        assertTrue(output.contains("Dynamic configs for cluster-mirror mirror 
are:"), output);
+        assertTrue(output.contains("a=b"), output);
+        // without --all, only dynamic cluster mirror configs are shown
+        assertFalse(output.contains("c=d"), output);
+    }
+
+    @Test
+    public void shouldNotDescribeClusterMirrorConfigWithoutEntityName() {
+        ConfigCommand.ConfigCommandOptions describeOpts = new 
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server", 
"localhost:9092",
+            "--entity-type", "cluster-mirrors",
+            "--describe"));
+
+        IllegalArgumentException exception = 
assertThrows(IllegalArgumentException.class, describeOpts::checkArgs);
+        assertEquals("An entity name must be specified with --describe of 
cluster-mirrors", exception.getMessage());
+    }
+
+    @Test
+    public void shouldNotAlterClusterMirrorConfigWithoutEntityName() {
+        ConfigCommand.ConfigCommandOptions alterOpts = new 
ConfigCommand.ConfigCommandOptions(toArray("--bootstrap-server", 
"localhost:9092",
+            "--entity-type", "cluster-mirrors",
+            "--alter",
+            "--add-config", "a=b"));
+
+        IllegalArgumentException exception = 
assertThrows(IllegalArgumentException.class, alterOpts::checkArgs);
+        assertEquals("An entity name must be specified with --alter of 
cluster-mirrors", exception.getMessage());
+    }
+

Review Comment:
   Done



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to