Skip to content

Commit 080c20b

Browse files
committed
Merge pull request #20917 from dhirenmathur
* pr/20917: Polish "Align Kafka's missingTopicsFatal default value" Align Kafka's missingTopicsFatal default value Closes gh-20917
2 parents 856543c + 3cdb5a6 commit 080c20b

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -876,7 +876,7 @@ public enum Type {
876876
* Whether the container should fail to start if at least one of the configured
877877
* topics are not present on the broker.
878878
*/
879-
private boolean missingTopicsFatal = true;
879+
private boolean missingTopicsFatal = false;
880880

881881
public Type getType() {
882882
return this.type;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.junit.jupiter.api.Test;
3939

4040
import org.springframework.boot.autoconfigure.AutoConfigurations;
41-
import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener;
4241
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
4342
import org.springframework.context.annotation.Bean;
4443
import org.springframework.context.annotation.Configuration;
@@ -364,7 +363,7 @@ void listenerProperties() {
364363
"spring.kafka.listener.no-poll-threshold=2.5", "spring.kafka.listener.type=batch",
365364
"spring.kafka.listener.idle-event-interval=1s", "spring.kafka.listener.monitor-interval=45",
366365
"spring.kafka.listener.log-container-config=true",
367-
"spring.kafka.listener.missing-topics-fatal=false", "spring.kafka.jaas.enabled=true",
366+
"spring.kafka.listener.missing-topics-fatal=true", "spring.kafka.jaas.enabled=true",
368367
"spring.kafka.producer.transaction-id-prefix=foo", "spring.kafka.jaas.login-module=foo",
369368
"spring.kafka.jaas.control-flag=REQUISITE", "spring.kafka.jaas.options.useKeyTab=true")
370369
.run((context) -> {
@@ -389,7 +388,7 @@ void listenerProperties() {
389388
assertThat(containerProperties.getIdleEventInterval()).isEqualTo(1000L);
390389
assertThat(containerProperties.getMonitorInterval()).isEqualTo(45);
391390
assertThat(containerProperties.isLogContainerConfig()).isTrue();
392-
assertThat(containerProperties.isMissingTopicsFatal()).isFalse();
391+
assertThat(containerProperties.isMissingTopicsFatal()).isTrue();
393392
assertThat(ReflectionTestUtils.getField(kafkaListenerContainerFactory, "concurrency")).isEqualTo(3);
394393
assertThat(kafkaListenerContainerFactory.isBatchListener()).isTrue();
395394
assertThat(context.getBeansOfType(KafkaJaasLoginModuleInitializer.class)).hasSize(1);
@@ -403,17 +402,6 @@ void listenerProperties() {
403402
});
404403
}
405404

406-
@Test
407-
void listenerPropertiesMatchDefaults() {
408-
this.contextRunner.run((context) -> {
409-
Listener listenerProperties = new KafkaProperties().getListener();
410-
AbstractKafkaListenerContainerFactory<?, ?, ?> kafkaListenerContainerFactory = (AbstractKafkaListenerContainerFactory<?, ?, ?>) context
411-
.getBean(KafkaListenerContainerFactory.class);
412-
ContainerProperties containerProperties = kafkaListenerContainerFactory.getContainerProperties();
413-
assertThat(containerProperties.isMissingTopicsFatal()).isEqualTo(listenerProperties.isMissingTopicsFatal());
414-
});
415-
}
416-
417405
@Test
418406
void testKafkaTemplateRecordMessageConverters() {
419407
this.contextRunner.withUserConfiguration(MessageConverterConfiguration.class)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.kafka;
18+
19+
import org.apache.kafka.clients.producer.KafkaProducer;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener;
23+
import org.springframework.kafka.listener.ContainerProperties;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* Tests for {@link KafkaProducer}.
29+
*
30+
* @author Stephane Nicoll
31+
*/
32+
class KafkaPropertiesTests {
33+
34+
@Test
35+
void listenerDefaultValuesAreConsistent() {
36+
ContainerProperties container = new ContainerProperties("test");
37+
Listener listenerProperties = new KafkaProperties().getListener();
38+
assertThat(listenerProperties.isMissingTopicsFatal()).isEqualTo(container.isMissingTopicsFatal());
39+
}
40+
41+
}

0 commit comments

Comments
 (0)