From b1dfc2828ab277c82c5bade15063013d6bbdbe83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E9=94=90?= <18120364@suning.com> Date: Thu, 28 May 2020 22:48:22 +0800 Subject: [PATCH 1/2] KAFKA-10057 optimize class ConfigCommand method alterConfig parameters --- core/src/main/scala/kafka/admin/ConfigCommand.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/scala/kafka/admin/ConfigCommand.scala b/core/src/main/scala/kafka/admin/ConfigCommand.scala index 75600cfbb536..3789db81f653 100644 --- a/core/src/main/scala/kafka/admin/ConfigCommand.scala +++ b/core/src/main/scala/kafka/admin/ConfigCommand.scala @@ -105,7 +105,7 @@ object ConfigCommand extends Config { } } - private[admin] def alterConfig(zkClient: KafkaZkClient, opts: ConfigCommandOptions, adminZkClient: AdminZkClient) { + private[admin] def alterConfig(opts: ConfigCommandOptions, adminZkClient: AdminZkClient) { val configsToBeAdded = parseConfigsToBeAdded(opts) val configsToBeDeleted = parseConfigsToBeDeleted(opts) val entity = parseEntity(opts) From 6e33fd9103d688847ca1ed2313f52cd6017e182a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E9=94=90?= <18120364@suning.com> Date: Tue, 16 Jun 2020 22:46:51 +0800 Subject: [PATCH 2/2] modify test --- .../scala/kafka/admin/ConfigCommand.scala | 2 +- .../unit/kafka/admin/ConfigCommandTest.scala | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/main/scala/kafka/admin/ConfigCommand.scala b/core/src/main/scala/kafka/admin/ConfigCommand.scala index 3789db81f653..6c47d31f70c2 100644 --- a/core/src/main/scala/kafka/admin/ConfigCommand.scala +++ b/core/src/main/scala/kafka/admin/ConfigCommand.scala @@ -97,7 +97,7 @@ object ConfigCommand extends Config { val adminZkClient = new AdminZkClient(zkClient) try { if (opts.options.has(opts.alterOpt)) - alterConfig(zkClient, opts, adminZkClient) + alterConfig(opts, adminZkClient) else if (opts.options.has(opts.describeOpt)) describeConfig(zkClient, opts, adminZkClient) } finally { diff --git a/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala b/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala index a17f060996b4..a037ec6c66b3 100644 --- a/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala +++ b/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala @@ -143,7 +143,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { def shouldFailIfUnrecognisedEntityType(): Unit = { val createOpts = new ConfigCommandOptions(Array("--zookeeper", zkConnect, "--entity-name", "client", "--entity-type", "not-recognised", "--alter", "--add-config", "a=b,c=d")) - ConfigCommand.alterConfig(null, createOpts, new DummyAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new DummyAdminZkClient(zkClient)) } @Test @@ -162,7 +162,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { } } - ConfigCommand.alterConfig(null, createOpts, new TestAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new TestAdminZkClient(zkClient)) } @Test @@ -181,7 +181,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { } } - ConfigCommand.alterConfig(null, createOpts, new TestAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new TestAdminZkClient(zkClient)) } @Test @@ -200,7 +200,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { } } - ConfigCommand.alterConfig(null, alterOpts, new TestAdminZkClient(zkClient)) + ConfigCommand.alterConfig(alterOpts, new TestAdminZkClient(zkClient)) } @Test @@ -279,7 +279,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { override def changeTopicConfig(topic: String, configs: Properties): Unit = {} } - ConfigCommand.alterConfig(null, createOpts, new TestAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new TestAdminZkClient(zkClient)) } @Test (expected = classOf[IllegalArgumentException]) @@ -289,7 +289,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { "--entity-type", "brokers", "--alter", "--add-config", "leader.replication.throttled.rate=10")) - ConfigCommand.alterConfig(null, createOpts, new DummyAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new DummyAdminZkClient(zkClient)) } @Test (expected = classOf[IllegalArgumentException]) @@ -299,7 +299,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { "--entity-type", "brokers", "--alter", "--add-config", "message.max.size=100000")) - ConfigCommand.alterConfig(null, createOpts, new DummyAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new DummyAdminZkClient(zkClient)) } @Test (expected = classOf[IllegalArgumentException]) @@ -309,7 +309,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { "--entity-type", "brokers", "--alter", "--add-config", "a=")) - ConfigCommand.alterConfig(null, createOpts, new DummyAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new DummyAdminZkClient(zkClient)) } @Test (expected = classOf[IllegalArgumentException]) @@ -319,7 +319,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { "--entity-type", "brokers", "--alter", "--add-config", "a=[b,c,d=e")) - ConfigCommand.alterConfig(null, createOpts, new DummyAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new DummyAdminZkClient(zkClient)) } @Test (expected = classOf[InvalidConfigException]) @@ -329,7 +329,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { "--entity-type", "topics", "--alter", "--delete-config", "missing_config1, missing_config2")) - ConfigCommand.alterConfig(null, createOpts, new DummyAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new DummyAdminZkClient(zkClient)) } @Test @@ -355,7 +355,7 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { } } - ConfigCommand.alterConfig(null, createOpts, new TestAdminZkClient(zkClient)) + ConfigCommand.alterConfig(createOpts, new TestAdminZkClient(zkClient)) } @Test @@ -393,14 +393,14 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { } } val optsA = createOpts("userA", "SCRAM-SHA-256=[iterations=8192,password=abc, def]") - ConfigCommand.alterConfig(null, optsA, CredentialChange("userA", Set("SCRAM-SHA-256"), 8192)) + ConfigCommand.alterConfig(optsA, CredentialChange("userA", Set("SCRAM-SHA-256"), 8192)) val optsB = createOpts("userB", "SCRAM-SHA-256=[iterations=4096,password=abc, def],SCRAM-SHA-512=[password=1234=abc]") - ConfigCommand.alterConfig(null, optsB, CredentialChange("userB", Set("SCRAM-SHA-256", "SCRAM-SHA-512"), 4096)) + ConfigCommand.alterConfig(optsB, CredentialChange("userB", Set("SCRAM-SHA-256", "SCRAM-SHA-512"), 4096)) val del256 = deleteOpts("userB", "SCRAM-SHA-256") - ConfigCommand.alterConfig(null, del256, CredentialChange("userB", Set("SCRAM-SHA-512"), 4096)) + ConfigCommand.alterConfig(del256, CredentialChange("userB", Set("SCRAM-SHA-512"), 4096)) val del512 = deleteOpts("userB", "SCRAM-SHA-512") - ConfigCommand.alterConfig(null, del512, CredentialChange("userB", Set(), 4096)) + ConfigCommand.alterConfig(del512, CredentialChange("userB", Set(), 4096)) } @Test