-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e87eb0d
commit 92a74f2
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
modules/milvus/src/main/scala/com/dimafeng/testcontainers/MilvusContainer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
modules/milvus/src/test/scala/com/dimafeng/testcontainers/MilvusSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters