Skip to content

Commit 5063d52

Browse files
authored
CXX-2700 add search index management e2e testing against atlas (#1002)
1 parent 8a0ffd5 commit 5063d52

12 files changed

+353
-23
lines changed

.mci.yml

+56-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ functions:
324324
if [ ! -d "drivers-evergreen-tools" ]; then
325325
git clone [email protected]:mongodb-labs/drivers-evergreen-tools.git --depth=1
326326
fi
327-
327+
echo "DRIVERS_TOOLS: $(pwd)/drivers-evergreen-tools" > det-expansion.yml
328+
# Set DRIVERS_TOOLS expansion.
329+
- command: expansions.update
330+
params:
331+
file: det-expansion.yml
328332
"run_kms_servers":
329333
- command: shell.exec
330334
params:
@@ -1172,6 +1176,56 @@ tasks:
11721176
- func: "run_kms_servers"
11731177
- func: "test"
11741178

1179+
- name: test_search_index_helpers
1180+
commands:
1181+
- func: "install_c_driver"
1182+
- func: "compile"
1183+
- command: shell.exec
1184+
params:
1185+
shell: bash
1186+
working_dir: mongo-cxx-driver
1187+
script: |
1188+
export MONGODB_URI=${MONGODB_URI}
1189+
1190+
if [ -n "${lib_dir}" ]; then
1191+
export LD_LIBRARY_PATH=$(pwd)/../mongoc/${lib_dir}/
1192+
else
1193+
export LD_LIBRARY_PATH=$(pwd)/../mongoc/lib/
1194+
fi
1195+
1196+
./build/src/mongocxx/test/test_driver "atlas search indexes prose tests"
1197+
1198+
task_groups:
1199+
- name: test_atlas_task_group_search_indexes
1200+
setup_group:
1201+
- func: "setup"
1202+
- func: "clone_drivers-evergreen-tools"
1203+
- command: subprocess.exec
1204+
params:
1205+
working_dir: mongo-cxx-driver
1206+
binary: bash
1207+
add_expansions_to_env: true
1208+
env:
1209+
MONGODB_VERSION: '7.0'
1210+
args:
1211+
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
1212+
- command: expansions.update
1213+
# Expected to set MONGODB_URI expansion.
1214+
params:
1215+
file: mongo-cxx-driver/atlas-expansion.yml
1216+
teardown_group:
1217+
- command: subprocess.exec
1218+
params:
1219+
working_dir: mongo-cxx-driver
1220+
binary: bash
1221+
add_expansions_to_env: true
1222+
args:
1223+
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
1224+
setup_group_can_fail_task: true
1225+
setup_group_timeout_secs: 1800
1226+
tasks:
1227+
- test_search_index_helpers
1228+
11751229
#######################################
11761230
# MongoDB Version Matrix #
11771231
#######################################
@@ -1673,6 +1727,7 @@ buildvariants:
16731727
tasks:
16741728
- name: clang-tidy
16751729
- name: compile_without_tests
1730+
- name: test_atlas_task_group_search_indexes
16761731

16771732
- name: ubuntu2204-debug-gcc
16781733
display_name: "Ubuntu 22.04 Debug (GCC)"

data/index-management/createSearchIndex.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
}
5555
},
5656
"expectError": {
57-
"isError": true
57+
"isError": true,
58+
"errorContains": "Search index commands are only supported with Atlas"
5859
}
5960
}
6061
],
@@ -100,7 +101,8 @@
100101
}
101102
},
102103
"expectError": {
103-
"isError": true
104+
"isError": true,
105+
"errorContains": "Search index commands are only supported with Atlas"
104106
}
105107
}
106108
],

