diff --git a/build.sbt b/build.sbt index 0396acb..2dc2cff 100644 --- a/build.sbt +++ b/build.sbt @@ -88,6 +88,7 @@ lazy val root = (project in file(".")) moduleMockserver, moduleNginx, modulePulsar, + moduleQuadrant, moduleRabbitmq, moduleRedis, moduleToxiproxy, @@ -431,6 +432,14 @@ lazy val modulePulsar = (project in file("modules/pulsar")) libraryDependencies ++= Dependencies.modulePulsar.value ) +lazy val moduleQuadrant = (project in file("modules/quadrant")) + .dependsOn(core % "compile->compile;test->test;provided->provided", scalatest % "test->test") + .settings(commonSettings) + .settings( + name := "testcontainers-scala-quadrant", + libraryDependencies ++= Dependencies.moduleQuadrant.value + ) + lazy val moduleRabbitmq = (project in file("modules/rabbitmq")) .dependsOn(core % "compile->compile;test->test;provided->provided", scalatest % "test->test") .settings(commonSettings) diff --git a/modules/quadrant/src/main/scala/com/dimafeng/testcontainers/QdrantContainer.scala b/modules/quadrant/src/main/scala/com/dimafeng/testcontainers/QdrantContainer.scala new file mode 100644 index 0000000..3d14505 --- /dev/null +++ b/modules/quadrant/src/main/scala/com/dimafeng/testcontainers/QdrantContainer.scala @@ -0,0 +1,43 @@ +package com.dimafeng.testcontainers + +import org.testcontainers.images.builder.Transferable +import org.testcontainers.qdrant.{QdrantContainer => JavaQdrantContainer} +import org.testcontainers.utility.DockerImageName + +class QdrantContainer( + underlying: JavaQdrantContainer +) extends SingleContainer[JavaQdrantContainer] { self => + + override val container: JavaQdrantContainer = underlying + + def grpcPort: Int = container.getGrpcPort + + def grpcHostAddress: String = container.getGrpcHostAddress + +} + +object QdrantContainer { + + val defaultImage = "qdrant/qdrant" + val defaultTag = "v1.12.1" + val defaultDockerImageName = s"$defaultImage:$defaultTag" + + case class Def( + dockerImageName: DockerImageName = DockerImageName.parse(QdrantContainer.defaultDockerImageName), + builder: List[JavaQdrantContainer => JavaQdrantContainer] = List.empty + ) extends ContainerDef { + override type Container = QdrantContainer + + def withApiKey(apiKey: String): Def = + copy(builder = ((_: JavaQdrantContainer).withApiKey(apiKey)) :: builder) + + def withConfigFile(configFile: Transferable): Def = + copy(builder = ((_: JavaQdrantContainer).withConfigFile(configFile)) :: builder) + + override def createContainer(): QdrantContainer = + new QdrantContainer( + builder + .foldRight(new JavaQdrantContainer(dockerImageName))((f, underlying) => f(underlying)) + ) + } +} diff --git a/modules/quadrant/src/test/scala/com/dimafeng/testcontainers/QdrantSpec.scala b/modules/quadrant/src/test/scala/com/dimafeng/testcontainers/QdrantSpec.scala new file mode 100644 index 0000000..e437f9e --- /dev/null +++ b/modules/quadrant/src/test/scala/com/dimafeng/testcontainers/QdrantSpec.scala @@ -0,0 +1,31 @@ +package com.dimafeng.testcontainers + +import com.dimafeng.testcontainers.scalatest.TestContainersForAll +import io.qdrant.client.{QdrantClient, QdrantGrpcClient} +import org.scalatest.flatspec.AnyFlatSpec + +import java.util.UUID + +class QdrantSpec extends AnyFlatSpec with TestContainersForAll { + override type Containers = QdrantContainer + + override def startContainers(): QdrantContainer = + QdrantContainer.Def().withApiKey(QdrantSpec.apiKey).start() + + "Qdrant container" should "be started" in withContainers { qdrantContainer => + val client = new QdrantClient( + QdrantGrpcClient + .newBuilder(qdrantContainer.host, qdrantContainer.grpcPort, false) + .withApiKey(QdrantSpec.apiKey) + .build() + ) + val healthCheckReply = client.healthCheckAsync().get() + + assert(healthCheckReply.getVersion.nonEmpty) + } + +} + +object QdrantSpec { + val apiKey: String = UUID.randomUUID().toString +} diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 2a65ddd..3590d19 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -40,6 +40,7 @@ object Dependencies { private val jedisVersion = "5.0.0" private val wireMockTestcontainersVersion = "1.0-alpha-13" private val milvusSdkVersion = "2.4.1" + private val quadrantClientVersion = "1.12.0" private val yugabyteJdbcVersion = "42.3.5-yb-6" private val yugabyteJavaDriverVersion = "4.15.0-yb-2-TESTFIX.0" @@ -257,6 +258,14 @@ object Dependencies { ) ) + val moduleQuadrant = Def.setting( + COMPILE( + "org.testcontainers" % "qdrant" % testcontainersVersion + ) ++ TEST( + "io.qdrant" % "client" % quadrantClientVersion + ) + ) + val moduleRabbitmq = Def.setting( COMPILE( "org.testcontainers" % "rabbitmq" % testcontainersVersion