Search in sources :

Example 6 with RateLimitedException

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

the class RateLimitingIntegrationTest method queryRateLimitEgress.

@Test
@IgnoreWhen(missesCapabilities = Capabilities.QUERY)
void queryRateLimitEgress() throws Exception {
    String username = "queryRateLimitEgress";
    Limits limits = new Limits();
    limits.queryLimits = new QueryLimits(10000, 10000, 10, 1);
    createRateLimitedUser(username, limits);
    Cluster cluster = createTestCluster(username);
    try {
        cluster.waitUntilReady(Duration.ofSeconds(10));
        String content = repeatString(1024 * 1024, "a");
        Collection collection = cluster.bucket(config().bucketname()).defaultCollection();
        collection.upsert("key1", content, UpsertOptions.upsertOptions().timeout(Duration.ofSeconds(5)));
        RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
            for (int i = 0; i < 50; i++) {
                cluster.query("SELECT * FROM `" + config().bucketname() + "` USE KEYS [\"key1\"]", QueryOptions.queryOptions().timeout(Duration.ofSeconds(15)));
            }
        });
        assertTrue(ex.getMessage().contains("User has exceeded results size limit"));
    } finally {
        cluster.disconnect();
        adminCluster.users().dropUser(username);
    }
}
Also used : RateLimitedException(com.couchbase.client.core.error.RateLimitedException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with RateLimitedException

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

the class RateLimitingIntegrationTest method clusterManagerRateLimitConcurrentRequests.

@Test
void clusterManagerRateLimitConcurrentRequests() throws Exception {
    String username = "clusterManagerRateLimitConcurrentRequests";
    Limits limits = new Limits();
    limits.clusterManagerLimits = new ClusterManagerLimits(1, 10, 10);
    createRateLimitedUser(username, limits);
    Cluster cluster = createTestCluster(username);
    try {
        cluster.waitUntilReady(Duration.ofSeconds(10));
        RateLimitedException ex = assertThrows(RateLimitedException.class, () -> Flux.range(0, 10).flatMap(i -> cluster.reactive().buckets().getAllBuckets()).blockLast());
        assertTrue(ex.getMessage().contains("Limit(s) exceeded [num_concurrent_requests]"));
    } finally {
        cluster.disconnect();
        adminCluster.users().dropUser(username);
    }
}
Also used : RateLimitedException(com.couchbase.client.core.error.RateLimitedException) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 8 with RateLimitedException

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

the class RateLimitingIntegrationTest method queryRateLimitConcurrentRequests.

@Test
@IgnoreWhen(missesCapabilities = Capabilities.QUERY)
void queryRateLimitConcurrentRequests() throws Exception {
    String username = "queryRateLimitConcurrentRequests";
    Limits limits = new Limits();
    limits.queryLimits = new QueryLimits(1, 100, 10, 10);
    createRateLimitedUser(username, limits);
    Cluster cluster = createTestCluster(username);
    try {
        cluster.waitUntilReady(Duration.ofSeconds(10));
        RateLimitedException ex = assertThrows(RateLimitedException.class, () -> Flux.range(0, 50).flatMap(i -> cluster.reactive().query("select 1=1")).blockLast());
        assertTrue(ex.getMessage().contains("User has more requests running than allowed"));
    } finally {
        cluster.disconnect();
        adminCluster.users().dropUser(username);
    }
}
Also used : RateLimitedException(com.couchbase.client.core.error.RateLimitedException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with RateLimitedException

use of com.couchbase.client.core.error.RateLimitedException 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 10 with RateLimitedException

use of com.couchbase.client.core.error.RateLimitedException 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)

Aggregations

RateLimitedException (com.couchbase.client.core.error.RateLimitedException)14 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)12 Test (org.junit.jupiter.api.Test)12 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)8 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)5 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)4 SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)4 TimeoutException (com.couchbase.client.core.error.TimeoutException)3 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)2 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)2 InternalServerFailureException (com.couchbase.client.core.error.InternalServerFailureException)2 QuotaLimitedException (com.couchbase.client.core.error.QuotaLimitedException)2 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)1 DmlFailureException (com.couchbase.client.core.error.DmlFailureException)1 DocumentExistsException (com.couchbase.client.core.error.DocumentExistsException)1 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)1 ErrorCodeAndMessage (com.couchbase.client.core.error.ErrorCodeAndMessage)1 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)1 IndexFailureException (com.couchbase.client.core.error.IndexFailureException)1 ParsingFailureException (com.couchbase.client.core.error.ParsingFailureException)1