Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Couchbase module. closes #2447 #2491

Merged
merged 9 commits into from Apr 12, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 19 additions & 59 deletions docs/modules/databases/couchbase.md
Expand Up @@ -8,65 +8,25 @@ Testcontainers module for Couchbase. [Couchbase](https://www.couchbase.com/) is

Running Couchbase as a stand-in in a test:

### Create your own bucket

```java
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

```java
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](https://developer.couchbase.com/documentation/server/current/install/install-ports.html) for some ports only, as [Couchbase Java SDK](https://developer.couchbase.com/documentation/server/current/sdk/java/start-using-sdk.html) permit to configure only some ports:

- **8091** : REST/HTTP traffic ([bootstrapHttpDirectPort](http://docs.couchbase.com/sdk-api/couchbase-java-client-2.4.6/com/couchbase/client/java/env/DefaultCouchbaseEnvironment.Builder.html#bootstrapCarrierDirectPort-int-))
- **18091** : REST/HTTP traffic with SSL ([bootstrapHttpSslPort](http://docs.couchbase.com/sdk-api/couchbase-java-client-2.4.6/com/couchbase/client/java/env/DefaultCouchbaseEnvironment.Builder.html#bootstrapCarrierSslPort-int-))
- **11210** : memcached ([bootstrapCarrierDirectPort](http://docs.couchbase.com/sdk-api/couchbase-java-client-2.4.6/com/couchbase/client/java/env/DefaultCouchbaseEnvironment.Builder.html#bootstrapCarrierDirectPort-int-))
- **11207** : memcached SSL ([bootstrapCarrierSslPort](http://docs.couchbase.com/sdk-api/couchbase-java-client-2.4.6/com/couchbase/client/java/env/DefaultCouchbaseEnvironment.Builder.html#bootstrapCarrierSslPort-int-))

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.

1. Define a bucket:
<!--codeinclude-->
[Bucket Definition](../../../modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java) inside_block:bucket_definition
<!--/codeinclude-->

2. define a container:
<!--codeinclude-->
[Container definition](../../../modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java) inside_block:container_definition
<!--/codeinclude-->

3. create an environment & cluster:
<!--codeinclude-->
[Cluster creation](../../../modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java) inside_block:cluster_creation
<!--/codeinclude-->

4. authenticate:
<!--codeinclude-->
[Authentication](../../../modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java) inside_block:auth
<!--/codeinclude-->

## Adding this module to your project dependencies

Expand Down
3 changes: 1 addition & 2 deletions modules/couchbase/build.gradle
Expand Up @@ -2,7 +2,6 @@ description = "Testcontainers :: Couchbase"

dependencies {
compile project(':testcontainers')
compile 'com.couchbase.client:java-client:2.7.13'

testCompile project(':test-support')
testCompile 'com.couchbase.client:java-client:2.7.13'
}

This file was deleted.

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2020 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we add the original source of this file, for future reference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is invalid ;)

*/

package org.testcontainers.couchbase;

/**
* Allows to configure the properties of a bucket that should be created.
*/
public class BucketDefinition {

private final String name;
private boolean queryPrimaryIndex = true;
private int quota = 100;

public BucketDefinition(final String name) {
this.name = name;
}

/**
* Sets a custom bucket quota (100MB by default).
*
* @param quota the quota to set for the bucket.
* @return this {@link BucketDefinition} for chaining purposes.
*/
public BucketDefinition withQuota(final int quota) {
if (quota < 100) {
throw new IllegalArgumentException("Bucket quota cannot be less than 100MB!");
}
this.quota = quota;
return this;
}

/**
* Allows to disable creating a primary index for this bucket (enabled by default).
*
* @param create if false, a primary index will not be created.
* @return this {@link BucketDefinition} for chaining purposes.
*/
public BucketDefinition withPrimaryIndex(final boolean create) {
this.queryPrimaryIndex = create;
return this;
}

public String getName() {
return name;
}

public boolean hasPrimaryIndex() {
return queryPrimaryIndex;
}

public int getQuota() {
return quota;
}

}