Skip to content

Commit

Permalink
[Couchbase] Add support for Eventing service (#4953)
Browse files Browse the repository at this point in the history
  • Loading branch information
tchlyah committed Jan 31, 2022
1 parent 639fe41 commit 242dfde
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class CouchbaseContainer extends GenericContainer<CouchbaseContainer> {

private static final int ANALYTICS_SSL_PORT = 18095;

private static final int EVENTING_PORT = 8096;

private static final int EVENTING_SSL_PORT = 18096;

private static final int KV_PORT = 11210;

private static final int KV_SSL_PORT = 11207;
Expand Down Expand Up @@ -196,6 +200,17 @@ public CouchbaseContainer withAnalyticsService() {
return this;
}

/**
* Enables the eventing service which is not enabled by default.
*
* @return this {@link CouchbaseContainer} for chaining purposes.
*/
public CouchbaseContainer withEventingService() {
checkNotRunning();
this.enabledServices.add(CouchbaseService.EVENTING);
return this;
}

public final String getUsername() {
return username;
}
Expand Down Expand Up @@ -232,7 +247,9 @@ protected void configure() {
ANALYTICS_PORT,
ANALYTICS_SSL_PORT,
KV_PORT,
KV_SSL_PORT
KV_SSL_PORT,
EVENTING_PORT,
EVENTING_SSL_PORT
);

WaitAllStrategy waitStrategy = new WaitAllStrategy();
Expand Down Expand Up @@ -278,6 +295,16 @@ protected void configure() {
);
}

if (enabledServices.contains(CouchbaseService.EVENTING)) {
waitStrategy = waitStrategy.withStrategy(
new HttpWaitStrategy()
.forPath("/api/v1/config")
.forPort(EVENTING_PORT)
.withBasicCredentials(username, password)
.forStatusCode(200)
);
}

waitingFor(waitStrategy);
}

Expand Down Expand Up @@ -328,8 +355,13 @@ private void initializeIsEnterprise() {
throw new IllegalStateException("Couchbase /pools did not return valid JSON");
}

if (!isEnterprise && enabledServices.contains(CouchbaseService.ANALYTICS)) {
throw new IllegalStateException("The Analytics Service is only supported with the Enterprise version");
if (!isEnterprise) {
if (enabledServices.contains(CouchbaseService.ANALYTICS)) {
throw new IllegalStateException("The Analytics Service is only supported with the Enterprise version");
}
if (enabledServices.contains(CouchbaseService.EVENTING)) {
throw new IllegalStateException("The Eventing Service is only supported with the Enterprise version");
}
}
}

Expand Down Expand Up @@ -452,6 +484,11 @@ private void configureExternalPorts() {
builder.add("cbasSSL", Integer.toString(getMappedPort(ANALYTICS_SSL_PORT)));
}

if (enabledServices.contains(CouchbaseService.EVENTING)) {
builder.add("eventingAdminPort", Integer.toString(getMappedPort(EVENTING_PORT)));
builder.add("eventingSSL", Integer.toString(getMappedPort(EVENTING_SSL_PORT)));
}

@Cleanup Response response = doHttpRequest(
MGMT_PORT,
"/node/controller/setupAlternateAddresses/external",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public enum CouchbaseService {
/**
* Analytics service.
*/
ANALYTICS("cbas", 1024);
ANALYTICS("cbas", 1024),

/**
* Eventing service.
*/
EVENTING("eventing", 256);

private final String identifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
public class CouchbaseContainerTest {

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

@Test
public void testBasicContainerUsageForEnterpriseContainer() {
Expand Down Expand Up @@ -127,6 +127,20 @@ public void testFailureIfCommunityUsedWithAnalytics() {
}
}

/**
* Make sure that the code fails fast if the Eventing service is enabled on the community
* edition which is not supported.
*/
@Test
public void testFailureIfCommunityUsedWithEventing() {
try (
CouchbaseContainer container = new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY)
.withEnabledServices(CouchbaseService.KV, CouchbaseService.EVENTING)
) {
assertThrows(ContainerLaunchException.class, () -> setUpClient(container, cluster -> {}));
}
}

private void setUpClient(CouchbaseContainer container, Consumer<Cluster> consumer) {
container.start();

Expand Down

0 comments on commit 242dfde

Please sign in to comment.