tombentley commented on a change in pull request #8966:
URL: https://github.com/apache/kafka/pull/8966#discussion_r448208882



##########
File path: core/src/test/scala/unit/kafka/server/AdminManagerTest.scala
##########
@@ -0,0 +1,65 @@
+/*
+ * 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.server
+
+import kafka.zk.KafkaZkClient
+import org.apache.kafka.common.metrics.Metrics
+import org.easymock.EasyMock
+import kafka.utils.TestUtils
+import org.apache.kafka.common.config.ConfigResource
+import org.apache.kafka.common.message.DescribeConfigsRequestData
+import org.apache.kafka.common.message.DescribeConfigsResponseData
+import org.apache.kafka.common.protocol.Errors
+
+import org.junit.{After, Test}
+import org.junit.Assert.assertEquals
+
+class AdminManagerTest {
+
+  private val zkClient: KafkaZkClient = 
EasyMock.createNiceMock(classOf[KafkaZkClient])
+  private val metrics = new Metrics()
+  private val brokerId = 1
+  private val topic = "topic-1"
+  private val metadataCache: MetadataCache = 
EasyMock.createNiceMock(classOf[MetadataCache])
+
+  @After
+  def tearDown(): Unit = {
+    metrics.close()
+  }
+
+  def createAdminManager(): AdminManager = {
+    val props = TestUtils.createBrokerConfig(brokerId, "zk")
+    new AdminManager(KafkaConfig.fromProps(props), metrics, metadataCache, 
zkClient)
+  }
+
+  @Test
+  def testDescribeConfigs(): Unit = {

Review comment:
       ```suggestion
     def testDescribeConfigsWithNullConfigurationKeys(): Unit = {
   ```

##########
File path: core/src/main/scala/kafka/server/AdminManager.scala
##########
@@ -355,8 +355,8 @@ class AdminManager(val config: KafkaConfig,
       def createResponseConfig(configs: Map[String, Any],
                                createConfigEntry: (String, Any) => 
DescribeConfigsResponseData.DescribeConfigsResourceResult): 
DescribeConfigsResponseData.DescribeConfigsResult = {
         val filteredConfigPairs = configs.filter { case (configName, _) =>
-          /* Always returns true if configNames is None */
-          resource.configurationKeys.asScala.forall(_.contains(configName))
+          /* Always returns true if configurationKeys is null */
+          if (resource.configurationKeys != null) 
resource.configurationKeys.asScala.forall(_.contains(configName)) else true

Review comment:
       Since null means "all the keys" perhaps it would be better to move the 
`if` to the topic level to avoid an unneccessary traversal in the null case:
   
   ```scala
           val filteredConfigPairs = if (resource.configurationKeys == null)
             configs.toBuffer
           else 
             configs.filter { case (configName, _) =>
               /* Always returns true if configNames is None */
               resource.configurationKeys.asScala.forall(_.contains(configName))
             }.toBuffer
   ```




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