From a12eace2a8b629646356ea74eaa7c7db4f6289f1 Mon Sep 17 00:00:00 2001 From: dhimathu Date: Sat, 11 Apr 2020 12:11:32 +0530 Subject: [PATCH 1/3] Align Kafka's missingTopicsFatal default value See gh-20917 --- .../autoconfigure/kafka/KafkaProperties.java | 3 ++- .../kafka/KafkaAutoConfigurationTests.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java index 7f9b95c6d4..16da7dbd8a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java @@ -53,6 +53,7 @@ import org.springframework.util.unit.DataSize; * @author Stephane Nicoll * @author Artem Bilan * @author Nakul Mishra + * @author Dhiren Mathur * @since 1.5.0 */ @ConfigurationProperties(prefix = "spring.kafka") @@ -876,7 +877,7 @@ public class KafkaProperties { * Whether the container should fail to start if at least one of the configured * topics are not present on the broker. */ - private boolean missingTopicsFatal = true; + private boolean missingTopicsFatal = false; public Type getType() { return this.type; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java index 4081cdce5b..854db1dfda 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java @@ -86,6 +86,7 @@ import static org.mockito.Mockito.verify; * @author Stephane Nicoll * @author Eddú Meléndez * @author Nakul Mishra + * @author Dhiren Mathur */ class KafkaAutoConfigurationTests { @@ -364,7 +365,7 @@ class KafkaAutoConfigurationTests { "spring.kafka.listener.no-poll-threshold=2.5", "spring.kafka.listener.type=batch", "spring.kafka.listener.idle-event-interval=1s", "spring.kafka.listener.monitor-interval=45", "spring.kafka.listener.log-container-config=true", - "spring.kafka.listener.missing-topics-fatal=false", "spring.kafka.jaas.enabled=true", + "spring.kafka.listener.missing-topics-fatal=true", "spring.kafka.jaas.enabled=true", "spring.kafka.producer.transaction-id-prefix=foo", "spring.kafka.jaas.login-module=foo", "spring.kafka.jaas.control-flag=REQUISITE", "spring.kafka.jaas.options.useKeyTab=true") .run((context) -> { @@ -389,7 +390,7 @@ class KafkaAutoConfigurationTests { assertThat(containerProperties.getIdleEventInterval()).isEqualTo(1000L); assertThat(containerProperties.getMonitorInterval()).isEqualTo(45); assertThat(containerProperties.isLogContainerConfig()).isTrue(); - assertThat(containerProperties.isMissingTopicsFatal()).isFalse(); + assertThat(containerProperties.isMissingTopicsFatal()).isTrue(); assertThat(ReflectionTestUtils.getField(kafkaListenerContainerFactory, "concurrency")).isEqualTo(3); assertThat(kafkaListenerContainerFactory.isBatchListener()).isTrue(); assertThat(context.getBeansOfType(KafkaJaasLoginModuleInitializer.class)).hasSize(1); @@ -580,6 +581,17 @@ class KafkaAutoConfigurationTests { }); } + @Test + void testConcurrentKafkaListenerContainerFactoryMatchesDefaults() { + Listener listenerProperties = new KafkaProperties().getListener(); + this.contextRunner.withUserConfiguration(ConsumerFactoryConfiguration.class).run((context) -> { + ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory = context + .getBean(ConcurrentKafkaListenerContainerFactory.class); + assertThat(kafkaListenerContainerFactory.getContainerProperties().isMissingTopicsFatal()) + .isEqualTo(listenerProperties.isMissingTopicsFatal()); + }); + } + @Configuration(proxyBeanMethods = false) static class MessageConverterConfiguration { From 3cdb5a690a00b3b5de404597a647844b59913f87 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sat, 11 Apr 2020 10:19:32 +0200 Subject: [PATCH 2/3] Polish "Align Kafka's missingTopicsFatal default value" See gh-20917 --- .../autoconfigure/kafka/KafkaProperties.java | 3 +- .../kafka/KafkaAutoConfigurationTests.java | 24 ----------- .../kafka/KafkaPropertiesTests.java | 41 +++++++++++++++++++ 3 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java index 16da7dbd8a..cbcf08706e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,6 @@ import org.springframework.util.unit.DataSize; * @author Stephane Nicoll * @author Artem Bilan * @author Nakul Mishra - * @author Dhiren Mathur * @since 1.5.0 */ @ConfigurationProperties(prefix = "spring.kafka") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java index 854db1dfda..e8845ca35f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java @@ -38,7 +38,6 @@ import org.apache.kafka.streams.StreamsConfig; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -86,7 +85,6 @@ import static org.mockito.Mockito.verify; * @author Stephane Nicoll * @author Eddú Meléndez * @author Nakul Mishra - * @author Dhiren Mathur */ class KafkaAutoConfigurationTests { @@ -404,17 +402,6 @@ class KafkaAutoConfigurationTests { }); } - @Test - void listenerPropertiesMatchDefaults() { - this.contextRunner.run((context) -> { - Listener listenerProperties = new KafkaProperties().getListener(); - AbstractKafkaListenerContainerFactory kafkaListenerContainerFactory = (AbstractKafkaListenerContainerFactory) context - .getBean(KafkaListenerContainerFactory.class); - ContainerProperties containerProperties = kafkaListenerContainerFactory.getContainerProperties(); - assertThat(containerProperties.isMissingTopicsFatal()).isEqualTo(listenerProperties.isMissingTopicsFatal()); - }); - } - @Test void testKafkaTemplateRecordMessageConverters() { this.contextRunner.withUserConfiguration(MessageConverterConfiguration.class) @@ -581,17 +568,6 @@ class KafkaAutoConfigurationTests { }); } - @Test - void testConcurrentKafkaListenerContainerFactoryMatchesDefaults() { - Listener listenerProperties = new KafkaProperties().getListener(); - this.contextRunner.withUserConfiguration(ConsumerFactoryConfiguration.class).run((context) -> { - ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory = context - .getBean(ConcurrentKafkaListenerContainerFactory.class); - assertThat(kafkaListenerContainerFactory.getContainerProperties().isMissingTopicsFatal()) - .isEqualTo(listenerProperties.isMissingTopicsFatal()); - }); - } - @Configuration(proxyBeanMethods = false) static class MessageConverterConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java new file mode 100644 index 0000000000..5305d9236b --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.kafka; + +import org.apache.kafka.clients.producer.KafkaProducer; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener; +import org.springframework.kafka.listener.ContainerProperties; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link KafkaProducer}. + * + * @author Stephane Nicoll + */ +class KafkaPropertiesTests { + + @Test + void listenerDefaultValuesAreConsistent() { + ContainerProperties container = new ContainerProperties("test"); + Listener listenerProperties = new KafkaProperties().getListener(); + assertThat(listenerProperties.isMissingTopicsFatal()).isEqualTo(container.isMissingTopicsFatal()); + } + +} From 60f726a08097f09a110e7c575f7b739d9f3a6450 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sat, 11 Apr 2020 10:27:05 +0200 Subject: [PATCH 3/3] Polish --- .../boot/autoconfigure/kafka/KafkaPropertiesTests.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java index 5305d9236b..b106ff28e1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.kafka; -import org.apache.kafka.clients.producer.KafkaProducer; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener; @@ -25,7 +24,7 @@ import org.springframework.kafka.listener.ContainerProperties; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link KafkaProducer}. + * Tests for {@link KafkaProperties}. * * @author Stephane Nicoll */