GH-2943: EmbeddedKafka usage improvements in Kafka binder
* Currently, EmbeddedKafka is initialized as part of the class initialization in a few tests in the Kafka binder. This is preventing individual JUnit tests from being executed from an IDE (IntelliJ, for example). If we move this initialization to the JUnit method, then that seems to be working. Resolves https://github.com/spring-cloud/spring-cloud-stream/issues/2943
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2023 the original author or authors.
|
||||
* Copyright 2018-2024 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.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.stream.binder.kafka;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.kafka.common.errors.UnknownTopicOrPartitionException;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
|
||||
@@ -44,7 +45,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@EmbeddedKafka(brokerProperties = {"auto.create.topics.enable=false"})
|
||||
class AutoCreateTopicDisabledTests {
|
||||
|
||||
private static final EmbeddedKafkaBroker embeddedKafka = EmbeddedKafkaCondition.getBroker();
|
||||
private static EmbeddedKafkaBroker embeddedKafka;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
embeddedKafka = EmbeddedKafkaCondition.getBroker();
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoCreateTopicDisabledFailsOnConsumerIfTopicNonExistentOnBroker() {
|
||||
|
||||
@@ -45,8 +45,6 @@ class KafkaBinderJaasInitializerListenerTest {
|
||||
|
||||
private static final String KAFKA_BROKERS_PROPERTY = "spring.cloud.stream.kafka.binder.brokers";
|
||||
|
||||
private static final EmbeddedKafkaBroker embeddedKafka = EmbeddedKafkaCondition.getBroker();
|
||||
|
||||
private static String JAVA_LOGIN_CONFIG_PARAM_VALUE;
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
@@ -54,6 +52,7 @@ class KafkaBinderJaasInitializerListenerTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
EmbeddedKafkaBroker embeddedKafka = EmbeddedKafkaCondition.getBroker();
|
||||
System.setProperty(KAFKA_BROKERS_PROPERTY,
|
||||
embeddedKafka.getBrokersAsString());
|
||||
//Retrieve the current value for this system property if there is one set.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
* Copyright 2017-2024 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.stream.binder.kafka.bootstrap;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
@@ -32,11 +33,17 @@ import org.springframework.kafka.test.context.EmbeddedKafka;
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
* @author Chris Bono
|
||||
* @author Soby Chacko
|
||||
*/
|
||||
@EmbeddedKafka(controlledShutdown = true)
|
||||
class KafkaBinderBootstrapTest {
|
||||
|
||||
private static final EmbeddedKafkaBroker embeddedKafka = EmbeddedKafkaCondition.getBroker();
|
||||
private static EmbeddedKafkaBroker embeddedKafka;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
embeddedKafka = EmbeddedKafkaCondition.getBroker();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = { false, true })
|
||||
|
||||
@@ -72,7 +72,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
"spring.cloud.stream.pollable-source=input"}
|
||||
)
|
||||
@DirtiesContext
|
||||
@EmbeddedKafka(bootstrapServersProperty = "spring.kafka.bootstrap-servers")
|
||||
@EmbeddedKafka
|
||||
class KafkaBinderActuatorTests {
|
||||
|
||||
static final String TEST_CONSUMER_GROUP = "testGroup-actuatorTests";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2023 the original author or authors.
|
||||
* Copyright 2018-2024 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.
|
||||
@@ -69,7 +69,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
"spring.cloud.stream.kafka.default.consumer.ackEachRecord=true",
|
||||
"spring.cloud.stream.kafka.bindings.custom-in.consumer.ackEachRecord=false" })
|
||||
@DirtiesContext
|
||||
@EmbeddedKafka(bootstrapServersProperty = "spring.kafka.bootstrap-servers")
|
||||
@EmbeddedKafka
|
||||
class KafkaBinderExtendedPropertiesTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
* Copyright 2023-2024 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.
|
||||
@@ -42,8 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
"spring.cloud.stream.bindings.kafka-binding-service-test.producer.partition-count=2",
|
||||
"spring.cloud.stream.bindings.kafka-binding-service-test.producer.partition-key-expression=headers['partitionKey']"})
|
||||
@DirtiesContext
|
||||
@EmbeddedKafka(topics = "kafka-binding-service-test", controlledShutdown = true, partitions = 4,
|
||||
bootstrapServersProperty = "spring.kafka.bootstrap-servers")
|
||||
@EmbeddedKafka(topics = "kafka-binding-service-test", controlledShutdown = true, partitions = 4)
|
||||
class KafkaBindingServiceTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2023 the original author or authors.
|
||||
* Copyright 2016-2024 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.
|
||||
@@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
"spring.kafka.consumer.auto-offset-reset=earliest",
|
||||
"spring.cloud.stream.function.bindings.inputListen-in-0=kafkaNullInput"})
|
||||
@DirtiesContext
|
||||
@EmbeddedKafka(bootstrapServersProperty = "spring.kafka.bootstrap-servers")
|
||||
@EmbeddedKafka
|
||||
class KafkaNullConverterTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2023 the original author or authors.
|
||||
* Copyright 2021-2024 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.
|
||||
@@ -59,7 +59,7 @@ import static org.mockito.Mockito.mock;
|
||||
"spring.cloud.stream.bindings.retryInContainer-in-0.group=bar",
|
||||
"spring.cloud.stream.kafka.bindings.retryInBinder-in-0.consumer.enable-dlq=true",
|
||||
"spring.cloud.stream.kafka.bindings.retryInContainer-in-0.consumer.enable-dlq=true"})
|
||||
@EmbeddedKafka(bootstrapServersProperty = "spring.kafka.bootstrap-servers")
|
||||
@EmbeddedKafka
|
||||
@DirtiesContext
|
||||
class KafkaRetryDlqBinderOrContainerTests {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2023 the original author or authors.
|
||||
* Copyright 2019-2024 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.
|
||||
@@ -64,7 +64,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
"spring.cloud.stream.kafka.binder.transaction.producer.configuration.acks=all"})
|
||||
@DirtiesContext
|
||||
@EmbeddedKafka(topics = "output", controlledShutdown = true, brokerProperties = {"transaction.state.log.replication.factor=1",
|
||||
"transaction.state.log.min.isr=1"}, bootstrapServersProperty = "spring.kafka.bootstrap-servers")
|
||||
"transaction.state.log.min.isr=1"})
|
||||
class ProducerOnlyTransactionTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2023 the original author or authors.
|
||||
* Copyright 2019-2024 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.
|
||||
@@ -51,6 +51,7 @@ import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Soby Chacko
|
||||
* @since 3.0
|
||||
*
|
||||
*/
|
||||
@@ -74,7 +75,7 @@ import static org.mockito.Mockito.mock;
|
||||
"spring.cloud.stream.kafka.binder.transaction.producer.configuration.acks=all"})
|
||||
@DirtiesContext
|
||||
@EmbeddedKafka(topics = "consumer.producer.txOut", controlledShutdown = true, brokerProperties = {"transaction.state.log.replication.factor=1",
|
||||
"transaction.state.log.min.isr=1"}, bootstrapServersProperty = "spring.kafka.bootstrap-servers")
|
||||
"transaction.state.log.min.isr=1"})
|
||||
class ConsumerProducerTransactionTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user