-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add container implementation for Typesense (#9454)
- Loading branch information
1 parent
c1ad4b8
commit e0321d9
Showing
12 changed files
with
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ body: | |
- Timeplus | ||
- ToxiProxy | ||
- Trino | ||
- Typesense | ||
- Vault | ||
- Weaviate | ||
- YugabyteDB | ||
|
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 |
---|---|---|
|
@@ -64,6 +64,7 @@ body: | |
- Timeplus | ||
- ToxiProxy | ||
- Trino | ||
- Typesense | ||
- Vault | ||
- Weaviate | ||
- YugabyteDB | ||
|
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 |
---|---|---|
|
@@ -64,6 +64,7 @@ body: | |
- Timeplus | ||
- ToxiProxy | ||
- Trino | ||
- Typesense | ||
- Vault | ||
- Weaviate | ||
- YugabyteDB | ||
|
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
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
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
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,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> | ||
``` |
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
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,8 @@ | ||
description = "Testcontainers :: Typesense" | ||
|
||
dependencies { | ||
api project(':testcontainers') | ||
|
||
testImplementation 'org.assertj:assertj-core:3.26.3' | ||
testImplementation 'org.typesense:typesense-java:0.9.0' | ||
} |
58 changes: 58 additions & 0 deletions
58
modules/typesense/src/main/java/org/testcontainers/typesense/TypesenseContainer.java
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,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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
modules/typesense/src/test/java/org/testcontainers/typesense/TypesenseContainerTest.java
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,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); | ||
} | ||
} | ||
} |
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,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> |