forked from testcontainers/testcontainers-java
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…tainers#2491)" This reverts commit c6e0cd9.
- Loading branch information
Showing
13 changed files
with
708 additions
and
530 deletions.
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
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
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.BucketSettings; | ||
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 org.junit.After; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Basic class that can be used for couchbase tests. It will clear the database after every test. | ||
*/ | ||
public abstract class AbstractCouchbaseTest { | ||
|
||
public static final String TEST_BUCKET = "test"; | ||
|
||
public static final String DEFAULT_PASSWORD = "password"; | ||
|
||
Bucket bucket; | ||
|
||
@After | ||
public void clear() { | ||
try { | ||
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(); | ||
} | ||
} finally { | ||
bucket.close(60, TimeUnit.SECONDS); | ||
bucket = null; | ||
} | ||
} | ||
|
||
protected abstract CouchbaseContainer getCouchbaseContainer(); | ||
|
||
protected static CouchbaseContainer initCouchbaseContainer(String imageName) { | ||
CouchbaseContainer couchbaseContainer = (imageName == null) ? new CouchbaseContainer() : new CouchbaseContainer(imageName); | ||
couchbaseContainer.withNewBucket(getDefaultBucketSettings()); | ||
return couchbaseContainer; | ||
} | ||
|
||
protected static BucketSettings getDefaultBucketSettings() { | ||
return DefaultBucketSettings.builder() | ||
.enableFlush(true) | ||
.name(TEST_BUCKET) | ||
.password(DEFAULT_PASSWORD) | ||
.quota(100) | ||
.replicas(0) | ||
.type(BucketType.COUCHBASE) | ||
.build(); | ||
} | ||
|
||
protected synchronized Bucket getBucket() { | ||
if (bucket == null) { | ||
bucket = openBucket(TEST_BUCKET, DEFAULT_PASSWORD); | ||
} | ||
return bucket; | ||
} | ||
|
||
private Bucket openBucket(String bucketName, String password) { | ||
CouchbaseCluster cluster = getCouchbaseContainer().getCouchbaseCluster(); | ||
return cluster.openBucket(bucketName, password); | ||
} | ||
} |
69 changes: 0 additions & 69 deletions
69
modules/couchbase/src/main/java/org/testcontainers/couchbase/BucketDefinition.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.