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));
}
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);
}
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());
}
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);
}
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");
}
}
Aggregations