Skip to content

Commit c6e0cd9

Browse files
bsideupdaschlkiview
authored
Rewrite Couchbase module. closes testcontainers#2447 (testcontainers#2491)
* Rewrite couchbase module. closes testcontainers#2447 This changeset completely reworks the couchbase module and hopefully greatly improve the out-of-the-box experience. Note that this is a breaking change over the previous code because by intention it does NOT depend on SDK 2 so you can test SDK 2 and 3 with it at the same time. Highlights: - Removed the need for a SDK, so both 2 and 3 can be used with it. - Updated to 6.5.0 baseline and using alternate addresses for "proper" port exposure without having to rely on the socat proxy container like the previous version had to. - Allows to define which services should be exposed and handles states automatically (i.e. will not try to create the primary index if the query service is not enabled). Note that a bunch of tests have been removed since they are not adequate anymore. A side effect of the alternate address change is that older servers cannot be used. 6.5.0 is available in both CE and EE, and Couchbase in general allows EE versions to be used in development and testing so we should use it if we can. * Wait until query respsonds with 200 * fixes * add `getBootstrap*DirectPort()` methods, review fixes * Restore `getConnectionString()` * Apply suggestions from code review Co-Authored-By: Kevin Wittek <[email protected]> * Update docs * Update docs (2) Co-authored-by: Michael Nitschinger <[email protected]> Co-authored-by: Kevin Wittek <[email protected]>
1 parent 631a3f4 commit c6e0cd9

File tree

13 files changed

+530
-708
lines changed

13 files changed

+530
-708
lines changed

docs/modules/databases/couchbase.md

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,25 @@ Testcontainers module for Couchbase. [Couchbase](https://www.couchbase.com/) is
88

99
Running Couchbase as a stand-in in a test:
1010

11-
### Create your own bucket
12-
13-
```java
14-
public class SomeTest {
15-
16-
@Rule
17-
public CouchbaseContainer couchbase = new CouchbaseContainer()
18-
.withClusterAdmin("admin", "secret")
19-
.withNewBucket(DefaultBucketSettings.builder()
20-
.enableFlush(true)
21-
.name("bucket-name")
22-
.password("secret")
23-
.quota(100)
24-
.type(BucketType.COUCHBASE)
25-
.build());
26-
27-
@Test
28-
public void someTestMethod() {
29-
Bucket bucket = couchbase.getCouchbaseCluster().openBucket("bucket-name");
30-
31-
// ... interact with client as if using Couchbase normally
32-
}
33-
}
34-
```
35-
36-
### Use preconfigured default bucket
37-
38-
Bucket is cleared after each test
39-
40-
```java
41-
public class SomeTest extends AbstractCouchbaseTest {
42-
43-
@Test
44-
public void someTestMethod() {
45-
Bucket bucket = getBucket();
46-
47-
// ... interact with client as if using Couchbase normally
48-
}
49-
}
50-
```
51-
52-
### Special consideration
53-
54-
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:
55-
56-
- **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-))
57-
- **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-))
58-
- **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-))
59-
- **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-))
60-
61-
All other ports cannot be changed by Java SDK, there are sadly fixed:
62-
63-
- **8092** : Queries, views, XDCR
64-
- **8093** : REST/HTTP Query service
65-
- **8094** : REST/HTTP Search Service
66-
- **8095** : REST/HTTP Analytic service
67-
68-
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.
69-
11+
1. Define a bucket:
12+
<!--codeinclude-->
13+
[Bucket Definition](../../../modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java) inside_block:bucket_definition
14+
<!--/codeinclude-->
15+
16+
2. define a container:
17+
<!--codeinclude-->
18+
[Container definition](../../../modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java) inside_block:container_definition
19+
<!--/codeinclude-->
20+
21+
3. create an environment & cluster:
22+
<!--codeinclude-->
23+
[Cluster creation](../../../modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java) inside_block:cluster_creation
24+
<!--/codeinclude-->
25+
26+
4. authenticate:
27+
<!--codeinclude-->
28+
[Authentication](../../../modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java) inside_block:auth
29+
<!--/codeinclude-->
7030

7131
## Adding this module to your project dependencies
7232

modules/couchbase/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ description = "Testcontainers :: Couchbase"
22

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

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

modules/couchbase/src/main/java/org/testcontainers/couchbase/AbstractCouchbaseTest.java

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2020 Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.testcontainers.couchbase;
18+
19+
/**
20+
* Allows to configure the properties of a bucket that should be created.
21+
*/
22+
public class BucketDefinition {
23+
24+
private final String name;
25+
private boolean queryPrimaryIndex = true;
26+
private int quota = 100;
27+
28+
public BucketDefinition(final String name) {
29+
this.name = name;
30+
}
31+
32+
/**
33+
* Sets a custom bucket quota (100MB by default).
34+
*
35+
* @param quota the quota to set for the bucket.
36+
* @return this {@link BucketDefinition} for chaining purposes.
37+
*/
38+
public BucketDefinition withQuota(final int quota) {
39+
if (quota < 100) {
40+
throw new IllegalArgumentException("Bucket quota cannot be less than 100MB!");
41+
}
42+
this.quota = quota;
43+
return this;
44+
}
45+
46+
/**
47+
* Allows to disable creating a primary index for this bucket (enabled by default).
48+
*
49+
* @param create if false, a primary index will not be created.
50+
* @return this {@link BucketDefinition} for chaining purposes.
51+
*/
52+
public BucketDefinition withPrimaryIndex(final boolean create) {
53+
this.queryPrimaryIndex = create;
54+
return this;
55+
}
56+
57+
public String getName() {
58+
return name;
59+
}
60+
61+
public boolean hasPrimaryIndex() {
62+
return queryPrimaryIndex;
63+
}
64+
65+
public int getQuota() {
66+
return quota;
67+
}
68+
69+
}

0 commit comments

Comments
 (0)