use of com.couchbase.client.java.search.result.SearchResult in project couchbase-jvm-clients by couchbase.
the class SearchTest method alltimeouts.
@Test
void alltimeouts() throws ExecutionException, InterruptedException, IOException {
InputStream json = getClass().getClassLoader().getResourceAsStream("sdk-testcases/search/alltimeouts.json");
SearchResult result = SearchMock.loadSearchTestCase(json);
assertEquals(6, result.metaData().errors().size());
assertEquals(6, result.metaData().metrics().errorPartitionCount());
assertEquals(6, result.metaData().metrics().totalPartitionCount());
assertEquals(0, result.metaData().metrics().successPartitionCount());
}
use of com.couchbase.client.java.search.result.SearchResult in project couchbase-jvm-clients by couchbase.
the class SearchIntegrationTest method simpleSearch.
@Test
void simpleSearch() throws Throwable {
String docId = UUID.randomUUID().toString();
MutationResult insertResult = collection.insert(docId, mapOf("name", "michael"));
try {
// should not have to retry here, but newly-created index is flaky
runWithRetry(Duration.ofSeconds(30), () -> {
SearchResult result = cluster.searchQuery(indexName, queryString("michael"), searchOptions().consistentWith(MutationState.from(insertResult.mutationToken().get())));
List<String> actualDocIds = result.rows().stream().map(SearchRow::id).collect(toList());
// make assertion inside the retry, because newly-created index sometimes returns
// no rows even though we specified mutation tokens for consistency :-/
assertEquals(listOf(docId), actualDocIds);
});
} finally {
collection.remove(docId);
}
}
use of com.couchbase.client.java.search.result.SearchResult in project couchbase-jvm-clients by couchbase.
the class SearchIntegrationTest method searchMatchOperatorOr.
@Test
void searchMatchOperatorOr() throws Throwable {
String docId1 = UUID.randomUUID().toString();
String docId2 = UUID.randomUUID().toString();
MutationResult insertResult1 = collection.insert(docId1, mapOf("name", "milly"));
MutationResult insertResult2 = collection.insert(docId2, mapOf("name", "tilly"));
try {
runWithRetry(Duration.ofSeconds(30), () -> {
SearchResult result = cluster.searchQuery(indexName, match("milly tilly").operator(MatchOperator.OR), searchOptions().consistentWith(MutationState.from(insertResult1.mutationToken().get(), insertResult2.mutationToken().get())));
List<String> actualDocIds = result.rows().stream().map(SearchRow::id).collect(toList());
assertEquals(listOf(docId1, docId2), actualDocIds);
});
} finally {
collection.remove(docId1);
collection.remove(docId2);
}
}
use of com.couchbase.client.java.search.result.SearchResult 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.search.result.SearchResult 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");
}
}
Aggregations