Search in sources :

Example 1 with SearchIndex

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()));
}
Also used : SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with SearchIndex

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;
        }
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) SearchResult(com.couchbase.client.java.search.result.SearchResult)

Example 3 with SearchIndex

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");
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) SearchResult(com.couchbase.client.java.search.result.SearchResult) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) TimeoutException(com.couchbase.client.core.error.TimeoutException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with SearchIndex

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");
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) TimeoutException(com.couchbase.client.core.error.TimeoutException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with SearchIndex

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");
    }
}
Also used : SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)8 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)5 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)5 Test (org.junit.jupiter.api.Test)5 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)4 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)4 TimeoutException (com.couchbase.client.core.error.TimeoutException)3 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)3 SearchResult (com.couchbase.client.java.search.result.SearchResult)2 QuotaLimitedException (com.couchbase.client.core.error.QuotaLimitedException)1 Bucket (com.couchbase.client.java.Bucket)1 Cluster (com.couchbase.client.java.Cluster)1 JsonObject (com.couchbase.client.java.json.JsonObject)1 MutationResult (com.couchbase.client.java.kv.MutationResult)1 CollectionManager (com.couchbase.client.java.manager.collection.CollectionManager)1 CollectionSpec (com.couchbase.client.java.manager.collection.CollectionSpec)1 SearchIndexManager (com.couchbase.client.java.manager.search.SearchIndexManager)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1