Skip to content

Commit

Permalink
Add support for community edition of couchbase server (#4221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerschtli committed Jul 16, 2021
1 parent a4a475f commit 014500b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class CouchbaseContainer extends GenericContainer<CouchbaseContainer> {

private final List<BucketDefinition> buckets = new ArrayList<>();

private boolean isEnterprise = false;

/**
* Creates a new couchbase container with the default image and version.
* @deprecated use {@link CouchbaseContainer(DockerImageName)} instead
Expand Down Expand Up @@ -220,6 +222,7 @@ protected void containerIsStarting(final InspectContainerResponse containerInfo)
logger().debug("Couchbase container is starting, performing configuration.");

waitUntilNodeIsOnline();
initializeIsEnterprise();
renameNode();
initializeServices();
configureAdminUser();
Expand All @@ -246,6 +249,19 @@ private void waitUntilNodeIsOnline() {
.waitUntilReady(this);
}

/**
* Fetches edition (enterprise or community) of started container.
*/
private void initializeIsEnterprise() {
@Cleanup Response response = doHttpRequest(MGMT_PORT, "/pools", "GET", null, true);

try {
isEnterprise = MAPPER.readTree(response.body().string()).get("isEnterprise").asBoolean();
} catch (IOException e) {
throw new IllegalStateException("Couchbase /pools did not return valid JSON");
}
}

/**
* Rebinds/renames the internal hostname.
* <p>
Expand Down Expand Up @@ -349,7 +365,7 @@ private void configureIndexer() {
logger().debug("Configuring the indexer service");

@Cleanup Response response = doHttpRequest(MGMT_PORT, "/settings/indexes", "POST", new FormBody.Builder()
.add("storageMode", "memory_optimized")
.add("storageMode", isEnterprise ? "memory_optimized" : "forestdb")
.build(), true
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@

public class CouchbaseContainerTest {

private static final DockerImageName COUCHBASE_IMAGE = DockerImageName.parse("couchbase/server:6.5.1");
private static final DockerImageName COUCHBASE_IMAGE_ENTERPRISE =
DockerImageName.parse("couchbase/server:enterprise-6.6.2");
private static final DockerImageName COUCHBASE_IMAGE_COMMUNITY =
DockerImageName.parse("couchbase/server:community-6.6.0");

@Test
public void testBasicContainerUsage() {
public void testBasicContainerUsageForEnterpriseContainer() {
// bucket_definition {
BucketDefinition bucketDefinition = new BucketDefinition("mybucket");
// }

try (
// container_definition {
CouchbaseContainer container = new CouchbaseContainer(COUCHBASE_IMAGE)
CouchbaseContainer container = new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE)
.withBucket(bucketDefinition)
// }
) {
Expand All @@ -61,13 +64,36 @@ public void testBasicContainerUsage() {
}
}

@Test
public void testBasicContainerUsageForCommunityContainer() {
BucketDefinition bucketDefinition = new BucketDefinition("mybucket");

try (
CouchbaseContainer container = new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY)
.withBucket(bucketDefinition)
) {
setUpClient(container, cluster -> {
Bucket bucket = cluster.bucket(bucketDefinition.getName());
bucket.waitUntilReady(Duration.ofSeconds(10L));

Collection collection = bucket.defaultCollection();

collection.upsert("foo", JsonObject.create().put("key", "value"));

JsonObject fooObject = collection.get("foo").contentAsObject();

assertEquals("value", fooObject.getString("key"));
});
}
}

@Test
public void testBucketIsFlushableIfEnabled() {
BucketDefinition bucketDefinition = new BucketDefinition("mybucket")
.withFlushEnabled(true);

try (
CouchbaseContainer container = new CouchbaseContainer(COUCHBASE_IMAGE)
CouchbaseContainer container = new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE)
.withBucket(bucketDefinition)
) {
setUpClient(container, cluster -> {
Expand Down

0 comments on commit 014500b

Please sign in to comment.