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



##########
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")

Review comment:
       See later comment as for bootstrap-server.

##########
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:
       We should have an assertion with multiple `--bootstrap-servers` given.

##########
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:
       If we're changing this class we ought to deprecate this option and 
replace it with one with a less contentious name.

##########
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:
       `TopicCommandOtions` and `ConfigCommandOptions` describes this as 
`.describedAs("server to connect to")`, so I guess we should do the same here.

##########
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:
       whitelist is a term we should avoid (see 
[KIP-629](https://cwiki.apache.org/confluence/display/KAFKA/KIP-629%3A+Use+racially+neutral+terms+in+our+codebase)
 and [KAFKA-10201](https://issues.apache.org/jira/browse/KAFKA-10201)).




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