use of com.couchbase.client.java.manager.search.SearchIndex 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.java.manager.search.SearchIndex in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method searchQuotaLimitScopesMaxIndexes.
@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchQuotaLimitScopesMaxIndexes() throws Exception {
String scopeName = "ratelimitSearch";
String collectionName = "searchCollection";
ScopeRateLimits limits = new ScopeRateLimits();
limits.fts = new SearchScopeRateLimit(1);
createLimitedScope(scopeName, config().bucketname(), limits);
CollectionManager collectionManager = adminCluster.bucket(config().bucketname()).collections();
Map<String, Object> params = mapOf("mapping", mapOf("types", mapOf(scopeName + "." + collectionName, mapOf("enabled", true, "dynamic", true)), "default_mapping", mapOf("enabled", false), "default_type", "_default", "default_analyzer", "standard", "default_field", "_all"), "doc_config", mapOf("mode", "scope.collection.type_field", "type_field", "type"));
try {
CollectionSpec collectionSpec = CollectionSpec.create(collectionName, scopeName);
collectionManager.createCollection(collectionSpec);
waitUntilCondition(() -> collectionExists(collectionManager, collectionSpec));
waitForService(adminCluster.bucket(config().bucketname()), ServiceType.SEARCH);
adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits1", config().bucketname()).params(params));
QuotaLimitedException ex = assertThrows(QuotaLimitedException.class, () -> adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits2", config().bucketname()).params(params)));
} finally {
collectionManager.dropScope(scopeName);
}
}
use of com.couchbase.client.java.manager.search.SearchIndex in project couchbase-jvm-clients by couchbase.
the class SearchIndexManagement method main.
public static void main(String... args) throws Exception {
Cluster cluster = Cluster.connect("127.0.0.1", "Administrator", "password");
Bucket bucket = cluster.bucket("travel-sample");
/*
* Provides access to the index manager.
*/
SearchIndexManager manager = cluster.searchIndexes();
/*
* Loads an index from cluster if it exists (will fail otherwise).
*/
SearchIndex index = manager.getIndex("ts");
/*
* Replaces or inserts the loaded index on the server.
*/
manager.upsertIndex(index);
/*
* Drops an index.
*/
manager.dropIndex("ts");
}
Aggregations