chia7712 commented on code in PR #15761:
URL: https://github.com/apache/kafka/pull/15761#discussion_r1581597711


##########
core/src/test/scala/integration/kafka/server/KafkaServerKRaftRegistrationTest.scala:
##########
@@ -71,11 +72,16 @@ class KafkaServerKRaftRegistrationTest {
       val readyFuture = 
kraftCluster.controllers().values().asScala.head.controller.waitForReadyBrokers(3)
 
       // Enable migration configs and restart brokers
-      
zkCluster.config().serverProperties().put(KafkaConfig.MigrationEnabledProp, 
"true")
-      
zkCluster.config().serverProperties().put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
kraftCluster.quorumVotersConfig())
-      
zkCluster.config().serverProperties().put(KafkaConfig.ControllerListenerNamesProp,
 "CONTROLLER")
-      
zkCluster.config().serverProperties().put(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG,
 "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT")
-      zkCluster.rollingBrokerRestart()
+      val serverProperties = new java.util.HashMap[String, String]()

Review Comment:
   ```java
   val serverProperties = new util.HashMap[String, 
String](zkCluster.config().serverProperties(zkCluster.config().serverProperties()))
   
   ```



##########
core/src/test/java/kafka/test/ClusterConfigTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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 kafka.test;
+
+import kafka.test.annotation.Type;
+import org.apache.kafka.common.security.auth.SecurityProtocol;
+import org.apache.kafka.server.common.MetadataVersion;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Optional;
+
+public class ClusterConfigTest {
+
+    @Test
+    public void testClusterConfigBuilder() throws IOException {
+        File trustStoreFile = TestUtils.tempFile();
+
+        ClusterConfig clusterConfig = ClusterConfig.builder()
+                .setType(Type.KRAFT)
+                .setBrokers(1)
+                .setControllers(1)
+                .setName("builder-test")
+                .setAutoStart(true)
+                .setSecurityProtocol(SecurityProtocol.PLAINTEXT)
+                .setListenerName("EXTERNAL")
+                .setTrustStoreFile(trustStoreFile)
+                .setMetadataVersion(MetadataVersion.IBP_0_8_0)
+                .setServerProperties(Collections.singletonMap("broker", 
"broker_value"))
+                .setConsumerProperties(Collections.singletonMap("consumer", 
"consumer_value"))
+                .setProducerProperties(Collections.singletonMap("producer", 
"producer_value"))
+                
.setAdminClientProperties(Collections.singletonMap("admin_client", 
"admin_client_value"))
+                
.setSaslClientProperties(Collections.singletonMap("sasl_client", 
"sasl_client_value"))
+                
.setSaslServerProperties(Collections.singletonMap("sasl_server", 
"sasl_server_value"))
+                .setPerBrokerProperties(Collections.singletonMap(0, 
Collections.singletonMap("broker_0", "broker_0_value")))
+                .build();
+
+        Assertions.assertEquals(Type.KRAFT, clusterConfig.clusterType());

Review Comment:
   Dear friend, this test can't protect us from overlooking the field copy 
since we don't check the field added in the future, right? Maybe we can use 
reflection to get all fields and then check all dynamically.
   ```java
       private static Map<String, Object> fields(ClusterConfig config) {
           return 
Arrays.stream(config.getClass().getDeclaredFields()).collect(Collectors.toMap(Field::getName,
 f -> {
               f.setAccessible(true);
               return Assertions.assertDoesNotThrow(() -> f.get(config));
           }));
       }
   
       @Test
       public void testClusterConfigBuilder() throws IOException {
           File trustStoreFile = TestUtils.tempFile();
   
           ClusterConfig clusterConfig = ClusterConfig.builder()
                   .setType(Type.KRAFT)
                   .setBrokers(3)
                   .setControllers(2)
                   .setName("builder-test")
                   .setAutoStart(true)
                   .setSecurityProtocol(SecurityProtocol.PLAINTEXT)
                   .setListenerName("EXTERNAL")
                   .setTrustStoreFile(trustStoreFile)
                   .setMetadataVersion(MetadataVersion.IBP_0_8_0)
                   .setServerProperties(Collections.singletonMap("broker", 
"broker_value"))
                   .setConsumerProperties(Collections.singletonMap("consumer", 
"consumer_value"))
                   .setProducerProperties(Collections.singletonMap("producer", 
"producer_value"))
                   
.setAdminClientProperties(Collections.singletonMap("admin_client", 
"admin_client_value"))
                   
.setSaslClientProperties(Collections.singletonMap("sasl_client", 
"sasl_client_value"))
                   
.setSaslServerProperties(Collections.singletonMap("sasl_server", 
"sasl_server_value"))
                   .setPerBrokerProperties(Collections.singletonMap(0, 
Collections.singletonMap("broker_0", "broker_0_value")))
                   .build();
   
           Map<String, Object> fields = fields(clusterConfig);
           Map<String, Object> copy = 
fields(ClusterConfig.builder(clusterConfig).build());
           Assertions.assertEquals(fields, copy);
       }
   ```



##########
core/src/test/scala/integration/kafka/zk/ZkMigrationIntegrationTest.scala:
##########
@@ -667,11 +693,16 @@ class ZkMigrationIntegrationTest {
 
       // Enable migration configs and restart brokers
       log.info("Restart brokers in migration mode")
-      
zkCluster.config().serverProperties().put(KafkaConfig.MigrationEnabledProp, 
"true")
-      
zkCluster.config().serverProperties().put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
kraftCluster.quorumVotersConfig())
-      
zkCluster.config().serverProperties().put(KafkaConfig.ControllerListenerNamesProp,
 "CONTROLLER")
-      
zkCluster.config().serverProperties().put(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG,
 "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT")
-      zkCluster.rollingBrokerRestart()
+      val serverProperties = new util.HashMap[String, String]()
+      serverProperties.putAll(zkCluster.config().serverProperties())

Review Comment:
   please fix this



##########
core/src/test/scala/integration/kafka/zk/ZkMigrationIntegrationTest.scala:
##########
@@ -802,11 +838,16 @@ class ZkMigrationIntegrationTest {
 
       // Enable migration configs and restart brokers
       log.info("Restart brokers in migration mode")
-      
zkCluster.config().serverProperties().put(KafkaConfig.MigrationEnabledProp, 
"true")
-      
zkCluster.config().serverProperties().put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
kraftCluster.quorumVotersConfig())
-      
zkCluster.config().serverProperties().put(KafkaConfig.ControllerListenerNamesProp,
 "CONTROLLER")
-      
zkCluster.config().serverProperties().put(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG,
 "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT")
-      zkCluster.rollingBrokerRestart()
+      val serverProperties = new util.HashMap[String, String]()
+      serverProperties.putAll(zkCluster.config().serverProperties())

Review Comment:
   please fix this



##########
core/src/test/scala/integration/kafka/zk/ZkMigrationIntegrationTest.scala:
##########
@@ -517,11 +533,16 @@ class ZkMigrationIntegrationTest {
 
       // Enable migration configs and restart brokers
       log.info("Restart brokers in migration mode")
-      
zkCluster.config().serverProperties().put(KafkaConfig.MigrationEnabledProp, 
"true")
-      
zkCluster.config().serverProperties().put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
kraftCluster.quorumVotersConfig())
-      
zkCluster.config().serverProperties().put(KafkaConfig.ControllerListenerNamesProp,
 "CONTROLLER")
-      
zkCluster.config().serverProperties().put(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG,
 "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT")
-      zkCluster.rollingBrokerRestart() // This would throw if authorizers 
weren't allowed
+      val serverProperties = new util.HashMap[String, String]()
+      serverProperties.putAll(zkCluster.config().serverProperties())

Review Comment:
   please fix this



##########
core/src/test/scala/integration/kafka/server/KafkaServerKRaftRegistrationTest.scala:
##########
@@ -108,11 +114,16 @@ class KafkaServerKRaftRegistrationTest {
       kraftCluster.startup()
 
       // Enable migration configs and restart brokers
-      
zkCluster.config().serverProperties().put(KafkaConfig.MigrationEnabledProp, 
"true")
-      
zkCluster.config().serverProperties().put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
kraftCluster.quorumVotersConfig())
-      
zkCluster.config().serverProperties().put(KafkaConfig.ControllerListenerNamesProp,
 "CONTROLLER")
-      
zkCluster.config().serverProperties().put(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG,
 "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT")
-      assertThrows(classOf[IllegalArgumentException], () => 
zkCluster.rollingBrokerRestart())
+      val serverProperties = new java.util.HashMap[String, String]()
+      serverProperties.putAll(zkCluster.config().serverProperties())

Review Comment:
   ditto



##########
core/src/test/java/kafka/test/ClusterConfigTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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 kafka.test;
+
+import kafka.test.annotation.Type;
+import org.apache.kafka.common.security.auth.SecurityProtocol;
+import org.apache.kafka.server.common.MetadataVersion;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Optional;
+
+public class ClusterConfigTest {
+
+    @Test
+    public void testClusterConfigBuilder() throws IOException {

Review Comment:
   `testCopy`



##########
core/src/test/scala/integration/kafka/zk/ZkMigrationIntegrationTest.scala:
##########
@@ -602,11 +623,16 @@ class ZkMigrationIntegrationTest {
 
       // Enable migration configs and restart brokers
       log.info("Restart brokers in migration mode")
-      
zkCluster.config().serverProperties().put(KafkaConfig.MigrationEnabledProp, 
"true")
-      
zkCluster.config().serverProperties().put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
kraftCluster.quorumVotersConfig())
-      
zkCluster.config().serverProperties().put(KafkaConfig.ControllerListenerNamesProp,
 "CONTROLLER")
-      
zkCluster.config().serverProperties().put(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG,
 "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT")
-      zkCluster.rollingBrokerRestart()
+      val serverProperties = new util.HashMap[String, String]()
+      serverProperties.putAll(zkCluster.config().serverProperties())

Review Comment:
   please fix this



##########
core/src/test/scala/integration/kafka/zk/ZkMigrationIntegrationTest.scala:
##########
@@ -727,11 +758,16 @@ class ZkMigrationIntegrationTest {
 
       // Enable migration configs and restart brokers
       log.info("Restart brokers in migration mode")
-      
zkCluster.config().serverProperties().put(KafkaConfig.MigrationEnabledProp, 
"true")
-      
zkCluster.config().serverProperties().put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
kraftCluster.quorumVotersConfig())
-      
zkCluster.config().serverProperties().put(KafkaConfig.ControllerListenerNamesProp,
 "CONTROLLER")
-      
zkCluster.config().serverProperties().put(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG,
 "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT")
-      zkCluster.rollingBrokerRestart()
+      val serverProperties = new util.HashMap[String, String]()
+      serverProperties.putAll(zkCluster.config().serverProperties())

Review Comment:
   please fix this



##########
core/src/test/scala/integration/kafka/zk/ZkMigrationIntegrationTest.scala:
##########
@@ -453,11 +464,16 @@ class ZkMigrationIntegrationTest {
 
       // Enable migration configs and restart brokers
       log.info("Restart brokers in migration mode")
-      
zkCluster.config().serverProperties().put(KafkaConfig.MigrationEnabledProp, 
"true")
-      
zkCluster.config().serverProperties().put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
kraftCluster.quorumVotersConfig())
-      
zkCluster.config().serverProperties().put(KafkaConfig.ControllerListenerNamesProp,
 "CONTROLLER")
-      
zkCluster.config().serverProperties().put(SocketServerConfigs.LISTENER_SECURITY_PROTOCOL_MAP_CONFIG,
 "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT")
-      zkCluster.rollingBrokerRestart()
+      val serverProperties = new util.HashMap[String, String]()
+      serverProperties.putAll(zkCluster.config().serverProperties())

Review Comment:
   please fix this



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