Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/src/main/scala/kafka/tools/ConsumerPerformance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicLong
import java.util.{Properties, Random}

import com.typesafe.scalalogging.LazyLogging
import joptsimple.OptionException
import kafka.utils.{CommandLineUtils, ToolsUtils}
import org.apache.kafka.clients.consumer.{ConsumerRebalanceListener, KafkaConsumer}
import org.apache.kafka.common.serialization.ByteArrayDeserializer
Expand Down Expand Up @@ -255,7 +256,12 @@ object ConsumerPerformance extends LazyLogging {
.ofType(classOf[Long])
.defaultsTo(10000)

options = parser.parse(args: _*)
try
options = parser.parse(args: _*)
catch {
case e: OptionException =>
CommandLineUtils.printUsageAndDie(parser, e.getMessage)
}

if(options.has(numThreadsOpt) || options.has(numFetchersOpt))
println("WARNING: option [threads] and [num-fetch-threads] have been deprecated and will be ignored by the test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package kafka.tools
import java.io.ByteArrayOutputStream
import java.text.SimpleDateFormat

import joptsimple.OptionException
import kafka.utils.Exit
import org.junit.Assert.assertEquals
import org.junit.Test

Expand Down Expand Up @@ -97,18 +97,22 @@ class ConsumerPerformanceTest {
assertEquals(10, config.numMessages)
}

@Test(expected = classOf[OptionException])
@Test(expected = classOf[IllegalArgumentException])
def testConfigWithUnrecognizedOption(): Unit = {
Exit.setExitProcedure((_, message) => throw new IllegalArgumentException(message.orNull))
//Given
val args: Array[String] = Array(
"--broker-list", "localhost:9092",
"--topic", "test",
"--messages", "10",
"--new-consumer"
)

//When
new ConsumerPerformance.ConsumerPerfConfig(args)
try {
//When
new ConsumerPerformance.ConsumerPerfConfig(args)
} finally {
Exit.resetExitProcedure()
}
}

private def testHeaderMatchContent(detailed: Boolean, expectedOutputLineCount: Int, fun: () => Unit): Unit = {
Expand Down