Search in sources :

Example 1 with FeatureNotAvailableException

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);
}
Also used : FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) ExecutionException(java.util.concurrent.ExecutionException) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with 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());
}
Also used : FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) BucketConfig(com.couchbase.client.core.config.BucketConfig) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 3 with FeatureNotAvailableException

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);
    }
}
Also used : CompositeByteBuf(com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf) FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) CompositeByteBuf(com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) DocumentTooDeepException(com.couchbase.client.core.error.subdoc.DocumentTooDeepException) XattrInvalidKeyComboException(com.couchbase.client.core.error.subdoc.XattrInvalidKeyComboException) DocumentNotJsonException(com.couchbase.client.core.error.subdoc.DocumentNotJsonException) FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) DocumentAlreadyAliveException(com.couchbase.client.core.error.subdoc.DocumentAlreadyAliveException)

Example 4 with FeatureNotAvailableException

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);
}
Also used : FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) ExecutionException(java.util.concurrent.ExecutionException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with 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;
}
Also used : FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) ReplicaNotConfiguredException(com.couchbase.client.core.error.ReplicaNotConfiguredException)

Aggregations

FeatureNotAvailableException (com.couchbase.client.core.error.FeatureNotAvailableException)7 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)3 Test (org.junit.jupiter.api.Test)3 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)2 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)2 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)2 InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)2 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)2 Core (com.couchbase.client.core.Core)1 CbTracing (com.couchbase.client.core.cnc.CbTracing)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 TypeReference (com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)1 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)1 CompositeByteBuf (com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf)1 HttpHeaderNames (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpHeaderNames)1 CoreHttpClient (com.couchbase.client.core.endpoint.http.CoreHttpClient)1 CoreHttpPath.path (com.couchbase.client.core.endpoint.http.CoreHttpPath.path)1 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)1