Search in sources :

Example 6 with TimeoutException

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

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

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

the class KeyValueErrorIntegrationTest method verifyGetAndLockDoubleLock.

/**
 * The mock still returns tmpfail but we want to check that the rerty reason is actually locked as it should
 * be post 5.0.
 */
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void verifyGetAndLockDoubleLock() {
    String validId = UUID.randomUUID().toString();
    collection.upsert(validId, JsonObject.create());
    collection.getAndLock(validId, Duration.ofSeconds(5));
    TimeoutException exception = assertThrows(TimeoutException.class, () -> collection.getAndLock(validId, Duration.ofSeconds(5), getAndLockOptions().timeout(Duration.ofSeconds(1))));
    assertTrue(exception.context().requestContext().retryReasons().contains(RetryReason.KV_LOCKED));
}
Also used : 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 9 with TimeoutException

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

the class KeyValueIntegrationTest method getAndLock.

/**
 * We need to ignore this test on the mock because the mock returns TMPFAIL instead of LOCKED when the
 * document is locked (which used to be the old functionality but now since XERROR is negotiated it
 * returns LOCKED properly).
 *
 * <p>Once the mock is modified to return LOCKED, this test can also be run on the mock again.</p>
 */
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void getAndLock() {
    String id = UUID.randomUUID().toString();
    JsonObject expected = JsonObject.create().put("foo", true);
    MutationResult insert = collection.insert(id, expected);
    assertTrue(insert.cas() != 0);
    GetResult getAndLock = collection.getAndLock(id, Duration.ofSeconds(30));
    assertTrue(getAndLock.cas() != 0);
    assertNotEquals(insert.cas(), getAndLock.cas());
    assertEquals(expected, getAndLock.contentAsObject());
    TimeoutException exception = assertThrows(TimeoutException.class, () -> collection.getAndLock(id, Duration.ofSeconds(30), getAndLockOptions().timeout(Duration.ofMillis(100))));
    assertEquals(EnumSet.of(RetryReason.KV_LOCKED), exception.context().requestContext().retryReasons());
    assertThrows(DocumentNotFoundException.class, () -> collection.getAndLock("some_doc", Duration.ofSeconds(30)));
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) 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

TimeoutException (com.couchbase.client.core.error.TimeoutException)9 Test (org.junit.jupiter.api.Test)9 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)8 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)7 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)3 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)3 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)3 MutationResult (com.couchbase.client.java.kv.MutationResult)3 SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)3 JsonObject (com.couchbase.client.java.json.JsonObject)2 GetResult (com.couchbase.client.java.kv.GetResult)2 ExecutionException (java.util.concurrent.ExecutionException)2 RequestCanceledException (com.couchbase.client.core.error.RequestCanceledException)1 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)1 CancellationReason (com.couchbase.client.core.msg.CancellationReason)1 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)1 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)1 SearchResult (com.couchbase.client.java.search.result.SearchResult)1