Skip to content

Commit

Permalink
add MilvusContainer wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
victornguen committed Jun 28, 2024
1 parent e87eb0d commit 92a74f2
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
9 changes: 9 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ lazy val root = (project in file("."))
moduleLocalstack,
moduleLocalstackV2,
moduleMariadb,
moduleMilvus,
moduleMockserver,
moduleNginx,
modulePulsar,
Expand Down Expand Up @@ -397,6 +398,14 @@ lazy val moduleMariadb = (project in file("modules/mariadb"))
libraryDependencies ++= Dependencies.moduleMariadb.value
)

lazy val moduleMilvus = (project in file("modules/milvus"))
.dependsOn(core % "compile->compile;test->test;provided->provided", scalatest % "test->test")
.settings(commonSettings)
.settings(
name := "testcontainers-scala-milvus",
libraryDependencies ++= Dependencies.moduleMilvus.value
)

lazy val moduleMockserver = (project in file("modules/mockserver"))
.dependsOn(core % "compile->compile;test->test;provided->provided", scalatest % "test->test")
.settings(commonSettings)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dimafeng.testcontainers

import org.testcontainers.milvus.{MilvusContainer => JavaMilvusIOContainer}
import org.testcontainers.utility.DockerImageName

case class MilvusContainer(
dockerImageName: DockerImageName = DockerImageName.parse(MilvusContainer.defaultDockerImageName),
httpPort: Int = MilvusContainer.defaultPort,
etcdEndpoint: Option[String] = None
) extends SingleContainer[JavaMilvusIOContainer] {

override val container: JavaMilvusIOContainer = {
val c = new JavaMilvusIOContainer(dockerImageName)
c.withExposedPorts(httpPort, MilvusContainer.managementPort)
etcdEndpoint.foreach(c.withEtcdEndpoint)
c
}

def endpoint: String = container.getEndpoint
}

object MilvusContainer {

val defaultImage = "milvusdb/milvus"
val defaultTag = "v2.4.4"
val defaultDockerImageName = s"$defaultImage:$defaultTag"

val defaultPort = 19530
val managementPort = 9091

case class Def(dockerImageName: DockerImageName = DockerImageName.parse(MilvusContainer.defaultDockerImageName),
port: Int = MilvusContainer.defaultPort) extends ContainerDef {
override type Container = MilvusContainer

override def createContainer(): MilvusContainer = {
new MilvusContainer(dockerImageName, port)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dimafeng.testcontainers

import com.dimafeng.testcontainers.scalatest.TestContainersForAll
import org.scalatest.flatspec.AnyFlatSpec
import io.milvus.client.{MilvusServiceClient, MilvusClient}
import io.milvus.param.ConnectParam
import io.milvus.param.collection.CreateDatabaseParam

import java.util

class MilvusSpec extends AnyFlatSpec with TestContainersForAll {
override type Containers = MilvusContainer

override def startContainers(): MilvusContainer =
MilvusContainer.Def().start()

"Milvus container" should "be started" in withContainers {
milvusContainer =>
val connect = ConnectParam
.newBuilder()
.withUri(milvusContainer.endpoint)
.build()
val milvus = new MilvusServiceClient(connect)
val dbName = "testcontainers_database"

MilvusSpec.createDatabase(milvus, dbName)

assert(milvus.listDatabases().getData.getDbNamesList.containsAll(util.Arrays.asList("default", dbName)))
}
}

object MilvusSpec {
def createDatabase(milvusClient: MilvusClient, databaseName: String): Unit = {
val param = CreateDatabaseParam.newBuilder().withDatabaseName(databaseName).build()

milvusClient.createDatabase(param).getData
}

}
11 changes: 10 additions & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object Dependencies {
scope.map(s => modules.map(_ % s)).getOrElse(modules)
}

private val testcontainersVersion = "1.19.1"
private val testcontainersVersion = "1.19.8"
private val seleniumVersion = "2.53.1"
private val slf4jVersion = "1.7.32"
private val scalaTestVersion = "3.2.9"
Expand All @@ -39,6 +39,7 @@ object Dependencies {
private val redisTestcontainersVersion = "2.0.1"
private val jedisVersion = "5.0.0"
private val wireMockTestcontainersVersion = "1.0-alpha-13"
private val milvusSdkVersion = "2.4.1"

val allOld = Def.setting(
PROVIDED(
Expand Down Expand Up @@ -225,6 +226,14 @@ object Dependencies {
)
)

val moduleMilvus = Def.setting(
COMPILE(
"org.testcontainers" % "milvus" % testcontainersVersion
) ++ TEST(
"io.milvus" % "milvus-sdk-java" % milvusSdkVersion
)
)

val moduleMockserver = Def.setting(
COMPILE(
"org.testcontainers" % "mockserver" % testcontainersVersion
Expand Down

0 comments on commit 92a74f2

Please sign in to comment.