ijuma commented on a change in pull request #9855: URL: https://github.com/apache/kafka/pull/9855#discussion_r558976200
########## File path: core/src/test/scala/integration/kafka/api/BaseProducerSendTest.scala ########## @@ -375,14 +372,10 @@ abstract class BaseProducerSendTest extends KafkaServerTestHarness { // Trying to send a record to a partition beyond topic's partition range before adding the partition should fail. val partition1 = 1 - try { - producer.send(new ProducerRecord(topic, partition1, null, "value".getBytes(StandardCharsets.UTF_8))).get() - fail("Should not allow sending a record to a partition not present in the metadata") - } catch { - case e: ExecutionException => e.getCause match { - case _: TimeoutException => // this is ok - case ex => throw new Exception("Sending to a partition not present in the metadata should result in a TimeoutException", ex) - } + val e = assertThrows(classOf[ExecutionException], () => producer.send(new ProducerRecord(topic, partition1, null, "value".getBytes(StandardCharsets.UTF_8))).get()) + e.getCause match { + case _: TimeoutException => // this is ok + case ex => throw new Exception("Sending to a partition not present in the metadata should result in a TimeoutException", ex) Review comment: I think you can assert that the cause is TimeoutException instead of this approach. ---------------------------------------------------------------- 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