Skip to content

Commit 1f3a1f7

Browse files
authored
couchbase: allow to configure bucket replicas and default to 0. (#5840)
This change allows the user to configure the number of bucket replicas and defaults it to 0 since most of the time the user ever only needs no replicas since it is a single container. Note: technically this is a behavioral change since before the number of replicas was 1 (if not defined) but this causes issues when testing transactions (as seen in #5835). Fixes #5835
1 parent 6e46662 commit 1f3a1f7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,32 @@ public class BucketDefinition {
2929

3030
private int quota = 100;
3131

32+
private int numReplicas = 0;
33+
3234
public BucketDefinition(final String name) {
3335
this.name = name;
3436
}
3537

38+
/**
39+
* Allows to configure the number of replicas on a bucket (defaults to 0).
40+
* <p>
41+
* By default the bucket is initialized with 0 replicas since only a single container is launched. Modifying
42+
* this value can still be useful in some test scenarios (i.e. to test failures with the wrong number of replicas
43+
* and durability requirements on operations).
44+
* <p>
45+
* Couchbase buckets can have a maximum of three replicas configured.
46+
*
47+
* @param numReplicas the number of replicas to configure.
48+
* @return this {@link BucketDefinition} for chaining purposes.
49+
*/
50+
public BucketDefinition withReplicas(final int numReplicas) {
51+
if (numReplicas < 0 || numReplicas > 3) {
52+
throw new IllegalArgumentException("The number of replicas must be between 0 and 3 (inclusive)");
53+
}
54+
this.numReplicas = numReplicas;
55+
return this;
56+
}
57+
3658
/**
3759
* Enables flush for this bucket (disabled by default).
3860
*
@@ -45,9 +67,9 @@ public BucketDefinition withFlushEnabled(final boolean flushEnabled) {
4567
}
4668

4769
/**
48-
* Sets a custom bucket quota (100MB by default).
70+
* Sets a custom bucket quota (100MiB by default).
4971
*
50-
* @param quota the quota to set for the bucket.
72+
* @param quota the quota to set for the bucket in mebibytes.
5173
* @return this {@link BucketDefinition} for chaining purposes.
5274
*/
5375
public BucketDefinition withQuota(final int quota) {
@@ -84,4 +106,8 @@ public boolean hasPrimaryIndex() {
84106
public int getQuota() {
85107
return quota;
86108
}
109+
110+
public int getNumReplicas() {
111+
return numReplicas;
112+
}
87113
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ private void createBuckets() {
573573
.add("name", bucket.getName())
574574
.add("ramQuotaMB", Integer.toString(bucket.getQuota()))
575575
.add("flushEnabled", bucket.hasFlushEnabled() ? "1" : "0")
576+
.add("replicaNumber", Integer.toString(bucket.getNumReplicas()))
576577
.build(),
577578
true
578579
);

0 commit comments

Comments
 (0)