Skip to content
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 docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Examples of different use cases provided by Testcontainers can be found below:
- [Spring Boot with Kotlin](https://github.com/testcontainers/testcontainers-java/tree/main/examples/spring-boot-kotlin-redis)
- [TestNG](https://github.com/testcontainers/testcontainers-java/tree/main/examples/redis-backed-cache-testng)
- [ImmuDb](https://github.com/testcontainers/testcontainers-java/tree/main/examples/immudb)
- [Zookeeper](https://github.com/testcontainers/testcontainers-java/tree/main/examples/zookeper)
1 change: 1 addition & 0 deletions examples/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ include 'spring-boot'
include 'cucumber'
include 'spring-boot-kotlin-redis'
include 'immudb'
include 'zookeeper'

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

Expand Down
14 changes: 14 additions & 0 deletions examples/zookeeper/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
testImplementation 'org.apache.curator:curator-framework:5.3.0'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.assertj:assertj-core:3.23.1'
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryOneTime;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;

import java.nio.charset.StandardCharsets;

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

public class ZookeeperContainerTest {

private static final int ZOOKEEPER_PORT = 2181;

@Test
public void test() throws Exception {
String path = "/messages/zk-tc";
String content = "Running Zookeeper with Testcontainers";
try (
GenericContainer<?> zookeeper = new GenericContainer<>("zookeeper:3.8.0").withExposedPorts(ZOOKEEPER_PORT)
) {
zookeeper.start();

String connectionString = zookeeper.getHost() + ":" + zookeeper.getMappedPort(ZOOKEEPER_PORT);
CuratorFramework curatorFramework = CuratorFrameworkFactory
.builder()
.connectString(connectionString)
.retryPolicy(new RetryOneTime(100))
.build();
curatorFramework.start();
curatorFramework.create().creatingParentsIfNeeded().forPath(path, content.getBytes());

byte[] bytes = curatorFramework.getData().forPath(path);
curatorFramework.close();

assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo(content);
}
}
}
16 changes: 16 additions & 0 deletions examples/zookeeper/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>