use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method shortCircuitCollectionsIfNotAvailable.
@Test
@IgnoreWhen(hasCapabilities = { Capabilities.COLLECTIONS })
void shortCircuitCollectionsIfNotAvailable() {
String id = UUID.randomUUID().toString();
byte[] content = "hello, world".getBytes(UTF_8);
InsertRequest insertRequest = new InsertRequest(id, content, 0, 0, kvTimeout, core.context(), new CollectionIdentifier(config().bucketname(), Optional.of(CollectionIdentifier.DEFAULT_SCOPE), Optional.of("my_collection_name")), env.retryStrategy(), Optional.empty(), null);
core.send(insertRequest);
ExecutionException exception = assertThrows(ExecutionException.class, () -> insertRequest.response().get());
assertTrue(exception.getCause() instanceof FeatureNotAvailableException);
InsertRequest insertRequest2 = new InsertRequest(id, content, 0, 0, kvTimeout, core.context(), new CollectionIdentifier(config().bucketname(), Optional.of("my_custom_scope"), Optional.of(CollectionIdentifier.DEFAULT_COLLECTION)), env.retryStrategy(), Optional.empty(), null);
core.send(insertRequest2);
exception = assertThrows(ExecutionException.class, () -> insertRequest2.response().get());
assertTrue(exception.getCause() instanceof FeatureNotAvailableException);
}
use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.
the class Observe method poll.
public static Mono<Void> poll(final ObserveContext ctx) {
if (ctx.persistTo() == ObservePersistTo.NONE && ctx.replicateTo() == ObserveReplicateTo.NONE) {
return Mono.empty();
}
if (!ctx.environment().ioConfig().mutationTokensEnabled() || !ctx.mutationToken().isPresent()) {
return Mono.error(new FeatureNotAvailableException("To use PersistTo and/or ReplicateTo, mutation tokens must " + "be enabled on the IO configuration"));
}
final RequestSpan parentSpan = ctx.environment().requestTracer().requestSpan("observe", ctx.parentSpan());
Flux<ObserveItem> observed = Flux.defer(() -> {
BucketConfig config = ctx.core().clusterConfig().bucketConfig(ctx.collectionIdentifier().bucket());
return Flux.just(validateReplicas(config, ctx.persistTo(), ctx.replicateTo()));
}).flatMap(replicas -> viaMutationToken(replicas, ctx, parentSpan));
return maybeRetry(observed, ctx).timeout(ctx.timeout(), ctx.environment().scheduler()).doFinally(t -> parentSpan.end());
}
use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.
the class SubdocMutateRequest method encode.
@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
ByteBuf key = null;
ByteBuf extras = null;
ByteBuf content = null;
ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType, preserveExpiry);
try {
if (createAsDeleted && !ctx.createAsDeleted()) {
// It is left purely as an additional safety measure.
throw new FeatureNotAvailableException("Cannot use createAsDeleted Sub-Document flag, as it is not supported by this version of the cluster");
}
key = encodedKeyWithCollection(alloc, ctx);
extras = alloc.buffer();
if (expiration != 0) {
extras.writeInt((int) expiration);
}
if (flags != 0) {
extras.writeByte(flags);
}
if (commands.size() == 1) {
content = commands.get(0).encode(alloc);
} else {
content = alloc.compositeBuffer(commands.size());
for (Command command : commands) {
ByteBuf commandBuffer = command.encode(alloc);
try {
((CompositeByteBuf) content).addComponent(commandBuffer);
content.writerIndex(content.writerIndex() + commandBuffer.readableBytes());
} catch (Exception ex) {
ReferenceCountUtil.release(commandBuffer);
throw ex;
}
}
}
return flexibleRequest(alloc, Opcode.SUBDOC_MULTI_MUTATE, noDatatype(), partition(), opaque, cas, flexibleExtras, extras, key, content);
} finally {
ReferenceCountUtil.release(key);
ReferenceCountUtil.release(extras);
ReferenceCountUtil.release(flexibleExtras);
ReferenceCountUtil.release(content);
}
}
use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method failFastIfSyncReplicationNotAvailable.
@Test
@IgnoreWhen(hasCapabilities = { Capabilities.SYNC_REPLICATION })
void failFastIfSyncReplicationNotAvailable() {
String id = UUID.randomUUID().toString();
byte[] content = "hello, world".getBytes(UTF_8);
InsertRequest insertRequest = new InsertRequest(id, content, 0, 0, kvTimeout, core.context(), CollectionIdentifier.fromDefault(config().bucketname()), env.retryStrategy(), Optional.of(DurabilityLevel.MAJORITY), null);
core.send(insertRequest);
ExecutionException exception = assertThrows(ExecutionException.class, () -> insertRequest.response().get());
assertTrue(exception.getCause() instanceof FeatureNotAvailableException);
}
use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.
the class Observe method validateReplicas.
private static int validateReplicas(final BucketConfig bucketConfig, final ObservePersistTo persistTo, final ObserveReplicateTo replicateTo) {
if (!(bucketConfig instanceof CouchbaseBucketConfig)) {
throw new FeatureNotAvailableException("Only couchbase buckets support PersistTo and/or ReplicateTo");
}
CouchbaseBucketConfig cbc = (CouchbaseBucketConfig) bucketConfig;
int numReplicas = cbc.numberOfReplicas();
if (cbc.ephemeral() && persistTo.value() != 0) {
throw new FeatureNotAvailableException("Ephemeral Buckets do not support " + "PersistTo");
}
if (replicateTo.touchesReplica() && replicateTo.value() > numReplicas) {
throw new ReplicaNotConfiguredException("Not enough replicas configured on " + "the bucket");
}
if (persistTo.touchesReplica() && persistTo.value() - 1 > numReplicas) {
throw new ReplicaNotConfiguredException("Not enough replicas configured on " + "the bucket");
}
return numReplicas;
}
Aggregations