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