lianetm commented on code in PR #17150:
URL: https://github.com/apache/kafka/pull/17150#discussion_r1831340053
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/events/ApplicationEventProcessorTest.java:
##########
@@ -360,6 +383,87 @@ public void
testUpdatePatternSubscriptionEventOnlyTakesEffectWhenMetadataHasNewV
assertDoesNotThrow(() -> event2.future().get());
}
+ @ParameterizedTest
+ @MethodSource("offsetsGenerator")
+ public void testSyncCommitEvent(Optional<Map<TopicPartition,
OffsetAndMetadata>> offsets) {
+ SyncCommitEvent event = new SyncCommitEvent(offsets, 12345);
+
+ setupProcessor(true);
+
doReturn(CompletableFuture.completedFuture(offsets.orElse(Map.of()))).when(commitRequestManager).commitSync(offsets,
12345);
+
+ processor.process(event);
+ verify(commitRequestManager).commitSync(offsets, 12345);
+ Map<TopicPartition, OffsetAndMetadata> committedOffsets =
assertDoesNotThrow(() -> event.future().get());
+ assertEquals(offsets.orElse(Map.of()), committedOffsets);
+ }
+
+ @Test
+ public void testSyncCommitEventWithoutCommitRequestManager() {
+ SyncCommitEvent event = new SyncCommitEvent(Optional.empty(), 12345);
+
+ setupProcessor(false);
+ processor.process(event);
+ assertThrows(ExecutionException.class, () -> event.future().get());
+ }
+
+ @Test
+ public void testSyncCommitEventWithException() {
+ SyncCommitEvent event = new SyncCommitEvent(Optional.empty(), 12345);
+
+ setupProcessor(true);
+ CompletableFuture<Map<TopicPartition, OffsetAndMetadata>> future = new
CompletableFuture<>();
+ future.completeExceptionally(new IllegalStateException());
+ doReturn(future).when(commitRequestManager).commitSync(any(),
anyLong());
+ processor.process(event);
+
+ verify(commitRequestManager).commitSync(Optional.empty(), 12345);
+ TestUtils.assertFutureThrows(event.future(),
IllegalStateException.class);
+ }
+
+ @ParameterizedTest
+ @MethodSource("offsetsGenerator")
+ public void testAsyncCommitEventWithOffsets(Optional<Map<TopicPartition,
OffsetAndMetadata>> offsets) {
+ AsyncCommitEvent event = new AsyncCommitEvent(offsets);
+
+ setupProcessor(true);
+
doReturn(CompletableFuture.completedFuture(offsets.orElse(Map.of()))).when(commitRequestManager).commitAsync(offsets);
+
+ processor.process(event);
+ verify(commitRequestManager).commitAsync(offsets);
+ Map<TopicPartition, OffsetAndMetadata> committedOffsets =
assertDoesNotThrow(() -> event.future().get());
+ assertEquals(offsets.orElse(Map.of()), committedOffsets);
+ }
+
+ @Test
+ public void testAsyncCommitEventWithoutCommitRequestManager() {
+ AsyncCommitEvent event = new AsyncCommitEvent(Optional.empty());
+
+ setupProcessor(false);
+ processor.process(event);
+ assertThrows(ExecutionException.class, () -> event.future().get());
Review Comment:
this should also assertFutureThrows(KafkaException) right? (and nit/taste, I
would import TestUtils.assertFutureThrows and simplify the code to have calls
to assertFutureThrows)
--
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]