-
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.
Merge pull request #374 from victornguen/qdrant-wrapper
Add QdrantContainer wrapper
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
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
43 changes: 43 additions & 0 deletions
43
modules/quadrant/src/main/scala/com/dimafeng/testcontainers/QdrantContainer.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,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)) | ||
) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
modules/quadrant/src/test/scala/com/dimafeng/testcontainers/QdrantSpec.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,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 | ||
} |
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