showuon commented on code in PR #13459:
URL: https://github.com/apache/kafka/pull/13459#discussion_r1159239494


##########
tools/src/test/java/org/apache/kafka/tools/FeatureCommandTest.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.tools;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import kafka.test.ClusterInstance;
+import kafka.test.annotation.ClusterTest;
+import kafka.test.annotation.ClusterTestDefaults;
+import kafka.test.annotation.Type;
+import kafka.test.junit.ClusterTestExtensions;
+import net.sourceforge.argparse4j.inf.Namespace;
+import org.apache.kafka.clients.admin.MockAdminClient;
+import org.apache.kafka.server.common.MetadataVersion;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import static java.lang.String.format;
+import static java.util.Collections.emptyMap;
+import static java.util.Collections.singletonMap;
+
+import static 
org.apache.kafka.clients.admin.FeatureUpdate.UpgradeType.SAFE_DOWNGRADE;
+import static 
org.apache.kafka.clients.admin.FeatureUpdate.UpgradeType.UNSAFE_DOWNGRADE;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@ExtendWith(value = ClusterTestExtensions.class)
+@ClusterTestDefaults(clusterType = Type.KRAFT)
+@Tag("integration")
+public class FeatureCommandTest {
+
+    private final ClusterInstance cluster;
+    public FeatureCommandTest(ClusterInstance cluster) {
+        this.cluster = cluster;
+    }
+
+    @ClusterTest(clusterType = Type.ZK, metadataVersion = 
MetadataVersion.IBP_3_3_IV1)
+    public void testDescribeWithZK() {
+        String commandOutput = ToolsTestUtils.captureStandardOut(() ->
+                assertEquals(0, 
FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), 
"describe"))
+        );
+        assertEquals("", commandOutput);
+    }
+
+    @ClusterTest(clusterType = Type.KRAFT, metadataVersion = 
MetadataVersion.IBP_3_3_IV1)
+    public void testDescribeWithKRaft() {
+        String commandOutput = ToolsTestUtils.captureStandardOut(() ->
+                assertEquals(0, 
FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), 
"describe"))
+        );
+        assertEquals("Feature: metadata.version\tSupportedMinVersion: 
3.0-IV1\t" +
+                "SupportedMaxVersion: 3.5-IV1\tFinalizedVersionLevel: 
3.3-IV1\t", outputWithoutEpoch(commandOutput));
+    }
+
+    @ClusterTest(clusterType = Type.ZK, metadataVersion = 
MetadataVersion.IBP_3_3_IV1)
+    public void testUpgradeMetadataVersionWithZk() {
+        String commandOutput = ToolsTestUtils.captureStandardOut(() ->
+                assertEquals(1, 
FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
+                        "upgrade", "--metadata", "3.3-IV2"))
+        );
+        assertEquals("Could not upgrade metadata.version to 6. Could not apply 
finalized feature " +
+                "update because the provided feature is not supported.", 
commandOutput);
+    }
+
+    @ClusterTest(clusterType = Type.KRAFT, metadataVersion = 
MetadataVersion.IBP_3_3_IV1)
+    public void testUpgradeMetadataVersionWithKraft() {
+        String commandOutput = ToolsTestUtils.captureStandardOut(() ->
+                assertEquals(0, 
FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
+                        "upgrade", "--feature", "metadata.version=5"))
+        );
+        assertEquals("metadata.version was upgraded to 5.", commandOutput);
+
+        commandOutput = ToolsTestUtils.captureStandardOut(() ->
+                assertEquals(0, 
FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
+                        "upgrade", "--metadata", "3.3-IV2"))
+        );
+        assertEquals("metadata.version was upgraded to 6.", commandOutput);
+    }
+
+    @ClusterTest(clusterType = Type.ZK, metadataVersion = 
MetadataVersion.IBP_3_3_IV1)
+    public void testDowngradeMetadataVersionWithZk() {
+        String commandOutput = ToolsTestUtils.captureStandardOut(() ->
+                assertEquals(1, 
FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
+                        "disable", "--feature", "metadata.version"))
+        );
+        assertEquals("Could not disable metadata.version. Can not delete 
non-existing finalized feature.", commandOutput);
+
+        commandOutput = ToolsTestUtils.captureStandardOut(() ->
+                assertEquals(1, 
FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
+                        "downgrade", "--metadata", "3.3-IV0"))
+        );
+        assertEquals("Could not downgrade metadata.version to 4. Could not 
apply finalized feature " +
+                        "update because the provided feature is not 
supported.", commandOutput);
+
+        commandOutput = ToolsTestUtils.captureStandardOut(() ->
+                assertEquals(1, 
FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
+                        "downgrade", "--unsafe", "--metadata", "3.3-IV0"))
+        );
+        assertEquals("Could not downgrade metadata.version to 4. Could not 
apply finalized feature " +
+                "update because the provided feature is not supported.", 
commandOutput);
+    }
+
+    @ClusterTest(clusterType = Type.KRAFT, metadataVersion = 
MetadataVersion.IBP_3_3_IV1)
+    public void testDowngradeMetadataVersionWithKRaft() {
+        String commandOutput = ToolsTestUtils.captureStandardOut(() ->

Review Comment:
   Not related to your PR, but I found the stream resource in 
`captureStandardOut` is not closed, causing resource leaking. Could you fix it 
in this PR or create another PR to fix it? Thanks.



-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to