File tree Expand file tree Collapse file tree 5 files changed +73
-0
lines changed
Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -14,3 +14,4 @@ Examples of different use cases provided by Testcontainers can be found below:
1414- [ Spring Boot with Kotlin] ( https://github.com/testcontainers/testcontainers-java/tree/main/examples/spring-boot-kotlin-redis )
1515- [ TestNG] ( https://github.com/testcontainers/testcontainers-java/tree/main/examples/redis-backed-cache-testng )
1616- [ ImmuDb] ( https://github.com/testcontainers/testcontainers-java/tree/main/examples/immudb )
17+ - [ Zookeeper] ( https://github.com/testcontainers/testcontainers-java/tree/main/examples/zookeper )
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ include 'spring-boot'
3131include ' cucumber'
3232include ' spring-boot-kotlin-redis'
3333include ' immudb'
34+ include ' zookeeper'
3435
3536ext. isCI = System . getenv(" CI" ) != null
3637
Original file line number Diff line number Diff line change 1+ plugins {
2+ id ' java'
3+ }
4+
5+ repositories {
6+ mavenCentral()
7+ }
8+
9+ dependencies {
10+ testImplementation ' org.apache.curator:curator-framework:5.3.0'
11+ testImplementation ' org.testcontainers:testcontainers'
12+ testImplementation ' org.assertj:assertj-core:3.23.1'
13+ testImplementation ' ch.qos.logback:logback-classic:1.2.11'
14+ }
Original file line number Diff line number Diff line change 1+ package com .example ;
2+
3+ import org .apache .curator .framework .CuratorFramework ;
4+ import org .apache .curator .framework .CuratorFrameworkFactory ;
5+ import org .apache .curator .retry .RetryOneTime ;
6+ import org .junit .Test ;
7+ import org .testcontainers .containers .GenericContainer ;
8+
9+ import java .nio .charset .StandardCharsets ;
10+
11+ import static org .assertj .core .api .Assertions .assertThat ;
12+
13+ public class ZookeeperContainerTest {
14+
15+ private static final int ZOOKEEPER_PORT = 2181 ;
16+
17+ @ Test
18+ public void test () throws Exception {
19+ String path = "/messages/zk-tc" ;
20+ String content = "Running Zookeeper with Testcontainers" ;
21+ try (
22+ GenericContainer <?> zookeeper = new GenericContainer <>("zookeeper:3.8.0" ).withExposedPorts (ZOOKEEPER_PORT )
23+ ) {
24+ zookeeper .start ();
25+
26+ String connectionString = zookeeper .getHost () + ":" + zookeeper .getMappedPort (ZOOKEEPER_PORT );
27+ CuratorFramework curatorFramework = CuratorFrameworkFactory
28+ .builder ()
29+ .connectString (connectionString )
30+ .retryPolicy (new RetryOneTime (100 ))
31+ .build ();
32+ curatorFramework .start ();
33+ curatorFramework .create ().creatingParentsIfNeeded ().forPath (path , content .getBytes ());
34+
35+ byte [] bytes = curatorFramework .getData ().forPath (path );
36+ curatorFramework .close ();
37+
38+ assertThat (new String (bytes , StandardCharsets .UTF_8 )).isEqualTo (content );
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ <configuration >
2+
3+ <appender name =" STDOUT" class =" ch.qos.logback.core.ConsoleAppender" >
4+ <!-- encoders are assigned the type
5+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
6+ <encoder >
7+ <pattern >%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern >
8+ </encoder >
9+ </appender >
10+
11+ <root level =" INFO" >
12+ <appender-ref ref =" STDOUT" />
13+ </root >
14+
15+ <logger name =" org.testcontainers" level =" INFO" />
16+ </configuration >
You can’t perform that action at this time.
0 commit comments