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

Add support for community edition of couchbase server #4221

Merged
merged 1 commit into from
Jul 16, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
kiview marked this conversation as resolved.
Show resolved Hide resolved
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