From 40cbe9cf449f519f5aeecf1770b7e58b6014a5e6 Mon Sep 17 00:00:00 2001 From: Jeppe Cramon <96371136+cloudcreate-dk@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:13:59 +0100 Subject: [PATCH] - Updated from the deprecated `org.testcontainers.containers.KafkaContainer` to `org.testcontainers.kafka.KafkaContainer` - Switched to use the `apache/kafka-native` docker image as required by `org.testcontainers.kafka.KafkaContainer` - Added custom env as recommended in https://github.com/testcontainers/testcontainers-java/issues/9506 - Added `objenesis` dependency where needed to deserialize outbox messages - Adjusted test timeout parameters - Adjusted logging to be less verbose when running the application --- docker-compose.yml | 22 +------------------ mongodb-inbox-outbox/pom.xml | 10 ++++----- .../shipping/OrderShippingProcessorIT.java | 3 ++- .../postgresql/cqrs/banking/AccountsIT.java | 3 ++- .../banking/TransferMoneyProcessorIT.java | 3 ++- .../shipping/OrderShippingProcessorIT.java | 7 +++--- postgresql-inbox-outbox/pom.xml | 10 ++++----- .../src/main/resources/logback-spring.xml | 16 +++++++------- .../messaging/AbstractIntegrationTest.java | 3 ++- .../messaging/DurableQueuesLoadIT.java | 5 +++-- .../LoadOrderShippingProcessorIT.java | 2 +- 11 files changed, 34 insertions(+), 50 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1645a06..3110230 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,31 +24,11 @@ services: - "27017:27017" command: [--replSet, "rs0"] - # From https://developer.confluent.io/quickstart/kafka-docker/ - zookeeper: - image: confluentinc/cp-zookeeper:latest - container_name: zookeeper - environment: - ZOOKEEPER_CLIENT_PORT: 2181 - ZOOKEEPER_TICK_TIME: 2000 - broker: - image: confluentinc/cp-kafka:latest + image: apache/kafka-native:latest container_name: kafka_broker ports: - # To learn about configuring Kafka for access across networks see - # https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/ - "9092:9092" - depends_on: - - zookeeper - environment: - KAFKA_BROKER_ID: 1 - KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT - KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092 - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 - KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 # Tracing, Latency and Metric setup is inspired by https://spring.io/blog/2022/10/12/observability-with-spring-boot-3 / https://github.com/marcingrzejszczak/observability-boot-blog-post tempo: diff --git a/mongodb-inbox-outbox/pom.xml b/mongodb-inbox-outbox/pom.xml index 164eaf9..2172a43 100644 --- a/mongodb-inbox-outbox/pom.xml +++ b/mongodb-inbox-outbox/pom.xml @@ -38,11 +38,11 @@ spring-boot-starter-mongodb ${essentials.version} - - - - - + + org.objenesis + objenesis + ${objenesis.version} + org.springframework.boot spring-boot-starter-data-mongodb diff --git a/mongodb-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/mongodb/messaging/shipping/OrderShippingProcessorIT.java b/mongodb-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/mongodb/messaging/shipping/OrderShippingProcessorIT.java index b4ac1cf..abbd8d9 100644 --- a/mongodb-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/mongodb/messaging/shipping/OrderShippingProcessorIT.java +++ b/mongodb-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/mongodb/messaging/shipping/OrderShippingProcessorIT.java @@ -53,7 +53,8 @@ public class OrderShippingProcessorIT { static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:latest"); @Container - static KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + static org.testcontainers.kafka.KafkaContainer kafkaContainer = new org.testcontainers.kafka.KafkaContainer("apache/kafka-native:latest") + .withEnv("KAFKA_LISTENERS", "PLAINTEXT://:9092,BROKER://:9093,CONTROLLER://:9094"); private KafkaMessageListenerContainer kafkaListenerContainer; @DynamicPropertySource diff --git a/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/banking/AccountsIT.java b/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/banking/AccountsIT.java index 0d54aee..e66c0ef 100644 --- a/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/banking/AccountsIT.java +++ b/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/banking/AccountsIT.java @@ -50,7 +50,8 @@ public class AccountsIT { .withUsername("test"); @Container - static KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + static org.testcontainers.kafka.KafkaContainer kafkaContainer = new org.testcontainers.kafka.KafkaContainer("apache/kafka-native:latest") + .withEnv("KAFKA_LISTENERS", "PLAINTEXT://:9092,BROKER://:9093,CONTROLLER://:9094"); @DynamicPropertySource static void setProperties(DynamicPropertyRegistry registry) { diff --git a/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/banking/TransferMoneyProcessorIT.java b/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/banking/TransferMoneyProcessorIT.java index 34b3b4e..f13c1ef 100644 --- a/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/banking/TransferMoneyProcessorIT.java +++ b/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/banking/TransferMoneyProcessorIT.java @@ -53,7 +53,8 @@ public class TransferMoneyProcessorIT { .withUsername("test"); @Container - static KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + static org.testcontainers.kafka.KafkaContainer kafkaContainer = new org.testcontainers.kafka.KafkaContainer("apache/kafka-native:latest") + .withEnv("KAFKA_LISTENERS", "PLAINTEXT://:9092,BROKER://:9093,CONTROLLER://:9094"); @DynamicPropertySource static void setProperties(DynamicPropertyRegistry registry) { diff --git a/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/shipping/OrderShippingProcessorIT.java b/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/shipping/OrderShippingProcessorIT.java index f6e165a..0529266 100644 --- a/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/shipping/OrderShippingProcessorIT.java +++ b/postgresql-cqrs/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/cqrs/shipping/OrderShippingProcessorIT.java @@ -33,11 +33,9 @@ import org.springframework.kafka.listener.*; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.*; -import org.testcontainers.containers.*; -import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.*; import org.testcontainers.shaded.org.awaitility.Awaitility; -import org.testcontainers.utility.DockerImageName; import java.time.Duration; import java.util.*; @@ -57,7 +55,8 @@ public class OrderShippingProcessorIT { .withUsername("test"); @Container - static KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + static org.testcontainers.kafka.KafkaContainer kafkaContainer = new org.testcontainers.kafka.KafkaContainer("apache/kafka-native:latest") + .withEnv("KAFKA_LISTENERS", "PLAINTEXT://:9092,BROKER://:9093,CONTROLLER://:9094"); private KafkaMessageListenerContainer kafkaListenerContainer; @DynamicPropertySource diff --git a/postgresql-inbox-outbox/pom.xml b/postgresql-inbox-outbox/pom.xml index a657beb..6e6e77a 100644 --- a/postgresql-inbox-outbox/pom.xml +++ b/postgresql-inbox-outbox/pom.xml @@ -43,11 +43,11 @@ types-springdata-jpa ${essentials.version} - - - - - + + org.objenesis + objenesis + ${objenesis.version} + org.springframework.boot spring-boot-starter-data-jpa diff --git a/postgresql-inbox-outbox/src/main/resources/logback-spring.xml b/postgresql-inbox-outbox/src/main/resources/logback-spring.xml index c80d65e..941856a 100644 --- a/postgresql-inbox-outbox/src/main/resources/logback-spring.xml +++ b/postgresql-inbox-outbox/src/main/resources/logback-spring.xml @@ -37,15 +37,15 @@ - + - - - - - - - + + + + + + + diff --git a/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/AbstractIntegrationTest.java b/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/AbstractIntegrationTest.java index 5ba2e72..ab4424b 100644 --- a/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/AbstractIntegrationTest.java +++ b/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/AbstractIntegrationTest.java @@ -46,7 +46,8 @@ public class AbstractIntegrationTest { .withUsername("test"); @Container - static KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + static org.testcontainers.kafka.KafkaContainer kafkaContainer = new org.testcontainers.kafka.KafkaContainer("apache/kafka-native:latest") + .withEnv("KAFKA_LISTENERS", "PLAINTEXT://:9092,BROKER://:9093,CONTROLLER://:9094"); protected KafkaMessageListenerContainer kafkaListenerContainer; @DynamicPropertySource diff --git a/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/DurableQueuesLoadIT.java b/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/DurableQueuesLoadIT.java index bee3db5..b8bcb64 100644 --- a/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/DurableQueuesLoadIT.java +++ b/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/DurableQueuesLoadIT.java @@ -53,7 +53,8 @@ public class DurableQueuesLoadIT { .withPassword("test") .withUsername("test"); @Container - static KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + static org.testcontainers.kafka.KafkaContainer kafkaContainer = new org.testcontainers.kafka.KafkaContainer("apache/kafka-native:latest") + .withEnv("KAFKA_LISTENERS", "PLAINTEXT://:9092,BROKER://:9093,CONTROLLER://:9094"); @DynamicPropertySource @@ -116,7 +117,7 @@ void queue_a_large_number_of_messages() { assertThat(nextMessages).hasSize(10); - Awaitility.waitAtMost(Duration.ofSeconds(10)) + Awaitility.waitAtMost(Duration.ofSeconds(20)) .untilAsserted(() -> { System.out.println("-----> " + Instant.now() + " messages received: " + msgHandler.messagesReceived.get()); assertThat(msgHandler.messagesReceived.get()).isGreaterThan(10); diff --git a/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/shipping/LoadOrderShippingProcessorIT.java b/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/shipping/LoadOrderShippingProcessorIT.java index 2adb1bb..4f48483 100644 --- a/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/shipping/LoadOrderShippingProcessorIT.java +++ b/postgresql-inbox-outbox/src/test/java/dk/cloudcreate/essentials/spring/examples/postgresql/messaging/shipping/LoadOrderShippingProcessorIT.java @@ -58,7 +58,7 @@ public void stress_test_durable_queues_and_local_eventbus() { log.debug("########## TotalMessagesQueued for '{}': '{}'", queueName, totalMessagesQueuedFor); var stopWatch = StopWatch.start(); - Awaitility.waitAtMost(Duration.ofMinutes(60)) + Awaitility.waitAtMost(Duration.ofMinutes(3)) .pollDelay(Duration.ofSeconds(5)) .pollInterval(Duration.ofSeconds(10)) .until(() -> {