use of com.couchbase.client.core.error.RateLimitedException in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method kvRateLimitEgress.
@Test
void kvRateLimitEgress() throws Exception {
String username = "kvRateLimitEgress";
Limits limits = new Limits();
limits.keyValueLimits = new KeyValueLimits(10, 100, 10, 1);
createRateLimitedUser(username, limits);
Cluster cluster = createTestCluster(username);
try {
Bucket bucket = cluster.bucket(config().bucketname());
Collection collection = bucket.defaultCollection();
bucket.waitUntilReady(Duration.ofSeconds(10));
collection.upsert("ratelimitegress", randomString(1024 * 512), UpsertOptions.upsertOptions().timeout(Duration.ofSeconds(5)));
collection.get("ratelimitegress");
collection.get("ratelimitegress");
RateLimitedException ex = assertThrows(RateLimitedException.class, () -> collection.get("ratelimitegress"));
assertTrue(ex.getMessage().contains("RATE_LIMITED_NETWORK_EGRESS"));
} finally {
cluster.disconnect();
adminCluster.users().dropUser(username);
}
}
use of com.couchbase.client.core.error.RateLimitedException in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method searchRateLimitConcurrentRequests.
@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchRateLimitConcurrentRequests() throws Exception {
String username = "searchRateLimitConcurrentRequests";
Limits limits = new Limits();
limits.searchLimits = new SearchLimits(1, 100, 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, () -> Flux.range(0, 50).flatMap(i -> cluster.reactive().searchQuery("ratelimits", QueryStringQuery.queryString("a"))).blockLast());
assertTrue(ex.getMessage().contains("num_concurrent_requests"));
} finally {
cluster.disconnect();
adminCluster.users().dropUser(username);
adminCluster.searchIndexes().dropIndex("ratelimits");
}
}
use of com.couchbase.client.core.error.RateLimitedException 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.RateLimitedException in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method queryRateLimitMaxCommands.
@Test
@IgnoreWhen(missesCapabilities = Capabilities.QUERY)
void queryRateLimitMaxCommands() throws Exception {
String username = "queryRateLimit";
Limits limits = new Limits();
limits.queryLimits = new QueryLimits(10, 1, 10, 10);
createRateLimitedUser(username, limits);
Cluster cluster = createTestCluster(username);
try {
cluster.waitUntilReady(Duration.ofSeconds(10));
RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
for (int i = 0; i < 50; i++) {
cluster.query("select 1 = 1");
}
});
assertTrue(ex.getMessage().contains("User has exceeded request rate limit"));
} finally {
cluster.disconnect();
adminCluster.users().dropUser(username);
}
}
Aggregations