lianetm commented on code in PR #14503: URL: https://github.com/apache/kafka/pull/14503#discussion_r1356866475
########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/PrototypeAsyncConsumerTest.java: ########## @@ -322,6 +323,25 @@ public void testOffsetsForTimesOnNullPartitions() { Duration.ofMillis(1))); } + @Test + public void testOffsetsForTimesFailsOnNegativeTargetTimes() { + PrototypeAsyncConsumer<?, ?> consumer = newConsumer(time, new StringDeserializer(), new StringDeserializer()); + assertThrows(IllegalArgumentException.class, + () -> consumer.offsetsForTimes(Collections.singletonMap(new TopicPartition( + "topic1", 1), ListOffsetsRequest.EARLIEST_TIMESTAMP), + Duration.ofMillis(1))); + + assertThrows(IllegalArgumentException.class, + () -> consumer.offsetsForTimes(Collections.singletonMap(new TopicPartition( Review Comment: These constants are defined public in the [ListOffsetsRequest](https://github.com/apache/kafka/blob/4cf86c5d2f6355c5684ecedeb1bf96e90877244d/clients/src/main/java/org/apache/kafka/common/requests/ListOffsetsRequest.java#L41-L43). You're right that the validation is indeed for all negative values, but this test is what I expect could be the most common misuse of this API (a user trying to retrieve offsets using an "abstract" timestamp like EARLIEST or LATEST). This also was the initial motivation for the validation in the old consumer with [this](https://github.com/apache/kafka/blob/4cf86c5d2f6355c5684ecedeb1bf96e90877244d/clients/src/main/java/org/apache/kafka/clients/consumer/KafkaConsumer.java#L2115) comment, so aligning with it. Makes sense? -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org