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
2 changes: 0 additions & 2 deletions core/src/main/scala/kafka/admin/TopicCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,6 @@ object TopicCommand extends Logging {
}
if (!has(listOpt) && !has(describeOpt))
CommandLineUtils.checkRequiredArgs(parser, options, topicOpt)
if (has(createOpt) && !has(replicaAssignmentOpt))
CommandLineUtils.checkRequiredArgs(parser, options, partitionsOpt, replicationFactorOpt)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove them since it is only checked for zookeeper option case before.

if (has(alterOpt)) {
CommandLineUtils.checkInvalidArgsSet(parser, options, Set(bootstrapServerOpt, configOpt), Set(alterOpt),
Some(kafkaConfigsCanAlterTopicConfigsViaBootstrapServer))
Expand Down
47 changes: 33 additions & 14 deletions core/src/test/scala/unit/kafka/admin/TopicCommandTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ class TopicCommandTest {
}

@Test
def testCreateWithPartitionCountWithoutReplicationFactor(): Unit = {
assertCheckArgsExitCode(1,
new TopicCommandOptions(
Array("--bootstrap-server", brokerList,
"--create",
"--partitions", "2",
"--topic", topicName)))
def testCreateWithPartitionCountWithoutReplicationFactorShouldSucceed(): Unit = {
val opts = new TopicCommandOptions(
Array("--bootstrap-server", brokerList,
"--create",
"--partitions", "2",
"--topic", topicName))
opts.checkArgs()
}

@Test
def testCreateWithReplicationFactorWithoutPartitionCount(): Unit = {
assertCheckArgsExitCode(1,
new TopicCommandOptions(
Array("--bootstrap-server", brokerList,
"--create",
"--replication-factor", "3",
"--topic", topicName)))
def testCreateWithReplicationFactorWithoutPartitionCountShouldSucceed(): Unit = {
val opts = new TopicCommandOptions(
Array("--bootstrap-server", brokerList,
"--create",
"--replication-factor", "3",
"--topic", topicName))
opts.checkArgs()
}

@Test
Expand All @@ -123,6 +123,25 @@ class TopicCommandTest {
"--topic", topicName)))
}

@Test
def testCreateWithoutPartitionCountAndReplicationFactorShouldSucceed(): Unit = {
val opts = new TopicCommandOptions(
Array("--bootstrap-server", brokerList,
"--create",
"--topic", topicName))
opts.checkArgs()
}

@Test
def testDescribeShouldSucceed(): Unit = {
val opts = new TopicCommandOptions(
Array("--bootstrap-server", brokerList,
"--describe",
"--topic", topicName))
opts.checkArgs()
}
Comment on lines +126 to +142

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure the 2 command lines from quick start will pass successfully.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this case-by-case approach + it also works like a charm. 😃
20211024-214641



@Test
def testParseAssignmentDuplicateEntries(): Unit = {
assertThrows(classOf[AdminCommandFailedException], () => TopicCommand.parseReplicaAssignment("5:5"))
Expand Down