|
43 | 43 | import org.apache.kafka.common.metrics.Metrics;
|
44 | 44 | import org.apache.kafka.common.protocol.Errors;
|
45 | 45 | import org.apache.kafka.common.serialization.StringDeserializer;
|
| 46 | +import org.apache.kafka.common.utils.LogCaptureAppender; |
46 | 47 | import org.apache.kafka.common.utils.LogContext;
|
47 | 48 | import org.apache.kafka.common.utils.MockTime;
|
48 | 49 | import org.apache.kafka.common.utils.Time;
|
|
77 | 78 | import static java.util.Collections.singletonList;
|
78 | 79 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
79 | 80 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 81 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
80 | 82 | import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
81 | 83 | import static org.junit.jupiter.api.Assertions.assertNull;
|
82 | 84 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
@@ -207,11 +209,19 @@ public void testFailConstructor() {
|
207 | 209 | props.put(ConsumerConfig.GROUP_ID_CONFIG, "group-id");
|
208 | 210 | props.put(ConsumerConfig.METRIC_REPORTER_CLASSES_CONFIG, "an.invalid.class");
|
209 | 211 | final ConsumerConfig config = new ConsumerConfig(props);
|
| 212 | + |
| 213 | + LogCaptureAppender appender = LogCaptureAppender.createAndRegister(); |
210 | 214 | KafkaException ce = assertThrows(
|
211 | 215 | KafkaException.class,
|
212 | 216 | () -> newConsumer(config));
|
213 | 217 | assertTrue(ce.getMessage().contains("Failed to construct Kafka share consumer"), "Unexpected exception message: " + ce.getMessage());
|
214 | 218 | assertTrue(ce.getCause().getMessage().contains("Class an.invalid.class cannot be found"), "Unexpected cause: " + ce.getCause());
|
| 219 | + |
| 220 | + boolean npeLogged = appender.getEvents().stream() |
| 221 | + .flatMap(event -> event.getThrowableInfo().stream()) |
| 222 | + .anyMatch(str -> str.contains("NullPointerException")); |
| 223 | + |
| 224 | + assertFalse(npeLogged, "Unexpected NullPointerException during consumer construction"); |
215 | 225 | }
|
216 | 226 |
|
217 | 227 | @Test
|
|
0 commit comments