From 4576ae7cea6a8c50c6b6b0d11792bad87f9a7cfd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Nov 2025 04:04:06 +0000 Subject: [PATCH 1/6] Bump testContainerVersion from 0.43.6 to 0.44.0 Bumps `testContainerVersion` from 0.43.6 to 0.44.0. Updates `com.dimafeng:testcontainers-scala-scalatest_3` from 0.43.6 to 0.44.0 - [Release notes](https://github.com/testcontainers/testcontainers-scala/releases) - [Changelog](https://github.com/testcontainers/testcontainers-scala/blob/master/release-notes.md) - [Commits](https://github.com/testcontainers/testcontainers-scala/compare/v0.43.6...v0.44.0) Updates `com.dimafeng:testcontainers-scala-postgresql_3` from 0.43.6 to 0.44.0 - [Release notes](https://github.com/testcontainers/testcontainers-scala/releases) - [Changelog](https://github.com/testcontainers/testcontainers-scala/blob/master/release-notes.md) - [Commits](https://github.com/testcontainers/testcontainers-scala/compare/v0.43.6...v0.44.0) Updates `com.dimafeng:testcontainers-scala-kafka_3` from 0.43.6 to 0.44.0 - [Release notes](https://github.com/testcontainers/testcontainers-scala/releases) - [Changelog](https://github.com/testcontainers/testcontainers-scala/blob/master/release-notes.md) - [Commits](https://github.com/testcontainers/testcontainers-scala/compare/v0.43.6...v0.44.0) --- updated-dependencies: - dependency-name: com.dimafeng:testcontainers-scala-scalatest_3 dependency-version: 0.44.0 dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: com.dimafeng:testcontainers-scala-postgresql_3 dependency-version: 0.44.0 dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: com.dimafeng:testcontainers-scala-kafka_3 dependency-version: 0.44.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index bbeaf2b893..c1398b1617 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ ext { scapegoatVersion = '3.2.2' junitVersion = '6.0.1' - testContainerVersion = '0.43.6' + testContainerVersion = '0.44.0' scriptsLocation = 'gradle' + File.separator + 'scripts' + File.separator // location of script plugins From 98072bd48dd0565b3db961b0c4814d6dd6975137 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Wed, 3 Dec 2025 23:39:26 +0100 Subject: [PATCH 2/6] fix KafkaSpecLike --- src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala index 4267fa9e29..a218c74738 100644 --- a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala +++ b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala @@ -24,7 +24,9 @@ trait KafkaSpecLike extends BeforeAndAfterAll { protected val testTopics: Seq[Topic] protected val kafka: KafkaContainer = KafkaContainer( - DockerImageName.parse("confluentinc/cp-kafka:7.3.1") + DockerImageName + .parse("confluentinc/cp-kafka:7.3.1") + .asCompatibleSubstituteFor("apache/kafka") ) protected lazy val admin: Admin = Admin.create( Map[String, AnyRef]("bootstrap.servers" -> kafka.bootstrapServers).asJava From 25840dbd42b9a404eb54adf9d48c3eaf60a0f434 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Thu, 4 Dec 2025 00:48:28 +0100 Subject: [PATCH 3/6] fix KafkaSpecLike --- .../edu/ie3/simona/test/KafkaSpecLike.scala | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala index a218c74738..01be35621e 100644 --- a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala +++ b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala @@ -1,5 +1,5 @@ /* - * © 2021. TU Dortmund University, + * © 2025. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation */ @@ -15,43 +15,36 @@ import org.testcontainers.utility.DockerImageName import java.util.concurrent.TimeUnit import scala.jdk.CollectionConverters.* -/** Adapted from - * https://kafka-tutorials.confluent.io/produce-consume-lang/scala.html - */ -trait KafkaSpecLike extends BeforeAndAfterAll { - this: TestSuite => +trait KafkaSpecLike extends BeforeAndAfterAll { this: TestSuite => protected val testTopics: Seq[Topic] - protected val kafka: KafkaContainer = KafkaContainer( - DockerImageName - .parse("confluentinc/cp-kafka:7.3.1") - .asCompatibleSubstituteFor("apache/kafka") - ) - protected lazy val admin: Admin = Admin.create( - Map[String, AnyRef]("bootstrap.servers" -> kafka.bootstrapServers).asJava - ) + private var kafka: KafkaContainer = _ + private var admin: Admin = _ override def beforeAll(): Unit = { super.beforeAll() + + // create and start container here – not during trait init + kafka = KafkaContainer(DockerImageName.parse("apache/kafka:3.7.0")) kafka.start() - val result = admin.createTopics( - testTopics.map { topic => - new NewTopic( - topic.name, - topic.partitions, - topic.replicationFactor, - ) - }.asJava + + // now ports exist; safe to build Admin client + admin = Admin.create( + Map[String, AnyRef]("bootstrap.servers" -> kafka.bootstrapServers).asJava ) - // wait for result, throw exception if applicable + val result = admin.createTopics( + testTopics + .map(t => new NewTopic(t.name, t.partitions, t.replicationFactor)) + .asJava + ) result.all().get(1, TimeUnit.MINUTES) } override def afterAll(): Unit = { - admin.close() - kafka.stop() + if admin != null then admin.close() + if kafka != null then kafka.stop() super.afterAll() } } From 319c4b4a4f5d01bdd6ae6998dd180b5f3ec50ff0 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Thu, 4 Dec 2025 00:54:15 +0100 Subject: [PATCH 4/6] remove vars --- .../edu/ie3/simona/test/KafkaSpecLike.scala | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala index 01be35621e..d565893940 100644 --- a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala +++ b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala @@ -14,37 +14,44 @@ import org.testcontainers.utility.DockerImageName import java.util.concurrent.TimeUnit import scala.jdk.CollectionConverters.* +import scala.util.{Failure, Success, Try} trait KafkaSpecLike extends BeforeAndAfterAll { this: TestSuite => protected val testTopics: Seq[Topic] - private var kafka: KafkaContainer = _ - private var admin: Admin = _ + protected lazy val kafka: KafkaContainer = + KafkaContainer(DockerImageName.parse("apache/kafka:3.7.0")) + + protected lazy val admin: Try[Admin] = + if kafka.container.isRunning then + Success( + Admin.create(Map("bootstrap.servers" -> kafka.bootstrapServers).asJava) + ) + else + Failure( + new IllegalStateException( + "Kafka container must be started before creating Admin client" + ) + ) override def beforeAll(): Unit = { super.beforeAll() - - // create and start container here – not during trait init - kafka = KafkaContainer(DockerImageName.parse("apache/kafka:3.7.0")) kafka.start() - // now ports exist; safe to build Admin client - admin = Admin.create( - Map[String, AnyRef]("bootstrap.servers" -> kafka.bootstrapServers).asJava - ) - - val result = admin.createTopics( - testTopics - .map(t => new NewTopic(t.name, t.partitions, t.replicationFactor)) - .asJava + val result = admin.map( + _.createTopics( + testTopics + .map(t => new NewTopic(t.name, t.partitions, t.replicationFactor)) + .asJava + ) ) - result.all().get(1, TimeUnit.MINUTES) + result.map(_.all().get(15, TimeUnit.SECONDS)) } override def afterAll(): Unit = { - if admin != null then admin.close() - if kafka != null then kafka.stop() + if admin != null then admin.map(_.close()) + kafka.stop() super.afterAll() } } From 1feed4aea93f254ace2ad3154a6a552854263d09 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Thu, 4 Dec 2025 00:56:47 +0100 Subject: [PATCH 5/6] more improvements --- .../edu/ie3/simona/test/KafkaSpecLike.scala | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala index d565893940..82a337829b 100644 --- a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala +++ b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala @@ -18,39 +18,41 @@ import scala.util.{Failure, Success, Try} trait KafkaSpecLike extends BeforeAndAfterAll { this: TestSuite => + /** Topics that should exist in the test broker */ protected val testTopics: Seq[Topic] + /** Kafka container definition; started in [[beforeAll]] */ protected lazy val kafka: KafkaContainer = KafkaContainer(DockerImageName.parse("apache/kafka:3.7.0")) - protected lazy val admin: Try[Admin] = - if kafka.container.isRunning then - Success( - Admin.create(Map("bootstrap.servers" -> kafka.bootstrapServers).asJava) - ) - else - Failure( - new IllegalStateException( - "Kafka container must be started before creating Admin client" - ) - ) + /** Create an Admin client once the container is running */ + protected def createAdmin(): Admin = + Admin.create(Map("bootstrap.servers" -> kafka.bootstrapServers).asJava) override def beforeAll(): Unit = { super.beforeAll() kafka.start() - val result = admin.map( - _.createTopics( - testTopics + val result = Try { + val admin = createAdmin() + try { + val topics = testTopics .map(t => new NewTopic(t.name, t.partitions, t.replicationFactor)) .asJava - ) - ) - result.map(_.all().get(15, TimeUnit.SECONDS)) + admin.createTopics(topics).all().get(15, TimeUnit.SECONDS) + } finally { + admin.close() + } + } + + result match { + case Success(_) => + case Failure(ex) => + throw new IllegalStateException("Failed to create Kafka topics", ex) + } } override def afterAll(): Unit = { - if admin != null then admin.map(_.close()) kafka.stop() super.afterAll() } From 94e299cf840cfecb8d26410e0113bd6e160a6701 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Thu, 4 Dec 2025 00:59:28 +0100 Subject: [PATCH 6/6] fmt --- src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala index 82a337829b..82bed2a0f3 100644 --- a/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala +++ b/src/test/scala/edu/ie3/simona/test/KafkaSpecLike.scala @@ -1,5 +1,5 @@ /* - * © 2025. TU Dortmund University, + * © 2021. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation */ @@ -16,6 +16,9 @@ import java.util.concurrent.TimeUnit import scala.jdk.CollectionConverters.* import scala.util.{Failure, Success, Try} +/** Adapted from + * https://kafka-tutorials.confluent.io/produce-consume-lang/scala.html + */ trait KafkaSpecLike extends BeforeAndAfterAll { this: TestSuite => /** Topics that should exist in the test broker */