Skip to content

Commit

Permalink
feat : using apachekafka container for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Jul 19, 2024
1 parent 13f240e commit 87012a5
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion kafka-spring-cloud-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<version>3.4.0-M1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.kafka.KafkaContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
Expand All @@ -15,9 +15,7 @@ class TestCloudKafkaSampleApplication {
@Bean
@ServiceConnection
KafkaContainer kafkaContainer(DynamicPropertyRegistry dynamicPropertyRegistry) {
KafkaContainer kafkaContainer = new KafkaContainer(
DockerImageName.parse("confluentinc/cp-kafka").withTag("7.6.2"))
.withKraft()
KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("apache/kafka").withTag("3.7.1"))
.withReuse(true);
dynamicPropertyRegistry.add("spring.cloud.stream.kafka.binder.brokers", kafkaContainer::getBootstrapServers);
return kafkaContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<version>3.4.0-M1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.kafka.KafkaContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class TestAnalyticsConsumerApplication {

private static final DockerImageName KAFKA_IMAGE_NAME =
DockerImageName.parse("confluentinc/cp-kafka").withTag("7.6.2");
DockerImageName.parse("apache/kafka").withTag("3.7.1");

@Bean
@ServiceConnection
KafkaContainer kafkaContainer(DynamicPropertyRegistry registry) {
KafkaContainer kafkaContainer = new KafkaContainer(KAFKA_IMAGE_NAME).withKraft();
KafkaContainer kafkaContainer = new KafkaContainer(KAFKA_IMAGE_NAME);
registry.add("spring.kafka.bootstrap-servers", kafkaContainer::getBootstrapServers);
return kafkaContainer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<version>3.4.0-M1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.kafka.KafkaContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
Expand All @@ -16,8 +16,7 @@ class TestAnalyticsProducerApplication {
@ServiceConnection
KafkaContainer kafkaContainer(DynamicPropertyRegistry propertyRegistry) {
KafkaContainer kafkaContainer =
new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("7.6.2"))
.withKraft();
new KafkaContainer(DockerImageName.parse("apache/kafka").withTag("3.7.1"));
propertyRegistry.add("spring.kafka.bootstrapServers", kafkaContainer::getBootstrapServers);
return kafkaContainer;
}
Expand Down
2 changes: 1 addition & 1 deletion spring-modulith-outbox-pattern/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<version>3.4.0-M1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.outboxpattern</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.kafka.KafkaContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
Expand All @@ -21,9 +21,8 @@ PostgreSQLContainer<?> postgreSQLContainer() {
@Bean
@ServiceConnection
KafkaContainer kafkaContainer(DynamicPropertyRegistry dynamicPropertyRegistry) {
KafkaContainer kafkaContainer = new KafkaContainer(
DockerImageName.parse("confluentinc/cp-kafka").withTag("7.6.2"))
.withKraft();
KafkaContainer kafkaContainer =
new KafkaContainer(DockerImageName.parse("apache/kafka").withTag("3.7.1"));
// Connect our Spring application to our Testcontainers Kafka instance
dynamicPropertyRegistry.add("spring.kafka.consumer.bootstrap-servers", kafkaContainer::getBootstrapServers);
dynamicPropertyRegistry.add("spring.kafka.producer.bootstrap-servers", kafkaContainer::getBootstrapServers);
Expand Down

0 comments on commit 87012a5

Please sign in to comment.