data/index-management/createSearchIndexes.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"models": []
4949
},
5050
"expectError": {
51-
"isError": true
51+
"isError": true,
52+
"errorContains": "Search index commands are only supported with Atlas"
5253
}
5354
}
5455
],
@@ -87,7 +88,8 @@
8788
]
8889
},
8990
"expectError": {
90-
"isError": true
91+
"isError": true,
92+
"errorContains": "Search index commands are only supported with Atlas"
9193
}
9294
}
9395
],
@@ -135,7 +137,8 @@
135137
]
136138
},
137139
"expectError": {
138-
"isError": true
140+
"isError": true,
141+
"errorContains": "Search index commands are only supported with Atlas"
139142
}
140143
}
141144
],

data/index-management/dropSearchIndex.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"name": "test index"
4949
},
5050
"expectError": {
51-
"isError": true
51+
"isError": true,
52+
"errorContains": "Search index commands are only supported with Atlas"
5253
}
5354
}
5455
],

data/index-management/listSearchIndexes.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"name": "listSearchIndexes",
4646
"object": "collection0",
4747
"expectError": {
48-
"isError": true
48+
"isError": true,
49+
"errorContains": "Search index commands are only supported with Atlas"
4950
}
5051
}
5152
],
@@ -79,7 +80,8 @@
7980
"name": "test index"
8081
},
8182
"expectError": {
82-
"isError": true
83+
"isError": true,
84+
"errorContains": "Search index commands are only supported with Atlas"
8385
}
8486
}
8587
],
@@ -119,7 +121,8 @@
119121
}
120122
},
121123
"expectError": {
122-
"isError": true
124+
"isError": true,
125+
"errorContains": "Search index commands are only supported with Atlas"
123126
}
124127
}
125128
],

data/index-management/updateSearchIndex.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"definition": {}
5050
},
5151
"expectError": {
52-
"isError": true
52+
"isError": true,
53+
"errorContains": "Search index commands are only supported with Atlas"
5354
}
5455
}
5556
],

src/mongocxx/private/search_index_view.hh

