lianetm commented on code in PR #17150:
URL: https://github.com/apache/kafka/pull/17150#discussion_r1831284182
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/events/ApplicationEventProcessorTest.java:
##########
@@ -360,6 +382,89 @@ 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);
+ ExecutionException e = assertThrows(ExecutionException.class, () ->
event.future().get());
+ assertInstanceOf(IllegalStateException.class, e.getCause());
Review Comment:
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]