Search in sources :

Example 1 with TimeoutException

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

the class KeyValueErrorIntegrationTest method verifyTouchingLocked.

/**
 * 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 verifyTouchingLocked() {
    String validId = UUID.randomUUID().toString();
    collection.upsert(validId, JsonObject.create());
    collection.getAndLock(validId, Duration.ofSeconds(5));
    TimeoutException exception = assertThrows(TimeoutException.class, () -> collection.getAndTouch(validId, Duration.ofSeconds(2), getAndTouchOptions().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 2 with TimeoutException

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

the class CircuitBreakerIntegrationTest method shouldTriggerWithTimeouts.

@Test
void shouldTriggerWithTimeouts() {
    int threshold = collection.environment().ioConfig().kvCircuitBreakerConfig().volumeThreshold();
    int timeouts = 0;
    int cancellations = 0;
    for (int i = 0; i < threshold * 3; i++) {
        FailingGetRequestOnEncode request = new FailingGetRequestOnEncode("foo", Duration.ofMillis(1), collection.core().context(), new CollectionIdentifier(config().bucketname(), Optional.of(collection.scopeName()), Optional.of(collection.name())), FailFastRetryStrategy.INSTANCE);
        collection.core().send(request);
        try {
            request.response().get();
            fail();
        } catch (ExecutionException ex) {
            if (ex.getCause() instanceof TimeoutException) {
                timeouts++;
            } else if (ex.getCause() instanceof RequestCanceledException) {
                cancellations++;
                CancellationReason reason = ((RequestCanceledException) ex.getCause()).context().requestContext().request().cancellationReason();
                assertEquals(reason.innerReason(), RetryReason.ENDPOINT_CIRCUIT_OPEN);
            }
        } catch (Throwable t) {
            fail(t);
        }
    }
    assertTrue(timeouts > 0);
    assertTrue(cancellations > 0);
}
Also used : CancellationReason(com.couchbase.client.core.msg.CancellationReason) RequestCanceledException(com.couchbase.client.core.error.RequestCanceledException) ExecutionException(java.util.concurrent.ExecutionException) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) TimeoutException(com.couchbase.client.core.error.TimeoutException) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with TimeoutException

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

the class KeyValueIntegrationTest method unlock.

/**
 * The mock returns TMPFAIL instead of LOCKED, so this test is ignored on the mock.
 */
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void unlock() {
    String id = UUID.randomUUID().toString();
    MutationResult upsert = collection.upsert(id, JsonObject.create().put("foo", true));
    assertTrue(upsert.cas() != 0);
    GetResult locked = collection.getAndLock(id, Duration.ofSeconds(30));
    TimeoutException exception = assertThrows(TimeoutException.class, () -> collection.upsert(id, JsonObject.create(), upsertOptions().timeout(Duration.ofMillis(100))));
    assertEquals(EnumSet.of(RetryReason.KV_LOCKED), exception.context().requestContext().retryReasons());
    assertThrows(CasMismatchException.class, () -> collection.unlock(id, locked.cas() + 1));
    collection.unlock(id, locked.cas());
    JsonObject expected = JsonObject.create().put("foo", false);
    MutationResult replaced = collection.replace(id, expected);
    assertTrue(replaced.cas() != 0);
    assertEquals(expected, collection.get(id).contentAsObject());
}
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)

Example 4 with TimeoutException

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

the class KeyValueIntegrationTest method timesOutVeryLowTimeoutDurations.

/**
 * The timer wheel has a resolution if 100ms by default, so very low timeouts might go through and never have
 * a chance of getting into the next tick.
 *
 * <p>The code has additional checks in place to proactively check for such a timeout. This test makes sure that
 * super low timeouts always hit.</p>
 */
@Test
void timesOutVeryLowTimeoutDurations() {
    GetRequest getRequest = new GetRequest("foo", Duration.ofNanos(1), core.context(), CollectionIdentifier.fromDefault(config().bucketname()), env.retryStrategy(), null);
    core.send(getRequest);
    ExecutionException exception = assertThrows(ExecutionException.class, () -> getRequest.response().get());
    assertTrue(exception.getCause() instanceof TimeoutException);
}
Also used : GetRequest(com.couchbase.client.core.msg.kv.GetRequest) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(com.couchbase.client.core.error.TimeoutException) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with TimeoutException

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

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