You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "chia7712 (via GitHub)" <gi...@apache.org> on 2026/08/01 03:06:48 UTC
Re: [PR] KAFKA-14648: Do not fail clients if bootstrap servers is not immediately resolvable [kafka]
chia7712 commented on code in PR #21080:
URL: https://github.com/apache/kafka/pull/21080#discussion_r3694456769
##########
clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java:
##########
@@ -3398,4 +3406,59 @@ public static void resetCounters() {
CLOSE_COUNT.set(0);
}
}
+
+ @Test
+ public void testProducerBootstrapResolutionExceptionPropagated() {
+ String invalidHost = "unresolvable.invalid:9092";
+ Map<String, Object> configs = Map.of(
+ ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName(),
+ ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName(),
+ CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, invalidHost,
+ CommonClientConfigs.BOOTSTRAP_RESOLVE_TIMEOUT_MS_CONFIG, "3000"
+ );
+
+ try (KafkaProducer<String, String> producer = new KafkaProducer<>(configs)) {
+ assertThrows(BootstrapResolutionException.class, () -> {
+ long startTime = System.currentTimeMillis();
+ long maxWaitTime = 15000;
+ while (System.currentTimeMillis() - startTime < maxWaitTime) {
+ producer.partitionsFor("test-topic");
+ }
+ fail("Expected BootstrapResolutionException to be thrown within " + maxWaitTime + "ms");
+ });
+
+ // After the first failure, any further API call must also throw. This guards against
+ // accidentally clearing the bootstrap error from the metadata layer.
+ assertThrows(BootstrapResolutionException.class, () -> producer.partitionsFor("test-topic"));
+ }
+ }
+
+ @Test
+ public void testProducerSendOffsetsToTransactionBootstrapResolutionExceptionPropagated() {
+ // sendOffsetsToTransaction became metadata-aware in KIP-1319, so it can also block on
+ // bootstrap and must surface BootstrapResolutionException.
+ String invalidHost = "unresolvable.invalid:9092";
+ Map<String, Object> configs = Map.of(
+ ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName(),
+ ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName(),
+ CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, invalidHost,
+ CommonClientConfigs.BOOTSTRAP_RESOLVE_TIMEOUT_MS_CONFIG, "3000",
+ ProducerConfig.TRANSACTIONAL_ID_CONFIG, "test-tx-id"
+ );
+
+ Map<TopicPartition, OffsetAndMetadata> offsets = Map.of(
+ new TopicPartition("test-topic", 0),
+ new OffsetAndMetadata(0L)
+ );
+ ConsumerGroupMetadata groupMetadata = new ConsumerGroupMetadata("test-group");
Review Comment:
We should use mock instead of constructing `ConsumerGroupMetadata`.
```java
ConsumerGroupMetadata groupMetadata = mock(ConsumerGroupMetadata.class);
when(groupMetadata.groupId()).thenReturn("test-group");
```
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org