use of com.couchbase.client.java.manager.search.SearchIndex in project couchbase-jvm-clients by couchbase.
the class SearchIntegrationTest method setup.
@BeforeAll
static void setup() {
cluster = Cluster.connect(seedNodes(), clusterOptions());
Bucket bucket = cluster.bucket(config().bucketname());
collection = bucket.defaultCollection();
bucket.waitUntilReady(Duration.ofSeconds(5));
waitForService(bucket, ServiceType.SEARCH);
cluster.searchIndexes().upsertIndex(new SearchIndex(indexName, config().bucketname()));
}
use of com.couchbase.client.java.manager.search.SearchIndex in project spring-data-couchbase by spring-projects.
the class JavaIntegrationTests method createFtsCollectionIndex.
public static void createFtsCollectionIndex(Cluster cluster, String indexName, String bucketName, String scopeName, String collectionName) {
SearchIndex searchIndex = new SearchIndex(indexName, bucketName);
if (scopeName != null) {
// searchIndex = searchIndex.forScopeCollection(scopeName, collectionName);
throw new RuntimeException("forScopeCollection not implemented in current java client version");
}
cluster.searchIndexes().upsertIndex(searchIndex, UpsertSearchIndexOptions.upsertSearchIndexOptions().timeout(Duration.ofSeconds(60)));
int maxTries = 5;
for (int i = 0; i < maxTries; i++) {
try {
SearchResult result = cluster.searchQuery(indexName, SearchQuery.queryString("junk"));
break;
} catch (CouchbaseException | IllegalStateException ex) {
// this is a pretty dirty hack to avoid a race where we don't know if the index is ready yet
if (i < (maxTries - 1) && (ex.getMessage().contains("no planPIndexes for indexName") || ex.getMessage().contains("pindex_consistency mismatched partition") || ex.getMessage().contains("pindex not available"))) {
sleepMs(1000);
continue;
}
throw ex;
}
}
}
use of com.couchbase.client.java.manager.search.SearchIndex 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");
}
}
use of com.couchbase.client.java.manager.search.SearchIndex 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.java.manager.search.SearchIndex 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");
}
}
Aggregations