rajinisivaram commented on a change in pull request #9334:
URL: https://github.com/apache/kafka/pull/9334#discussion_r494510121



##########
File path: core/src/main/scala/kafka/admin/TopicCommand.scala
##########
@@ -69,16 +71,26 @@ object TopicCommand extends Logging {
       else if (opts.hasDeleteOption)
         topicService.deleteTopic(opts)
     } catch {
+      case e: ExecutionException =>
+        if (e.getCause != null)
+          printException(e.getCause)
+        else
+          printException(e)
+        exitCode = 1
       case e: Throwable =>
-        println("Error while executing topic command : " + e.getMessage)
-        error(Utils.stackTrace(e))
+        printException(e)
         exitCode = 1
     } finally {
       topicService.close()
       Exit.exit(exitCode)
     }
   }
 
+  private def printException(e: Throwable): Unit = {
+    println("Error while executing topic command : " + e.getMessage)
+    error(Utils.stackTrace(e))

Review comment:
       Couldn't we just use `error(message, e)`?

##########
File path: 
core/src/test/scala/unit/kafka/admin/TopicCommandWithAdminClientTest.scala
##########
@@ -844,4 +851,72 @@ class TopicCommandWithAdminClientTest extends 
KafkaServerTestHarness with Loggin
     assertEquals(2, rows.size)
     rows(0).startsWith(s"Topic:$testTopicName\tPartitionCount:1")
   }
+
+  @Test
+  def testCreateTopicDoesNotRetryThrottlingQuotaExceededException(): Unit = {
+    val adminClient = Mockito.mock(classOf[Admin])
+    val topicService = AdminClientTopicService(adminClient)
+
+    val result = AdminClientTestUtils.createTopicsResult(testTopicName, 
Errors.THROTTLING_QUOTA_EXCEEDED.exception())
+    Mockito.when(adminClient.createTopics(ArgumentMatchers.any(), 
ArgumentMatchers.any())).thenReturn(result)
+
+    assertThrows(classOf[ThrottlingQuotaExceededException],
+      () => topicService.createTopic(new TopicCommandOptions(Array("--topic", 
testTopicName))))
+
+    val expectedNewTopic = new NewTopic(testTopicName, 
Option.empty[Integer].asJava, Option.empty[java.lang.Short].asJava)

Review comment:
       We could just use Optional.empty instead of creating in Scala and 
converting?

##########
File path: 
core/src/test/scala/unit/kafka/admin/TopicCommandWithAdminClientTest.scala
##########
@@ -844,4 +851,72 @@ class TopicCommandWithAdminClientTest extends 
KafkaServerTestHarness with Loggin
     assertEquals(2, rows.size)
     rows(0).startsWith(s"Topic:$testTopicName\tPartitionCount:1")
   }
+
+  @Test
+  def testCreateTopicDoesNotRetryThrottlingQuotaExceededException(): Unit = {
+    val adminClient = Mockito.mock(classOf[Admin])
+    val topicService = AdminClientTopicService(adminClient)
+
+    val result = AdminClientTestUtils.createTopicsResult(testTopicName, 
Errors.THROTTLING_QUOTA_EXCEEDED.exception())
+    Mockito.when(adminClient.createTopics(ArgumentMatchers.any(), 
ArgumentMatchers.any())).thenReturn(result)

Review comment:
       May be worth importing `org.mockito.Mockito._` and  
`org.mockito.ArgumentMatchers._` to avoid repeating the class name everywhere.

##########
File path: core/src/main/scala/kafka/admin/TopicCommand.scala
##########
@@ -69,16 +71,26 @@ object TopicCommand extends Logging {
       else if (opts.hasDeleteOption)
         topicService.deleteTopic(opts)
     } catch {
+      case e: ExecutionException =>
+        if (e.getCause != null)
+          printException(e.getCause)
+        else
+          printException(e)
+        exitCode = 1
       case e: Throwable =>
-        println("Error while executing topic command : " + e.getMessage)
-        error(Utils.stackTrace(e))
+        printException(e)
         exitCode = 1
     } finally {
       topicService.close()
       Exit.exit(exitCode)
     }
   }
 
+  private def printException(e: Throwable): Unit = {
+    println("Error while executing topic command : " + e.getMessage)
+    error(Utils.stackTrace(e))

Review comment:
       Sorry, I should have been more clear. I just meant, why do we call 
`Utils.stackTrace(e))` when `error(message, e)` gives you a stack trace for 
free. In terms of changing from `error` to `debug`, I think we include stack 
track in other commands. But each command seems to use something different. 
ConfigCommand, for example, doesn't print stacktrace for config exceptions. It 
logs both the error message and stacktrace to stderr. AclCommand prints for 
everything to stdout. Let's just keep `error` for now and maybe open a JIRA to 
improve and make tools consistent later?




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