Skip to content

Commit 93b8d04

Browse files
committed
update after namespace/api refactoring
1 parent f8c5e6d commit 93b8d04

File tree

3 files changed

+71
-64
lines changed

3 files changed

+71
-64
lines changed

test/test_integration_search.cxx

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
*/
1717

1818
#include "test_helper_integration.hxx"
19-
#include <couchbase/operations/management/collection_create.hxx>
20-
#include <couchbase/operations/management/search_index_drop.hxx>
21-
#include <couchbase/operations/management/search_index_get_documents_count.hxx>
22-
#include <couchbase/operations/management/search_index_upsert.hxx>
19+
20+
#include "core/operations/management/collection_create.hxx"
21+
#include "core/operations/management/search_index_drop.hxx"
22+
#include "core/operations/management/search_index_get_documents_count.hxx"
23+
#include "core/operations/management/search_index_upsert.hxx"
2324

2425
using Catch::Matchers::StartsWith;
2526

2627
void
27-
wait_until_indexed(std::shared_ptr<couchbase::cluster> cluster, const std::string& index_name, std::uint64_t expected_count)
28+
wait_until_indexed(std::shared_ptr<couchbase::core::cluster> cluster, const std::string& index_name, std::uint64_t expected_count)
2829
{
2930
auto indexed = test ::utils::wait_until([cluster = std::move(cluster), &index_name, &expected_count]() {
30-
couchbase::operations::management::search_index_get_documents_count_request req{};
31+
couchbase::core::operations::management::search_index_get_documents_count_request req{};
3132
req.index_name = index_name;
3233
req.timeout = std::chrono::seconds{ 1 };
3334
auto resp = test::utils::execute(cluster, req);
@@ -43,13 +44,14 @@ TEST_CASE("integration: search query")
4344
test::utils::open_bucket(integration.cluster, integration.ctx.bucket);
4445

4546
{
46-
auto sample_data = couchbase::utils::json::parse(couchbase::json_string(test::utils::read_test_data("search_beers_dataset.json")));
47+
auto sample_data =
48+
couchbase::core::utils::json::parse(couchbase::core::json_string(test::utils::read_test_data("search_beers_dataset.json")));
4749
auto const& o = sample_data.get_object();
4850
for (const auto& [key, value] : o) {
49-
couchbase::document_id id(integration.ctx.bucket, "_default", "_default", key);
50-
couchbase::operations::upsert_request req{ id, couchbase::utils::json::generate(value) };
51+
couchbase::core::document_id id(integration.ctx.bucket, "_default", "_default", key);
52+
couchbase::core::operations::upsert_request req{ id, couchbase::core::utils::json::generate_binary(value) };
5153
auto resp = test::utils::execute(integration.cluster, req);
52-
REQUIRE_FALSE(resp.ctx.ec);
54+
REQUIRE_FALSE(resp.ctx.ec());
5355
}
5456
}
5557

@@ -58,27 +60,27 @@ TEST_CASE("integration: search query")
5860
{
5961
auto params = test::utils::read_test_data("search_beers_index_params.json");
6062

61-
couchbase::management::search::index index{};
63+
couchbase::core::management::search::index index{};
6264
index.name = index_name;
6365
index.params_json = params;
6466
index.type = "fulltext-index";
6567
index.source_name = integration.ctx.bucket;
6668
index.source_type = "couchbase";
67-
couchbase::operations::management::search_index_upsert_request req{};
69+
couchbase::core::operations::management::search_index_upsert_request req{};
6870
req.index = index;
6971

7072
auto resp = test::utils::execute(integration.cluster, req);
71-
REQUIRE((!resp.ctx.ec || resp.ctx.ec == couchbase::error::common_errc::index_exists));
73+
REQUIRE((!resp.ctx.ec || resp.ctx.ec == couchbase::core::error::common_errc::index_exists));
7274
}
7375

74-
couchbase::json_string simple_query(R"({"query": "description:belgian"})");
76+
couchbase::core::json_string simple_query(R"({"query": "description:belgian"})");
7577

7678
std::uint64_t beer_sample_doc_count = 5;
7779
// Wait until expected documents are indexed
7880
{
7981
wait_until_indexed(integration.cluster, index_name, beer_sample_doc_count);
8082
auto ok = test::utils::wait_until([&]() {
81-
couchbase::operations::search_request req{};
83+
couchbase::core::operations::search_request req{};
8284
req.index_name = index_name;
8385
req.query = simple_query;
8486
auto resp = test::utils::execute(integration.cluster, req);
@@ -90,7 +92,7 @@ TEST_CASE("integration: search query")
9092

9193
SECTION("simple query")
9294
{
93-
couchbase::operations::search_request req{};
95+
couchbase::core::operations::search_request req{};
9496
req.index_name = index_name;
9597
req.query = simple_query;
9698
auto resp = test::utils::execute(integration.cluster, req);
@@ -110,7 +112,7 @@ TEST_CASE("integration: search query")
110112

111113
SECTION("limit")
112114
{
113-
couchbase::operations::search_request req{};
115+
couchbase::core::operations::search_request req{};
114116
req.index_name = index_name;
115117
req.query = simple_query;
116118
req.limit = 1;
@@ -121,7 +123,7 @@ TEST_CASE("integration: search query")
121123

122124
SECTION("skip")
123125
{
124-
couchbase::operations::search_request req{};
126+
couchbase::core::operations::search_request req{};
125127
req.index_name = index_name;
126128
req.query = simple_query;
127129
req.skip = 1;
@@ -133,7 +135,7 @@ TEST_CASE("integration: search query")
133135

134136
SECTION("explain")
135137
{
136-
couchbase::operations::search_request req{};
138+
couchbase::core::operations::search_request req{};
137139
req.index_name = index_name;
138140
req.query = simple_query;
139141
req.explain = true;
@@ -145,7 +147,7 @@ TEST_CASE("integration: search query")
145147
if (integration.cluster_version().supports_search_disable_scoring()) {
146148
SECTION("disable scoring")
147149
{
148-
couchbase::operations::search_request req{};
150+
couchbase::core::operations::search_request req{};
149151
req.index_name = index_name;
150152
req.query = simple_query;
151153
req.disable_scoring = true;
@@ -158,7 +160,7 @@ TEST_CASE("integration: search query")
158160

159161
SECTION("include locations")
160162
{
161-
couchbase::operations::search_request req{};
163+
couchbase::core::operations::search_request req{};
162164
req.index_name = index_name;
163165
req.query = simple_query;
164166
req.include_locations = true;
@@ -174,7 +176,7 @@ TEST_CASE("integration: search query")
174176

175177
SECTION("highlight fields default highlight style")
176178
{
177-
couchbase::operations::search_request req{};
179+
couchbase::core::operations::search_request req{};
178180
req.index_name = index_name;
179181
req.query = simple_query;
180182
req.highlight_fields = { "description" };
@@ -186,22 +188,22 @@ TEST_CASE("integration: search query")
186188
SECTION("highlight style")
187189
{
188190
{
189-
couchbase::operations::search_request req{};
191+
couchbase::core::operations::search_request req{};
190192
req.index_name = index_name;
191193
req.query = simple_query;
192194
req.highlight_fields = { "description" };
193-
req.highlight_style = couchbase::search_highlight_style::html;
195+
req.highlight_style = couchbase::core::search_highlight_style::html;
194196
auto resp = test::utils::execute(integration.cluster, req);
195197
REQUIRE_FALSE(resp.ctx.ec);
196198
REQUIRE(resp.rows[0].fragments["description"][0] == "A <mark>Belgian</mark> Double Abbey.");
197199
}
198200

199201
{
200-
couchbase::operations::search_request req{};
202+
couchbase::core::operations::search_request req{};
201203
req.index_name = index_name;
202204
req.query = simple_query;
203205
req.highlight_fields = { "description" };
204-
req.highlight_style = couchbase::search_highlight_style::ansi;
206+
req.highlight_style = couchbase::core::search_highlight_style::ansi;
205207
auto resp = test::utils::execute(integration.cluster, req);
206208
REQUIRE_FALSE(resp.ctx.ec);
207209
// TODO: is there a better way to compare ansi strings?
@@ -216,22 +218,22 @@ TEST_CASE("integration: search query")
216218

217219
SECTION("fields")
218220
{
219-
couchbase::operations::search_request req{};
221+
couchbase::core::operations::search_request req{};
220222
req.index_name = index_name;
221223
req.query = simple_query;
222224
req.fields.emplace_back("description");
223225
auto resp = test::utils::execute(integration.cluster, req);
224226
REQUIRE_FALSE(resp.ctx.ec);
225-
auto fields = couchbase::utils::json::parse(resp.rows[0].fields).get_object();
227+
auto fields = couchbase::core::utils::json::parse(resp.rows[0].fields).get_object();
226228
REQUIRE(fields.at("description").get_string() == "A Belgian Double Abbey.");
227229
}
228230

229231
SECTION("sort")
230232
{
231-
couchbase::operations::search_request req{};
233+
couchbase::core::operations::search_request req{};
232234
req.index_name = index_name;
233235
req.query = simple_query;
234-
req.sort_specs.emplace_back(couchbase::utils::json::generate("_score"));
236+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_score"));
235237
req.timeout = std::chrono::seconds(1);
236238
auto resp = test::utils::execute(integration.cluster, req);
237239
REQUIRE_FALSE(resp.ctx.ec);
@@ -240,7 +242,7 @@ TEST_CASE("integration: search query")
240242

241243
SECTION("term facet")
242244
{
243-
couchbase::operations::search_request req{};
245+
couchbase::core::operations::search_request req{};
244246
req.index_name = index_name;
245247
req.query = simple_query;
246248
req.facets.insert(std::make_pair("type", R"({"field": "type", "size": 1})"));
@@ -259,7 +261,7 @@ TEST_CASE("integration: search query")
259261

260262
SECTION("date range facet")
261263
{
262-
couchbase::operations::search_request req{};
264+
couchbase::core::operations::search_request req{};
263265
req.index_name = index_name;
264266
req.query = simple_query;
265267
req.facets.insert(std::make_pair(
@@ -286,7 +288,7 @@ TEST_CASE("integration: search query")
286288

287289
SECTION("numeric range facet")
288290
{
289-
couchbase::operations::search_request req{};
291+
couchbase::core::operations::search_request req{};
290292
req.index_name = index_name;
291293
req.query = simple_query;
292294
req.facets.insert(std::make_pair(
@@ -318,11 +320,11 @@ TEST_CASE("integration: search query")
318320

319321
SECTION("raw")
320322
{
321-
couchbase::operations::search_request req{};
323+
couchbase::core::operations::search_request req{};
322324
req.index_name = index_name;
323325
req.query = simple_query;
324-
std::map<std::string, couchbase::json_string> raw{};
325-
raw.insert(std::make_pair("size", couchbase::json_string("1")));
326+
std::map<std::string, couchbase::core::json_string> raw{};
327+
raw.insert(std::make_pair("size", couchbase::core::json_string("1")));
326328
req.raw = raw;
327329
auto resp = test::utils::execute(integration.cluster, req);
328330
REQUIRE_FALSE(resp.ctx.ec);
@@ -357,7 +359,7 @@ TEST_CASE("integration: search query consistency", "[integration]")
357359
auto index_name = test::utils::uniq_id("search_index");
358360

359361
{
360-
couchbase::management::search::index index{};
362+
couchbase::core::management::search::index index{};
361363
index.name = index_name;
362364
index.params_json = params;
363365
index.type = "fulltext-index";
@@ -366,7 +368,7 @@ TEST_CASE("integration: search query consistency", "[integration]")
366368
// TODO: there seems to be a server bug related to default number of partitions
367369
// remove when it is identified and fixed
368370
index.plan_params_json = R"({"indexPartitions": 1})";
369-
couchbase::operations::management::search_index_upsert_request req{};
371+
couchbase::core::operations::management::search_index_upsert_request req{};
370372
req.index = index;
371373
auto resp = test::utils::execute(integration.cluster, req);
372374
REQUIRE_FALSE(resp.ctx.ec);
@@ -375,26 +377,26 @@ TEST_CASE("integration: search query consistency", "[integration]")
375377
REQUIRE(test::utils::wait_for_search_pindexes_ready(integration.cluster, integration.ctx.bucket, index_name));
376378

377379
auto key = test::utils::uniq_id("key");
378-
auto id = couchbase::document_id(integration.ctx.bucket, "_default", "_default", key);
380+
auto id = couchbase::core::document_id(integration.ctx.bucket, "_default", "_default", key);
379381
auto value = test::utils::uniq_id("value");
380-
auto doc = couchbase::utils::json::generate(tao::json::value{
382+
auto doc = couchbase::core::utils::json::generate_binary(tao::json::value{
381383
{ "value", value },
382384
});
383385

384-
couchbase::mutation_token token;
386+
couchbase::core::mutation_token token;
385387

386388
{
387-
couchbase::operations::upsert_request req{ id, doc };
389+
couchbase::core::operations::upsert_request req{ id, doc };
388390
auto resp = test::utils::execute(integration.cluster, req);
389-
REQUIRE_FALSE(resp.ctx.ec);
391+
REQUIRE_FALSE(resp.ctx.ec());
390392
token = resp.token;
391393
}
392394

393395
tao::json::value query{ { "query", fmt::format("value:{}", value) } };
394-
auto query_json = couchbase::json_string(couchbase::utils::json::generate(query));
396+
auto query_json = couchbase::core::json_string(couchbase::core::utils::json::generate(query));
395397

396398
{
397-
couchbase::operations::search_request req{};
399+
couchbase::core::operations::search_request req{};
398400
req.index_name = index_name;
399401
req.query = query_json;
400402
req.mutation_state.emplace_back(token);
@@ -404,7 +406,7 @@ TEST_CASE("integration: search query consistency", "[integration]")
404406
}
405407

406408
{
407-
couchbase::operations::management::search_index_drop_request req{};
409+
couchbase::core::operations::management::search_index_drop_request req{};
408410
req.index_name = index_name;
409411
test::utils::execute(integration.cluster, req);
410412
}
@@ -427,7 +429,7 @@ TEST_CASE("integration: search query collections")
427429

428430
for (const auto& collection : { collection1_name, collection2_name }) {
429431
{
430-
couchbase::operations::management::collection_create_request req{ integration.ctx.bucket, "_default", collection };
432+
couchbase::core::operations::management::collection_create_request req{ integration.ctx.bucket, "_default", collection };
431433
auto resp = test::utils::execute(integration.cluster, req);
432434
REQUIRE_FALSE(resp.ctx.ec);
433435
auto created = test::utils::wait_until_collection_manifest_propagated(integration.cluster, integration.ctx.bucket, resp.uid);
@@ -436,10 +438,10 @@ TEST_CASE("integration: search query collections")
436438

437439
{
438440
auto key = test::utils::uniq_id("key");
439-
auto id = couchbase::document_id(integration.ctx.bucket, "_default", collection, key);
440-
couchbase::operations::upsert_request req{ id, doc };
441+
auto id = couchbase::core::document_id(integration.ctx.bucket, "_default", collection, key);
442+
couchbase::core::operations::upsert_request req{ id, couchbase::core::utils::to_binary(doc) };
441443
auto resp = test::utils::execute(integration.cluster, req);
442-
REQUIRE_FALSE(resp.ctx.ec);
444+
REQUIRE_FALSE(resp.ctx.ec());
443445
}
444446
}
445447

@@ -474,25 +476,25 @@ TEST_CASE("integration: search query collections")
474476
)";
475477
// clang-format on
476478

477-
couchbase::management::search::index index{};
479+
couchbase::core::management::search::index index{};
478480
index.name = index_name;
479481
index.params_json = params;
480482
index.type = "fulltext-index";
481483
index.source_name = integration.ctx.bucket;
482484
index.source_type = "couchbase";
483-
couchbase::operations::management::search_index_upsert_request req{};
485+
couchbase::core::operations::management::search_index_upsert_request req{};
484486
req.index = index;
485487
auto resp = test::utils::execute(integration.cluster, req);
486488
REQUIRE_FALSE(resp.ctx.ec);
487489
}
488490

489491
wait_until_indexed(integration.cluster, index_name, 2);
490492

491-
couchbase::json_string simple_query(R"({"query": "name:test"})");
493+
couchbase::core::json_string simple_query(R"({"query": "name:test"})");
492494

493495
// no collections parameter - both docs returned
494496
{
495-
couchbase::operations::search_request req{};
497+
couchbase::core::operations::search_request req{};
496498
req.index_name = index_name;
497499
req.query = simple_query;
498500
auto resp = test::utils::execute(integration.cluster, req);
@@ -502,7 +504,7 @@ TEST_CASE("integration: search query collections")
502504

503505
// one collection - only docs from that collection returned
504506
{
505-
couchbase::operations::search_request req{};
507+
couchbase::core::operations::search_request req{};
506508
req.index_name = index_name;
507509
req.query = simple_query;
508510
req.collections.emplace_back(collection1_name);
@@ -513,7 +515,7 @@ TEST_CASE("integration: search query collections")
513515

514516
// two collections - both docs returned
515517
{
516-
couchbase::operations::search_request req{};
518+
couchbase::core::operations::search_request req{};
517519
req.index_name = index_name;
518520
req.query = simple_query;
519521
req.collections.emplace_back(collection1_name);

0 commit comments

Comments
 (0)