Skip to content

CXX-2700 Add search index management e2e testing against Atlas #1002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion .mci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ functions:
if [ ! -d "drivers-evergreen-tools" ]; then
git clone [email protected]:mongodb-labs/drivers-evergreen-tools.git --depth=1
fi

echo "DRIVERS_TOOLS: $(pwd)/drivers-evergreen-tools" > det-expansion.yml
# Set DRIVERS_TOOLS expansion.
- command: expansions.update
params:
file: det-expansion.yml
"run_kms_servers":
- command: shell.exec
params:
Expand Down Expand Up @@ -1134,6 +1138,56 @@ tasks:
- func: "run_kms_servers"
- func: "test"

- name: test_search_index_helpers
commands:
- func: "install_c_driver"
- func: "compile"
- command: shell.exec
params:
shell: bash
working_dir: mongo-cxx-driver
script: |
export MONGODB_URI=${MONGODB_URI}

if [ -n "${lib_dir}" ]; then
export LD_LIBRARY_PATH=$(pwd)/../mongoc/${lib_dir}/
else
export LD_LIBRARY_PATH=$(pwd)/../mongoc/lib/
fi

./build/src/mongocxx/test/test_driver "atlas search indexes prose tests"

task_groups:
- name: test_atlas_task_group_search_indexes
setup_group:
- func: "setup"
- func: "clone_drivers-evergreen-tools"
- command: subprocess.exec
params:
working_dir: mongo-cxx-driver
binary: bash
add_expansions_to_env: true
env:
MONGODB_VERSION: '7.0'
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
# Expected to set MONGODB_URI expansion.
params:
file: mongo-cxx-driver/atlas-expansion.yml
teardown_group:
- command: subprocess.exec
params:
working_dir: mongo-cxx-driver
binary: bash
add_expansions_to_env: true
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800
tasks:
- test_search_index_helpers

#######################################
# MongoDB Version Matrix #
#######################################
Expand Down Expand Up @@ -1623,6 +1677,7 @@ buildvariants:
tasks:
- name: clang-tidy
- name: compile_without_tests
- name: test_atlas_task_group_search_indexes

