Skip to content

Commit e2aeb68

Browse files
Test container example for ImmuDB (#5860)
Test container example using ImmuDB, performing basic operations Fixes #5594 Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
1 parent f0dd614 commit e2aeb68

File tree

4 files changed

+90
-11
lines changed

4 files changed

+90
-11
lines changed

docs/examples.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
Examples of different use cases provided by Testcontainers can be found below:
44

5-
- [Kafka Cluster with multiple brokers](https://github.com/testcontainers/testcontainers-java/tree/main/examples/kafka-cluster)
6-
- [Linked containers](https://github.com/testcontainers/testcontainers-java/tree/main/examples/linked-container)
7-
- [Neo4j](https://github.com/testcontainers/testcontainers-java/tree/main/examples/neo4j-container)
8-
- [Redis](https://github.com/testcontainers/testcontainers-java/tree/main/examples/redis-backed-cache)
9-
- [Selenium](https://github.com/testcontainers/testcontainers-java/tree/main/examples/selenium-container)
10-
- [Selenium Module with Cucumber](https://github.com/testcontainers/testcontainers-java/tree/main/examples/cucumber)
11-
- [Singleton Container Pattern](https://github.com/testcontainers/testcontainers-java/tree/main/examples/singleton-container)
12-
- [Solr](https://github.com/testcontainers/testcontainers-java/tree/main/examples/solr-container)
13-
- [Spring Boot](https://github.com/testcontainers/testcontainers-java/tree/main/examples/spring-boot)
14-
- [Spring Boot with Kotlin](https://github.com/testcontainers/testcontainers-java/tree/main/examples/spring-boot-kotlin-redis)
15-
- [TestNG](https://github.com/testcontainers/testcontainers-java/tree/main/examples/redis-backed-cache-testng)
5+
- [Kafka Cluster with multiple brokers](https://github.com/testcontainers/testcontainers-java/tree/master/examples/kafka-cluster)
6+
- [Linked containers](https://github.com/testcontainers/testcontainers-java/tree/master/examples/linked-container)
7+
- [Neo4j](https://github.com/testcontainers/testcontainers-java/tree/master/examples/neo4j-container)
8+
- [Redis](https://github.com/testcontainers/testcontainers-java/tree/master/examples/redis-backed-cache)
9+
- [Selenium](https://github.com/testcontainers/testcontainers-java/tree/master/examples/selenium-container)
10+
- [Selenium Module with Cucumber](https://github.com/testcontainers/testcontainers-java/tree/master/examples/cucumber)
11+
- [Singleton Container Pattern](https://github.com/testcontainers/testcontainers-java/tree/master/examples/singleton-container)
12+
- [Solr](https://github.com/testcontainers/testcontainers-java/tree/master/examples/solr-container)
13+
- [Spring Boot](https://github.com/testcontainers/testcontainers-java/tree/master/examples/spring-boot)
14+
- [Spring Boot with Kotlin](https://github.com/testcontainers/testcontainers-java/tree/master/examples/spring-boot-kotlin-redis)
15+
- [TestNG](https://github.com/testcontainers/testcontainers-java/tree/master/examples/redis-backed-cache-testng)
16+
- [ImmuDb](https://github.com/testcontainers/testcontainers-java/tree/master/examples/immudb)

examples/immudb/build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
compileOnly 'org.slf4j:slf4j-api:2.0.0'
11+
implementation 'io.codenotary:immudb4j:0.9.10.2'
12+
testImplementation 'org.testcontainers:testcontainers'
13+
testImplementation 'org.assertj:assertj-core:3.23.1'
14+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import io.codenotary.immudb4j.Entry;
2+
import io.codenotary.immudb4j.ImmuClient;
3+
import io.codenotary.immudb4j.exceptions.CorruptedDataException;
4+
import io.codenotary.immudb4j.exceptions.VerificationException;
5+
import org.junit.Assert;
6+
import org.junit.Before;
7+
import org.junit.ClassRule;
8+
import org.junit.Test;
9+
import org.testcontainers.containers.GenericContainer;
10+
import org.testcontainers.containers.wait.strategy.Wait;
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
/**
14+
* Test class for the ImmuDbClient.
15+
*/
16+
public class ImmuDbTest {
17+
18+
// Default port for the ImmuDb server
19+
private static final int IMMUDB_PORT = 3322;
20+
// Default username for the ImmuDb server
21+
private final String IMMUDB_USER = "immudb";
22+
// Default password for the ImmuDb server
23+
private final String IMMUDB_PASSWORD = "immudb";
24+
// Default database name for the ImmuDb server
25+
private final String IMMUDB_DATABASE = "defaultdb";
26+
27+
// Test container for the ImmuDb database, with the latest version of the image and exposed port
28+
@ClassRule
29+
public static final GenericContainer<?> immuDbContainer = new GenericContainer<>("codenotary/immudb:1.3")
30+
.withExposedPorts(IMMUDB_PORT).waitingFor(
31+
Wait.forLogMessage(".*Web API server enabled.*", 1)
32+
);
33+
// ImmuClient used to interact with the DB
34+
private ImmuClient immuClient;
35+
36+
@Before
37+
public void setUp() {
38+
this.immuClient = ImmuClient.newBuilder()
39+
.withServerUrl(immuDbContainer.getHost())
40+
.withServerPort(immuDbContainer.getMappedPort(IMMUDB_PORT))
41+
.build();
42+
this.immuClient.login(IMMUDB_USER, IMMUDB_PASSWORD);
43+
this.immuClient.useDatabase(IMMUDB_DATABASE);
44+
}
45+
46+
@Test
47+
public void testGetValue() {
48+
try {
49+
immuClient.set("test1", "test2".getBytes());
50+
51+
Entry entry = immuClient.verifiedGet("test1");
52+
53+
if (entry != null) {
54+
byte[] value = entry.getValue();
55+
assertThat(new String(value)).isEqualTo("test2");
56+
} else {
57+
Assert.fail();
58+
}
59+
} catch (CorruptedDataException | VerificationException e) {
60+
Assert.fail();
61+
}
62+
}
63+
}

examples/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ include 'solr-container'
3030
include 'spring-boot'
3131
include 'cucumber'
3232
include 'spring-boot-kotlin-redis'
33+
include 'immudb'
3334

3435
ext.isCI = System.getenv("CI") != null
3536

0 commit comments

Comments
 (0)