+8
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ class search_index_view::impl {
137137
bool result = libmongoc::collection_write_command_with_opts(
138138
_coll, command_bson.bson(), opts_bson.bson(), reply.bson_for_init(), &error);
139139

140+
const uint32_t serverErrorNamespaceNotFound = 26;
141+
if (error.domain == MONGOC_ERROR_QUERY && error.code == serverErrorNamespaceNotFound) {
142+
// Ignore NamespaceNotFound error.
143+
// NamespaceNotFound server error code is documented in server code:
144+
// https://github.com/mongodb/mongo/blob/07e852967e936adbc255518ebaa9c116937becc4/src/mongo/base/error_codes.yml#L64
145+
return;
146+
}
147+
140148
if (!result) {
141149
throw_exception<operation_exception>(reply.steal(), error);
142150
}

src/mongocxx/search_index_view.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ cursor search_index_view::list(const client_session& session,
4545
return _get_impl().list(&session, name, options);
4646
}
4747

48+
std::string search_index_view::create_one(bsoncxx::document::view_or_value definition) {
49+
return create_one(search_index_model(definition));
50+
}
51+
52+
std::string search_index_view::create_one(const client_session& session,
53+
bsoncxx::document::view_or_value definition) {
54+
return create_one(session, search_index_model(definition));
55+
}
56+
4857
std::string search_index_view::create_one(bsoncxx::string::view_or_value name,
4958
bsoncxx::document::view_or_value definition) {
5059
return create_one(search_index_model(name, definition));
@@ -65,23 +74,24 @@ std::string search_index_view::create_one(const client_session& session,
6574
return _get_impl().create_one(&session, model);
6675
}
6776

68-
std::vector<bsoncxx::string::view_or_value> search_index_view::create_many(
77+
std::vector<std::string> search_index_view::create_many(
6978
const std::vector<search_index_model>& models) {
7079
auto response = _get_impl().create_many(nullptr, models);
7180
return _create_many_helper(response["indexesCreated"].get_array().value);
7281
}
7382

74-
std::vector<bsoncxx::string::view_or_value> search_index_view::create_many(
83+
std::vector<std::string> search_index_view::create_many(
7584
const client_session& session, const std::vector<search_index_model>& models) {
7685
auto response = _get_impl().create_many(&session, models);
7786
return _create_many_helper(response["indexesCreated"].get_array().value);
7887
}
7988

80-
std::vector<bsoncxx::string::view_or_value> search_index_view::_create_many_helper(
89+
std::vector<std::string> search_index_view::_create_many_helper(
8190
bsoncxx::array::view created_indexes) {
82-
std::vector<bsoncxx::string::view_or_value> search_index_names;
91+
std::vector<std::string> search_index_names;
8392
for (auto&& index : created_indexes) {
84-
search_index_names.push_back(index.get_document().value["name"].get_string().value);
93+
search_index_names.push_back(
94+
bsoncxx::string::to_string(index.get_document().value["name"].get_string().value));
8595
}
8696
return search_index_names;
8797
}

src/mongocxx/search_index_view.hpp

+25-5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ class MONGOCXX_API search_index_view {
8686

8787
///
8888
/// @{
89+
///
90+
/// This is a convenience method for creating a single search index with a default name.
91+
///
92+
/// @param definition
93+
/// The document describing the search index to be created.
94+
///
95+
/// @return The name of the created search index.
96+
///
97+
std::string create_one(bsoncxx::document::view_or_value definition);
98+
99+
///
100+
/// This is a convenience method for creating a single search index with a default name.
101+
///
102+
/// @param definition
103+
/// The document describing the search index to be created.
104+
///
105+
/// @return The name of the created search index.
106+
///
107+
std::string create_one(const client_session& session,
108+
bsoncxx::document::view_or_value definition);
109+
89110
///
90111
/// This is a convenience method for creating a single search index.
91112
///
@@ -151,8 +172,7 @@ class MONGOCXX_API search_index_view {
151172
///
152173
/// @return The names of the created indexes.
153174
///
154-
std::vector<bsoncxx::string::view_or_value> create_many(
155-
const std::vector<search_index_model>& models);
175+
std::vector<std::string> create_many(const std::vector<search_index_model>& models);
156176

157177
///
158178
/// Creates multiple search indexes in the collection.
@@ -164,8 +184,8 @@ class MONGOCXX_API search_index_view {
164184
///
165185
/// @return The names of the created indexes.
166186
///
167-
std::vector<bsoncxx::string::view_or_value> create_many(
168-
const client_session& session, const std::vector<search_index_model>& models);
187+
std::vector<std::string> create_many(const client_session& session,
188+
const std::vector<search_index_model>& models);
169189

170190
///
171191
/// @}
@@ -232,7 +252,7 @@ class MONGOCXX_API search_index_view {
232252

233253
MONGOCXX_PRIVATE search_index_view(void* coll, void* client);
234254

235-
MONGOCXX_PRIVATE std::vector<bsoncxx::string::view_or_value> _create_many_helper(
255+
MONGOCXX_PRIVATE std::vector<std::string> _create_many_helper(
236256
bsoncxx::array::view created_indexes);
237257

238258
MONGOCXX_PRIVATE const impl& _get_impl() const;

src/mongocxx/test/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ set(test_driver_sources
6868
result/insert_one.cpp
6969
result/replace_one.cpp
7070
result/update.cpp
71+
search_index_view.cpp
7172
sdam-monitoring.cpp
7273
spec/initial_dns_seedlist_discovery.cpp
7374
spec/monitoring.cpp
@@ -337,6 +338,7 @@ set_dist_list (src_mongocxx_test_DIST
337338
result/insert_one.cpp
338339
result/replace_one.cpp
339340
result/update.cpp
341+
search_index_view.cpp
340342
sdam-monitoring.cpp
341343
spec/client_side_encryption.cpp
342344
spec/command_monitoring.cpp

0 commit comments

Comments
 (0)