Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,9 @@ private void close(final Duration timeout, final boolean swallowException) {
}

private void stopFindCoordinatorOnClose() {
if (applicationEventHandler == null) {
return;
}
log.debug("Stop finding coordinator during consumer close");
applicationEventHandler.add(new StopFindCoordinatorOnCloseEvent());
}
Expand All @@ -944,6 +947,10 @@ private Timer createTimerForCloseRequests(Duration timeout) {
* 2. leave the group
*/
private void sendAcknowledgementsAndLeaveGroup(final Timer timer, final AtomicReference<Throwable> firstException) {
Comment thread
ShivsundarR marked this conversation as resolved.
if (applicationEventHandler == null || backgroundEventProcessor == null ||
backgroundEventReaper == null || backgroundEventQueue == null) {
return;
}
completeQuietly(
() -> applicationEventHandler.addAndGet(new ShareAcknowledgeOnCloseEvent(acknowledgementsToSend(), calculateDeadlineMs(timer))),
"Failed to send pending acknowledgements with a timeout(ms)=" + timer.timeoutMs(), firstException);
Expand Down Expand Up @@ -1035,6 +1042,9 @@ private void maybeThrowInvalidGroupIdException() {
* If the acknowledgement commit callback throws an exception, this method will throw an exception.
*/
private void handleCompletedAcknowledgements(boolean onClose) {
if (backgroundEventQueue == null || backgroundEventReaper == null || backgroundEventProcessor == null) {
return;
}
// If the user gets any fatal errors, they will get these exceptions in the background queue.
// While closing, we ignore these exceptions so that the consumers close successfully.
processBackgroundEvents(onClose ? e -> (e instanceof GroupAuthorizationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.kafka.common.metrics.Metrics;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.utils.LogCaptureAppender;
import org.apache.kafka.common.utils.LogContext;
import org.apache.kafka.common.utils.MockTime;
import org.apache.kafka.common.utils.Time;
Expand Down Expand Up @@ -77,6 +78,7 @@
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -207,11 +209,19 @@ public void testFailConstructor() {
props.put(ConsumerConfig.GROUP_ID_CONFIG, "group-id");
props.put(ConsumerConfig.METRIC_REPORTER_CLASSES_CONFIG, "an.invalid.class");
final ConsumerConfig config = new ConsumerConfig(props);

LogCaptureAppender appender = LogCaptureAppender.createAndRegister();
KafkaException ce = assertThrows(
KafkaException.class,
() -> newConsumer(config));
assertTrue(ce.getMessage().contains("Failed to construct Kafka share consumer"), "Unexpected exception message: " + ce.getMessage());
assertTrue(ce.getCause().getMessage().contains("Class an.invalid.class cannot be found"), "Unexpected cause: " + ce.getCause());

boolean npeLogged = appender.getEvents().stream()
.flatMap(event -> event.getThrowableInfo().stream())
.anyMatch(str -> str.contains("NullPointerException"));

assertFalse(npeLogged, "Unexpected NullPointerException during consumer construction");
}

@Test
Expand Down