philipnee commented on code in PR #16043: URL: https://github.com/apache/kafka/pull/16043#discussion_r1630912266
########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java: ########## @@ -360,6 +370,52 @@ void testSendUnsentRequest() { assertFalse(networkClient.hasAnyPendingRequests()); } + @Test + void testInvalidTopicMetadataErrorEvent() { + String invalidTopicName = "topic abc"; // Invalid topic name due to space + + when(testBuilder.subscriptions.matchesSubscribedPattern(invalidTopicName)) + .thenReturn(true); + + Cluster cluster = metadata.fetch(); + List<MetadataResponse.TopicMetadata> topicMetadata = new ArrayList<>(); + topicMetadata.add(new MetadataResponse.TopicMetadata(Errors.INVALID_TOPIC_EXCEPTION, + invalidTopicName, false, Collections.emptyList())); + MetadataResponse updateResponse = RequestTestUtils.metadataResponse(cluster.nodes(), + cluster.clusterResource().clusterId(), + cluster.controller().id(), + topicMetadata); + + client.prepareMetadataUpdate(updateResponse); + metadata.requestUpdateForNewTopics(); + consumerNetworkThread.runOnce(); + + BackgroundEvent event = backgroundEventsQueue.poll(); + assertNotNull(event); + assertEquals(BackgroundEvent.Type.ERROR, event.type()); + assertEquals(InvalidTopicException.class, ((ErrorEvent) event).error().getClass()); + assertEquals(String.format("Invalid topics: [%s]", invalidTopicName), + ((ErrorEvent) event).error().getMessage()); + } + + @Test + void testMetadataErrorEvent() { + metadata.fatalError(new AuthenticationException("Authentication failed")); + + consumerNetworkThread.runOnce(); + BackgroundEvent event = backgroundEventsQueue.poll(); + assertNotNull(event); + assertEquals(BackgroundEvent.Type.ERROR, event.type()); + assertEquals(AuthenticationException.class, ((ErrorEvent) event).error().getClass()); + assertEquals("Authentication failed", ((ErrorEvent) event).error().getMessage()); + } + + @Test + void testNoMetadataErrorEvent() { Review Comment: same, you don't need to test this in the consumer network thread -- 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