Search in sources :

Example 36 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.

the class RateLimitingIntegrationTest method searchRateLimitMaxIngress.

@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchRateLimitMaxIngress() throws Exception {
    String username = "searchRateLimitIngress";
    Limits limits = new Limits();
    limits.searchLimits = new SearchLimits(10, 100, 1, 10);
    createRateLimitedUser(username, limits);
    adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits-ingress", config().bucketname()));
    Cluster cluster = createTestCluster(username);
    try {
        cluster.waitUntilReady(Duration.ofSeconds(10));
        String content = repeatString(1024 * 1024, "a");
        RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
            for (int i = 0; i < 10; i++) {
                try {
                    SearchResult res = cluster.searchQuery("ratelimits-ingress", QueryStringQuery.match(content), SearchOptions.searchOptions().timeout(Duration.ofSeconds(10)).limit(1));
                } catch (TimeoutException e) {
                // continue
                } catch (CouchbaseException e) {
                    if (e.getMessage().contains("no planPIndexes")) {
                        continue;
                    }
                    throw e;
                }
            }
        });
        assertTrue(ex.getMessage().contains("ingress_mib_per_min"));
    } finally {
        cluster.disconnect();
        adminCluster.users().dropUser(username);
        adminCluster.searchIndexes().dropIndex("ratelimits-ingress");
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) SearchResult(com.couchbase.client.java.search.result.SearchResult) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) TimeoutException(com.couchbase.client.core.error.TimeoutException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 37 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.

the class RateLimitingIntegrationTest method searchRateLimitMaxCommands.

@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchRateLimitMaxCommands() throws Exception {
    String username = "searchRateLimit";
    Limits limits = new Limits();
    limits.searchLimits = new SearchLimits(10, 1, 10, 10);
    createRateLimitedUser(username, limits);
    adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits", config().bucketname()));
    Cluster cluster = createTestCluster(username);
    try {
        cluster.waitUntilReady(Duration.ofSeconds(10));
        RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
            for (int i = 0; i < 50; i++) {
                try {
                    cluster.searchQuery("ratelimits", QueryStringQuery.queryString("a"), SearchOptions.searchOptions().timeout(Duration.ofSeconds(1)));
                } catch (TimeoutException e) {
                // continue
                } catch (CouchbaseException e) {
                    if (e.getMessage().contains("no planPIndexes")) {
                        continue;
                    }
                    throw e;
                }
            }
        });
        assertTrue(ex.getMessage().contains("num_queries_per_min"));
    } finally {
        cluster.disconnect();
        adminCluster.users().dropUser(username);
        adminCluster.searchIndexes().dropIndex("ratelimits");
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) TimeoutException(com.couchbase.client.core.error.TimeoutException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 38 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.

the class RateLimitingIntegrationTest method searchRateLimitMaxEgress.

@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchRateLimitMaxEgress() throws Exception {
    String username = "searchRateLimitEgress";
    Limits limits = new Limits();
    limits.searchLimits = new SearchLimits(10, 100, 10, 1);
    createRateLimitedUser(username, limits);
    adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits-egress", config().bucketname()));
    Cluster cluster = createTestCluster(username);
    try {
        cluster.waitUntilReady(Duration.ofSeconds(10));
        String content = repeatString(1024 * 1024, "a");
        MutationResult mutationResult = cluster.bucket(config().bucketname()).defaultCollection().upsert("fts-egress", JsonObject.create().put("content", content), UpsertOptions.upsertOptions().timeout(Duration.ofSeconds(10)));
        RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
            for (int i = 0; i < 10; i++) {
                try {
                    cluster.searchQuery("ratelimits-egress", SearchQuery.wildcard("a*"), SearchOptions.searchOptions().timeout(Duration.ofSeconds(10)).fields("content").consistentWith(MutationState.from(mutationResult.mutationToken().get())).highlight(HighlightStyle.HTML, "content"));
                } catch (TimeoutException e) {
                // continue
                } catch (CouchbaseException e) {
                    if (e.getMessage().contains("no planPIndexes")) {
                        continue;
                    }
                    throw e;
                }
            }
        });
        assertTrue(ex.getMessage().contains("egress_mib_per_min"));
    } finally {
        cluster.disconnect();
        adminCluster.users().dropUser(username);
        adminCluster.searchIndexes().dropIndex("ratelimits-egress");
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) MutationResult(com.couchbase.client.java.kv.MutationResult) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) TimeoutException(com.couchbase.client.core.error.TimeoutException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 39 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.

the class Sdk2CompatibleLegacyTranscoder method decode.

@Override
@SuppressWarnings("unchecked")
public <T> T decode(final Class<T> target, byte[] input, final int flags) {
    Object decoded;
    if ((flags & COMPRESSED) != 0) {
        input = decompress(input);
    }
    int maskedFlags = flags & SPECIAL_MASK;
    if ((flags & SERIALIZED) != 0 && input != null) {
        decoded = deserialize(input);
    } else if (maskedFlags != 0 && input != null) {
        switch(maskedFlags) {
            case SPECIAL_BOOLEAN:
                decoded = input[0] == '1';
                break;
            case SPECIAL_INT:
                decoded = (int) decodeLong(input);
                break;
            case SPECIAL_LONG:
                decoded = decodeLong(input);
                break;
            case SPECIAL_DATE:
                decoded = new Date(decodeLong(input));
                break;
            case SPECIAL_BYTE:
                decoded = input[0];
                break;
            case SPECIAL_FLOAT:
                decoded = Float.intBitsToFloat((int) decodeLong(input));
                break;
            case SPECIAL_DOUBLE:
                decoded = Double.longBitsToDouble(decodeLong(input));
                break;
            case SPECIAL_BYTEARRAY:
                decoded = input;
                break;
            default:
                throw new CouchbaseException("Undecodeable with flags " + flags);
        }
    } else {
        decoded = new String(input, StandardCharsets.UTF_8);
    }
    return (T) decoded;
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) Date(java.util.Date)

Example 40 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.

the class CouchbaseArrayList method remove.

@Override
public E remove(int index) {
    // fail fast on negative values, as they are interpreted as "starting from the back of the array" otherwise
    if (index < 0) {
        throw new IndexOutOfBoundsException("Index: " + index);
    }
    String idx = "[" + index + "]";
    for (int i = 0; i < arrayListOptions.casMismatchRetries(); i++) {
        try {
            // this loop will allow us to _know_ what element we really did remove.
            LookupInResult current = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(idx)), lookupInOptions);
            long returnCas = current.cas();
            E result = current.contentAs(0, entityTypeClass);
            collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(idx)), arrayListOptions.mutateInOptions().cas(returnCas));
            return result;
        } catch (DocumentNotFoundException e) {
            // ArrayList will throw if underlying list was cleared before a remove.
            throw new IndexOutOfBoundsException("Index:" + index);
        } catch (CasMismatchException ex) {
        // will have to retry get-and-remove
        } catch (PathNotFoundException e) {
            throw new IndexOutOfBoundsException("Index: " + index);
        }
    }
    throw new CouchbaseException("CouchbaseArrayList remove failed", new RetryExhaustedException("Couldn't perform remove in less than " + arrayListOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
Also used : LookupInResult(com.couchbase.client.java.kv.LookupInResult) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) RetryExhaustedException(com.couchbase.client.core.retry.reactor.RetryExhaustedException) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) PathNotFoundException(com.couchbase.client.core.error.subdoc.PathNotFoundException)

Aggregations

CouchbaseException (com.couchbase.client.core.error.CouchbaseException)46 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)8 Test (org.junit.jupiter.api.Test)8 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)7 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)7 RetryExhaustedException (com.couchbase.client.core.retry.reactor.RetryExhaustedException)7 LookupInResult (com.couchbase.client.java.kv.LookupInResult)7 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)7 Duration (java.time.Duration)7 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)6 ArrayList (java.util.ArrayList)6 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)5 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)5 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)4 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)4 PathNotFoundException (com.couchbase.client.core.error.subdoc.PathNotFoundException)4 JsonObject (com.couchbase.client.java.json.JsonObject)4 SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)4 List (java.util.List)4 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)3