Skip to content

Couchbase Module

Testcontainers module for Couchbase. Couchbase is a document oriented NoSQL database.

Usage example

Running Couchbase as a stand-in in a test:

Create your own bucket

public class SomeTest {

    @Rule
    public CouchbaseContainer couchbase = new CouchbaseContainer()
             .withClusterAdmin("admin", "secret")
             .withNewBucket(DefaultBucketSettings.builder()
                        .enableFlush(true)
                        .name("bucket-name")
                        .password("secret")
                        .quota(100)
                        .type(BucketType.COUCHBASE)
                        .build());

    @Test
    public void someTestMethod() {
        Bucket bucket = couchbase.getCouchbaseCluster().openBucket("bucket-name");

        // ... interact with client as if using Couchbase normally
    }
}

Use preconfigured default bucket

Bucket is cleared after each test

public class SomeTest extends AbstractCouchbaseTest {

    @Test
    public void someTestMethod() {
        Bucket bucket = getBucket();

        // ... interact with client as if using Couchbase normally
    }
}

Special consideration

Couchbase container is configured to use random available ports for some ports only, as Couchbase Java SDK permit to configure only some ports:

All other ports cannot be changed by Java SDK, there are sadly fixed:

  • 8092 : Queries, views, XDCR
  • 8093 : REST/HTTP Query service
  • 8094 : REST/HTTP Search Service
  • 8095 : REST/HTTP Analytic service

So if you disable Query, Search and Analytic service, you can run multiple instance of this container, otherwise, you're stuck with one instance, for now.

Adding this module to your project dependencies

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

testCompile "org.testcontainers:couchbase:1.11.2"
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>couchbase</artifactId>
    <version>1.11.2</version>
    <scope>test</scope>
</dependency>