-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Couchbase module #688
Merged
Merged
Couchbase module #688
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8c9102d
First implementation
tchlyah 3f84f46
Activate primary index by default
tchlyah 7328c95
Add compatibility with Couchbase v5
tchlyah 16f9d42
Fix backward compatibility with older version
tchlyah 39e3167
Use more lombok annotations to reduce boilerplate code
tchlyah 6add329
Move src to modules/couchbase
tchlyah 5d01553
Add build with gradle
tchlyah 8934841
Replace shaded libraries with real ones
tchlyah bc45a31
Fix waiting for Couchbase start
tchlyah 96f71c8
Add AUTHORS and README
tchlyah ffc2488
Fix Couchbase version
tchlyah 50eeb6f
Add Cleanup lombok annotation to auto close resources
tchlyah 00232fe
Update README
tchlyah a1ae86b
Use new AbstractWaitStrategy implementation
tchlyah 666f092
Respect Codacy quality standards
tchlyah 6e45640
Some optimizations
tchlyah 3739a51
Update CHANGELOG
tchlyah cc51bce
Replace CouchbaseWaitStrategy by HttpWaitStrategy and ResponsePredicate
tchlyah 0661c3b
Merge branch 'master' into couchbase-module
bsideup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Tayeb Chlyah <tayebchlyah@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<img src="https://cdn.worldvectorlogo.com/logos/couchbase.svg" width="300" /> | ||
|
||
# TestContainers Couchbase Module | ||
Testcontainers module for Couchbase. [Couchbase](https://www.couchbase.com/) is a Document oriented NoSQL database. | ||
|
||
## Usage example | ||
|
||
Running Couchbase as a stand-in in a test: | ||
|
||
### Create you own bucket | ||
|
||
```java | ||
public class SomeTest { | ||
|
||
@Rule | ||
public CouchbaseContainer couchbase = new CouchbaseContainer() | ||
.withNewBucket(DefaultBucketSettings.builder() | ||
.enableFlush(true) | ||
.name('bucket-name') | ||
.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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
description = "Testcontainers :: Couchbase" | ||
|
||
dependencies { | ||
compile project(':testcontainers') | ||
compile 'com.couchbase.client:java-client:2.5.7' | ||
} |
59 changes: 59 additions & 0 deletions
59
modules/couchbase/src/main/java/org/testcontainers/couchbase/AbstractCouchbaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.testcontainers.couchbase; | ||
|
||
import com.couchbase.client.java.Bucket; | ||
import com.couchbase.client.java.CouchbaseCluster; | ||
import com.couchbase.client.java.bucket.BucketType; | ||
import com.couchbase.client.java.cluster.DefaultBucketSettings; | ||
import com.couchbase.client.java.query.N1qlParams; | ||
import com.couchbase.client.java.query.N1qlQuery; | ||
import com.couchbase.client.java.query.consistency.ScanConsistency; | ||
import lombok.Getter; | ||
import org.junit.After; | ||
|
||
/** | ||
* @author ctayeb | ||
*/ | ||
public abstract class AbstractCouchbaseTest { | ||
|
||
public static final String TEST_BUCKET = "test"; | ||
|
||
public static final String DEFAULT_PASSWORD = "password"; | ||
|
||
@Getter(lazy = true) | ||
private final static CouchbaseContainer couchbaseContainer = initCouchbaseContainer(); | ||
|
||
@Getter(lazy = true) | ||
private final static Bucket bucket = openBucket(TEST_BUCKET, DEFAULT_PASSWORD); | ||
|
||
@After | ||
public void clear() { | ||
if (getCouchbaseContainer().isIndex() && getCouchbaseContainer().isQuery() && getCouchbaseContainer().isPrimaryIndex()) { | ||
getBucket().query( | ||
N1qlQuery.simple(String.format("DELETE FROM `%s`", getBucket().name()), | ||
N1qlParams.build().consistency(ScanConsistency.STATEMENT_PLUS))); | ||
} else { | ||
getBucket().bucketManager().flush(); | ||
} | ||
} | ||
|
||
private static CouchbaseContainer initCouchbaseContainer() { | ||
CouchbaseContainer couchbaseContainer = new CouchbaseContainer() | ||
.withNewBucket(DefaultBucketSettings.builder() | ||
.enableFlush(true) | ||
.name(TEST_BUCKET) | ||
.password(DEFAULT_PASSWORD) | ||
.quota(100) | ||
.replicas(0) | ||
.type(BucketType.COUCHBASE) | ||
.build()); | ||
couchbaseContainer.start(); | ||
return couchbaseContainer; | ||
} | ||
|
||
private static Bucket openBucket(String bucketName, String password) { | ||
CouchbaseCluster cluster = getCouchbaseContainer().getCouchbaseCluster(); | ||
Bucket bucket = cluster.openBucket(bucketName, password); | ||
Runtime.getRuntime().addShutdownHook(new Thread(bucket::close)); | ||
return bucket; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compileOnly
perhaps?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couchbase java client is actually used, so if the client doesn't add this library, it won't run.
It is also used in test, it will force me to add testCompile.