diff --git a/modules/couchbase/src/main/java/org/testcontainers/couchbase/BucketDefinition.java b/modules/couchbase/src/main/java/org/testcontainers/couchbase/BucketDefinition.java index ad666b4ffef..c698855927c 100644 --- a/modules/couchbase/src/main/java/org/testcontainers/couchbase/BucketDefinition.java +++ b/modules/couchbase/src/main/java/org/testcontainers/couchbase/BucketDefinition.java @@ -29,10 +29,32 @@ public class BucketDefinition { private int quota = 100; + private int numReplicas = 0; + public BucketDefinition(final String name) { this.name = name; } + /** + * Allows to configure the number of replicas on a bucket (defaults to 0). + *

+ * By default the bucket is initialized with 0 replicas since only a single container is launched. Modifying + * this value can still be useful in some test scenarios (i.e. to test failures with the wrong number of replicas + * and durability requirements on operations). + *

+ * Couchbase buckets can have a maximum of three replicas configured. + * + * @param numReplicas the number of replicas to configure. + * @return this {@link BucketDefinition} for chaining purposes. + */ + public BucketDefinition withReplicas(final int numReplicas) { + if (numReplicas < 0 || numReplicas > 3) { + throw new IllegalArgumentException("The number of replicas must be between 0 and 3 (inclusive)"); + } + this.numReplicas = numReplicas; + return this; + } + /** * Enables flush for this bucket (disabled by default). * @@ -45,9 +67,9 @@ public BucketDefinition withFlushEnabled(final boolean flushEnabled) { } /** - * Sets a custom bucket quota (100MB by default). + * Sets a custom bucket quota (100MiB by default). * - * @param quota the quota to set for the bucket. + * @param quota the quota to set for the bucket in mebibytes. * @return this {@link BucketDefinition} for chaining purposes. */ public BucketDefinition withQuota(final int quota) { @@ -84,4 +106,8 @@ public boolean hasPrimaryIndex() { public int getQuota() { return quota; } + + public int getNumReplicas() { + return numReplicas; + } } diff --git a/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java b/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java index 8603a0b0787..2817b79d71f 100644 --- a/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java +++ b/modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java @@ -573,6 +573,7 @@ private void createBuckets() { .add("name", bucket.getName()) .add("ramQuotaMB", Integer.toString(bucket.getQuota())) .add("flushEnabled", bucket.hasFlushEnabled() ? "1" : "0") + .add("replicaNumber", Integer.toString(bucket.getNumReplicas())) .build(), true );