Skip to content

Commit 242dfde

Browse files
authored
[Couchbase] Add support for Eventing service (#4953)
1 parent 639fe41 commit 242dfde

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public class CouchbaseContainer extends GenericContainer<CouchbaseContainer> {
7474

7575
private static final int ANALYTICS_SSL_PORT = 18095;
7676

77+
private static final int EVENTING_PORT = 8096;
78+
79+
private static final int EVENTING_SSL_PORT = 18096;
80+
7781
private static final int KV_PORT = 11210;
7882

7983
private static final int KV_SSL_PORT = 11207;
@@ -196,6 +200,17 @@ public CouchbaseContainer withAnalyticsService() {
196200
return this;
197201
}
198202

203+
/**
204+
* Enables the eventing service which is not enabled by default.
205+
*
206+
* @return this {@link CouchbaseContainer} for chaining purposes.
207+
*/
208+
public CouchbaseContainer withEventingService() {
209+
checkNotRunning();
210+
this.enabledServices.add(CouchbaseService.EVENTING);
211+
return this;
212+
}
213+
199214
public final String getUsername() {
200215
return username;
201216
}
@@ -232,7 +247,9 @@ protected void configure() {
232247
ANALYTICS_PORT,
233248
ANALYTICS_SSL_PORT,
234249
KV_PORT,
235-
KV_SSL_PORT
250+
KV_SSL_PORT,
251+
EVENTING_PORT,
252+
EVENTING_SSL_PORT
236253
);
237254

238255
WaitAllStrategy waitStrategy = new WaitAllStrategy();
@@ -278,6 +295,16 @@ protected void configure() {
278295
);
279296
}
280297

298+
if (enabledServices.contains(CouchbaseService.EVENTING)) {
299+
waitStrategy = waitStrategy.withStrategy(
300+
new HttpWaitStrategy()
301+
.forPath("/api/v1/config")
302+
.forPort(EVENTING_PORT)
303+
.withBasicCredentials(username, password)
304+
.forStatusCode(200)
305+
);
306+
}
307+
281308
waitingFor(waitStrategy);
282309
}
283310

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

331-
if (!isEnterprise && enabledServices.contains(CouchbaseService.ANALYTICS)) {
332-
throw new IllegalStateException("The Analytics Service is only supported with the Enterprise version");
358+
if (!isEnterprise) {
359+
if (enabledServices.contains(CouchbaseService.ANALYTICS)) {
360+
throw new IllegalStateException("The Analytics Service is only supported with the Enterprise version");
361+
}
362+
if (enabledServices.contains(CouchbaseService.EVENTING)) {
363+
throw new IllegalStateException("The Eventing Service is only supported with the Enterprise version");
364+
}
333365
}
334366
}
335367

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

487+
if (enabledServices.contains(CouchbaseService.EVENTING)) {
488+
builder.add("eventingAdminPort", Integer.toString(getMappedPort(EVENTING_PORT)));
489+
builder.add("eventingSSL", Integer.toString(getMappedPort(EVENTING_SSL_PORT)));
490+
}
491+
455492
@Cleanup Response response = doHttpRequest(
456493
MGMT_PORT,
457494
"/node/controller/setupAlternateAddresses/external",

modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public enum CouchbaseService {
4646
/**
4747
* Analytics service.
4848
*/
49-
ANALYTICS("cbas", 1024);
49+
ANALYTICS("cbas", 1024),
50+
51+
/**
52+
* Eventing service.
53+
*/
54+
EVENTING("eventing", 256);
5055

5156
private final String identifier;
5257

modules/couchbase/src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
public class CouchbaseContainerTest {
3636

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

4242
@Test
4343
public void testBasicContainerUsageForEnterpriseContainer() {
@@ -127,6 +127,20 @@ public void testFailureIfCommunityUsedWithAnalytics() {
127127
}
128128
}
129129

130+
/**
131+
* Make sure that the code fails fast if the Eventing service is enabled on the community
132+
* edition which is not supported.
133+
*/
134+
@Test
135+
public void testFailureIfCommunityUsedWithEventing() {
136+
try (
137+
CouchbaseContainer container = new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY)
138+
.withEnabledServices(CouchbaseService.KV, CouchbaseService.EVENTING)
139+
) {
140+
assertThrows(ContainerLaunchException.class, () -> setUpClient(container, cluster -> {}));
141+
}
142+
}
143+
130144
private void setUpClient(CouchbaseContainer container, Consumer<Cluster> consumer) {
131145
container.start();
132146

0 commit comments

Comments
 (0)