brandboat commented on code in PR #18105:
URL: https://github.com/apache/kafka/pull/18105#discussion_r1877047149
##########
core/src/test/java/kafka/test/api/ShareConsumerTest.java:
##########
@@ -1749,23 +1642,18 @@ public void
testShareAutoOffsetResetEarliestAfterLsoMovement(String persister) t
ProducerRecord<byte[], byte[]> record = new
ProducerRecord<>(tp.topic(), tp.partition(), null, "key".getBytes(),
"value".getBytes());
// We write 10 records to the topic, so they would be written from
offsets 0-9 on the topic.
- try {
- for (int i = 0; i < 10; i++) {
- producer.send(record).get();
- }
- } catch (Exception e) {
- fail("Failed to send records: " + e);
+ for (int i = 0; i < 10; i++) {
+ assertDoesNotThrow(() -> producer.send(record).get(), "Failed
to send records");
Review Comment:
Thanks for the comment @apoorvmittal10, I did a quick test to check if
`assertDoesNotThrow` captures the exception details.
Here’s the test I wrote:
```java
@Test
public void testT() {
assertDoesNotThrow(() -> {
throw new RuntimeException("foobar");
}, "Failed to send records");
}
```
When I run this, the output includes the custom error message, the thrown
exception, and its stack trace:
```
Failed to send records ==> Unexpected exception thrown:
java.lang.RuntimeException: foobar
org.opentest4j.AssertionFailedError: Failed to send records ==> Unexpected
exception thrown: java.lang.RuntimeException: foobar
at
org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152)
at
org.junit.jupiter.api.AssertDoesNotThrow.createAssertionFailedError(AssertDoesNotThrow.java:84)
at
org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:75)
at
org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:62)
at
org.junit.jupiter.api.Assertions.assertDoesNotThrow(Assertions.java:3249)
at
kafka.server.logger.RuntimeLoggerManagerTest.testT(RuntimeLoggerManagerTest.java:46)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.RuntimeException: foobar
at
kafka.server.logger.RuntimeLoggerManagerTest.lambda$testT$0(RuntimeLoggerManagerTest.java:47)
at
org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:71)
... 6 more
```
Is this the level of detail you were hoping to see, or is there something
additional you'd like? Let me know!
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]