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 container implementation for Typesense #9454

Merged
merged 1 commit into from
Oct 23, 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 @@ -64,6 +64,7 @@ body:
- Timeplus
- ToxiProxy
- Trino
- Typesense
- Vault
- Weaviate
- YugabyteDB
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 @@ -64,6 +64,7 @@ body:
- Timeplus
- ToxiProxy
- Trino
- Typesense
- Vault
- Weaviate
- YugabyteDB
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 @@ -64,6 +64,7 @@ body:
- Timeplus
- ToxiProxy
- Trino
- Typesense
- Vault
- Weaviate
- YugabyteDB
Expand Down
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ updates:
schedule:
interval: "weekly"
open-pull-requests-limit: 10
- package-ecosystem: "gradle"
directory: "/modules/typesense"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
- package-ecosystem: "gradle"
directory: "/modules/vault"
schedule:
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@
- changed-files:
- any-glob-to-any-file:
- modules/trino/**/*
"modules/typesense":
- changed-files:
- any-glob-to-any-file:
- modules/typesense/**/*
"modules/vault":
- 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 @@ -262,6 +262,9 @@ labels:
- name: modules/trino
color: '#006b75'

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

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

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

Testcontainers module for [Typesense](https://hub.docker.com/r/typesense/typesense).

## TypesenseContainer's usage examples

You can start an Typesense container instance from any Java application by using:

<!--codeinclude-->
[Typesense container](../../modules/typesense/src/test/java/org/testcontainers/typesense/TypesenseContainerTest.java) inside_block:container
<!--/codeinclude-->

## Adding this module to your project dependencies

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

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

=== "Maven"
```xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>typesense</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 @@ -102,6 +102,7 @@ nav:
- modules/solace.md
- modules/solr.md
- modules/toxiproxy.md
- modules/typesense.md
- modules/vault.md
- modules/weaviate.md
- modules/webdriver_containers.md
Expand Down
8 changes: 8 additions & 0 deletions modules/typesense/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
description = "Testcontainers :: Typesense"

dependencies {
api project(':testcontainers')

testImplementation 'org.assertj:assertj-core:3.26.3'
testImplementation 'org.typesense:typesense-java:0.9.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.testcontainers.typesense;

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

/**
* Testcontainers implementation for Typesense.
* <p>
* Supported image: {@code typesense/typesense}
* <p>
* Exposed ports: 8108
*/
public class TypesenseContainer extends GenericContainer<TypesenseContainer> {

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

private static final int PORT = 8108;

private static final String DEFAULT_API_KEY = "testcontainers";

private String apiKey = DEFAULT_API_KEY;

public TypesenseContainer(String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}

public TypesenseContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
withExposedPorts(PORT);
withEnv("TYPESENSE_DATA_DIR", "/tmp");
waitingFor(
Wait
.forHttp("/health")
.forStatusCode(200)
.forResponsePredicate(response -> response.contains("\"ok\":true"))
);
}

@Override
protected void configure() {
withEnv("TYPESENSE_API_KEY", this.apiKey);
}

public TypesenseContainer withApiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}

public String getHttpPort() {
return String.valueOf(getMappedPort(PORT));
}

public String getApiKey() {
return this.apiKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.testcontainers.typesense;

import org.junit.Test;
import org.typesense.api.Client;
import org.typesense.api.Configuration;
import org.typesense.resources.Node;

import java.time.Duration;
import java.util.Collections;
import java.util.List;

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

public class TypesenseContainerTest {

@Test
public void query() throws Exception {
try ( // container {
TypesenseContainer typesense = new TypesenseContainer("typesense/typesense:27.1")
// }
) {
typesense.start();
List<Node> nodes = Collections.singletonList(
new Node("http", typesense.getHost(), typesense.getHttpPort())
);

assertThat(typesense.getApiKey()).isEqualTo("testcontainers");
Configuration configuration = new Configuration(nodes, Duration.ofSeconds(5), typesense.getApiKey());
Client client = new Client(configuration);
System.out.println(client.health.retrieve());
assertThat(client.health.retrieve()).containsEntry("ok", true);
}
}

@Test
public void withCustomApiKey() throws Exception {
try (TypesenseContainer typesense = new TypesenseContainer("typesense/typesense:27.1").withApiKey("s3cr3t")) {
typesense.start();
List<Node> nodes = Collections.singletonList(
new Node("http", typesense.getHost(), typesense.getHttpPort())
);

assertThat(typesense.getApiKey()).isEqualTo("s3cr3t");
Configuration configuration = new Configuration(nodes, Duration.ofSeconds(5), typesense.getApiKey());
Client client = new Client(configuration);
assertThat(client.health.retrieve()).containsEntry("ok", true);
}
}
}
16 changes: 16 additions & 0 deletions modules/typesense/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