Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Milvus module #8352

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ body:
- Kafka
- LocalStack
- MariaDB
- Milvus
- MinIO
- MockServer
- MongoDB
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/enhancement.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ body:
- Kafka
- LocalStack
- MariaDB
- Milvus
- MinIO
- MockServer
- MongoDB
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ body:
- Kafka
- LocalStack
- MariaDB
- Milvus
- MinIO
- MockServer
- MongoDB
Expand Down
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ updates:
ignore:
- dependency-name: "org.mariadb:r2dbc-mariadb"
update-types: [ "version-update:semver-minor" ]
- package-ecosystem: "gradle"
directory: "/modules/milvus"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
- package-ecosystem: "gradle"
directory: "/modules/minio"
schedule:
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
- changed-files:
- any-glob-to-any-file:
- modules/mariadb/**/*
"modules/milvus":
- changed-files:
- any-glob-to-any-file:
- modules/milvus/**/*
"modules/minio":
- changed-files:
- any-glob-to-any-file:
Expand Down
3 changes: 3 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ labels:
- name: modules/mariadb
color: '#006b75'

- name: modules/milvus
color: '#006b75'

- name: modules/minio
color: '#006b75'

Expand Down
36 changes: 36 additions & 0 deletions docs/modules/milvus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Milvus

Testcontainers module for [Milvus](https://hub.docker.com/r/milvusdb/milvus).

## Milvus's usage examples

You can start a Milvus container instance from any Java application by using:

<!--codeinclude-->
[Default config](../../modules/milvus/src/test/java/org/testcontainers/milvus/MilvusContainerTest.java) inside_block:milvusContainer
<!--/codeinclude-->

With external Etcd:

<!--codeinclude-->
[External Etcd](../../modules/milvus/src/test/java/org/testcontainers/milvus/MilvusContainerTest.java) inside_block:externalEtcd
<!--/codeinclude-->

## Adding this module to your project dependencies

Add the following dependency to your `pom.xml`/`build.gradle` file:

=== "Gradle"
```groovy
testImplementation "org.testcontainers:milvus:{{latest_version}}"
```

=== "Maven"
```xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>milvus</artifactId>
<version>{{latest_version}}</version>
<scope>test</scope>
</dependency>
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ nav:
- modules/k3s.md
- modules/kafka.md
- modules/localstack.md
- modules/milvus.md
- modules/minio.md
- modules/mockserver.md
- modules/nginx.md
Expand Down
8 changes: 8 additions & 0 deletions modules/milvus/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
description = "Testcontainers :: ActiveMQ"

dependencies {
api project(':testcontainers')

testImplementation 'org.assertj:assertj-core:3.25.1'
testImplementation 'io.milvus:milvus-sdk-java:2.3.4'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.testcontainers.milvus;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

/**
* Testcontainers implementation for Milvus.
* <p>
* Supported image: {@code milvusdb/milvus}
* <p>
* Exposed ports:
* <ul>
* <li>Management port: 9091</li>
* <li>HTTP: 19530</li>
* </ul>
*/
public class MilvusContainer extends GenericContainer<MilvusContainer> {

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("milvusdb/milvus");

private String etcdEndpoint;

public MilvusContainer(String image) {
this(DockerImageName.parse(image));
}

public MilvusContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
withExposedPorts(9091, 19530);
waitingFor(Wait.forHttp("/healthz").forPort(9091));
withCommand("milvus", "run", "standalone");
withCopyFileToContainer(
MountableFile.forClasspathResource("testcontainers/embedEtcd.yaml"),
"/milvus/configs/embedEtcd.yaml"
);
withEnv("COMMON_STORAGETYPE", "local");
}

@Override
protected void configure() {
if (this.etcdEndpoint == null) {
withEnv("ETCD_USE_EMBED", "true");
withEnv("ETCD_DATA_DIR", "/var/lib/milvus/etcd");
withEnv("ETCD_CONFIG_PATH", "/milvus/configs/embedEtcd.yaml");
} else {
withEnv("ETCD_ENDPOINTS", this.etcdEndpoint);
}
}

public MilvusContainer withEtcdEndpoint(String etcdEndpoint) {
this.etcdEndpoint = etcdEndpoint;
return this;
}

public String getEndpoint() {
return "http://" + getHost() + ":" + getMappedPort(19530);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
listen-client-urls: http://0.0.0.0:2379
advertise-client-urls: http://0.0.0.0:2379
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.testcontainers.milvus;

import io.milvus.client.MilvusServiceClient;
import io.milvus.param.ConnectParam;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;

import static org.assertj.core.api.Assertions.assertThat;

public class MilvusContainerTest {

@Test
public void withDefaultConfig() {
try (
// milvusContainer {
MilvusContainer milvus = new MilvusContainer("milvusdb/milvus:v2.3.9")
// }
) {
milvus.start();

assertThat(milvus.getEnvMap()).doesNotContainKey("ETCD_ENDPOINTS");
assertMilvusVersion(milvus);
}
}

@Test
public void withExternalEtcd() {
try (
// externalEtcd {
Network network = Network.newNetwork();
GenericContainer<?> etcd = new GenericContainer<>("quay.io/coreos/etcd:v3.5.5")
.withNetwork(network)
.withNetworkAliases("etcd")
.withCommand(
"etcd",
"-advertise-client-urls=http://127.0.0.1:2379",
"-listen-client-urls=http://0.0.0.0:2379",
"--data-dir=/etcd"
)
.withEnv("ETCD_AUTO_COMPACTION_MODE", "revision")
.withEnv("ETCD_AUTO_COMPACTION_RETENTION", "1000")
.withEnv("ETCD_QUOTA_BACKEND_BYTES", "4294967296")
.withEnv("ETCD_SNAPSHOT_COUNT", "50000")
.waitingFor(Wait.forLogMessage(".*ready to serve client requests.*", 1));
MilvusContainer milvus = new MilvusContainer("milvusdb/milvus:v2.3.9")
.withNetwork(network)
.withEtcdEndpoint("etcd:2379")
.dependsOn(etcd)
// }
) {
milvus.start();

assertThat(milvus.getEnvMap()).doesNotContainKey("ETCD_USE_EMBED");
assertMilvusVersion(milvus);
}
}

private static void assertMilvusVersion(MilvusContainer milvus) {
MilvusServiceClient milvusClient = new MilvusServiceClient(
ConnectParam.newBuilder().withUri(milvus.getEndpoint()).build()
);
assertThat(milvusClient.getVersion().getData().getVersion()).isEqualTo("v2.3.9");
}
}
16 changes: 16 additions & 0 deletions modules/milvus/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

<logger name="org.testcontainers" level="INFO"/>
</configuration>
Loading