dongjinleekr commented on a change in pull request #10827: URL: https://github.com/apache/kafka/pull/10827#discussion_r655162053
########## File path: core/src/test/scala/kafka/tools/ReplicaVerificationToolTest.scala ########## @@ -17,14 +17,40 @@ package kafka.tools +import kafka.tools.ReplicaVerificationTool.ReplicaVerificationToolOptions import org.apache.kafka.common.TopicPartition import org.apache.kafka.common.message.FetchResponseData import org.apache.kafka.common.record.{CompressionType, MemoryRecords, SimpleRecord} import org.junit.jupiter.api.Test -import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Assertions.{assertEquals, assertThrows, assertTrue} +import kafka.utils.Exit class ReplicaVerificationToolTest { + @Test + def testExitWithoutBootstrapServers(): Unit = { + Exit.setExitProcedure { + (exitCode: Int, _: Option[String]) => + assertEquals(1, exitCode) + throw new RuntimeException + } + + try assertThrows(classOf[RuntimeException], () => new ReplicaVerificationToolOptions(Array("--fetch-size", "1024"))) + finally Exit.resetExitProcedure() + } + + @Test + def testConfigOptWithBootstrapServers(): Unit = { + val opts1 = new ReplicaVerificationToolOptions(Array("--bootstrap-server", "localhost:9092")) + assertEquals("localhost:9092", opts1.bootstrapServer) + + val opts2 = new ReplicaVerificationToolOptions(Array("--broker-list", "127.0.0.1:9092")) + assertEquals("127.0.0.1:9092", opts2.bootstrapServer) + + val opts3 = new ReplicaVerificationToolOptions(Array("--broker-list", "127.0.0.1:9092", "--bootstrap-server", "localhost:9092")) + assertEquals("localhost:9092", opts3.bootstrapServer) + } Review comment: Great. :+1: ########## File path: core/src/main/scala/kafka/tools/ReplicaVerificationTool.scala ########## @@ -73,53 +74,61 @@ object ReplicaVerificationTool extends Logging { ReplicaVerificationTool.dateFormat.format(new Date(Time.SYSTEM.milliseconds)) } - def main(args: Array[String]): Unit = { - val parser = new OptionParser(false) - val brokerListOpt = parser.accepts("broker-list", "REQUIRED: The list of hostname and port of the server to connect to.") - .withRequiredArg - .describedAs("hostname:port,...,hostname:port") - .ofType(classOf[String]) - val fetchSizeOpt = parser.accepts("fetch-size", "The fetch size of each request.") - .withRequiredArg - .describedAs("bytes") - .ofType(classOf[java.lang.Integer]) - .defaultsTo(ConsumerConfig.DEFAULT_MAX_PARTITION_FETCH_BYTES) - val maxWaitMsOpt = parser.accepts("max-wait-ms", "The max amount of time each fetch request waits.") - .withRequiredArg - .describedAs("ms") - .ofType(classOf[java.lang.Integer]) - .defaultsTo(1000) + // Non-private for testing + sealed class ReplicaVerificationToolOptions(args: Array[String]) extends CommandDefaultOptions(args) { + private val brokerListOpt = parser.accepts("broker-list", "DEPRECATED, use --bootstrap-server instead; ignored if --bootstrap-server is specified. The list of hostname and port of the server to connect to.") + .withRequiredArg + .describedAs("HOST1:PORT1,...,HOST3:PORT3") + .ofType(classOf[String]) + private val bootstrapServerOpt = parser.accepts("bootstrap-server", "REQUIRED. The list of hostname and port of the server to connect to.") + .requiredUnless("broker-list") + .withRequiredArg + .describedAs("HOST1:PORT1,...,HOST3:PORT3") Review comment: `ConsoleConsumer`, `AclCommand`, `ConfigCommand` also do. :+1: ########## File path: core/src/main/scala/kafka/tools/ReplicaVerificationTool.scala ########## @@ -73,53 +74,61 @@ object ReplicaVerificationTool extends Logging { ReplicaVerificationTool.dateFormat.format(new Date(Time.SYSTEM.milliseconds)) } - def main(args: Array[String]): Unit = { - val parser = new OptionParser(false) - val brokerListOpt = parser.accepts("broker-list", "REQUIRED: The list of hostname and port of the server to connect to.") - .withRequiredArg - .describedAs("hostname:port,...,hostname:port") - .ofType(classOf[String]) - val fetchSizeOpt = parser.accepts("fetch-size", "The fetch size of each request.") - .withRequiredArg - .describedAs("bytes") - .ofType(classOf[java.lang.Integer]) - .defaultsTo(ConsumerConfig.DEFAULT_MAX_PARTITION_FETCH_BYTES) - val maxWaitMsOpt = parser.accepts("max-wait-ms", "The max amount of time each fetch request waits.") - .withRequiredArg - .describedAs("ms") - .ofType(classOf[java.lang.Integer]) - .defaultsTo(1000) + // Non-private for testing + sealed class ReplicaVerificationToolOptions(args: Array[String]) extends CommandDefaultOptions(args) { + private val brokerListOpt = parser.accepts("broker-list", "DEPRECATED, use --bootstrap-server instead; ignored if --bootstrap-server is specified. The list of hostname and port of the server to connect to.") + .withRequiredArg + .describedAs("HOST1:PORT1,...,HOST3:PORT3") + .ofType(classOf[String]) + private val bootstrapServerOpt = parser.accepts("bootstrap-server", "REQUIRED. The list of hostname and port of the server to connect to.") + .requiredUnless("broker-list") + .withRequiredArg + .describedAs("HOST1:PORT1,...,HOST3:PORT3") + .ofType(classOf[String]) + private val fetchSizeOpt = parser.accepts("fetch-size", "The fetch size of each request.") + .withRequiredArg + .describedAs("bytes") + .ofType(classOf[java.lang.Integer]) + .defaultsTo(ConsumerConfig.DEFAULT_MAX_PARTITION_FETCH_BYTES) + private val maxWaitMsOpt = parser.accepts("max-wait-ms", "The max amount of time each fetch request waits.") + .withRequiredArg + .describedAs("ms") + .ofType(classOf[java.lang.Integer]) + .defaultsTo(1000) val topicWhiteListOpt = parser.accepts("topic-white-list", "White list of topics to verify replica consistency. Defaults to all topics.") Review comment: Well, `fetchSizeOpt` and `maxWaitMsOpt` are precisely the same as the previous ones. Which change do you mean? :thinking: -- 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