splett2 commented on a change in pull request #9628: URL: https://github.com/apache/kafka/pull/9628#discussion_r536257595
########## File path: core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala ########## @@ -472,6 +512,134 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { EasyMock.reset(alterResult, describeResult) } + @Test + def shouldNotAlterNonQuotaIpConfigsUsingBootstrapServer(): Unit = { + // when using --bootstrap-server, it should be illegal to alter anything that is not a connection quota + // for ip entities + val node = new Node(1, "localhost", 9092) + val mockAdminClient = new MockAdminClient(util.Collections.singletonList(node), node) + + def verifyCommand(entityType: String, alterOpts: String*): Unit = { + val opts = new ConfigCommandOptions(Array("--bootstrap-server", "localhost:9092", + "--entity-type", entityType, "--entity-name", "admin", + "--alter") ++ alterOpts) + val e = intercept[IllegalArgumentException] { + ConfigCommand.alterConfig(mockAdminClient, opts) + } + assertTrue(s"Unexpected exception: $e", e.getMessage.contains("some_config")) + } + + verifyCommand("ips", "--add-config", "connection_creation_rate=10000,some_config=10") + verifyCommand("ips", "--add-config", "some_config=10") + verifyCommand("ips", "--delete-config", "connection_creation_rate=10000,some_config=10") + verifyCommand("ips", "--delete-config", "some_config=10") + } + + @Test + def testDescribeIpConfigs(): Unit = { + def testShouldDescribeIpConfig(ip: Option[String]): Unit = { + val entityType = ClientQuotaEntity.IP + val (ipArgs, filterComponent) = ip match { + case Some(null) => (Array("--entity-default"), ClientQuotaFilterComponent.ofDefaultEntity(entityType)) + case Some(addr) => (Array("--entity-name", addr), ClientQuotaFilterComponent.ofEntity(entityType, addr)) + case None => (Array.empty[String], ClientQuotaFilterComponent.ofEntityType(entityType)) + } + + val describeOpts = new ConfigCommandOptions(Array("--bootstrap-server", "localhost:9092", + "--describe", "--entity-type", "ips") ++ ipArgs) + + val expectedFilter = ClientQuotaFilter.containsOnly(List(filterComponent).asJava) + + var describedConfigs = false + val describeFuture = new KafkaFutureImpl[util.Map[ClientQuotaEntity, util.Map[String, java.lang.Double]]] + describeFuture.complete(Map.empty[ClientQuotaEntity, util.Map[String, java.lang.Double]].asJava) + val describeResult: DescribeClientQuotasResult = EasyMock.createNiceMock(classOf[DescribeClientQuotasResult]) + EasyMock.expect(describeResult.entities()).andReturn(describeFuture) + + val node = new Node(1, "localhost", 9092) + val mockAdminClient = new MockAdminClient(util.Collections.singletonList(node), node) { + override def describeClientQuotas(filter: ClientQuotaFilter, options: DescribeClientQuotasOptions): DescribeClientQuotasResult = { + assertTrue(filter.strict) + assertEquals(expectedFilter, filter) + describedConfigs = true + describeResult + } + } Review comment: hmm, good point. I did this because it's what a similar quotas config command test did, but you're right that a real mock would be more appropriate here. ---------------------------------------------------------------- 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