From f45bb444f0bbe54d791058bb015547ba2919beab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez=20Gonzales?= Date: Tue, 20 Feb 2024 12:46:01 -0500 Subject: [PATCH] Add Weaviate module (#8337) --- .github/ISSUE_TEMPLATE/bug_report.yaml | 1 + .github/ISSUE_TEMPLATE/enhancement.yaml | 1 + .github/ISSUE_TEMPLATE/feature.yaml | 1 + .github/dependabot.yml | 5 +++ .github/labeler.yml | 4 +++ .github/settings.yml | 3 ++ docs/modules/weaviate.md | 30 ++++++++++++++++ mkdocs.yml | 1 + modules/weaviate/build.gradle | 8 +++++ .../weaviate/WeaviateContainer.java | 36 +++++++++++++++++++ .../weaviate/WeaviateContainerTest.java | 25 +++++++++++++ .../src/test/resources/logback-test.xml | 16 +++++++++ 12 files changed, 131 insertions(+) create mode 100644 docs/modules/weaviate.md create mode 100644 modules/weaviate/build.gradle create mode 100644 modules/weaviate/src/main/java/org/testcontainers/weaviate/WeaviateContainer.java create mode 100644 modules/weaviate/src/test/java/org/testcontainers/weaviate/WeaviateContainerTest.java create mode 100644 modules/weaviate/src/test/resources/logback-test.xml diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 81e3dbbd900..a140ad15285 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -55,6 +55,7 @@ body: - ToxiProxy - Trino - Vault + - Weaviate - YugabyteDB validations: required: true diff --git a/.github/ISSUE_TEMPLATE/enhancement.yaml b/.github/ISSUE_TEMPLATE/enhancement.yaml index d073f8f1674..7c60044546f 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.yaml +++ b/.github/ISSUE_TEMPLATE/enhancement.yaml @@ -55,6 +55,7 @@ body: - ToxiProxy - Trino - Vault + - Weaviate - YugabyteDB validations: required: true diff --git a/.github/ISSUE_TEMPLATE/feature.yaml b/.github/ISSUE_TEMPLATE/feature.yaml index dedccecd4e5..91c750ef7f8 100644 --- a/.github/ISSUE_TEMPLATE/feature.yaml +++ b/.github/ISSUE_TEMPLATE/feature.yaml @@ -55,6 +55,7 @@ body: - ToxiProxy - Trino - Vault + - Weaviate - YugabyteDB - New Module - type: textarea diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 80a8780f6b2..7111d36c2a6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -302,6 +302,11 @@ updates: schedule: interval: "weekly" open-pull-requests-limit: 10 + - package-ecosystem: "gradle" + directory: "/modules/weaviate" + schedule: + interval: "weekly" + open-pull-requests-limit: 10 - package-ecosystem: "gradle" directory: "/modules/yugabytedb" schedule: diff --git a/.github/labeler.yml b/.github/labeler.yml index e3bce388744..0960bf74461 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -192,6 +192,10 @@ - changed-files: - any-glob-to-any-file: - modules/vault/**/* +"modules/weaviate": + - changed-files: + - any-glob-to-any-file: + - modules/weaviate/**/* "modules/yugabytedb": - changed-files: - any-glob-to-any-file: diff --git a/.github/settings.yml b/.github/settings.yml index 3047612d756..aa3b62b90fe 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -238,6 +238,9 @@ labels: - name: modules/vault color: '#006b75' + - name: modules/weaviate + color: '#006b75' + - name: modules/yugabytedb color: '#006b75' diff --git a/docs/modules/weaviate.md b/docs/modules/weaviate.md new file mode 100644 index 00000000000..da028cf3ce1 --- /dev/null +++ b/docs/modules/weaviate.md @@ -0,0 +1,30 @@ +# Weaviate + +Testcontainers module for [Weaviate](https://hub.docker.com/r/semitechnologies/weaviate) + +## WeaviateContainer's usage examples + +You can start a Weaviate container instance from any Java application by using: + + +[Default Weaviate container](../../modules/weaviate/src/test/java/org/testcontainers/weaviate/WeaviateContainerTest.java) inside_block:container + + +## Adding this module to your project dependencies + +Add the following dependency to your `pom.xml`/`build.gradle` file: + +=== "Gradle" +```groovy +testImplementation "org.testcontainers:weaviate:{{latest_version}}" +``` + +=== "Maven" +```xml + +org.testcontainers +weaviate +{{latest_version}} +test + +``` diff --git a/mkdocs.yml b/mkdocs.yml index 548efdaf945..86cfd3a823a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -93,6 +93,7 @@ nav: - modules/solr.md - modules/toxiproxy.md - modules/vault.md + - modules/weaviate.md - modules/webdriver_containers.md - Test framework integration: - test_framework_integration/junit_4.md diff --git a/modules/weaviate/build.gradle b/modules/weaviate/build.gradle new file mode 100644 index 00000000000..06a77aa434a --- /dev/null +++ b/modules/weaviate/build.gradle @@ -0,0 +1,8 @@ +description = "Testcontainers :: Weaviate" + +dependencies { + api project(':testcontainers') + + testImplementation 'org.assertj:assertj-core:3.25.1' + testImplementation 'io.weaviate:client:4.5.1' +} diff --git a/modules/weaviate/src/main/java/org/testcontainers/weaviate/WeaviateContainer.java b/modules/weaviate/src/main/java/org/testcontainers/weaviate/WeaviateContainer.java new file mode 100644 index 00000000000..bd217b13e75 --- /dev/null +++ b/modules/weaviate/src/main/java/org/testcontainers/weaviate/WeaviateContainer.java @@ -0,0 +1,36 @@ +package org.testcontainers.weaviate; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; + +/** + * Testcontainers implementation of Weaviate. + *

+ * Supported image: {@code semitechnologies/weaviate} + *

+ * Exposed ports: + *

+ */ +public class WeaviateContainer extends GenericContainer { + + private static final String WEAVIATE_IMAGE = "semitechnologies/weaviate"; + + public WeaviateContainer(String dockerImageName) { + this(DockerImageName.parse(dockerImageName)); + } + + public WeaviateContainer(DockerImageName dockerImageName) { + super(dockerImageName); + dockerImageName.assertCompatibleWith(DockerImageName.parse(WEAVIATE_IMAGE)); + withExposedPorts(8080, 50051); + withEnv("AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED", "true"); + withEnv("PERSISTENCE_DATA_PATH", "/var/lib/weaviate"); + } + + public String getHttpHostAddress() { + return getHost() + ":" + getMappedPort(8080); + } +} diff --git a/modules/weaviate/src/test/java/org/testcontainers/weaviate/WeaviateContainerTest.java b/modules/weaviate/src/test/java/org/testcontainers/weaviate/WeaviateContainerTest.java new file mode 100644 index 00000000000..562fc36de51 --- /dev/null +++ b/modules/weaviate/src/test/java/org/testcontainers/weaviate/WeaviateContainerTest.java @@ -0,0 +1,25 @@ +package org.testcontainers.weaviate; + +import io.weaviate.client.Config; +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.misc.model.Meta; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class WeaviateContainerTest { + + @Test + public void test() { + try ( // container { + WeaviateContainer weaviate = new WeaviateContainer("semitechnologies/weaviate:1.22.4") + // } + ) { + weaviate.start(); + WeaviateClient client = new WeaviateClient(new Config("http", weaviate.getHttpHostAddress())); + Result meta = client.misc().metaGetter().run(); + assertThat(meta.getResult().getVersion()).isEqualTo("1.22.4"); + } + } +} diff --git a/modules/weaviate/src/test/resources/logback-test.xml b/modules/weaviate/src/test/resources/logback-test.xml new file mode 100644 index 00000000000..83ef7a1a3ef --- /dev/null +++ b/modules/weaviate/src/test/resources/logback-test.xml @@ -0,0 +1,16 @@ + + + + + + %d{HH:mm:ss.SSS} %-5level %logger - %msg%n + + + + + + + + +