- name: ubuntu2204-debug-gcc
display_name: "Ubuntu 22.04 Debug (GCC)"
Expand Down
6 changes: 4 additions & 2 deletions data/index-management/createSearchIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
}
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -100,7 +101,8 @@
}
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
9 changes: 6 additions & 3 deletions data/index-management/createSearchIndexes.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"models": []
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -87,7 +88,8 @@
]
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -135,7 +137,8 @@
]
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
3 changes: 2 additions & 1 deletion data/index-management/dropSearchIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"name": "test index"
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
9 changes: 6 additions & 3 deletions data/index-management/listSearchIndexes.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"name": "listSearchIndexes",
"object": "collection0",
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -79,7 +80,8 @@
"name": "test index"
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down Expand Up @@ -119,7 +121,8 @@
}
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
3 changes: 2 additions & 1 deletion data/index-management/updateSearchIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"definition": {}
},
"expectError": {
"isError": true
"isError": true,
"errorContains": "Search index commands are only supported with Atlas"
}
}
],
Expand Down
8 changes: 8 additions & 0 deletions src/mongocxx/private/search_index_view.hh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ class search_index_view::impl {
bool result = libmongoc::collection_write_command_with_opts(
_coll, command_bson.bson(), opts_bson.bson(), reply.bson_for_init(), &error);

const uint32_t serverErrorNamespaceNotFound = 26;
if (error.domain == MONGOC_ERROR_QUERY && error.code == serverErrorNamespaceNotFound) {
// Ignore NamespaceNotFound error.
// NamespaceNotFound server error code is documented in server code:
// https://github.com/mongodb/mongo/blob/07e852967e936adbc255518ebaa9c116937becc4/src/mongo/base/error_codes.yml#L64
return;
}

if (!result) {
throw_exception<operation_exception>(reply.steal(), error);
}
Expand Down
20 changes: 15 additions & 5 deletions src/mongocxx/search_index_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ cursor search_index_view::list(const client_session& session,
return _get_impl().list(&session, name, options);
}

std::string search_index_view::create_one(bsoncxx::document::view_or_value definition) {
return create_one(search_index_model(definition));
}

std::string search_index_view::create_one(const client_session& session,
bsoncxx::document::view_or_value definition) {
return create_one(session, search_index_model(definition));
}

std::string search_index_view::create_one(bsoncxx::string::view_or_value name,
bsoncxx::document::view_or_value definition) {
return create_one(search_index_model(name, definition));
Expand All @@ -65,23 +74,24 @@ std::string search_index_view::create_one(const client_session& session,
return _get_impl().create_one(&session, model);
}

std::vector<bsoncxx::string::view_or_value> search_index_view::create_many(
std::vector<std::string> search_index_view::create_many(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into some issues with reading the values of the std::vector<bsoncxx::string::view_or_value> returned from this function due to ownership semantics. After talking to @eramongodb, we came to the conclusion that it would be easier and more clear to just make this a std::vector<std::string>. This minor change seen across this PR.

const std::vector<search_index_model>& models) {
auto response = _get_impl().create_many(nullptr, models);
return _create_many_helper(response["indexesCreated"].get_array().value);
}

std::vector<bsoncxx::string::view_or_value> search_index_view::create_many(
std::vector<std::string> search_index_view::create_many(
const client_session& session, const std::vector<search_index_model>& models) {
auto response = _get_impl().create_many(&session, models);
return _create_many_helper(response["indexesCreated"].get_array().value);
}

std::vector<bsoncxx::string::view_or_value> search_index_view::_create_many_helper(
std::vector<std::string> search_index_view::_create_many_helper(
bsoncxx::array::view created_indexes) {
std::vector<bsoncxx::string::view_or_value> search_index_names;
std::vector<std::string> search_index_names;
for (auto&& index : created_indexes) {
search_index_names.push_back(index.get_document().value["name"].get_string().value);
search_index_names.push_back(
bsoncxx::string::to_string(index.get_document().value["name"].get_string().value));
}
return search_index_names;
}
Expand Down
30 changes: 25 additions & 5 deletions src/mongocxx/search_index_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ class MONGOCXX_API search_index_view {

///
/// @{
///
/// This is a convenience method for creating a single search index with a default name.
///
/// @param definition
/// The document describing the search index to be created.
///
/// @return The name of the created search index.
///
std::string create_one(bsoncxx::document::view_or_value definition);

///
/// This is a convenience method for creating a single search index with a default name.
///
/// @param definition
/// The document describing the search index to be created.
///
/// @return The name of the created search index.
///
std::string create_one(const client_session& session,
bsoncxx::document::view_or_value definition);

///
/// This is a convenience method for creating a single search index.
///
Expand Down Expand Up @@ -151,8 +172,7 @@ class MONGOCXX_API search_index_view {
///
/// @return The names of the created indexes.
///
std::vector<bsoncxx::string::view_or_value> create_many(
const std::vector<search_index_model>& models);
std::vector<std::string> create_many(const std::vector<search_index_model>& models);

///
/// Creates multiple search indexes in the collection.
Expand All @@ -164,8 +184,8 @@ class MONGOCXX_API search_index_view {
///
/// @return The names of the created indexes.
///
std::vector<bsoncxx::string::view_or_value> create_many(
const client_session& session, const std::vector<search_index_model>& models);
std::vector<std::string> create_many(const client_session& session,
const std::vector<search_index_model>& models);

///
/// @}
Expand Down Expand Up @@ -232,7 +252,7 @@ class MONGOCXX_API search_index_view {

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

MONGOCXX_PRIVATE std::vector<bsoncxx::string::view_or_value> _create_many_helper(
MONGOCXX_PRIVATE std::vector<std::string> _create_many_helper(
bsoncxx::array::view created_indexes);

MONGOCXX_PRIVATE const impl& _get_impl() const;
Expand Down
2 changes: 2 additions & 0 deletions src/mongocxx/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ set(test_driver_sources
result/insert_one.cpp
result/replace_one.cpp
result/update.cpp
search_index_view.cpp
sdam-monitoring.cpp
spec/initial_dns_seedlist_discovery.cpp
spec/monitoring.cpp
Expand Down Expand Up @@ -337,6 +338,7 @@ set_dist_list (src_mongocxx_test_DIST
result/insert_one.cpp
result/replace_one.cpp
result/update.cpp
search_index_view.cpp
sdam-monitoring.cpp
spec/client_side_encryption.cpp
spec/command_monitoring.cpp
Expand Down
Loading