From 567bcd0e4822d726aea15f0338c89c49de2a56b5 Mon Sep 17 00:00:00 2001 From: jannaerin Date: Wed, 1 Feb 2023 20:54:39 +0000 Subject: SERVER-73112 Expose function to construct NamespaceString in unit tests --- src/mongo/client/dbclient_cursor_test.cpp | 23 +- src/mongo/client/dbclient_rs_test.cpp | 66 ++--- src/mongo/crypto/fle_crypto_test.cpp | 14 +- src/mongo/db/auth/auth_op_observer_test.cpp | 6 +- src/mongo/db/auth/authorization_session_test.cpp | 87 +++--- src/mongo/db/auth/builtin_roles_test.cpp | 4 +- src/mongo/db/auth/privilege_parser_test.cpp | 3 +- .../db/auth/sasl_authentication_session_test.cpp | 3 +- src/mongo/db/auth/sasl_mechanism_registry_test.cpp | 5 +- src/mongo/db/catalog/capped_collection_test.cpp | 6 +- src/mongo/db/catalog/capped_utils_test.cpp | 6 +- src/mongo/db/catalog/collection_catalog_test.cpp | 221 +++++++------- src/mongo/db/catalog/collection_test.cpp | 48 ++-- .../db/catalog/collection_validation_test.cpp | 11 +- src/mongo/db/catalog/collection_writer_test.cpp | 14 +- .../db/catalog/column_index_consistency_test.cpp | 2 +- src/mongo/db/catalog/create_collection_test.cpp | 24 +- src/mongo/db/catalog/database_test.cpp | 15 +- src/mongo/db/catalog/drop_database_test.cpp | 11 +- src/mongo/db/catalog/index_builds_manager_test.cpp | 2 +- src/mongo/db/catalog/index_key_validate_test.cpp | 16 +- src/mongo/db/catalog/index_signature_test.cpp | 2 +- src/mongo/db/catalog/multi_index_block_test.cpp | 2 +- src/mongo/db/catalog/rename_collection_test.cpp | 109 ++++--- src/mongo/db/catalog/throttle_cursor_test.cpp | 2 +- src/mongo/db/catalog/validate_state_test.cpp | 2 +- src/mongo/db/catalog_raii_test.cpp | 17 +- src/mongo/db/commands/create_indexes_test.cpp | 3 +- src/mongo/db/commands/fle_compact_test.cpp | 14 +- .../db/commands/index_filter_commands_test.cpp | 3 +- src/mongo/db/commands/map_reduce_agg_test.cpp | 24 +- src/mongo/db/commands/mr_test.cpp | 6 +- src/mongo/db/commands/plan_cache_commands_test.cpp | 3 +- src/mongo/db/commands_test.cpp | 4 +- src/mongo/db/concurrency/d_concurrency_test.cpp | 47 +-- src/mongo/db/concurrency/lock_manager_test.cpp | 80 ++++-- src/mongo/db/concurrency/lock_state_test.cpp | 105 ++++--- src/mongo/db/concurrency/lock_stats_test.cpp | 18 +- src/mongo/db/concurrency/resource_catalog_test.cpp | 14 +- src/mongo/db/cst/cst_literals_test.cpp | 2 +- src/mongo/db/cst/cst_match_translation_test.cpp | 2 +- src/mongo/db/cst/cst_pipeline_translation_test.cpp | 2 +- .../db/cst/cst_set_operator_translation_test.cpp | 2 +- src/mongo/db/cst/cst_sort_translation_test.cpp | 2 +- src/mongo/db/curop_test.cpp | 7 +- src/mongo/db/db_raii_multi_collection_test.cpp | 12 +- src/mongo/db/db_raii_test.cpp | 5 +- src/mongo/db/dbdirectclient_test.cpp | 2 +- src/mongo/db/error_labels_test.cpp | 3 +- src/mongo/db/exec/queued_data_stage_test.cpp | 2 +- src/mongo/db/exec/sbe/abt/sbe_abt_test.cpp | 8 +- src/mongo/db/exec/sort_test.cpp | 2 +- .../exhaust_cursor_currentop_integration_test.cpp | 3 +- src/mongo/db/fle_crud_test.cpp | 14 +- src/mongo/db/free_mon/free_mon_controller_test.cpp | 4 +- src/mongo/db/free_mon/free_mon_storage_test.cpp | 11 +- src/mongo/db/index/columns_access_method_test.cpp | 2 +- .../db/index/index_build_interceptor_test.cpp | 2 +- .../db/index_builds_coordinator_mongod_test.cpp | 12 +- src/mongo/db/index_builds_coordinator_test.cpp | 15 +- src/mongo/db/matcher/expression_optimize_test.cpp | 3 +- src/mongo/db/namespace_string.h | 33 +++ src/mongo/db/namespace_string_test.cpp | 20 +- .../db/op_observer/batched_write_context_test.cpp | 21 +- src/mongo/db/op_observer/op_observer_impl_test.cpp | 74 +++-- .../db/op_observer/op_observer_registry_test.cpp | 2 +- .../user_write_block_mode_op_observer_test.cpp | 69 +++-- .../write_ops_document_stream_integration_test.cpp | 2 +- src/mongo/db/ops/write_ops_exec_test.cpp | 3 +- src/mongo/db/ops/write_ops_parsers_test.cpp | 16 +- src/mongo/db/ops/write_ops_retryability_test.cpp | 71 +++-- src/mongo/db/persistent_task_store_test.cpp | 2 +- .../db/pipeline/abt/abt_optimization_test.cpp | 21 +- src/mongo/db/pipeline/abt/abt_translation_test.cpp | 17 +- .../db/pipeline/aggregation_context_fixture.h | 7 +- .../pipeline/aggregation_mongod_context_fixture.h | 3 +- src/mongo/db/pipeline/aggregation_request_test.cpp | 80 +++--- .../change_stream_event_transform_test.cpp | 24 +- .../document_source_change_stream_test.cpp | 66 +++-- .../pipeline/document_source_current_op_test.cpp | 2 +- .../db/pipeline/document_source_exchange_test.cpp | 3 +- ...nt_source_find_and_modify_image_lookup_test.cpp | 77 ++--- .../pipeline/document_source_graph_lookup_test.cpp | 66 +++-- .../db/pipeline/document_source_group_test.cpp | 8 +- .../db/pipeline/document_source_lookup_test.cpp | 159 +++++++---- .../document_source_merge_cursors_test.cpp | 3 +- .../db/pipeline/document_source_merge_test.cpp | 21 +- src/mongo/db/pipeline/document_source_out_test.cpp | 14 +- .../db/pipeline/document_source_telemetry_test.cpp | 2 +- .../pipeline/document_source_union_with_test.cpp | 46 +-- .../db/pipeline/document_source_unwind_test.cpp | 5 +- src/mongo/db/pipeline/expression_context_test.cpp | 226 ++++++++------- src/mongo/db/pipeline/expression_walker_test.cpp | 3 +- .../db/pipeline/pipeline_metadata_tree_test.cpp | 73 +++-- src/mongo/db/pipeline/pipeline_test.cpp | 71 +++-- .../shardsvr_process_interface_test.cpp | 3 +- .../sampling_based_initial_split_policy_test.cpp | 2 +- src/mongo/db/pipeline/semantic_analysis_test.cpp | 2 +- src/mongo/db/pipeline/sharded_union_test.cpp | 3 +- .../db/query/canonical_query_encoder_test.cpp | 6 +- src/mongo/db/query/canonical_query_test.cpp | 3 +- src/mongo/db/query/classic_stage_builder_test.cpp | 2 +- src/mongo/db/query/collection_query_info_test.cpp | 4 +- src/mongo/db/query/cursor_response_test.cpp | 27 +- src/mongo/db/query/get_executor_test.cpp | 3 +- src/mongo/db/query/killcursors_request_test.cpp | 2 +- src/mongo/db/query/parsed_distinct_test.cpp | 3 +- src/mongo/db/query/projection_test.cpp | 3 +- src/mongo/db/query/query_planner_options_test.cpp | 5 +- .../db/query/query_planner_partialidx_test.cpp | 2 +- .../query/query_planner_pipeline_pushdown_test.cpp | 3 +- src/mongo/db/query/query_request_test.cpp | 4 +- src/mongo/db/query/query_solution_test.cpp | 32 ++- src/mongo/db/query/sbe_and_hash_test.cpp | 3 +- src/mongo/db/query/sbe_and_sorted_test.cpp | 3 +- src/mongo/db/query/sbe_shard_filter_test.cpp | 5 +- .../db/query/sbe_stage_builder_lookup_test.cpp | 3 +- .../db/query/sbe_stage_builder_test_fixture.h | 3 +- .../db/query/stats/stats_cache_loader_test.cpp | 8 +- src/mongo/db/query/stats/stats_cache_test.cpp | 13 +- .../db/query/view_response_formatter_test.cpp | 8 +- src/mongo/db/repl/apply_ops_test.cpp | 44 +-- src/mongo/db/repl/database_cloner_test.cpp | 38 +-- .../repl/drop_pending_collection_reaper_test.cpp | 29 +- src/mongo/db/repl/initial_syncer_test.cpp | 34 +-- src/mongo/db/repl/multiapplier_test.cpp | 24 +- src/mongo/db/repl/oplog_applier_impl_test.cpp | 254 ++++++++++------- src/mongo/db/repl/oplog_applier_test.cpp | 108 ++++--- src/mongo/db/repl/oplog_batcher_test_fixture.cpp | 8 +- src/mongo/db/repl/oplog_buffer_collection_test.cpp | 7 +- src/mongo/db/repl/oplog_entry_test.cpp | 12 +- src/mongo/db/repl/oplog_fetcher_test.cpp | 40 +-- src/mongo/db/repl/oplog_test.cpp | 8 +- src/mongo/db/repl/primary_only_service_test.cpp | 6 +- .../db/repl/primary_only_service_util_test.cpp | 5 +- .../replication_consistency_markers_impl_test.cpp | 9 +- src/mongo/db/repl/replication_recovery_test.cpp | 8 +- src/mongo/db/repl/storage_interface_impl_test.cpp | 85 +++--- src/mongo/db/repl/storage_timestamp_test.cpp | 104 ++++--- src/mongo/db/repl/sync_source_resolver_test.cpp | 26 +- .../db/repl/tenant_all_database_cloner_test.cpp | 19 +- .../db/repl/tenant_collection_cloner_test.cpp | 6 +- src/mongo/db/repl/tenant_database_cloner_test.cpp | 39 +-- .../tenant_migration_access_blocker_util_test.cpp | 25 +- ...igration_recipient_service_shard_merge_test.cpp | 9 +- .../tenant_migration_recipient_service_test.cpp | 137 ++++----- src/mongo/db/repl/tenant_oplog_applier_test.cpp | 154 +++++++--- src/mongo/db/repl/tenant_oplog_batcher_test.cpp | 186 ++++++++---- src/mongo/db/s/active_migrations_registry_test.cpp | 54 ++-- ...lyze_shard_key_read_write_distribution_test.cpp | 3 +- src/mongo/db/s/auto_split_vector_test.cpp | 19 +- src/mongo/db/s/balancer/balance_stats_test.cpp | 2 +- .../balancer/balancer_commands_scheduler_test.cpp | 5 +- .../balancer_defragmentation_policy_test.cpp | 2 +- .../balancer/cluster_chunks_resize_policy_test.cpp | 2 +- .../db/s/collection_metadata_filtering_test.cpp | 2 +- src/mongo/db/s/collection_metadata_test.cpp | 2 +- .../db/s/collection_sharding_runtime_test.cpp | 8 +- src/mongo/db/s/config/index_on_config_test.cpp | 4 +- .../db/s/config/initial_split_policy_test.cpp | 24 +- .../sharding_catalog_manager_add_shard_test.cpp | 40 +-- ...talog_manager_assign_key_range_to_zone_test.cpp | 19 +- ...collection_version_and_change_metadata_test.cpp | 2 +- ...rding_catalog_manager_clear_jumbo_flag_test.cpp | 6 +- ..._catalog_manager_config_initialization_test.cpp | 27 +- .../sharding_catalog_manager_merge_chunks_test.cpp | 23 +- ...catalog_manager_remove_shard_from_zone_test.cpp | 4 +- .../sharding_catalog_manager_remove_shard_test.cpp | 4 +- ...rding_catalog_manager_shard_collection_test.cpp | 2 +- .../sharding_catalog_manager_split_chunk_test.cpp | 9 +- .../global_index_cloner_fetcher_test.cpp | 2 +- .../global_index_cloning_service_test.cpp | 3 +- .../s/global_index/global_index_inserter_test.cpp | 2 +- .../db/s/implicit_collection_creation_test.cpp | 6 +- src/mongo/db/s/metadata_manager_test.cpp | 2 +- src/mongo/db/s/migration_batch_fetcher_test.cpp | 4 +- .../db/s/migration_destination_manager_test.cpp | 2 +- src/mongo/db/s/migration_util_test.cpp | 36 ++- src/mongo/db/s/op_observer_sharding_test.cpp | 3 +- src/mongo/db/s/persistent_task_queue_test.cpp | 2 +- src/mongo/db/s/query_analysis_coordinator_test.cpp | 9 +- src/mongo/db/s/query_analysis_writer_test.cpp | 6 +- src/mongo/db/s/range_deletion_util_test.cpp | 8 +- .../resharding_collection_cloner_test.cpp | 3 +- .../db/s/resharding/resharding_collection_test.cpp | 15 +- .../resharding_coordinator_service_test.cpp | 43 +-- .../s/resharding/resharding_coordinator_test.cpp | 5 +- .../resharding_data_replication_test.cpp | 3 +- .../resharding_destined_recipient_test.cpp | 12 +- .../resharding_donor_oplog_iterator_test.cpp | 7 +- .../resharding_donor_recipient_common_test.cpp | 7 +- .../s/resharding/resharding_oplog_applier_test.cpp | 14 +- .../s/resharding/resharding_oplog_fetcher_test.cpp | 48 ++-- .../resharding_oplog_session_application_test.cpp | 4 +- ...rding_recipient_service_external_state_test.cpp | 4 +- .../resharding_recipient_service_test.cpp | 6 +- src/mongo/db/s/resharding/resharding_util_test.cpp | 2 +- .../session_catalog_migration_destination_test.cpp | 2 +- .../db/s/session_catalog_migration_source_test.cpp | 16 +- src/mongo/db/s/shard_key_index_util_test.cpp | 2 +- src/mongo/db/s/shard_local_test.cpp | 8 +- src/mongo/db/s/shard_metadata_util_test.cpp | 5 +- .../s/shard_server_catalog_cache_loader_test.cpp | 2 +- .../sharding_catalog_client_aggregations_test.cpp | 150 +++++----- ...arding_data_transform_instance_metrics_test.cpp | 2 +- .../sharding_data_transform_metrics_test_fixture.h | 3 +- src/mongo/db/s/sharding_ddl_util_test.cpp | 11 +- .../s/sharding_initialization_op_observer_test.cpp | 4 +- src/mongo/db/s/sharding_recovery_service_test.cpp | 6 +- src/mongo/db/s/sharding_util_refresh_test.cpp | 8 +- src/mongo/db/s/split_chunk_request_test.cpp | 6 +- src/mongo/db/s/split_vector_test.cpp | 30 +- src/mongo/db/s/start_chunk_clone_request_test.cpp | 5 +- src/mongo/db/s/type_shard_collection_test.cpp | 2 +- .../serverless/shard_split_donor_service_test.cpp | 3 +- src/mongo/db/shard_role_test.cpp | 15 +- src/mongo/db/stats/top_test.cpp | 2 +- .../db/storage/historical_ident_tracker_test.cpp | 316 ++++++++++++++------- .../db/storage/index_entry_comparison_test.cpp | 8 +- src/mongo/db/storage/kv/durable_catalog_test.cpp | 29 +- .../db/storage/kv/kv_engine_timestamps_test.cpp | 6 +- src/mongo/db/storage/kv/storage_engine_test.cpp | 32 ++- src/mongo/db/storage/storage_engine_test_fixture.h | 2 +- .../db/storage/storage_repair_observer_test.cpp | 15 +- .../wiredtiger_kv_engine_no_fixture_test.cpp | 2 +- .../wiredtiger/wiredtiger_kv_engine_test.cpp | 6 +- .../wiredtiger/wiredtiger_record_store_test.cpp | 2 +- .../wiredtiger/wiredtiger_recovery_unit_test.cpp | 2 +- .../wiredtiger_standard_record_store_test.cpp | 2 +- .../bucket_catalog/bucket_catalog_helpers_test.cpp | 2 +- .../bucket_catalog/bucket_catalog_test.cpp | 11 +- .../bucket_catalog/bucket_state_registry_test.cpp | 6 +- .../db/timeseries/bucket_compression_test.cpp | 4 +- .../timeseries_dotted_path_support_test.cpp | 2 +- .../timeseries_update_delete_util_test.cpp | 3 +- .../db/timeseries/timeseries_write_util_test.cpp | 6 +- src/mongo/db/transaction/transaction_api_test.cpp | 20 +- .../transaction_history_iterator_test.cpp | 36 +-- .../db/transaction/transaction_operations_test.cpp | 85 +++--- ...ansaction_participant_retryable_writes_test.cpp | 2 +- .../transaction/transaction_participant_test.cpp | 17 +- src/mongo/db/ttl_test.cpp | 14 +- src/mongo/db/update/update_driver_test.cpp | 8 +- src/mongo/db/vector_clock_test.cpp | 3 +- src/mongo/db/views/resolved_view_test.cpp | 5 +- src/mongo/db/views/view_catalog_test.cpp | 220 +++++++------- src/mongo/db/views/view_definition_test.cpp | 23 +- src/mongo/db/views/view_graph_test.cpp | 12 +- src/mongo/dbtests/cursor_manager_test.cpp | 50 ++-- .../dbtests/extensions_callback_real_test.cpp | 2 +- src/mongo/dbtests/index_access_method_test.cpp | 9 +- src/mongo/dbtests/insert_test.cpp | 2 +- src/mongo/dbtests/mock_dbclient_conn_test.cpp | 76 ++--- .../dbtests/plan_executor_invalidation_test.cpp | 3 +- .../dbtests/wildcard_multikey_persistence_test.cpp | 3 +- src/mongo/executor/async_rpc_test.cpp | 12 +- src/mongo/executor/hedged_async_rpc_test.cpp | 3 +- src/mongo/executor/mock_network_fixture.cpp | 4 +- .../task_executor_cursor_integration_test.cpp | 2 +- .../cluster_server_parameter_op_observer_test.cpp | 12 +- src/mongo/idl/idl_test.cpp | 67 +++-- src/mongo/rpc/op_msg_integration_test.cpp | 23 +- src/mongo/s/append_raw_responses_test.cpp | 2 +- src/mongo/s/async_requests_sender_test.cpp | 2 +- .../s/catalog/sharding_catalog_client_test.cpp | 32 ++- .../catalog/sharding_catalog_write_retry_test.cpp | 2 +- src/mongo/s/catalog/type_collection_test.cpp | 6 +- src/mongo/s/catalog_cache_refresh_test.cpp | 2 +- src/mongo/s/catalog_cache_test.cpp | 3 +- src/mongo/s/chunk_manager_query_test.cpp | 2 +- src/mongo/s/chunk_map_test.cpp | 2 +- src/mongo/s/chunk_test.cpp | 2 +- .../s/collection_routing_info_targeter_test.cpp | 2 +- src/mongo/s/commands/cluster_aggregate_test.cpp | 2 +- .../s/commands/cluster_command_test_fixture.h | 2 +- .../s/commands/document_shard_key_update_test.cpp | 4 +- .../s/query/cluster_client_cursor_impl_test.cpp | 67 +++-- src/mongo/s/query/cluster_cursor_manager_test.cpp | 2 +- src/mongo/s/query/cluster_exchange_test.cpp | 3 +- src/mongo/s/query/results_merger_test_fixture.cpp | 3 +- src/mongo/s/query/sharded_agg_test_fixture.h | 3 +- src/mongo/s/query/store_possible_cursor_test.cpp | 2 +- src/mongo/s/query_analysis_sampler_test.cpp | 12 +- .../s/request_types/balance_chunk_request_test.cpp | 4 +- .../s/request_types/merge_chunks_request_test.cpp | 3 +- src/mongo/s/routing_table_history_test.cpp | 2 +- ...rd_key_pattern_query_util_index_bounds_test.cpp | 6 +- src/mongo/s/shard_key_pattern_test.cpp | 2 +- src/mongo/s/stale_exception_test.cpp | 2 +- src/mongo/s/stale_shard_version_helpers_test.cpp | 2 +- src/mongo/s/transaction_router_test.cpp | 2 +- src/mongo/s/write_ops/batch_write_exec_test.cpp | 6 +- src/mongo/s/write_ops/batch_write_op_test.cpp | 64 ++--- .../s/write_ops/batched_command_request_test.cpp | 3 +- .../s/write_ops/batched_command_response_test.cpp | 5 +- src/mongo/s/write_ops/write_op_test.cpp | 2 +- .../write_without_shard_key_util_test.cpp | 2 +- src/mongo/util/namespace_string_util_test.cpp | 12 +- 298 files changed, 3750 insertions(+), 2544 deletions(-) (limited to 'src/mongo') diff --git a/src/mongo/client/dbclient_cursor_test.cpp b/src/mongo/client/dbclient_cursor_test.cpp index 266307d6b70..e9b0adaf203 100644 --- a/src/mongo/client/dbclient_cursor_test.cpp +++ b/src/mongo/client/dbclient_cursor_test.cpp @@ -145,7 +145,7 @@ protected: TEST_F(DBClientCursorTest, DBClientCursorCallsMetaDataReaderOncePerBatch) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, false); cursor.setBatchSize(2); @@ -192,7 +192,8 @@ TEST_F(DBClientCursorTest, DBClientCursorGetMoreWithTenant) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; const TenantId tenantId(OID::gen()); - const NamespaceString nss(tenantId, "test", "coll"); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, "test", "coll"); FindCommandRequest findCmd{nss}; RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); @@ -237,7 +238,7 @@ TEST_F(DBClientCursorTest, DBClientCursorHandlesOpMsgExhaustCorrectly) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, true /*isExhaust*/); cursor.setBatchSize(0); @@ -301,7 +302,7 @@ TEST_F(DBClientCursorTest, DBClientCursorResendsGetMoreIfMoreToComeFlagIsOmitted // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, true /*isExhaust*/); cursor.setBatchSize(0); @@ -385,7 +386,7 @@ TEST_F(DBClientCursorTest, DBClientCursorResendsGetMoreIfMoreToComeFlagIsOmitted TEST_F(DBClientCursorTest, DBClientCursorMoreThrowsExceptionOnNonOKResponse) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, true /*isExhaust*/); cursor.setBatchSize(0); @@ -416,7 +417,7 @@ TEST_F(DBClientCursorTest, DBClientCursorMoreThrowsExceptionOnNonOKResponse) { TEST_F(DBClientCursorTest, DBClientCursorMoreThrowsExceptionWhenMoreToComeFlagSetWithZeroCursorId) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, true /*isExhaust*/); cursor.setBatchSize(0); @@ -449,7 +450,7 @@ TEST_F(DBClientCursorTest, DBClientCursorMoreThrowsExceptionWhenMoreToComeFlagSe TEST_F(DBClientCursorTest, DBClientCursorPassesReadOnceFlag) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; findCmd.setReadOnce(true); DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, false); @@ -476,7 +477,7 @@ TEST_F(DBClientCursorTest, DBClientCursorPassesReadOnceFlag) { TEST_F(DBClientCursorTest, DBClientCursorPassesResumeFields) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; findCmd.setRequestResumeToken(true); findCmd.setResumeAfter(BSON("$recordId" << 5LL)); @@ -512,7 +513,7 @@ TEST_F(DBClientCursorTest, DBClientCursorTailable) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; findCmd.setTailable(true); DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, false); @@ -606,7 +607,7 @@ TEST_F(DBClientCursorTest, DBClientCursorTailableAwaitData) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; findCmd.setTailable(true); findCmd.setAwaitData(true); @@ -668,7 +669,7 @@ TEST_F(DBClientCursorTest, DBClientCursorTailableAwaitDataExhaust) { // Set up the DBClientCursor and a mock client connection. DBClientConnectionForTest conn; - const NamespaceString nss("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); FindCommandRequest findCmd{nss}; findCmd.setTailable(true); findCmd.setAwaitData(true); diff --git a/src/mongo/client/dbclient_rs_test.cpp b/src/mongo/client/dbclient_rs_test.cpp index 7053d8fe623..27d572f498c 100644 --- a/src/mongo/client/dbclient_rs_test.cpp +++ b/src/mongo/client/dbclient_rs_test.cpp @@ -157,7 +157,7 @@ TEST_F(BasicRS, QueryPrimary) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryOnly}); BSONObj doc = cursor->next(); @@ -173,7 +173,7 @@ TEST_F(BasicRS, QuerySecondaryOnly) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryOnly}); BSONObj doc = cursor->next(); @@ -190,7 +190,7 @@ TEST_F(BasicRS, QueryPrimaryPreferred) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); BSONObj doc = cursor->next(); @@ -206,7 +206,7 @@ TEST_F(BasicRS, QuerySecondaryPreferred) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryPreferred}); BSONObj doc = cursor->next(); @@ -270,7 +270,7 @@ TEST_F(AllNodesDown, QueryPrimary) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; ASSERT_THROWS( replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryOnly}), AssertionException); @@ -284,7 +284,7 @@ TEST_F(AllNodesDown, QuerySecondaryOnly) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; ASSERT_THROWS( replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryOnly}), AssertionException); @@ -298,7 +298,7 @@ TEST_F(AllNodesDown, QueryPrimaryPreferred) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; ASSERT_THROWS( replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryPreferred}), AssertionException); @@ -312,7 +312,7 @@ TEST_F(AllNodesDown, QuerySecondaryPreferred) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; ASSERT_THROWS(replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryPreferred}), AssertionException); @@ -326,7 +326,7 @@ TEST_F(AllNodesDown, QueryNearest) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; ASSERT_THROWS(replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::Nearest}), AssertionException); } @@ -372,7 +372,7 @@ TEST_F(PrimaryDown, QueryPrimary) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; ASSERT_THROWS( replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryOnly}), AssertionException); @@ -387,7 +387,7 @@ TEST_F(PrimaryDown, QuerySecondaryOnly) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryOnly}); BSONObj doc = cursor->next(); @@ -404,7 +404,7 @@ TEST_F(PrimaryDown, QueryPrimaryPreferred) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); BSONObj doc = cursor->next(); @@ -421,7 +421,7 @@ TEST_F(PrimaryDown, QuerySecondaryPreferred) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryPreferred}); BSONObj doc = cursor->next(); @@ -437,7 +437,7 @@ TEST_F(PrimaryDown, Nearest) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::Nearest}); BSONObj doc = cursor->next(); ASSERT_EQUALS(replSet->getSecondaries().front(), doc[HostField.name()].str()); @@ -482,7 +482,7 @@ TEST_F(SecondaryDown, QueryPrimary) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryOnly}); BSONObj doc = cursor->next(); @@ -497,7 +497,7 @@ TEST_F(SecondaryDown, QuerySecondaryOnly) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; ASSERT_THROWS( replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryOnly}), AssertionException); @@ -512,7 +512,7 @@ TEST_F(SecondaryDown, QueryPrimaryPreferred) { DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); // Note: IdentityNS contains the name of the server. - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); BSONObj doc = cursor->next(); @@ -527,7 +527,7 @@ TEST_F(SecondaryDown, QuerySecondaryPreferred) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryPreferred}); BSONObj doc = cursor->next(); @@ -542,7 +542,7 @@ TEST_F(SecondaryDown, QueryNearest) { MockReplicaSet* replSet = getReplSet(); DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData()); - FindCommandRequest findCmd{NamespaceString{IdentityNS}}; + FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)}; auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::Nearest}); BSONObj doc = cursor->next(); ASSERT_EQUALS(replSet->getPrimary(), doc[HostField.name()].str()); @@ -691,17 +691,17 @@ TEST_F(TaggedFiveMemberRS, ConnShouldPinIfSameSettings) { string dest; { // Note: IdentityNS contains the name of the server. - std::unique_ptr cursor = - replConn.find(FindCommandRequest{NamespaceString{IdentityNS}}, - ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); + std::unique_ptr cursor = replConn.find( + FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)}, + ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); BSONObj doc = cursor->next(); dest = doc[HostField.name()].str(); } { - std::unique_ptr cursor = - replConn.find(FindCommandRequest{NamespaceString{IdentityNS}}, - ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); + std::unique_ptr cursor = replConn.find( + FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)}, + ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); BSONObj doc = cursor->next(); const string newDest = doc[HostField.name()].str(); ASSERT_EQUALS(dest, newDest); @@ -718,9 +718,9 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfHostMarkedAsFailed) { string dest; { // Note: IdentityNS contains the name of the server. - std::unique_ptr cursor = - replConn.find(FindCommandRequest{NamespaceString{IdentityNS}}, - ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); + std::unique_ptr cursor = replConn.find( + FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)}, + ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); BSONObj doc = cursor->next(); dest = doc[HostField.name()].str(); } @@ -732,9 +732,9 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfHostMarkedAsFailed) { getTopologyManager()->setTopologyDescription(getReplSet()->getTopologyDescription(clock())); { - std::unique_ptr cursor = - replConn.find(FindCommandRequest{NamespaceString{IdentityNS}}, - ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); + std::unique_ptr cursor = replConn.find( + FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)}, + ReadPreferenceSetting{ReadPreference::PrimaryPreferred}); BSONObj doc = cursor->next(); const string newDest = doc[HostField.name()].str(); ASSERT_NOT_EQUALS(dest, newDest); @@ -752,8 +752,8 @@ TEST_F(TaggedFiveMemberRS, SecondaryConnReturnsSecConn) { mongo::DBClientConnection& secConn = replConn.secondaryConn(); // Note: IdentityNS contains the name of the server. - std::unique_ptr cursor = - secConn.find(FindCommandRequest{NamespaceString{IdentityNS}}); + std::unique_ptr cursor = secConn.find( + FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)}); BSONObj doc = cursor->next(); std::string dest = doc[HostField.name()].str(); ASSERT_NOT_EQUALS(dest, replSet->getPrimary()); diff --git a/src/mongo/crypto/fle_crypto_test.cpp b/src/mongo/crypto/fle_crypto_test.cpp index 4df11f3d9d8..f400d25eeef 100644 --- a/src/mongo/crypto/fle_crypto_test.cpp +++ b/src/mongo/crypto/fle_crypto_test.cpp @@ -2189,7 +2189,7 @@ EncryptedFieldConfig getTestEncryptedFieldConfig() { } TEST(EncryptionInformation, RoundTrip) { - NamespaceString ns("test.test"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.test"); EncryptedFieldConfig efc = getTestEncryptedFieldConfig(); auto obj = EncryptionInformationHelpers::encryptionInformationSerialize(ns, efc); @@ -2210,7 +2210,7 @@ TEST(EncryptionInformation, BadSchema) { auto obj = ei.toBSON(); - NamespaceString ns("test.test"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.test"); ASSERT_THROWS_CODE(EncryptionInformationHelpers::getAndValidateSchema( ns, EncryptionInformation::parse(IDLParserContext("foo"), obj)), DBException, @@ -2218,7 +2218,7 @@ TEST(EncryptionInformation, BadSchema) { } TEST(EncryptionInformation, MissingStateCollection) { - NamespaceString ns("test.test"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.test"); { EncryptedFieldConfig efc = getTestEncryptedFieldConfig(); @@ -2319,7 +2319,7 @@ TEST(IndexedFields, DuplicateIndexKeyIds) { TEST(DeleteTokens, Basic) { TestKeyVault keyVault; - NamespaceString ns("test.test"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.test"); EncryptedFieldConfig efc = getTestEncryptedFieldConfig(); auto obj = @@ -2330,7 +2330,7 @@ TEST(DeleteTokens, Basic) { TEST(DeleteTokens, Fetch) { TestKeyVault keyVault; - NamespaceString ns("test.test"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.test"); EncryptedFieldConfig efc = getTestEncryptedFieldConfig(); auto obj = @@ -2347,7 +2347,7 @@ TEST(DeleteTokens, Fetch) { TEST(DeleteTokens, CorruptDelete) { TestKeyVault keyVault; - NamespaceString ns("test.test"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.test"); EncryptedFieldConfig efc = getTestEncryptedFieldConfig(); EncryptionInformation ei; @@ -2741,7 +2741,7 @@ TEST(FLE_Update, PushToOtherfield) { TEST(FLE_Update, PullTokens) { TestKeyVault keyVault; - NamespaceString ns("test.test"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.test"); EncryptedFieldConfig efc = getTestEncryptedFieldConfig(); auto obj = diff --git a/src/mongo/db/auth/auth_op_observer_test.cpp b/src/mongo/db/auth/auth_op_observer_test.cpp index 56d9e80c82e..d1f6ac87506 100644 --- a/src/mongo/db/auth/auth_op_observer_test.cpp +++ b/src/mongo/db/auth/auth_op_observer_test.cpp @@ -90,7 +90,7 @@ public: }); } - NamespaceString _nss = {"test", "coll"}; + NamespaceString _nss = NamespaceString::createNamespaceString_forTest("test", "coll"); private: // Creates a reasonable set of ReplSettings for most tests. We need to be able to @@ -145,7 +145,7 @@ TEST_F(AuthOpObserverTest, OnRollbackDoesntInvalidateAuthCacheWhenNoAuthNamespac TEST_F(AuthOpObserverTest, MultipleAboutToDeleteAndOnDelete) { AuthOpObserver opObserver; auto opCtx = cc().makeOperationContext(); - NamespaceString nss = {"test", "coll"}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); WriteUnitOfWork wunit(opCtx.get()); AutoGetCollection autoColl(opCtx.get(), nss, MODE_IX); opObserver.aboutToDelete(opCtx.get(), *autoColl, BSON("_id" << 1)); @@ -158,7 +158,7 @@ DEATH_TEST_F(AuthOpObserverTest, AboutToDeleteMustPreceedOnDelete, "invariant") AuthOpObserver opObserver; auto opCtx = cc().makeOperationContext(); cc().swapLockState(std::make_unique()); - NamespaceString nss = {"test", "coll"}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); AutoGetCollection autoColl(opCtx.get(), nss, MODE_IX); opObserver.onDelete(opCtx.get(), *autoColl, {}, {}); } diff --git a/src/mongo/db/auth/authorization_session_test.cpp b/src/mongo/db/auth/authorization_session_test.cpp index 4f5b6a7c1f6..f2c9081a8a4 100644 --- a/src/mongo/db/auth/authorization_session_test.cpp +++ b/src/mongo/db/auth/authorization_session_test.cpp @@ -134,12 +134,12 @@ public: } rolesBSON.doneFast(); - return managerState->insert(_opCtx.get(), - NamespaceString(username.getTenant(), - NamespaceString::kAdminDb, - NamespaceString::kSystemUsers), - userDoc.obj(), - {}); + return managerState->insert( + _opCtx.get(), + NamespaceString::createNamespaceString_forTest( + username.getTenant(), NamespaceString::kAdminDb, NamespaceString::kSystemUsers), + userDoc.obj(), + {}); } void assertLogout(const ResourcePattern& resource, ActionType action) { @@ -197,9 +197,9 @@ protected: BSONObj credentials; }; -const NamespaceString testFooNss("test.foo"); -const NamespaceString testBarNss("test.bar"); -const NamespaceString testQuxNss("test.qux"); +const NamespaceString testFooNss = NamespaceString::createNamespaceString_forTest("test.foo"); +const NamespaceString testBarNss = NamespaceString::createNamespaceString_forTest("test.bar"); +const NamespaceString testQuxNss = NamespaceString::createNamespaceString_forTest("test.qux"); const ResourcePattern testDBResource(ResourcePattern::forDatabaseName("test")); const ResourcePattern otherDBResource(ResourcePattern::forDatabaseName("other")); @@ -207,24 +207,24 @@ const ResourcePattern adminDBResource(ResourcePattern::forDatabaseName("admin")) const ResourcePattern testFooCollResource(ResourcePattern::forExactNamespace(testFooNss)); const ResourcePattern testBarCollResource(ResourcePattern::forExactNamespace(testBarNss)); const ResourcePattern testQuxCollResource(ResourcePattern::forExactNamespace(testQuxNss)); -const ResourcePattern otherFooCollResource( - ResourcePattern::forExactNamespace(NamespaceString("other.foo"))); -const ResourcePattern thirdFooCollResource( - ResourcePattern::forExactNamespace(NamespaceString("third.foo"))); -const ResourcePattern adminFooCollResource( - ResourcePattern::forExactNamespace(NamespaceString("admin.foo"))); -const ResourcePattern testUsersCollResource( - ResourcePattern::forExactNamespace(NamespaceString("test.system.users"))); -const ResourcePattern otherUsersCollResource( - ResourcePattern::forExactNamespace(NamespaceString("other.system.users"))); -const ResourcePattern thirdUsersCollResource( - ResourcePattern::forExactNamespace(NamespaceString("third.system.users"))); -const ResourcePattern testProfileCollResource( - ResourcePattern::forExactNamespace(NamespaceString("test.system.profile"))); -const ResourcePattern otherProfileCollResource( - ResourcePattern::forExactNamespace(NamespaceString("other.system.profile"))); -const ResourcePattern thirdProfileCollResource( - ResourcePattern::forExactNamespace(NamespaceString("third.system.profile"))); +const ResourcePattern otherFooCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("other.foo"))); +const ResourcePattern thirdFooCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("third.foo"))); +const ResourcePattern adminFooCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("admin.foo"))); +const ResourcePattern testUsersCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("test.system.users"))); +const ResourcePattern otherUsersCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("other.system.users"))); +const ResourcePattern thirdUsersCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("third.system.users"))); +const ResourcePattern testProfileCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("test.system.profile"))); +const ResourcePattern otherProfileCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("other.system.profile"))); +const ResourcePattern thirdProfileCollResource(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("third.system.profile"))); const UserName kUser1Test("user1"_sd, "test"_sd); const UserRequest kUser1TestRequest(kUser1Test, boost::none); @@ -295,7 +295,8 @@ TEST_F(AuthorizationSessionTest, AddUserAndCheckAuthorization) { ASSERT_OK(authzSession->addAndAuthorizeUser(_opCtx.get(), kAdminAdminRequest, boost::none)); ASSERT_TRUE(authzSession->isAuthorizedForActionsOnResource( - ResourcePattern::forExactNamespace(NamespaceString("anydb.somecollection")), + ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("anydb.somecollection")), ActionType::insert)); ASSERT_TRUE( authzSession->isAuthorizedForActionsOnResource(otherDBResource, ActionType::insert)); @@ -327,7 +328,8 @@ TEST_F(AuthorizationSessionTest, AddUserAndCheckAuthorization) { std::initializer_list{ Privilege(ResourcePattern::forDatabaseName("ignored"), {ActionType::insert, ActionType::dbStats}), - Privilege(ResourcePattern::forExactNamespace(NamespaceString("ignored.ignored")), + Privilege(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("ignored.ignored")), {ActionType::insert, ActionType::collMod}), }); @@ -1397,7 +1399,8 @@ TEST_F(AuthorizationSessionTest, ExpiredSessionWithReauth) { // Check that explicit logout from an expired connection works as expected. authzSession->logoutDatabase(_client.get(), "test", "Kill the test!"); - assertLogout(ResourcePattern::forExactNamespace(NamespaceString("anydb.somecollection")), + assertLogout(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("anydb.somecollection")), ActionType::insert); } @@ -1442,12 +1445,14 @@ TEST_F(AuthorizationSessionTest, ExpirationWithSecurityTokenNOK) { // Assert that a connection-based user with an expiration policy can be authorized after token // logout. ASSERT_OK(authzSession->addAndAuthorizeUser(_opCtx.get(), adminUserRequest, expirationTime)); - assertActive(ResourcePattern::forExactNamespace(NamespaceString("anydb.somecollection")), + assertActive(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("anydb.somecollection")), ActionType::insert); // Check that logout proceeds normally. authzSession->logoutDatabase(_client.get(), "admin", "Kill the test!"); - assertLogout(ResourcePattern::forExactNamespace(NamespaceString("anydb.somecollection")), + assertLogout(ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("anydb.somecollection")), ActionType::insert); } @@ -1471,18 +1476,24 @@ protected: }; const ResourcePattern SystemBucketsTest::testMissingSystemBucketResource( - ResourcePattern::forExactNamespace(NamespaceString("sb_db_test.sb_coll_test"))); + ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("sb_db_test.sb_coll_test"))); const ResourcePattern SystemBucketsTest::otherMissingSystemBucketResource( - ResourcePattern::forExactNamespace(NamespaceString("sb_db_test.sb_coll_other"))); + ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("sb_db_test.sb_coll_other"))); const ResourcePattern SystemBucketsTest::otherDbMissingSystemBucketResource( - ResourcePattern::forExactNamespace(NamespaceString("sb_db_other.sb_coll_test"))); + ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("sb_db_other.sb_coll_test"))); const ResourcePattern SystemBucketsTest::testSystemBucketResource( - ResourcePattern::forExactNamespace(NamespaceString("sb_db_test.system.buckets.sb_coll_test"))); + ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("sb_db_test.system.buckets.sb_coll_test"))); const ResourcePattern SystemBucketsTest::otherSystemBucketResource( - ResourcePattern::forExactNamespace(NamespaceString("sb_db_test.system.buckets.sb_coll_other"))); + ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("sb_db_test.system.buckets.sb_coll_other"))); const ResourcePattern SystemBucketsTest::otherDbSystemBucketResource( - ResourcePattern::forExactNamespace(NamespaceString("sb_db_other.system.buckets.sb_coll_test"))); + ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("sb_db_other.system.buckets.sb_coll_test"))); const ResourcePattern SystemBucketsTest::testBucketResource( ResourcePattern::forExactSystemBucketsCollection("sb_db_test", "sb_coll_test")); diff --git a/src/mongo/db/auth/builtin_roles_test.cpp b/src/mongo/db/auth/builtin_roles_test.cpp index 6d84c11b52a..26d962db72b 100644 --- a/src/mongo/db/auth/builtin_roles_test.cpp +++ b/src/mongo/db/auth/builtin_roles_test.cpp @@ -112,8 +112,8 @@ TEST(BuiltinRoles, addPrivilegesForBuiltinRole) { ActionType::planCacheRead, }); const auto adminDB = ResourcePattern::forDatabaseName("admin"); - const auto adminSystemJS = - ResourcePattern::forExactNamespace(NamespaceString("admin", "system.js")); + const auto adminSystemJS = ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("admin", "system.js")); for (const auto& priv : privs) { auto resource = priv.getResourcePattern(); diff --git a/src/mongo/db/auth/privilege_parser_test.cpp b/src/mongo/db/auth/privilege_parser_test.cpp index fa3f1c5e6bd..36dc18d3ada 100644 --- a/src/mongo/db/auth/privilege_parser_test.cpp +++ b/src/mongo/db/auth/privilege_parser_test.cpp @@ -219,7 +219,8 @@ TEST(PrivilegeParserTest, ConvertBetweenPrivilegeTest) { ASSERT(privilege.getActions().contains(ActionType::find)); ASSERT(!privilege.getActions().contains(ActionType::insert)); ASSERT_EQUALS(privilege.getResourcePattern(), - ResourcePattern::forExactNamespace(NamespaceString("test.foo"))); + ResourcePattern::forExactNamespace( + NamespaceString::createNamespaceString_forTest("test.foo"))); ASSERT(ParsedPrivilege::privilegeToParsedPrivilege(privilege, &parsedPrivilege, &errmsg)); ASSERT(parsedPrivilege.isValid(&errmsg)); diff --git a/src/mongo/db/auth/sasl_authentication_session_test.cpp b/src/mongo/db/auth/sasl_authentication_session_test.cpp index d8df2909511..5c8d35544dc 100644 --- a/src/mongo/db/auth/sasl_authentication_session_test.cpp +++ b/src/mongo/db/auth/sasl_authentication_session_test.cpp @@ -128,7 +128,8 @@ SaslConversation::SaslConversation(std::string mech) ASSERT_OK( authManagerExternalState->insert(opCtx.get(), - NamespaceString("admin.system.users"), + NamespaceString::createNamespaceString_forTest( + "admin.system.users"), BSON("_id" << "test.andy" << "user" diff --git a/src/mongo/db/auth/sasl_mechanism_registry_test.cpp b/src/mongo/db/auth/sasl_mechanism_registry_test.cpp index a8942d99052..228558fb44c 100644 --- a/src/mongo/db/auth/sasl_mechanism_registry_test.cpp +++ b/src/mongo/db/auth/sasl_mechanism_registry_test.cpp @@ -207,7 +207,7 @@ public: ASSERT_OK(authManagerExternalState->insert( opCtx.get(), - NamespaceString("admin.system.users"), + NamespaceString::createNamespaceString_forTest("admin.system.users"), BSON("_id" << "test.sajack" << "user" @@ -222,7 +222,8 @@ public: ASSERT_OK(authManagerExternalState->insert(opCtx.get(), - NamespaceString("admin.system.users"), + NamespaceString::createNamespaceString_forTest( + "admin.system.users"), BSON("_id" << "$external.sajack" << "user" diff --git a/src/mongo/db/catalog/capped_collection_test.cpp b/src/mongo/db/catalog/capped_collection_test.cpp index 420a48d70c9..b95317f207d 100644 --- a/src/mongo/db/catalog/capped_collection_test.cpp +++ b/src/mongo/db/catalog/capped_collection_test.cpp @@ -132,7 +132,7 @@ Status _insertBSON(OperationContext* opCtx, const CollectionPtr& coll, RecordId } TEST_F(CappedCollectionTest, SeekNear) { - NamespaceString nss("local.non.oplog"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.non.oplog"); makeCapped(nss); { @@ -283,7 +283,7 @@ TEST_F(CappedCollectionTest, SeekNear) { } TEST_F(CappedCollectionTest, InsertOutOfOrder) { - NamespaceString nss("local.non.oplog"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.non.oplog"); makeCapped(nss); { // RecordId's are inserted out-of-order. @@ -306,7 +306,7 @@ TEST_F(CappedCollectionTest, InsertOutOfOrder) { } TEST_F(CappedCollectionTest, OplogOrder) { - NamespaceString nss("local.non.oplog"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.non.oplog"); makeCapped(nss); auto id1 = RecordId(1); diff --git a/src/mongo/db/catalog/capped_utils_test.cpp b/src/mongo/db/catalog/capped_utils_test.cpp index 0ada277fc4f..cec27d7a23b 100644 --- a/src/mongo/db/catalog/capped_utils_test.cpp +++ b/src/mongo/db/catalog/capped_utils_test.cpp @@ -107,7 +107,7 @@ CollectionOptions getCollectionOptions(OperationContext* opCtx, const NamespaceS const double cappedCollectionSize = 8192.0; TEST_F(CappedUtilsTest, ConvertToCappedReturnsNamespaceNotFoundIfCollectionIsMissing) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto opCtx = makeOpCtx(); ASSERT_FALSE(collectionExists(opCtx.get(), nss)); ASSERT_THROWS_CODE( @@ -115,7 +115,7 @@ TEST_F(CappedUtilsTest, ConvertToCappedReturnsNamespaceNotFoundIfCollectionIsMis } TEST_F(CappedUtilsTest, ConvertToCappedUpdatesCollectionOptionsOnSuccess) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto opCtx = makeOpCtx(); ASSERT_OK(_storage->createCollection(opCtx.get(), nss, {})); @@ -130,7 +130,7 @@ TEST_F(CappedUtilsTest, ConvertToCappedUpdatesCollectionOptionsOnSuccess) { } TEST_F(CappedUtilsTest, ConvertToCappedReturnsNamespaceNotFoundIfCollectionIsDropPending) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); repl::OpTime dropOpTime(Timestamp(Seconds(100), 0), 1LL); auto dropPendingNss = nss.makeDropPendingNamespace(dropOpTime); diff --git a/src/mongo/db/catalog/collection_catalog_test.cpp b/src/mongo/db/catalog/collection_catalog_test.cpp index 5d31306de97..4baf0274d15 100644 --- a/src/mongo/db/catalog/collection_catalog_test.cpp +++ b/src/mongo/db/catalog/collection_catalog_test.cpp @@ -110,8 +110,10 @@ public: globalLock.emplace(opCtx.get()); for (int counter = 0; counter < 5; ++counter) { - NamespaceString fooNss("foo", "coll" + std::to_string(counter)); - NamespaceString barNss("bar", "coll" + std::to_string(counter)); + NamespaceString fooNss = NamespaceString::createNamespaceString_forTest( + "foo", "coll" + std::to_string(counter)); + NamespaceString barNss = NamespaceString::createNamespaceString_forTest( + "bar", "coll" + std::to_string(counter)); auto fooUuid = UUID::gen(); std::shared_ptr fooColl = std::make_shared(fooNss); @@ -187,7 +189,8 @@ public: globalLock.emplace(opCtx.get()); for (int i = 0; i < 5; i++) { - NamespaceString nss("resourceDb", "coll" + std::to_string(i)); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "resourceDb", "coll" + std::to_string(i)); std::shared_ptr collection = std::make_shared(nss); auto uuid = collection->uuid(); @@ -250,7 +253,8 @@ TEST_F(CollectionCatalogResourceTest, RemoveAllResources) { ASSERT_EQ(boost::none, ResourceCatalog::get(getServiceContext()).name(rid)); for (int i = 0; i < 5; i++) { - NamespaceString nss("resourceDb", "coll" + std::to_string(i)); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "resourceDb", "coll" + std::to_string(i)); rid = ResourceId(RESOURCE_COLLECTION, nss); ASSERT_EQ(boost::none, ResourceCatalog::get(getServiceContext()).name(rid)); } @@ -272,7 +276,8 @@ TEST_F(CollectionCatalogResourceTest, LookupMissingDatabaseResource) { } TEST_F(CollectionCatalogResourceTest, LookupCollectionResource) { - const NamespaceString collNs = NamespaceString(boost::none, "resourceDb.coll1"); + const NamespaceString collNs = + NamespaceString::createNamespaceString_forTest(boost::none, "resourceDb.coll1"); auto rid = ResourceId(RESOURCE_COLLECTION, collNs); auto ridStr = ResourceCatalog::get(getServiceContext()).name(rid); @@ -281,13 +286,15 @@ TEST_F(CollectionCatalogResourceTest, LookupCollectionResource) { } TEST_F(CollectionCatalogResourceTest, LookupMissingCollectionResource) { - const NamespaceString nss = NamespaceString(boost::none, "resourceDb.coll5"); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "resourceDb.coll5"); auto rid = ResourceId(RESOURCE_COLLECTION, nss); ASSERT(!ResourceCatalog::get(getServiceContext()).name(rid)); } TEST_F(CollectionCatalogResourceTest, RemoveCollection) { - const NamespaceString collNs = NamespaceString(boost::none, "resourceDb.coll1"); + const NamespaceString collNs = + NamespaceString::createNamespaceString_forTest(boost::none, "resourceDb.coll1"); auto coll = catalog.lookupCollectionByNamespace(opCtx.get(), NamespaceString(collNs)); catalog.deregisterCollection(opCtx.get(), coll->uuid(), /*isDropPending=*/false, boost::none); auto rid = ResourceId(RESOURCE_COLLECTION, collNs); @@ -338,7 +345,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUID) { TEST_F(CollectionCatalogTest, InsertAfterLookup) { auto newUUID = UUID::gen(); - NamespaceString newNss(nss.db(), "newcol"); + NamespaceString newNss = NamespaceString::createNamespaceString_forTest(nss.dbName(), "newcol"); std::shared_ptr newCollShared = std::make_shared(newNss); auto newCol = newCollShared.get(); @@ -389,7 +396,7 @@ TEST_F(CollectionCatalogTest, OnDropCollection) { TEST_F(CollectionCatalogTest, RenameCollection) { auto uuid = UUID::gen(); - NamespaceString oldNss(nss.db(), "oldcol"); + NamespaceString oldNss = NamespaceString::createNamespaceString_forTest(nss.db(), "oldcol"); std::shared_ptr collShared = std::make_shared(uuid, oldNss); auto collection = collShared.get(); catalog.registerCollection(opCtx.get(), uuid, std::move(collShared), boost::none); @@ -420,7 +427,7 @@ TEST_F(CollectionCatalogTest, RenameCollection) { yieldableColl.yield(); ASSERT_FALSE(yieldableColl); - NamespaceString newNss(NamespaceString(nss.db(), "newcol")); + NamespaceString newNss = NamespaceString::createNamespaceString_forTest(nss.dbName(), "newcol"); ASSERT_OK(collection->rename(opCtx.get(), newNss, false)); ASSERT_EQ(collection->ns(), newNss); ASSERT_EQUALS(catalog.lookupCollectionByUUID(opCtx.get(), uuid), collection); @@ -450,7 +457,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsOldNSSIfDrop TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreatedNSS) { auto newUUID = UUID::gen(); - NamespaceString newNss(nss.db(), "newcol"); + NamespaceString newNss = NamespaceString::createNamespaceString_forTest(nss.dbName(), "newcol"); std::shared_ptr newCollShared = std::make_shared(newNss); auto newCol = newCollShared.get(); @@ -477,7 +484,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreated } TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS) { - NamespaceString newNss(nss.db(), "newcol"); + NamespaceString newNss = NamespaceString::createNamespaceString_forTest(nss.dbName(), "newcol"); std::shared_ptr newCollShared = std::make_shared(newNss); auto newCol = newCollShared.get(); @@ -522,13 +529,13 @@ TEST_F(CollectionCatalogTest, CollectionCatalogEpoch) { } TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNames) { - NamespaceString aColl("dbA", "collA"); - NamespaceString b1Coll("dbB", "collB1"); - NamespaceString b2Coll("dbB", "collB2"); - NamespaceString cColl("dbC", "collC"); - NamespaceString d1Coll("dbD", "collD1"); - NamespaceString d2Coll("dbD", "collD2"); - NamespaceString d3Coll("dbD", "collD3"); + NamespaceString aColl = NamespaceString::createNamespaceString_forTest("dbA", "collA"); + NamespaceString b1Coll = NamespaceString::createNamespaceString_forTest("dbB", "collB1"); + NamespaceString b2Coll = NamespaceString::createNamespaceString_forTest("dbB", "collB2"); + NamespaceString cColl = NamespaceString::createNamespaceString_forTest("dbC", "collC"); + NamespaceString d1Coll = NamespaceString::createNamespaceString_forTest("dbD", "collD1"); + NamespaceString d2Coll = NamespaceString::createNamespaceString_forTest("dbD", "collD2"); + NamespaceString d3Coll = NamespaceString::createNamespaceString_forTest("dbD", "collD3"); std::vector nsss = {aColl, b1Coll, b2Coll, cColl, d1Coll, d2Coll, d3Coll}; for (auto& nss : nsss) { @@ -557,10 +564,10 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNames) { TEST_F(CollectionCatalogTest, GetAllDbNamesForTenant) { TenantId tid1 = TenantId(OID::gen()); TenantId tid2 = TenantId(OID::gen()); - NamespaceString dbA(tid1, "dbA.collA"); - NamespaceString dbB(tid1, "dbB.collA"); - NamespaceString dbC(tid1, "dbC.collA"); - NamespaceString dbD(tid2, "dbB.collA"); + NamespaceString dbA = NamespaceString::createNamespaceString_forTest(tid1, "dbA.collA"); + NamespaceString dbB = NamespaceString::createNamespaceString_forTest(tid1, "dbB.collA"); + NamespaceString dbC = NamespaceString::createNamespaceString_forTest(tid1, "dbC.collA"); + NamespaceString dbD = NamespaceString::createNamespaceString_forTest(tid2, "dbB.collA"); std::vector nsss = {dbA, dbB, dbC, dbD}; for (auto& nss : nsss) { @@ -602,13 +609,13 @@ TEST_F(CollectionCatalogTest, DatabaseProfileLevel) { } TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommittedCollections) { - NamespaceString aColl("dbA", "collA"); - NamespaceString b1Coll("dbB", "collB1"); - NamespaceString b2Coll("dbB", "collB2"); - NamespaceString cColl("dbC", "collC"); - NamespaceString d1Coll("dbD", "collD1"); - NamespaceString d2Coll("dbD", "collD2"); - NamespaceString d3Coll("dbD", "collD3"); + NamespaceString aColl = NamespaceString::createNamespaceString_forTest("dbA", "collA"); + NamespaceString b1Coll = NamespaceString::createNamespaceString_forTest("dbB", "collB1"); + NamespaceString b2Coll = NamespaceString::createNamespaceString_forTest("dbB", "collB2"); + NamespaceString cColl = NamespaceString::createNamespaceString_forTest("dbC", "collC"); + NamespaceString d1Coll = NamespaceString::createNamespaceString_forTest("dbD", "collD1"); + NamespaceString d2Coll = NamespaceString::createNamespaceString_forTest("dbD", "collD2"); + NamespaceString d3Coll = NamespaceString::createNamespaceString_forTest("dbD", "collD3"); std::vector nsss = {aColl, b1Coll, b2Coll, cColl, d1Coll, d2Coll, d3Coll}; for (auto& nss : nsss) { @@ -682,13 +689,21 @@ public: tempCollOptions.temp = true; ASSERT_OK(storageInterface()->createCollection( - operationContext(), NamespaceString("db", "coll1"), emptyCollOptions)); + operationContext(), + NamespaceString::createNamespaceString_forTest("db", "coll1"), + emptyCollOptions)); ASSERT_OK(storageInterface()->createCollection( - operationContext(), NamespaceString("db", "coll2"), tempCollOptions)); + operationContext(), + NamespaceString::createNamespaceString_forTest("db", "coll2"), + tempCollOptions)); ASSERT_OK(storageInterface()->createCollection( - operationContext(), NamespaceString("db", "coll3"), tempCollOptions)); + operationContext(), + NamespaceString::createNamespaceString_forTest("db", "coll3"), + tempCollOptions)); ASSERT_OK(storageInterface()->createCollection( - operationContext(), NamespaceString("db2", "coll4"), emptyCollOptions)); + operationContext(), + NamespaceString::createNamespaceString_forTest("db2", "coll4"), + emptyCollOptions)); } }; @@ -1312,7 +1327,7 @@ public: }; TEST_F(CollectionCatalogTimestampTest, MinimumValidSnapshot) { - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createXIndexTs = Timestamp(20, 20); const Timestamp createYIndexTs = Timestamp(30, 30); @@ -1359,7 +1374,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenCollectionBeforeCreateTimestamp) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); createCollection(opCtx.get(), nss, createCollectionTs); @@ -1383,7 +1398,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenEarlierCollection) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); @@ -1424,7 +1439,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenEarlierCollectionWithIndex) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createXIndexTs = Timestamp(20, 20); const Timestamp createYIndexTs = Timestamp(30, 30); @@ -1477,7 +1492,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenLatestCollectionWithIndex) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createXIndexTs = Timestamp(20, 20); @@ -1517,7 +1532,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenEarlierCollectionWithDropPendingIndex RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp dropIndexTs = Timestamp(30, 30); @@ -1588,7 +1603,7 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const std::string xIndexName{"x_1"}; const std::string yIndexName{"y_1"}; @@ -1674,8 +1689,8 @@ TEST_F(CollectionCatalogTimestampTest, OpenEarlierAlreadyDropPendingCollection) RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString firstNss("a.b"); - const NamespaceString secondNss("c.d"); + const NamespaceString firstNss = NamespaceString::createNamespaceString_forTest("a.b"); + const NamespaceString secondNss = NamespaceString::createNamespaceString_forTest("c.d"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp dropCollectionTs = Timestamp(30, 30); @@ -1739,7 +1754,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenNewCollectionUsingDropPendingCollecti RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp dropCollectionTs = Timestamp(30, 30); @@ -1783,7 +1798,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenExistingCollectionWithReaper) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp dropCollectionTs = Timestamp(20, 20); @@ -1845,7 +1860,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenNewCollectionWithReaper) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp dropCollectionTs = Timestamp(20, 20); @@ -1899,7 +1914,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenExistingCollectionAndIndexesWithReape RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp dropXIndexTs = Timestamp(30, 30); @@ -2018,7 +2033,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenNewCollectionAndIndexesWithReaper) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp dropXIndexTs = Timestamp(30, 30); @@ -2123,7 +2138,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingCreate) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Initialize the oldest timestamp to (1, 1) CollectionCatalog::write(opCtx.get(), [](CollectionCatalog& catalog) { @@ -2152,7 +2167,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingDrop) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Initialize the oldest timestamp to (1, 1) CollectionCatalog::write(opCtx.get(), [](CollectionCatalog& catalog) { @@ -2189,8 +2204,8 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingRename) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString from("a.b"); - NamespaceString to("a.c"); + NamespaceString from = NamespaceString::createNamespaceString_forTest("a.b"); + NamespaceString to = NamespaceString::createNamespaceString_forTest("a.c"); // Initialize the oldest timestamp to (1, 1) CollectionCatalog::write(opCtx.get(), [](CollectionCatalog& catalog) { @@ -2241,8 +2256,8 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingRenameDropTarget) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString from("a.b"); - NamespaceString to("a.c"); + NamespaceString from = NamespaceString::createNamespaceString_forTest("a.b"); + NamespaceString to = NamespaceString::createNamespaceString_forTest("a.c"); // Initialize the oldest timestamp to (1, 1) CollectionCatalog::write(opCtx.get(), [](CollectionCatalog& catalog) { @@ -2276,7 +2291,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingDropCreate) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Create, drop and recreate collection on the same namespace. We have different catalogId. createCollection(opCtx.get(), nss, Timestamp(1, 5)); @@ -2310,7 +2325,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingCleanupEqDrop) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Create collection and verify we have nothing to cleanup createCollection(opCtx.get(), nss, Timestamp(1, 5)); @@ -2351,7 +2366,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingCleanupGtDrop) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Create collection and verify we have nothing to cleanup createCollection(opCtx.get(), nss, Timestamp(1, 5)); @@ -2393,7 +2408,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingCleanupGtRecreate) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Create collection and verify we have nothing to cleanup createCollection(opCtx.get(), nss, Timestamp(1, 5)); @@ -2435,7 +2450,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingCleanupMultiple) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Create and drop multiple namespace on the same namespace createCollection(opCtx.get(), nss, Timestamp(1, 5)); @@ -2523,7 +2538,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingCleanupMultipleSingleCall RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Create and drop multiple namespace on the same namespace createCollection(opCtx.get(), nss, Timestamp(1, 5)); @@ -2566,11 +2581,11 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingRollback) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString a("b.a"); - NamespaceString b("b.b"); - NamespaceString c("b.c"); - NamespaceString d("b.d"); - NamespaceString e("b.e"); + NamespaceString a = NamespaceString::createNamespaceString_forTest("b.a"); + NamespaceString b = NamespaceString::createNamespaceString_forTest("b.b"); + NamespaceString c = NamespaceString::createNamespaceString_forTest("b.c"); + NamespaceString d = NamespaceString::createNamespaceString_forTest("b.d"); + NamespaceString e = NamespaceString::createNamespaceString_forTest("b.e"); // Create and drop multiple namespace on the same namespace createCollection(opCtx.get(), a, Timestamp(1, 1)); @@ -2602,7 +2617,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingInsert) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Create a collection on the namespace createCollection(opCtx.get(), nss, Timestamp(1, 10)); @@ -2744,7 +2759,7 @@ TEST_F(CollectionCatalogTimestampTest, CatalogIdMappingInsertUnknown) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Simulate startup where we have a range [oldest, stable] by advancing the oldest timestamp and // then reading behind it. @@ -2768,7 +2783,7 @@ TEST_F(CollectionCatalogTimestampTest, CollectionLifetimeTiedToStorageTransactio RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); @@ -2855,7 +2870,7 @@ TEST_F(CollectionCatalogNoTimestampTest, CatalogIdMappingNoTimestamp) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); // Create a collection on the namespace and confirm that we can lookup createCollection(opCtx.get(), nss, Timestamp()); @@ -2872,8 +2887,8 @@ TEST_F(CollectionCatalogNoTimestampTest, CatalogIdMappingNoTimestampRename) { RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString a("a.a"); - NamespaceString b("a.b"); + NamespaceString a = NamespaceString::createNamespaceString_forTest("a.a"); + NamespaceString b = NamespaceString::createNamespaceString_forTest("a.b"); // Create a collection on the namespace and confirm that we can lookup createCollection(opCtx.get(), a, Timestamp()); @@ -2901,8 +2916,8 @@ TEST_F(CollectionCatalogNoTimestampTest, CatalogIdMappingNoTimestampRenameDropTa RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - NamespaceString a("a.a"); - NamespaceString b("a.b"); + NamespaceString a = NamespaceString::createNamespaceString_forTest("a.a"); + NamespaceString b = NamespaceString::createNamespaceString_forTest("a.b"); // Create collections on the namespaces and confirm that we can lookup createCollection(opCtx.get(), a, Timestamp()); @@ -2934,7 +2949,7 @@ DEATH_TEST_F(CollectionCatalogTimestampTest, OpenCollectionInWriteUnitOfWork, "i RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); @@ -2959,7 +2974,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentCreateCollectionAndOpenCollecti RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); // When the snapshot is opened right before the create is committed to the durable catalog, the @@ -2972,7 +2987,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentCreateCollectionAndOpenCollecti RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); // When the snapshot is opened right after the create is committed to the durable catalog, the @@ -2986,7 +3001,7 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); UUID uuid = UUID::gen(); @@ -3001,7 +3016,7 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); UUID uuid = UUID::gen(); @@ -3015,7 +3030,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentDropCollectionAndOpenCollection RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp dropCollectionTs = Timestamp(20, 20); @@ -3031,7 +3046,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentDropCollectionAndOpenCollection RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp dropCollectionTs = Timestamp(20, 20); @@ -3048,7 +3063,7 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp dropCollectionTs = Timestamp(20, 20); @@ -3067,7 +3082,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentDropCollectionAndOpenCollection RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp dropCollectionTs = Timestamp(20, 20); @@ -3087,8 +3102,8 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString originalNss("a.b"); - const NamespaceString newNss("a.c"); + const NamespaceString originalNss = NamespaceString::createNamespaceString_forTest("a.b"); + const NamespaceString newNss = NamespaceString::createNamespaceString_forTest("a.c"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp renameCollectionTs = Timestamp(20, 20); @@ -3105,8 +3120,8 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString originalNss("a.b"); - const NamespaceString newNss("a.c"); + const NamespaceString originalNss = NamespaceString::createNamespaceString_forTest("a.b"); + const NamespaceString newNss = NamespaceString::createNamespaceString_forTest("a.c"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp renameCollectionTs = Timestamp(20, 20); @@ -3137,8 +3152,8 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString originalNss("a.b"); - const NamespaceString newNss("a.c"); + const NamespaceString originalNss = NamespaceString::createNamespaceString_forTest("a.b"); + const NamespaceString newNss = NamespaceString::createNamespaceString_forTest("a.c"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp renameCollectionTs = Timestamp(20, 20); @@ -3169,8 +3184,8 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString originalNss("a.b"); - const NamespaceString newNss("a.c"); + const NamespaceString originalNss = NamespaceString::createNamespaceString_forTest("a.b"); + const NamespaceString newNss = NamespaceString::createNamespaceString_forTest("a.c"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp renameCollectionTs = Timestamp(20, 20); @@ -3187,8 +3202,8 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString originalNss("a.b"); - const NamespaceString newNss("a.c"); + const NamespaceString originalNss = NamespaceString::createNamespaceString_forTest("a.b"); + const NamespaceString newNss = NamespaceString::createNamespaceString_forTest("a.c"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp renameCollectionTs = Timestamp(20, 20); @@ -3214,8 +3229,8 @@ TEST_F(CollectionCatalogTimestampTest, RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString originalNss("a.b"); - const NamespaceString newNss("a.c"); + const NamespaceString originalNss = NamespaceString::createNamespaceString_forTest("a.b"); + const NamespaceString newNss = NamespaceString::createNamespaceString_forTest("a.c"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp renameCollectionTs = Timestamp(20, 20); @@ -3250,7 +3265,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentCreateIndexAndOpenCollectionBef RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createXIndexTs = Timestamp(20, 20); const Timestamp createYIndexTs = Timestamp(30, 30); @@ -3281,7 +3296,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentCreateIndexAndOpenCollectionAft RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createXIndexTs = Timestamp(20, 20); const Timestamp createYIndexTs = Timestamp(30, 30); @@ -3312,7 +3327,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentCreateIndexAndOpenCollectionByU RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createXIndexTs = Timestamp(20, 20); const Timestamp createYIndexTs = Timestamp(30, 30); @@ -3346,7 +3361,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentCreateIndexAndOpenCollectionByU RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createXIndexTs = Timestamp(20, 20); const Timestamp createYIndexTs = Timestamp(30, 30); @@ -3380,7 +3395,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentDropIndexAndOpenCollectionBefor RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp dropIndexTs = Timestamp(30, 30); @@ -3408,7 +3423,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentDropIndexAndOpenCollectionAfter RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp dropIndexTs = Timestamp(30, 30); @@ -3436,7 +3451,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentDropIndexAndOpenCollectionByUUI RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp dropIndexTs = Timestamp(30, 30); @@ -3468,7 +3483,7 @@ TEST_F(CollectionCatalogTimestampTest, ConcurrentDropIndexAndOpenCollectionByUUI RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp dropIndexTs = Timestamp(30, 30); @@ -3500,7 +3515,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenCollectionBetweenIndexBuildInProgress RAIIServerParameterControllerForTest featureFlagController( "featureFlagPointInTimeCatalogLookups", true); - const NamespaceString nss("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); const Timestamp createCollectionTs = Timestamp(10, 10); const Timestamp createIndexTs = Timestamp(20, 20); const Timestamp indexReadyTs = Timestamp(30, 30); diff --git a/src/mongo/db/catalog/collection_test.cpp b/src/mongo/db/catalog/collection_test.cpp index d5b3979b2e9..b1e2ea74d1a 100644 --- a/src/mongo/db/catalog/collection_test.cpp +++ b/src/mongo/db/catalog/collection_test.cpp @@ -73,7 +73,7 @@ void CollectionTest::makeTimeseries(NamespaceString nss) { } TEST_F(CollectionTest, CappedNotifierKillAndIsDead) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); makeCapped(nss); AutoGetCollectionForRead acfr(operationContext(), nss); @@ -85,7 +85,7 @@ TEST_F(CollectionTest, CappedNotifierKillAndIsDead) { } TEST_F(CollectionTest, CappedNotifierTimeouts) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); makeCapped(nss); AutoGetCollectionForRead acfr(operationContext(), nss); @@ -101,7 +101,7 @@ TEST_F(CollectionTest, CappedNotifierTimeouts) { } TEST_F(CollectionTest, CappedNotifierWaitAfterNotifyIsImmediate) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); makeCapped(nss); AutoGetCollectionForRead acfr(operationContext(), nss); @@ -120,7 +120,7 @@ TEST_F(CollectionTest, CappedNotifierWaitAfterNotifyIsImmediate) { } TEST_F(CollectionTest, CappedNotifierWaitUntilAsynchronousNotifyAll) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); makeCapped(nss); AutoGetCollectionForRead acfr(operationContext(), nss); @@ -145,7 +145,7 @@ TEST_F(CollectionTest, CappedNotifierWaitUntilAsynchronousNotifyAll) { } TEST_F(CollectionTest, CappedNotifierWaitUntilAsynchronousKill) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); makeCapped(nss); AutoGetCollectionForRead acfr(operationContext(), nss); @@ -169,7 +169,7 @@ TEST_F(CollectionTest, CappedNotifierWaitUntilAsynchronousKill) { } TEST_F(CollectionTest, HaveCappedWaiters) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); makeCapped(nss); AutoGetCollectionForRead acfr(operationContext(), nss); @@ -183,7 +183,7 @@ TEST_F(CollectionTest, HaveCappedWaiters) { } TEST_F(CollectionTest, NotifyCappedWaitersIfNeeded) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); makeCapped(nss); AutoGetCollectionForRead acfr(operationContext(), nss); @@ -198,7 +198,7 @@ TEST_F(CollectionTest, NotifyCappedWaitersIfNeeded) { } TEST_F(CollectionTest, AsynchronouslyNotifyCappedWaitersIfNeeded) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); makeCapped(nss); AutoGetCollectionForRead acfr(operationContext(), nss); @@ -243,7 +243,7 @@ void CollectionTest::makeCollectionForMultikey(NamespaceString nss, StringData i } TEST_F(CollectionTest, VerifyIndexIsUpdated) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto indexName = "myindex"_sd; makeCollectionForMultikey(nss, indexName); @@ -297,7 +297,7 @@ TEST_F(CollectionTest, VerifyIndexIsUpdated) { } TEST_F(CollectionTest, VerifyIndexIsUpdatedWithDamages) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto indexName = "myindex"_sd; makeCollectionForMultikey(nss, indexName); @@ -351,7 +351,7 @@ TEST_F(CollectionTest, VerifyIndexIsUpdatedWithDamages) { } TEST_F(CollectionTest, SetIndexIsMultikey) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto indexName = "myindex"_sd; makeCollectionForMultikey(nss, indexName); @@ -373,7 +373,7 @@ TEST_F(CollectionTest, SetIndexIsMultikey) { } TEST_F(CollectionTest, SetIndexIsMultikeyRemovesUncommittedChangesOnRollback) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto indexName = "myindex"_sd; makeCollectionForMultikey(nss, indexName); @@ -398,7 +398,7 @@ TEST_F(CollectionTest, SetIndexIsMultikeyRemovesUncommittedChangesOnRollback) { } TEST_F(CollectionTest, ForceSetIndexIsMultikey) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto indexName = "myindex"_sd; makeCollectionForMultikey(nss, indexName); @@ -421,7 +421,7 @@ TEST_F(CollectionTest, ForceSetIndexIsMultikey) { } TEST_F(CollectionTest, ForceSetIndexIsMultikeyRemovesUncommittedChangesOnRollback) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto indexName = "myindex"_sd; makeCollectionForMultikey(nss, indexName); @@ -448,7 +448,7 @@ TEST_F(CollectionTest, ForceSetIndexIsMultikeyRemovesUncommittedChangesOnRollbac } TEST_F(CollectionTest, CheckTimeseriesBucketDocsForMixedSchemaData) { - NamespaceString nss("test.system.buckets.ts"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.system.buckets.ts"); makeTimeseries(nss); auto opCtx = operationContext(); @@ -568,8 +568,8 @@ TEST_F(CollectionTest, CheckTimeseriesBucketDocsForMixedSchemaData) { } TEST_F(CatalogTestFixture, CollectionPtrYieldable) { - CollectionMock beforeYield(NamespaceString("test.t")); - CollectionMock afterYield(NamespaceString("test.t")); + CollectionMock beforeYield(NamespaceString::createNamespaceString_forTest("test.t")); + CollectionMock afterYield(NamespaceString::createNamespaceString_forTest("test.t")); int numRestoreCalls = 0; @@ -612,7 +612,7 @@ TEST_F(CatalogTestFixture, CollectionPtrYieldable) { } TEST_F(CatalogTestFixture, IsNotCapped) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; ASSERT_OK(storageInterface()->createCollection(operationContext(), nss, options)); @@ -623,7 +623,7 @@ TEST_F(CatalogTestFixture, IsNotCapped) { TEST_F(CatalogTestFixture, CappedDeleteRecord) { // Insert a document into a capped collection that has a maximum document size of 1. - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.capped = true; options.cappedMaxDocs = 1; @@ -667,7 +667,7 @@ TEST_F(CatalogTestFixture, CappedDeleteRecord) { TEST_F(CatalogTestFixture, CappedDeleteMultipleRecords) { // Insert multiple records at once, requiring multiple deletes. - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.capped = true; options.cappedMaxDocs = 10; @@ -719,7 +719,7 @@ TEST_F(CatalogTestFixture, CappedDeleteMultipleRecords) { } TEST_F(CatalogTestFixture, CappedVisibilityEmptyInitialState) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.capped = true; ASSERT_OK(storageInterface()->createCollection(operationContext(), nss, options)); @@ -780,7 +780,7 @@ TEST_F(CatalogTestFixture, CappedVisibilityEmptyInitialState) { } TEST_F(CatalogTestFixture, CappedVisibilityNonEmptyInitialState) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.capped = true; ASSERT_OK(storageInterface()->createCollection(operationContext(), nss, options)); @@ -861,7 +861,7 @@ TEST_F(CatalogTestFixture, CappedVisibilityNonEmptyInitialState) { } TEST_F(CollectionTest, CappedCursorRollover) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.capped = true; options.cappedMaxDocs = 5; @@ -911,7 +911,7 @@ TEST_F(CollectionTest, CappedCursorRollover) { } TEST_F(CatalogTestFixture, CappedCursorYieldFirst) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.capped = true; ASSERT_OK(storageInterface()->createCollection(operationContext(), nss, options)); diff --git a/src/mongo/db/catalog/collection_validation_test.cpp b/src/mongo/db/catalog/collection_validation_test.cpp index b2284fdee82..5a43456e94e 100644 --- a/src/mongo/db/catalog/collection_validation_test.cpp +++ b/src/mongo/db/catalog/collection_validation_test.cpp @@ -47,7 +47,7 @@ namespace mongo { namespace { -const NamespaceString kNss = NamespaceString("test.t"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.t"); class CollectionValidationTest : public CatalogTestFixture { protected: @@ -881,7 +881,8 @@ TEST_F(CollectionValidationColumnStoreIndexTest, SingleInvalidIndexEntryCSI) { for (int numDocs = 1; numDocs <= kMaxNumDocs; ++numDocs) { for (int corruptedFldIndex = 1; corruptedFldIndex <= numFields; ++corruptedFldIndex) { for (int corruptedDocIndex = 0; corruptedDocIndex < numDocs; ++corruptedDocIndex) { - const NamespaceString nss(kNss.toString() + std::to_string(++testCaseIdx)); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest( + kNss.toString() + std::to_string(++testCaseIdx)); // Create collection nss for unit tests to use. const CollectionOptions defaultCollectionOptions; @@ -1003,7 +1004,8 @@ TEST_F(CollectionValidationColumnStoreIndexTest, SingleExtraIndexEntry) { const int corruptedFldIndex = corruption.first; const int corruptedDocIndex = corruption.second; - const auto nss = NamespaceString(kNss.toString() + std::to_string(++testCaseIdx)); + const auto nss = NamespaceString::createNamespaceString_forTest( + kNss.toString() + std::to_string(++testCaseIdx)); // Create collection nss for unit tests to use. const CollectionOptions defaultCollectionOptions; @@ -1090,7 +1092,8 @@ TEST_F(CollectionValidationColumnStoreIndexTest, SingleMissingIndexEntryCSI) { for (int numDocs = 1; numDocs <= kMaxNumDocs; ++numDocs) { for (int corruptedFldIndex = 1; corruptedFldIndex <= numFields; ++corruptedFldIndex) { for (int corruptedDocIndex = 0; corruptedDocIndex < numDocs; ++corruptedDocIndex) { - const NamespaceString nss(kNss.toString() + std::to_string(++testCaseIdx)); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest( + kNss.toString() + std::to_string(++testCaseIdx)); // Create collection nss for unit tests to use. const CollectionOptions defaultCollectionOptions; diff --git a/src/mongo/db/catalog/collection_writer_test.cpp b/src/mongo/db/catalog/collection_writer_test.cpp index ec0d676d2f4..64401d38a3c 100644 --- a/src/mongo/db/catalog/collection_writer_test.cpp +++ b/src/mongo/db/catalog/collection_writer_test.cpp @@ -88,7 +88,8 @@ protected: t.join(); } - const NamespaceString kNss{"testdb", "testcol"}; + const NamespaceString kNss = + NamespaceString::createNamespaceString_forTest("testdb", "testcol"); }; TEST_F(CollectionWriterTest, Commit) { @@ -255,11 +256,12 @@ public: CollectionCatalog::write(getServiceContext(), [&](CollectionCatalog& catalog) { for (size_t i = 0; i < NumCollections; ++i) { - catalog.registerCollection(operationContext(), - UUID::gen(), - std::make_shared( - NamespaceString("many", fmt::format("coll{}", i))), - /*ts=*/boost::none); + catalog.registerCollection( + operationContext(), + UUID::gen(), + std::make_shared(NamespaceString::createNamespaceString_forTest( + "many", fmt::format("coll{}", i))), + /*ts=*/boost::none); } }); } diff --git a/src/mongo/db/catalog/column_index_consistency_test.cpp b/src/mongo/db/catalog/column_index_consistency_test.cpp index 0199b9627e1..459a2f1e340 100644 --- a/src/mongo/db/catalog/column_index_consistency_test.cpp +++ b/src/mongo/db/catalog/column_index_consistency_test.cpp @@ -37,7 +37,7 @@ namespace mongo { namespace { -const NamespaceString kNss = NamespaceString("test.t"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.t"); class ColumnIndexConsistencyTest : public CatalogTestFixture { protected: diff --git a/src/mongo/db/catalog/create_collection_test.cpp b/src/mongo/db/catalog/create_collection_test.cpp index 97d1384f40f..480feb06feb 100644 --- a/src/mongo/db/catalog/create_collection_test.cpp +++ b/src/mongo/db/catalog/create_collection_test.cpp @@ -103,7 +103,8 @@ ServiceContext::UniqueOperationContext makeOpCtx() { void CreateCollectionTest::validateValidator(const std::string& validatorStr, const int expectedError) { - NamespaceString newNss("test.newCollWithValidation"); + NamespaceString newNss = + NamespaceString::createNamespaceString_forTest("test.newCollWithValidation"); auto opCtx = makeOpCtx(); @@ -171,7 +172,7 @@ UUID getCollectionUuid(OperationContext* opCtx, const NamespaceString& nss) { } TEST_F(CreateCollectionTest, CreateCollectionForApplyOpsWithSpecificUuidNoExistingCollection) { - NamespaceString newNss("test.newColl"); + NamespaceString newNss = NamespaceString::createNamespaceString_forTest("test.newColl"); auto opCtx = makeOpCtx(); ASSERT_FALSE(collectionExists(opCtx.get(), newNss)); @@ -189,8 +190,8 @@ TEST_F(CreateCollectionTest, CreateCollectionForApplyOpsWithSpecificUuidNoExisti TEST_F(CreateCollectionTest, CreateCollectionForApplyOpsWithSpecificUuidNonDropPendingCurrentCollectionHasSameUuid) { - NamespaceString curNss("test.curColl"); - NamespaceString newNss("test.newColl"); + NamespaceString curNss = NamespaceString::createNamespaceString_forTest("test.curColl"); + NamespaceString newNss = NamespaceString::createNamespaceString_forTest("test.newColl"); auto opCtx = makeOpCtx(); auto uuid = UUID::gen(); @@ -219,7 +220,7 @@ TEST_F(CreateCollectionTest, TEST_F(CreateCollectionTest, CreateCollectionForApplyOpsWithSpecificUuidRenamesExistingCollectionWithSameNameOutOfWay) { - NamespaceString newNss("test.newColl"); + NamespaceString newNss = NamespaceString::createNamespaceString_forTest("test.newColl"); auto opCtx = makeOpCtx(); auto uuid = UUID::gen(); @@ -256,10 +257,10 @@ TEST_F(CreateCollectionTest, TEST_F(CreateCollectionTest, CreateCollectionForApplyOpsWithSpecificUuidReturnsNamespaceExistsIfCollectionIsDropPending) { - NamespaceString curNss("test.curColl"); + NamespaceString curNss = NamespaceString::createNamespaceString_forTest("test.curColl"); repl::OpTime dropOpTime(Timestamp(Seconds(100), 0), 1LL); auto dropPendingNss = curNss.makeDropPendingNamespace(dropOpTime); - NamespaceString newNss("test.newColl"); + NamespaceString newNss = NamespaceString::createNamespaceString_forTest("test.newColl"); auto opCtx = makeOpCtx(); auto uuid = UUID::gen(); @@ -305,7 +306,8 @@ TEST_F(CreateCollectionTest, ValidationOptions) { // .system.resharding.* collection. The primary donor is responsible for validating // documents before they are inserted into the recipient's temporary resharding collection. TEST_F(CreateCollectionTest, ValidationDisabledForTemporaryReshardingCollection) { - NamespaceString reshardingNss("myDb", "system.resharding.yay"); + NamespaceString reshardingNss = + NamespaceString::createNamespaceString_forTest("myDb", "system.resharding.yay"); auto opCtx = makeOpCtx(); Lock::GlobalLock lk(opCtx.get(), MODE_X); // Satisfy low-level locking invariants. @@ -328,7 +330,7 @@ const auto kValidUrl1 = ExternalDataSourceMetadata::kUrlProtocolFile + "named_pi const auto kValidUrl2 = ExternalDataSourceMetadata::kUrlProtocolFile + "named_pipe2"s; TEST_F(CreateVirtualCollectionTest, VirtualCollectionOptionsWithOneSource) { - NamespaceString vcollNss("myDb", "vcoll.name"); + NamespaceString vcollNss = NamespaceString::createNamespaceString_forTest("myDb", "vcoll.name"); auto opCtx = makeOpCtx(); Lock::GlobalLock lk(opCtx.get(), MODE_X); // Satisfy low-level locking invariants. @@ -350,7 +352,7 @@ TEST_F(CreateVirtualCollectionTest, VirtualCollectionOptionsWithOneSource) { } TEST_F(CreateVirtualCollectionTest, VirtualCollectionOptionsWithMultiSource) { - NamespaceString vcollNss("myDb", "vcoll.name"); + NamespaceString vcollNss = NamespaceString::createNamespaceString_forTest("myDb", "vcoll.name"); auto opCtx = makeOpCtx(); Lock::GlobalLock lk(opCtx.get(), MODE_X); // Satisfy low-level locking invariants. @@ -378,7 +380,7 @@ TEST_F(CreateVirtualCollectionTest, VirtualCollectionOptionsWithMultiSource) { TEST_F(CreateVirtualCollectionTest, InvalidVirtualCollectionOptions) { using namespace fmt::literals; - NamespaceString vcollNss("myDb", "vcoll.name"); + NamespaceString vcollNss = NamespaceString::createNamespaceString_forTest("myDb", "vcoll.name"); auto opCtx = makeOpCtx(); Lock::GlobalLock lk(opCtx.get(), MODE_X); // Satisfy low-level locking invariants. diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp index 98d1e15fd72..80a32d01791 100644 --- a/src/mongo/db/catalog/database_test.cpp +++ b/src/mongo/db/catalog/database_test.cpp @@ -99,7 +99,7 @@ void DatabaseTest::setUp() { opObserverRegistry->addObserver( std::make_unique(std::make_unique())); - _nss = NamespaceString("test.foo"); + _nss = NamespaceString::createNamespaceString_forTest("test.foo"); } void DatabaseTest::tearDown() { @@ -287,7 +287,7 @@ TEST_F(DatabaseTest, TEST_F(DatabaseTest, RenameCollectionPreservesUuidOfSourceCollectionAndUpdatesUuidCatalog) { auto opCtx = _opCtx.get(); auto fromNss = _nss; - auto toNss = NamespaceString(fromNss.getSisterNS("bar")); + auto toNss = NamespaceString::createNamespaceString_forTest(fromNss.getSisterNS("bar")); ASSERT_NOT_EQUALS(fromNss, toNss); AutoGetDb autoDb(opCtx, fromNss.dbName(), MODE_X); @@ -398,7 +398,8 @@ TEST_F( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"_sd; for (const auto c : charsToChooseFrom) { - NamespaceString nss(_nss.db(), model.substr(0, model.find('%')) + std::string(1U, c)); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + _nss.dbName(), model.substr(0, model.find('%')) + std::string(1U, c)); WriteUnitOfWork wuow(_opCtx.get()); ASSERT_TRUE(db->createCollection(_opCtx.get(), nss)); wuow.commit(); @@ -412,7 +413,7 @@ TEST_F( } TEST_F(DatabaseTest, AutoGetDBSucceedsWithDeadlineNow) { - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); Lock::DBLock lock(_opCtx.get(), nss.dbName(), MODE_X); ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); try { @@ -424,7 +425,7 @@ TEST_F(DatabaseTest, AutoGetDBSucceedsWithDeadlineNow) { } TEST_F(DatabaseTest, AutoGetDBSucceedsWithDeadlineMin) { - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); Lock::DBLock lock(_opCtx.get(), nss.dbName(), MODE_X); ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); try { @@ -436,7 +437,7 @@ TEST_F(DatabaseTest, AutoGetDBSucceedsWithDeadlineMin) { } TEST_F(DatabaseTest, AutoGetCollectionForReadCommandSucceedsWithDeadlineNow) { - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); Lock::DBLock dbLock(_opCtx.get(), nss.dbName(), MODE_X); ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); Lock::CollectionLock collLock(_opCtx.get(), nss, MODE_X); @@ -450,7 +451,7 @@ TEST_F(DatabaseTest, AutoGetCollectionForReadCommandSucceedsWithDeadlineNow) { } TEST_F(DatabaseTest, AutoGetCollectionForReadCommandSucceedsWithDeadlineMin) { - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); Lock::DBLock dbLock(_opCtx.get(), nss.dbName(), MODE_X); ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); Lock::CollectionLock collLock(_opCtx.get(), nss, MODE_X); diff --git a/src/mongo/db/catalog/drop_database_test.cpp b/src/mongo/db/catalog/drop_database_test.cpp index f08326b507d..cb01b58dd92 100644 --- a/src/mongo/db/catalog/drop_database_test.cpp +++ b/src/mongo/db/catalog/drop_database_test.cpp @@ -161,7 +161,7 @@ void DropDatabaseTest::setUp() { _opObserver = mockObserver.get(); opObserverRegistry->addObserver(std::move(mockObserver)); - _nss = NamespaceString("test.foo"); + _nss = NamespaceString::createNamespaceString_forTest("test.foo"); } void DropDatabaseTest::tearDown() { @@ -261,7 +261,8 @@ TEST_F(DropDatabaseTest, DropDatabaseNotifiesOpObserverOfDroppedUserCollection) } TEST_F(DropDatabaseTest, DropDatabaseNotifiesOpObserverOfDroppedReplicatedSystemCollection) { - NamespaceString replicatedSystemNss(_nss.getSisterNS("system.js")); + NamespaceString replicatedSystemNss = + NamespaceString::createNamespaceString_forTest(_nss.getSisterNS("system.js")); _testDropDatabase(_opCtx.get(), _opObserver, replicatedSystemNss, true); } @@ -302,7 +303,8 @@ TEST_F(DropDatabaseTest, DropDatabasePassedThroughAwaitReplicationErrorForDropPe TEST_F(DropDatabaseTest, DropDatabaseSkipsSystemProfileCollectionWhenDroppingCollections) { repl::OpTime dropOpTime(Timestamp(Seconds(100), 0), 1LL); - NamespaceString profileNss(_nss.getSisterNS("system.profile")); + NamespaceString profileNss = + NamespaceString::createNamespaceString_forTest(_nss.getSisterNS("system.profile")); _testDropDatabase(_opCtx.get(), _opObserver, profileNss, false); } @@ -426,7 +428,8 @@ TEST_F(DropDatabaseTest, } TEST_F(DropDatabaseTest, DropDatabaseFailsToDropAdmin) { - NamespaceString adminNSS(NamespaceString::kAdminDb, "foo"); + NamespaceString adminNSS = + NamespaceString::createNamespaceString_forTest(NamespaceString::kAdminDb, "foo"); _createCollection(_opCtx.get(), adminNSS); ASSERT_THROWS_CODE_AND_WHAT(dropDatabaseForApplyOps(_opCtx.get(), adminNSS.dbName()), AssertionException, diff --git a/src/mongo/db/catalog/index_builds_manager_test.cpp b/src/mongo/db/catalog/index_builds_manager_test.cpp index 1c5e62cd865..222f1412275 100644 --- a/src/mongo/db/catalog/index_builds_manager_test.cpp +++ b/src/mongo/db/catalog/index_builds_manager_test.cpp @@ -50,7 +50,7 @@ public: void createCollection(const NamespaceString& nss); const UUID _buildUUID = UUID::gen(); - const NamespaceString _nss = NamespaceString("test.foo"); + const NamespaceString _nss = NamespaceString::createNamespaceString_forTest("test.foo"); IndexBuildsManager _indexBuildsManager; }; diff --git a/src/mongo/db/catalog/index_key_validate_test.cpp b/src/mongo/db/catalog/index_key_validate_test.cpp index bcc0ee35e62..de3b2b66877 100644 --- a/src/mongo/db/catalog/index_key_validate_test.cpp +++ b/src/mongo/db/catalog/index_key_validate_test.cpp @@ -396,7 +396,7 @@ TEST(IndexKeyValidateTest, Background) { TEST(IndexKeyValidateTest, RemoveUnkownFieldsFromIndexSpecs) { ASSERT(fromjson("{key: {a: 1}, name: 'index'}") .binaryEqual(index_key_validate::removeUnknownFields( - NamespaceString("coll"), + NamespaceString::createNamespaceString_forTest("coll"), fromjson("{key: {a: 1}, name: 'index', safe: true, force: true}")))); } @@ -420,27 +420,27 @@ TEST(IndexKeyValidateTest, ValidateAfterSecondsAcceptsFloatingPointNumber) { TEST(IndexKeyValidateTest, RepairIndexSpecs) { ASSERT(fromjson("{key: {a: 1}, name: 'index'}") .binaryEqual(index_key_validate::repairIndexSpec( - NamespaceString("coll"), + NamespaceString::createNamespaceString_forTest("coll"), fromjson("{key: {a: 1}, name: 'index', safe: true, force: true}")))); ASSERT(fromjson("{key: {a: 1}, name: 'index', sparse: true}") .binaryEqual(index_key_validate::repairIndexSpec( - NamespaceString("coll"), + NamespaceString::createNamespaceString_forTest("coll"), fromjson("{key: {a: 1}, name: 'index', sparse: 'true'}")))); ASSERT(fromjson("{key: {a: 1}, name: 'index', background: true}") .binaryEqual(index_key_validate::repairIndexSpec( - NamespaceString("coll"), + NamespaceString::createNamespaceString_forTest("coll"), fromjson("{key: {a: 1}, name: 'index', background: '1'}")))); ASSERT(fromjson("{key: {a: 1}, name: 'index', sparse: true, background: true}") .binaryEqual(index_key_validate::repairIndexSpec( - NamespaceString("coll"), + NamespaceString::createNamespaceString_forTest("coll"), fromjson("{key: {a: 1}, name: 'index', sparse: 'true', background: '1'}")))); ASSERT(fromjson("{key: {a: 1}, name: 'index', sparse: true, background: true}") .binaryEqual(index_key_validate::repairIndexSpec( - NamespaceString("coll"), + NamespaceString::createNamespaceString_forTest("coll"), fromjson("{key: {a: 1}, name: 'index', sparse: 'true', background: '1', safe: " "true, force: true}")))); @@ -448,14 +448,14 @@ TEST(IndexKeyValidateTest, RepairIndexSpecs) { << "index" << "expireAfterSeconds" << std::numeric_limits::max()) .binaryEqual(index_key_validate::repairIndexSpec( - NamespaceString("coll"), + NamespaceString::createNamespaceString_forTest("coll"), fromjson("{key: {a: 1}, name: 'index', expireAfterSeconds: NaN}")))); ASSERT(BSON("key" << BSON("a" << 1) << "name" << "index" << "expireAfterSeconds" << std::numeric_limits::max()) .binaryEqual(index_key_validate::repairIndexSpec( - NamespaceString("coll"), + NamespaceString::createNamespaceString_forTest("coll"), fromjson("{key: {a: 1}, name: 'index', expireAfterSeconds: '123'}")))); } diff --git a/src/mongo/db/catalog/index_signature_test.cpp b/src/mongo/db/catalog/index_signature_test.cpp index b352bb205ca..a4640e07627 100644 --- a/src/mongo/db/catalog/index_signature_test.cpp +++ b/src/mongo/db/catalog/index_signature_test.cpp @@ -98,7 +98,7 @@ protected: private: boost::optional _coll; - NamespaceString _nss{"fooDB.barColl"}; + NamespaceString _nss = NamespaceString::createNamespaceString_forTest("fooDB.barColl"); }; TEST_F(IndexSignatureTest, CanCreateMultipleIndexesOnSameKeyPatternWithDifferentCollations) { diff --git a/src/mongo/db/catalog/multi_index_block_test.cpp b/src/mongo/db/catalog/multi_index_block_test.cpp index 4d63b0689f1..8607fd82aa8 100644 --- a/src/mongo/db/catalog/multi_index_block_test.cpp +++ b/src/mongo/db/catalog/multi_index_block_test.cpp @@ -69,7 +69,7 @@ void MultiIndexBlockTest::setUp() { repl::ReplicationCoordinator::set(service, std::make_unique(service)); - _nss = NamespaceString("db.coll"); + _nss = NamespaceString::createNamespaceString_forTest("db.coll"); CollectionOptions options; options.uuid = UUID::gen(); diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp index b8d37818602..8605bb21e37 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -316,9 +316,12 @@ protected: ServiceContext::UniqueOperationContext _opCtx; repl::ReplicationCoordinatorMock* _replCoord = nullptr; OpObserverMock* _opObserver = nullptr; - NamespaceString _sourceNss{NamespaceString(boost::none, "test.foo")}; - NamespaceString _targetNss{NamespaceString(boost::none, "test.bar")}; - NamespaceString _targetNssDifferentDb{NamespaceString(boost::none, "test2.bar")}; + NamespaceString _sourceNss{ + NamespaceString::createNamespaceString_forTest(boost::none, "test.foo")}; + NamespaceString _targetNss{ + NamespaceString::createNamespaceString_forTest(boost::none, "test.bar")}; + NamespaceString _targetNssDifferentDb{ + NamespaceString::createNamespaceString_forTest(boost::none, "test2.bar")}; }; // static @@ -543,7 +546,8 @@ TEST_F(RenameCollectionTest, RenameCollectionReturnsNotWritablePrimaryIfNotPrima TEST_F(RenameCollectionTest, TargetCollectionNameLong) { _createCollection(_opCtx.get(), _sourceNss); const std::string targetCollectionName(255, 'a'); - NamespaceString longTargetNss(_sourceNss.db(), targetCollectionName); + NamespaceString longTargetNss = + NamespaceString::createNamespaceString_forTest(_sourceNss.db(), targetCollectionName); ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, longTargetNss, {})); } @@ -562,7 +566,8 @@ TEST_F(RenameCollectionTest, LongIndexNameAllowedForTemporaryCollectionForRename // Using XXXXX to check namespace length. Each 'X' will be replaced by a random character in // renameCollection(). - const NamespaceString tempNss(_targetNssDifferentDb.getSisterNS("tmpXXXXX.renameCollection")); + const NamespaceString tempNss = NamespaceString::createNamespaceString_forTest( + _targetNssDifferentDb.getSisterNS("tmpXXXXX.renameCollection")); _createCollection(_opCtx.get(), _sourceNss); std::size_t longIndexLength = 500; @@ -603,7 +608,8 @@ TEST_F( auto options = _makeCollectionOptionsWithUuid(); _createCollection(_opCtx.get(), dropPendingNss, options); - NamespaceString ignoredSourceNss(_sourceNss.dbName(), "ignored"); + NamespaceString ignoredSourceNss = + NamespaceString::createNamespaceString_forTest(_sourceNss.dbName(), "ignored"); auto cmd = BSON("renameCollection" << ignoredSourceNss.ns() << "to" << _targetNss.ns()); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, renameCollectionForApplyOps(_opCtx.get(), options.uuid, boost::none, cmd, {})); @@ -631,7 +637,7 @@ TEST_F(RenameCollectionTest, RenameCollectionToItselfByUUIDForApplyOps) { } TEST_F(RenameCollectionTest, RenameCollectionByUUIDRatherThanNsForApplyOps) { - auto realRenameFromNss = NamespaceString("test.bar2"); + auto realRenameFromNss = NamespaceString::createNamespaceString_forTest("test.bar2"); auto uuid = _createCollectionWithUUID(_opCtx.get(), realRenameFromNss); auto cmd = BSON("renameCollection" << _sourceNss.ns() << "to" << _targetNss.ns() << "dropTarget" << true); @@ -640,9 +646,9 @@ TEST_F(RenameCollectionTest, RenameCollectionByUUIDRatherThanNsForApplyOps) { } TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetDoesNotExist) { - const auto& collA = NamespaceString("test.A"); - const auto& collB = NamespaceString("test.B"); - const auto& collC = NamespaceString("test.C"); + const auto& collA = NamespaceString::createNamespaceString_forTest("test.A"); + const auto& collB = NamespaceString::createNamespaceString_forTest("test.B"); + const auto& collC = NamespaceString::createNamespaceString_forTest("test.C"); auto collAUUID = _createCollectionWithUUID(_opCtx.get(), collA); auto collCUUID = _createCollectionWithUUID(_opCtx.get(), collC); // Rename A to B, drop C, where B is not an existing collection @@ -661,9 +667,9 @@ TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetDo } TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetExists) { - const auto& collA = NamespaceString("test.A"); - const auto& collB = NamespaceString("test.B"); - const auto& collC = NamespaceString("test.C"); + const auto& collA = NamespaceString::createNamespaceString_forTest("test.A"); + const auto& collB = NamespaceString::createNamespaceString_forTest("test.B"); + const auto& collC = NamespaceString::createNamespaceString_forTest("test.C"); auto collAUUID = _createCollectionWithUUID(_opCtx.get(), collA); auto collBUUID = _createCollectionWithUUID(_opCtx.get(), collB); auto collCUUID = _createCollectionWithUUID(_opCtx.get(), collC); @@ -688,9 +694,9 @@ TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetEx TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetExistsButTemporarily) { - const auto& collA = NamespaceString("test.A"); - const auto& collB = NamespaceString("test.B"); - const auto& collC = NamespaceString("test.C"); + const auto& collA = NamespaceString::createNamespaceString_forTest("test.A"); + const auto& collB = NamespaceString::createNamespaceString_forTest("test.B"); + const auto& collC = NamespaceString::createNamespaceString_forTest("test.C"); CollectionOptions collectionOptions = _makeCollectionOptionsWithUuid(); collectionOptions.temp = true; @@ -720,8 +726,8 @@ TEST_F(RenameCollectionTest, TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetExistsButRealDropTargetDoesNotExist) { - const auto& collA = NamespaceString("test.A"); - const auto& collB = NamespaceString("test.B"); + const auto& collA = NamespaceString::createNamespaceString_forTest("test.A"); + const auto& collB = NamespaceString::createNamespaceString_forTest("test.B"); auto collAUUID = _createCollectionWithUUID(_opCtx.get(), collA); auto collBUUID = _createCollectionWithUUID(_opCtx.get(), collB); auto collCUUID = UUID::gen(); @@ -806,7 +812,7 @@ TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsSourceAndTargetDoNotExis TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetEvenIfSourceDoesNotExist) { _createCollectionWithUUID(_opCtx.get(), _targetNss); - auto missingSourceNss = NamespaceString("test.bar2"); + auto missingSourceNss = NamespaceString::createNamespaceString_forTest("test.bar2"); auto uuid = UUID::gen(); auto cmd = BSON("renameCollection" << missingSourceNss.ns() << "to" << _targetNss.ns() << "dropTarget" @@ -816,8 +822,8 @@ TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetEvenIfSourceDo } TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDEvenIfSourceDoesNotExist) { - auto missingSourceNss = NamespaceString("test.bar2"); - auto dropTargetNss = NamespaceString("test.bar3"); + auto missingSourceNss = NamespaceString::createNamespaceString_forTest("test.bar2"); + auto dropTargetNss = NamespaceString::createNamespaceString_forTest("test.bar3"); _createCollectionWithUUID(_opCtx.get(), _targetNss); auto dropTargetUUID = _createCollectionWithUUID(_opCtx.get(), dropTargetNss); auto uuid = UUID::gen(); @@ -1055,8 +1061,9 @@ TEST_F(RenameCollectionTest, RenameCollectionAcrossDatabasesWithLocks) { } TEST_F(RenameCollectionTest, FailRenameCollectionFromReplicatedToUnreplicatedDB) { - NamespaceString sourceNss("foo.isReplicated"); - NamespaceString targetNss("local.isUnreplicated"); + NamespaceString sourceNss = NamespaceString::createNamespaceString_forTest("foo.isReplicated"); + NamespaceString targetNss = + NamespaceString::createNamespaceString_forTest("local.isUnreplicated"); _createCollection(_opCtx.get(), sourceNss); @@ -1065,8 +1072,9 @@ TEST_F(RenameCollectionTest, FailRenameCollectionFromReplicatedToUnreplicatedDB) } TEST_F(RenameCollectionTest, FailRenameCollectionFromUnreplicatedToReplicatedDB) { - NamespaceString sourceNss("foo.system.profile"); - NamespaceString targetNss("foo.bar"); + NamespaceString sourceNss = + NamespaceString::createNamespaceString_forTest("foo.system.profile"); + NamespaceString targetNss = NamespaceString::createNamespaceString_forTest("foo.bar"); _createCollection(_opCtx.get(), sourceNss); @@ -1079,7 +1087,8 @@ TEST_F(RenameCollectionTest, _createCollection(_opCtx.get(), _sourceNss); // Create a namespace that is not in the form "database.collection". - NamespaceString invalidTargetNss("invalidNamespace"); + NamespaceString invalidTargetNss = + NamespaceString::createNamespaceString_forTest("invalidNamespace"); auto cmd = BSON("renameCollection" << _sourceNss.ns() << "to" << invalidTargetNss.ns()); @@ -1088,8 +1097,9 @@ TEST_F(RenameCollectionTest, } TEST_F(RenameCollectionTest, FailRenameCollectionFromSystemJavascript) { - NamespaceString sourceNss("foo", NamespaceString::kSystemDotJavascriptCollectionName); - NamespaceString targetNss("foo.bar"); + NamespaceString sourceNss = NamespaceString::createNamespaceString_forTest( + "foo", NamespaceString::kSystemDotJavascriptCollectionName); + NamespaceString targetNss = NamespaceString::createNamespaceString_forTest("foo.bar"); _createCollection(_opCtx.get(), sourceNss); @@ -1107,8 +1117,9 @@ TEST_F(RenameCollectionTest, FailRenameCollectionFromSystemJavascript) { } TEST_F(RenameCollectionTest, FailRenameCollectionToSystemJavascript) { - NamespaceString sourceNss("foo.bar"); - NamespaceString targetNss("foo", NamespaceString::kSystemDotJavascriptCollectionName); + NamespaceString sourceNss = NamespaceString::createNamespaceString_forTest("foo.bar"); + NamespaceString targetNss = NamespaceString::createNamespaceString_forTest( + "foo", NamespaceString::kSystemDotJavascriptCollectionName); _createCollection(_opCtx.get(), sourceNss); @@ -1137,7 +1148,8 @@ protected: std::string _sourceNs{"test.foo"}; std::string _otherNs{"test.bar"}; - NamespaceString _sourceNssTid{NamespaceString(_tenantId, _sourceNs)}; + NamespaceString _sourceNssTid = + (NamespaceString::createNamespaceString_forTest(_tenantId, _sourceNs)); }; void RenameCollectionTestMultitenancy::setUp() { @@ -1156,7 +1168,8 @@ TEST_F(RenameCollectionTestMultitenancy, RenameCollectionForApplyOps) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); - const NamespaceString targetNssTid(_tenantId, _otherNs); + const NamespaceString targetNssTid = + NamespaceString::createNamespaceString_forTest(_tenantId, _otherNs); ASSERT_NOT_EQUALS(_sourceNssTid, targetNssTid); // A tid field supersedes tenantIds maintained in source or target, ie. we don't take into @@ -1178,7 +1191,8 @@ TEST_F(RenameCollectionTestMultitenancy, RenameCollectionForApplyOpsCommonRandom RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); - const NamespaceString targetNssTid(_otherTenantId, _sourceNs); + const NamespaceString targetNssTid = + NamespaceString::createNamespaceString_forTest(_otherTenantId, _sourceNs); ASSERT_NOT_EQUALS(_sourceNssTid, targetNssTid); // This test only has a single tenantId that belongs to neither source nor target. @@ -1197,15 +1211,17 @@ TEST_F(RenameCollectionTestMultitenancy, RenameCollectionForApplyOpsCommonTid) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); - const NamespaceString targetNssTid(_otherTenantId, _otherNs); + const NamespaceString targetNssTid = + NamespaceString::createNamespaceString_forTest(_otherTenantId, _otherNs); ASSERT_NOT_EQUALS(_sourceNssTid, targetNssTid); // A tid field supersedes tenantIds maintained in source or target. See above. auto cmd = BSON("renameCollection" << _sourceNssTid.toString() << "to" << targetNssTid.toString()); ASSERT_OK(renameCollectionForApplyOps(_opCtx.get(), boost::none, _tenantId, cmd, {})); - ASSERT_TRUE( - _collectionExists(_opCtx.get(), NamespaceString(_tenantId, targetNssTid.toString()))); + ASSERT_TRUE(_collectionExists( + _opCtx.get(), + NamespaceString::createNamespaceString_forTest(_tenantId, targetNssTid.toString()))); ASSERT_FALSE(_collectionExists(_opCtx.get(), _sourceNssTid)); } @@ -1213,8 +1229,10 @@ TEST_F(RenameCollectionTestMultitenancy, RenameCollectionForApplyOpsSourceExists RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); - const NamespaceString otherSourceNssTid(_otherTenantId, _sourceNs); - const NamespaceString targetNssTid(_otherTenantId, _otherNs); + const NamespaceString otherSourceNssTid = + NamespaceString::createNamespaceString_forTest(_otherTenantId, _sourceNs); + const NamespaceString targetNssTid = + NamespaceString::createNamespaceString_forTest(_otherTenantId, _otherNs); ASSERT_NOT_EQUALS(otherSourceNssTid, targetNssTid); // A tid field supersedes tenantIds maintained in source or target. See above. @@ -1232,8 +1250,10 @@ TEST_F(RenameCollectionTestMultitenancy, RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); - const NamespaceString otherSourceNssTid(_otherTenantId, _sourceNs); - const NamespaceString targetNssTid(_otherTenantId, _otherNs); + const NamespaceString otherSourceNssTid = + NamespaceString::createNamespaceString_forTest(_otherTenantId, _sourceNs); + const NamespaceString targetNssTid = + NamespaceString::createNamespaceString_forTest(_otherTenantId, _otherNs); ASSERT_NOT_EQUALS(otherSourceNssTid, targetNssTid); // A tid field supersedes tenantIds maintained in source or target. See above. @@ -1250,7 +1270,8 @@ TEST_F(RenameCollectionTestMultitenancy, RenameCollectionForApplyOpsRequireTenan RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); - const NamespaceString targetNssTid(_tenantId, _otherNs); + const NamespaceString targetNssTid = + NamespaceString::createNamespaceString_forTest(_tenantId, _otherNs); ASSERT_NOT_EQUALS(_sourceNssTid, targetNssTid); auto cmd = BSON("renameCollection" << _sourceNssTid.toStringWithTenantId() << "to" @@ -1283,7 +1304,8 @@ TEST_F(RenameCollectionTestMultitenancy, RenameCollectionForApplyOpsAcrossTenant RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); - const NamespaceString targetNssTid(_otherTenantId, _sourceNs); + const NamespaceString targetNssTid = + NamespaceString::createNamespaceString_forTest(_otherTenantId, _sourceNs); ASSERT_NOT_EQUALS(_sourceNssTid, targetNssTid); // This test is valid during the transition period, before featureFlagRequireTenantID is @@ -1297,7 +1319,8 @@ TEST_F(RenameCollectionTestMultitenancy, RenameCollectionForApplyOpsAcrossTenant TEST_F(RenameCollectionTestMultitenancy, RenameCollectionAcrossTenantIds) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); - const NamespaceString targetNssTid(_otherTenantId, _otherNs); + const NamespaceString targetNssTid = + NamespaceString::createNamespaceString_forTest(_otherTenantId, _otherNs); ASSERT_NOT_EQUALS(_sourceNssTid, targetNssTid); // Renaming collections across tenantIds is not allowed diff --git a/src/mongo/db/catalog/throttle_cursor_test.cpp b/src/mongo/db/catalog/throttle_cursor_test.cpp index 33cd3e9a0b7..80800882ae9 100644 --- a/src/mongo/db/catalog/throttle_cursor_test.cpp +++ b/src/mongo/db/catalog/throttle_cursor_test.cpp @@ -43,7 +43,7 @@ namespace mongo { namespace { -const NamespaceString kNss = NamespaceString("test.throttleCursor"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.throttleCursor"); const uint8_t kTickDelay = 200; class ThrottleCursorTest : public CatalogTestFixture { diff --git a/src/mongo/db/catalog/validate_state_test.cpp b/src/mongo/db/catalog/validate_state_test.cpp index caababd402a..e5c75eddb2b 100644 --- a/src/mongo/db/catalog/validate_state_test.cpp +++ b/src/mongo/db/catalog/validate_state_test.cpp @@ -48,7 +48,7 @@ namespace mongo { namespace { -const NamespaceString kNss = NamespaceString("fooDB.fooColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("fooDB.fooColl"); class ValidateStateTest : public CatalogTestFixture { protected: diff --git a/src/mongo/db/catalog_raii_test.cpp b/src/mongo/db/catalog_raii_test.cpp index c909488b192..7ed2fc9f3b5 100644 --- a/src/mongo/db/catalog_raii_test.cpp +++ b/src/mongo/db/catalog_raii_test.cpp @@ -55,12 +55,17 @@ public: return std::make_pair(std::move(client), std::move(opCtx)); } - const NamespaceString nss = NamespaceString("test", "coll"); - const NamespaceString kSecondaryNss1 = NamespaceString("test", "secondaryColl1"); - const NamespaceString kSecondaryNss2 = NamespaceString("test", "secondaryColl2"); - const NamespaceString kSecondaryNss3 = NamespaceString("test", "secondaryColl3"); - const NamespaceString kSecondaryNssOtherDb1 = NamespaceString("test2", "secondaryColl1"); - const NamespaceString kSecondaryNssOtherDb2 = NamespaceString("test2", "secondaryColl2"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); + const NamespaceString kSecondaryNss1 = + NamespaceString::createNamespaceString_forTest("test", "secondaryColl1"); + const NamespaceString kSecondaryNss2 = + NamespaceString::createNamespaceString_forTest("test", "secondaryColl2"); + const NamespaceString kSecondaryNss3 = + NamespaceString::createNamespaceString_forTest("test", "secondaryColl3"); + const NamespaceString kSecondaryNssOtherDb1 = + NamespaceString::createNamespaceString_forTest("test2", "secondaryColl1"); + const NamespaceString kSecondaryNssOtherDb2 = + NamespaceString::createNamespaceString_forTest("test2", "secondaryColl2"); const Milliseconds timeoutMs = Seconds(1); const ClientAndCtx client1 = makeClientWithLocker("client1"); const ClientAndCtx client2 = makeClientWithLocker("client2"); diff --git a/src/mongo/db/commands/create_indexes_test.cpp b/src/mongo/db/commands/create_indexes_test.cpp index 1477ab3dcb0..3c8cc4268e3 100644 --- a/src/mongo/db/commands/create_indexes_test.cpp +++ b/src/mongo/db/commands/create_indexes_test.cpp @@ -43,7 +43,8 @@ TEST_F(CreateIndexesTest, CreateIndexesFailsWhenIndexBuildsCollectionIsMissing) ASSERT_OK( storageInterface()->dropCollection(opCtx, NamespaceString::kIndexBuildEntryNamespace)); - NamespaceString nss("unittests.timestampMultiIndexBuilds"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampMultiIndexBuilds"); ASSERT_OK(storageInterface()->createCollection(operationContext(), nss, {})); diff --git a/src/mongo/db/commands/fle_compact_test.cpp b/src/mongo/db/commands/fle_compact_test.cpp index 3a97d158063..88209614fba 100644 --- a/src/mongo/db/commands/fle_compact_test.cpp +++ b/src/mongo/db/commands/fle_compact_test.cpp @@ -222,11 +222,11 @@ void FleCompactTest::setUp() { _queryImpl = std::make_unique(_opCtx.get(), _storage); - _namespaces.edcNss = NamespaceString("test.edc"); - _namespaces.escNss = NamespaceString("test.esc"); - _namespaces.eccNss = NamespaceString("test.ecc"); - _namespaces.ecocNss = NamespaceString("test.ecoc"); - _namespaces.ecocRenameNss = NamespaceString("test.ecoc.compact"); + _namespaces.edcNss = NamespaceString::createNamespaceString_forTest("test.edc"); + _namespaces.escNss = NamespaceString::createNamespaceString_forTest("test.esc"); + _namespaces.eccNss = NamespaceString::createNamespaceString_forTest("test.ecc"); + _namespaces.ecocNss = NamespaceString::createNamespaceString_forTest("test.ecoc"); + _namespaces.ecocRenameNss = NamespaceString::createNamespaceString_forTest("test.ecoc.compact"); createCollection(_namespaces.edcNss); createCollection(_namespaces.escNss); @@ -244,7 +244,9 @@ void FleCompactTest::createCollection(const NamespaceString& ns) { CollectionOptions collectionOptions; collectionOptions.uuid = UUID::gen(); auto statusCC = _storage->createCollection( - _opCtx.get(), NamespaceString(ns.db(), ns.coll()), collectionOptions); + _opCtx.get(), + NamespaceString::createNamespaceString_forTest(ns.dbName(), ns.coll()), + collectionOptions); ASSERT_OK(statusCC); } diff --git a/src/mongo/db/commands/index_filter_commands_test.cpp b/src/mongo/db/commands/index_filter_commands_test.cpp index 123576874bb..9dc5f8b88a0 100644 --- a/src/mongo/db/commands/index_filter_commands_test.cpp +++ b/src/mongo/db/commands/index_filter_commands_test.cpp @@ -349,7 +349,8 @@ private: QuerySettings _querySettings; }; -const NamespaceString IndexFilterCommandsTest::_nss{"test.collection"}; +const NamespaceString IndexFilterCommandsTest::_nss( + NamespaceString::createNamespaceString_forTest("test.collection")); /** * Tests for ListFilters diff --git a/src/mongo/db/commands/map_reduce_agg_test.cpp b/src/mongo/db/commands/map_reduce_agg_test.cpp index b47b2bfa0e4..36471106b0e 100644 --- a/src/mongo/db/commands/map_reduce_agg_test.cpp +++ b/src/mongo/db/commands/map_reduce_agg_test.cpp @@ -60,7 +60,7 @@ constexpr auto reduceJavascript = "reduce!"_sd; constexpr auto finalizeJavascript = "finalize!"_sd; TEST(MapReduceAggTest, testBasicTranslate) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -77,7 +77,7 @@ TEST(MapReduceAggTest, testBasicTranslate) { } TEST(MapReduceAggTest, testSortWithoutLimit) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -98,7 +98,7 @@ TEST(MapReduceAggTest, testSortWithoutLimit) { } TEST(MapReduceAggTest, testSortWithLimit) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -123,7 +123,7 @@ TEST(MapReduceAggTest, testSortWithLimit) { } TEST(MapReduceAggTest, testLimitNoSort) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -144,7 +144,7 @@ TEST(MapReduceAggTest, testLimitNoSort) { } TEST(MapReduceAggTest, testFeatureLadenTranslate) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{ nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -170,7 +170,7 @@ TEST(MapReduceAggTest, testFeatureLadenTranslate) { } TEST(MapReduceAggTest, testOutMergeTranslate) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{ nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -190,7 +190,7 @@ TEST(MapReduceAggTest, testOutMergeTranslate) { } TEST(MapReduceAggTest, testOutReduceTranslate) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{ nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -212,7 +212,7 @@ TEST(MapReduceAggTest, testOutReduceTranslate) { } TEST(MapReduceAggTest, testOutSameCollection) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{ nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -230,7 +230,7 @@ TEST(MapReduceAggTest, testOutSameCollection) { } TEST(MapReduceAggTest, testSourceDestinationCollectionsEqualMergeDoesNotFail) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{ nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -241,7 +241,7 @@ TEST(MapReduceAggTest, testSourceDestinationCollectionsEqualMergeDoesNotFail) { } TEST(MapReduceAggTest, testSourceDestinationCollectionsNotEqualMergeDoesNotFail) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{ nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -252,7 +252,7 @@ TEST(MapReduceAggTest, testSourceDestinationCollectionsNotEqualMergeDoesNotFail) } TEST(MapReduceAggTest, testShardedTrueWithReplaceActionIsNotAllowed) { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto mr = MapReduceCommandRequest{ nss, MapReduceJavascriptCode{mapJavascript.toString()}, @@ -265,7 +265,7 @@ TEST(MapReduceAggTest, testShardedTrueWithReplaceActionIsNotAllowed) { TEST(MapReduceAggTest, testErrorMessagesTranslated) { // Verifies that agg specific error messages are translated to be mapReduce specific. - auto nss = NamespaceString{"db", "coll1"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll1"); auto mr = MapReduceCommandRequest{ nss, diff --git a/src/mongo/db/commands/mr_test.cpp b/src/mongo/db/commands/mr_test.cpp index ed3bbd03458..0c1272e7613 100644 --- a/src/mongo/db/commands/mr_test.cpp +++ b/src/mongo/db/commands/mr_test.cpp @@ -393,8 +393,10 @@ protected: MapReduceOpObserver* _opObserver = nullptr; }; -const NamespaceString MapReduceCommandTest::inputNss("myDB.myCollection"); -const NamespaceString MapReduceCommandTest::outputNss(inputNss.getSisterNS("outCollection")); +const NamespaceString MapReduceCommandTest::inputNss = + NamespaceString::createNamespaceString_forTest("myDB.myCollection"); +const NamespaceString MapReduceCommandTest::outputNss = + NamespaceString::createNamespaceString_forTest(inputNss.getSisterNS("outCollection")); void MapReduceCommandTest::setUp() { ServiceContextMongoDTest::setUp(); diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp index 3495ee127d6..7c91d584801 100644 --- a/src/mongo/db/commands/plan_cache_commands_test.cpp +++ b/src/mongo/db/commands/plan_cache_commands_test.cpp @@ -38,7 +38,8 @@ namespace mongo { namespace { -static const NamespaceString nss{"test.collection"_sd}; +static const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("test.collection"_sd); PlanCacheKey makeClassicKey(const CanonicalQuery& cq) { CollectionMock coll(nss); diff --git a/src/mongo/db/commands_test.cpp b/src/mongo/db/commands_test.cpp index 6a82edd45fe..4e2234f1e14 100644 --- a/src/mongo/db/commands_test.cpp +++ b/src/mongo/db/commands_test.cpp @@ -167,7 +167,7 @@ TEST_F(ParseNsOrUUID, ParseValidColl) { auto cmd = BSON("query" << "coll"); auto parsedNss = CommandHelpers::parseNsOrUUID(DatabaseName(boost::none, "test"), cmd); - ASSERT_EQ(*parsedNss.nss(), NamespaceString("test.coll")); + ASSERT_EQ(*parsedNss.nss(), NamespaceString::createNamespaceString_forTest("test.coll")); } TEST_F(ParseNsOrUUID, ParseValidUUID) { @@ -435,7 +435,7 @@ protected: template void runIncr(T& command, std::function postAssert) { - const NamespaceString ns("testdb.coll"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("testdb.coll"); for (std::int32_t i : {123, 12345, 0, -456}) { const OpMsgRequest request = [&] { diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp index fae4f83cf84..246eb1610e7 100644 --- a/src/mongo/db/concurrency/d_concurrency_test.cpp +++ b/src/mongo/db/concurrency/d_concurrency_test.cpp @@ -1227,7 +1227,7 @@ TEST_F(DConcurrencyTestFixture, IsDbLockedForXMode) { } TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) { - const NamespaceString ns("db1.coll"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("db1.coll"); auto opCtx = makeOperationContext(); getClient()->swapLockState(std::make_unique(opCtx->getServiceContext())); @@ -1255,7 +1255,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) { } TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IX) { - const NamespaceString ns("db1.coll"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("db1.coll"); auto opCtx = makeOperationContext(); getClient()->swapLockState(std::make_unique(opCtx->getServiceContext())); @@ -1874,9 +1874,11 @@ TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextThrowsEvenWhen { boost::optional collLock; - ASSERT_THROWS_CODE(collLock.emplace(opCtx, NamespaceString("db.coll"), MODE_IX), - AssertionException, - ErrorCodes::Interrupted); + ASSERT_THROWS_CODE( + collLock.emplace( + opCtx, NamespaceString::createNamespaceString_forTest("db.coll"), MODE_IX), + AssertionException, + ErrorCodes::Interrupted); } } @@ -1886,15 +1888,18 @@ TEST_F(DConcurrencyTestFixture, auto opCtx = clients[0].second.get(); Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "db"), MODE_IX); - Lock::CollectionLock collLock(opCtx, NamespaceString("db.coll"), MODE_IX); + Lock::CollectionLock collLock( + opCtx, NamespaceString::createNamespaceString_forTest("db.coll"), MODE_IX); opCtx->markKilled(); { boost::optional recursiveCollLock; - ASSERT_THROWS_CODE(recursiveCollLock.emplace(opCtx, NamespaceString("db.coll"), MODE_X), - AssertionException, - ErrorCodes::Interrupted); + ASSERT_THROWS_CODE( + recursiveCollLock.emplace( + opCtx, NamespaceString::createNamespaceString_forTest("db.coll"), MODE_X), + AssertionException, + ErrorCodes::Interrupted); } } @@ -1906,8 +1911,10 @@ TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextRespectsUninte opCtx->markKilled(); - UninterruptibleLockGuard noInterrupt(opCtx->lockState()); // NOLINT. - Lock::CollectionLock collLock(opCtx, NamespaceString("db.coll"), MODE_IX); // Does not throw. + UninterruptibleLockGuard noInterrupt(opCtx->lockState()); // NOLINT. + Lock::CollectionLock collLock(opCtx, + NamespaceString::createNamespaceString_forTest("db.coll"), + MODE_IX); // Does not throw. } TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) { @@ -1921,15 +1928,21 @@ TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) { Lock::DBLock DBL1(opctx1, testDb, MODE_IX, Date_t::max()); ASSERT(opctx1->lockState()->isDbLockedForMode(testDb, MODE_IX)); - Lock::CollectionLock CL1(opctx1, NamespaceString("testdb.test"), MODE_X, Date_t::max()); - ASSERT(opctx1->lockState()->isCollectionLockedForMode(NamespaceString("testdb.test"), MODE_X)); + Lock::CollectionLock CL1(opctx1, + NamespaceString::createNamespaceString_forTest("testdb.test"), + MODE_X, + Date_t::max()); + ASSERT(opctx1->lockState()->isCollectionLockedForMode( + NamespaceString::createNamespaceString_forTest("testdb.test"), MODE_X)); Date_t t1 = Date_t::now(); Lock::DBLock DBL2(opctx2, testDb, MODE_IX, Date_t::max()); ASSERT(opctx2->lockState()->isDbLockedForMode(testDb, MODE_IX)); ASSERT_THROWS_CODE( - Lock::CollectionLock( - opctx2, NamespaceString("testdb.test"), MODE_X, Date_t::now() + timeoutMillis), + Lock::CollectionLock(opctx2, + NamespaceString::createNamespaceString_forTest("testdb.test"), + MODE_X, + Date_t::now() + timeoutMillis), AssertionException, ErrorCodes::LockTimeout); Date_t t2 = Date_t::now(); @@ -2388,7 +2401,9 @@ TEST_F(DConcurrencyTestFixture, FailPointInLockDoesNotFailUninterruptibleNonInte LockerImpl locker3(opCtx->getServiceContext()); // Granted MODE_X lock, fail incoming MODE_S and MODE_X. - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); locker1.lockGlobal(opCtx.get(), MODE_IX); diff --git a/src/mongo/db/concurrency/lock_manager_test.cpp b/src/mongo/db/concurrency/lock_manager_test.cpp index 8761569c812..c8b53a50f7f 100644 --- a/src/mongo/db/concurrency/lock_manager_test.cpp +++ b/src/mongo/db/concurrency/lock_manager_test.cpp @@ -42,7 +42,9 @@ TEST(ResourceId, Semantics) { ASSERT(resIdDb.getType() == RESOURCE_DATABASE); ASSERT(resIdDb.getHashId() == 324334234); - ResourceId resIdColl(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + ResourceId resIdColl( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); ASSERT(resIdColl.getType() == RESOURCE_COLLECTION); // Comparison functions @@ -93,7 +95,9 @@ DEATH_TEST_F(ResourceIdTest, CantCreateResourceMutexDirectly, "invariant") { TEST_F(LockManagerTest, Grant) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); TrackingLockGrantNotification notify; @@ -112,7 +116,9 @@ TEST_F(LockManagerTest, Grant) { TEST_F(LockManagerTest, GrantMultipleNoConflict) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); TrackingLockGrantNotification notify; @@ -145,7 +151,9 @@ TEST_F(LockManagerTest, GrantMultipleNoConflict) { TEST_F(LockManagerTest, GrantMultipleFIFOOrder) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); std::unique_ptr locker[6]; for (int i = 0; i < 6; i++) { @@ -178,7 +186,9 @@ TEST_F(LockManagerTest, GrantMultipleFIFOOrder) { TEST_F(LockManagerTest, GrantRecursive) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); LockRequestCombo request(&locker); @@ -206,7 +216,9 @@ TEST_F(LockManagerTest, GrantRecursive) { TEST_F(LockManagerTest, GrantRecursiveCompatibleConvertUp) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); LockRequestCombo request(&locker); @@ -234,7 +246,9 @@ TEST_F(LockManagerTest, GrantRecursiveCompatibleConvertUp) { TEST_F(LockManagerTest, GrantRecursiveNonCompatibleConvertUp) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); LockRequestCombo request(&locker); @@ -262,7 +276,9 @@ TEST_F(LockManagerTest, GrantRecursiveNonCompatibleConvertUp) { TEST_F(LockManagerTest, GrantRecursiveNonCompatibleConvertDown) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); LockRequestCombo request(&locker); @@ -290,7 +306,9 @@ TEST_F(LockManagerTest, GrantRecursiveNonCompatibleConvertDown) { TEST_F(LockManagerTest, Conflict) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(getServiceContext()); LockerImpl locker2(getServiceContext()); @@ -329,7 +347,9 @@ TEST_F(LockManagerTest, Conflict) { TEST_F(LockManagerTest, MultipleConflict) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); TrackingLockGrantNotification notify; @@ -362,7 +382,9 @@ TEST_F(LockManagerTest, MultipleConflict) { TEST_F(LockManagerTest, ConflictCancelWaiting) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(getServiceContext()); TrackingLockGrantNotification notify1; @@ -395,7 +417,9 @@ TEST_F(LockManagerTest, ConflictCancelWaiting) { TEST_F(LockManagerTest, ConflictCancelMultipleWaiting) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); TrackingLockGrantNotification notify; @@ -428,7 +452,9 @@ TEST_F(LockManagerTest, ConflictCancelMultipleWaiting) { TEST_F(LockManagerTest, CancelWaitingConversionWeakModes) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(getServiceContext()); LockerImpl locker2(getServiceContext()); @@ -463,7 +489,9 @@ TEST_F(LockManagerTest, CancelWaitingConversionWeakModes) { TEST_F(LockManagerTest, CancelWaitingConversionStrongModes) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(getServiceContext()); LockerImpl locker2(getServiceContext()); @@ -498,7 +526,9 @@ TEST_F(LockManagerTest, CancelWaitingConversionStrongModes) { TEST_F(LockManagerTest, ConflictingConversion) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(getServiceContext()); LockerImpl locker2(getServiceContext()); @@ -533,7 +563,9 @@ TEST_F(LockManagerTest, ConflictingConversion) { TEST_F(LockManagerTest, ConflictingConversionInTheMiddle) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(getServiceContext()); TrackingLockGrantNotification notify; @@ -565,7 +597,9 @@ TEST_F(LockManagerTest, ConflictingConversionInTheMiddle) { TEST_F(LockManagerTest, ConvertUpgrade) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(getServiceContext()); LockRequestCombo request1(&locker1); @@ -586,7 +620,9 @@ TEST_F(LockManagerTest, ConvertUpgrade) { TEST_F(LockManagerTest, Downgrade) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(getServiceContext()); LockRequestCombo request1(&locker1); @@ -614,7 +650,9 @@ static void checkConflict(ServiceContext* serviceContext, LockMode newMode, bool hasConflict) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl lockerExisting(serviceContext); TrackingLockGrantNotification notifyExisting; @@ -663,7 +701,9 @@ TEST_F(LockManagerTest, ValidateConflictMatrix) { TEST_F(LockManagerTest, EnqueueAtFront) { LockManager lockMgr; - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl lockerX(getServiceContext()); LockRequestCombo requestX(&lockerX); diff --git a/src/mongo/db/concurrency/lock_state_test.cpp b/src/mongo/db/concurrency/lock_state_test.cpp index 43784795915..d0475730565 100644 --- a/src/mongo/db/concurrency/lock_state_test.cpp +++ b/src/mongo/db/concurrency/lock_state_test.cpp @@ -55,7 +55,9 @@ class LockerImplTest : public ServiceContextTest {}; TEST_F(LockerImplTest, LockNoConflict) { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(opCtx->getServiceContext()); locker.lockGlobal(opCtx.get(), MODE_IX); @@ -75,7 +77,9 @@ TEST_F(LockerImplTest, LockNoConflict) { TEST_F(LockerImplTest, ReLockNoConflict) { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(opCtx->getServiceContext()); locker.lockGlobal(opCtx.get(), MODE_IX); @@ -95,7 +99,9 @@ TEST_F(LockerImplTest, ReLockNoConflict) { TEST_F(LockerImplTest, ConflictWithTimeout) { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(opCtx->getServiceContext()); locker1.lockGlobal(opCtx.get(), MODE_IX); @@ -119,7 +125,9 @@ TEST_F(LockerImplTest, ConflictWithTimeout) { TEST_F(LockerImplTest, ConflictUpgradeWithTimeout) { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(opCtx->getServiceContext()); locker1.lockGlobal(opCtx.get(), MODE_IS); @@ -175,7 +183,9 @@ TEST_F(LockerImplTest, FailPointInLockFailsNonIntentLocksIfTheyCannotBeImmediate auto newOpCtx = cc().makeOperationContext(); // Granted MODE_X lock, fail incoming MODE_S and MODE_X. - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker1(newOpCtx->getServiceContext()); locker1.lockGlobal(newOpCtx.get(), MODE_IX); @@ -336,8 +346,9 @@ TEST_F(LockerImplTest, saveAndRestoreDBAndCollection) { LockerImpl locker(opCtx->getServiceContext()); const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")); - const ResourceId resIdCollection(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resIdCollection( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); // Lock some stuff. locker.lockGlobal(opCtx.get(), MODE_IX); @@ -367,8 +378,9 @@ TEST_F(LockerImplTest, releaseWriteUnitOfWork) { LockerImpl locker(opCtx->getServiceContext()); const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")); - const ResourceId resIdCollection(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resIdCollection( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); locker.beginWriteUnitOfWork(); // Lock some stuff. @@ -398,8 +410,9 @@ TEST_F(LockerImplTest, restoreWriteUnitOfWork) { LockerImpl locker(opCtx->getServiceContext()); const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")); - const ResourceId resIdCollection(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resIdCollection( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); locker.beginWriteUnitOfWork(); // Lock some stuff. @@ -441,10 +454,12 @@ TEST_F(LockerImplTest, releaseAndRestoreWriteUnitOfWorkWithoutUnlock) { LockerImpl locker(opCtx->getServiceContext()); const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")); - const ResourceId resIdCollection(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection")); - const ResourceId resIdCollection2(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection2")); + const ResourceId resIdCollection( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); + const ResourceId resIdCollection2( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection2")); locker.beginWriteUnitOfWork(); // Lock some stuff. @@ -559,8 +574,9 @@ TEST_F(LockerImplTest, releaseAndRestoreReadOnlyWriteUnitOfWork) { LockerImpl locker(opCtx->getServiceContext()); const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")); - const ResourceId resIdCollection(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resIdCollection( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); // Snapshot transactions delay shared locks as well. locker.setSharedLocksShouldTwoPhaseLock(true); @@ -627,8 +643,9 @@ TEST_F(LockerImplTest, releaseAndRestoreWriteUnitOfWorkWithRecursiveLocks) { LockerImpl locker(opCtx->getServiceContext()); const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")); - const ResourceId resIdCollection(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resIdCollection( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); locker.beginWriteUnitOfWork(); // Lock some stuff. @@ -734,10 +751,12 @@ TEST_F(LockerImplTest, SharedLocksShouldTwoPhaseLockIsTrue) { const ResourceId resId1(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB1")); const ResourceId resId2(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB2")); - const ResourceId resId3(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection3")); - const ResourceId resId4(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection4")); + const ResourceId resId3( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection3")); + const ResourceId resId4( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection4")); LockerImpl locker(opCtx->getServiceContext()); locker.setSharedLocksShouldTwoPhaseLock(true); @@ -792,10 +811,12 @@ TEST_F(LockerImplTest, ModeIXAndXLockParticipatesInTwoPhaseLocking) { const ResourceId resId1(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB1")); const ResourceId resId2(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB2")); - const ResourceId resId3(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection3")); - const ResourceId resId4(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection4")); + const ResourceId resId3( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection3")); + const ResourceId resId4( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection4")); LockerImpl locker(opCtx->getServiceContext()); @@ -1030,8 +1051,9 @@ TEST_F(LockerImplTest, GetLockerInfoShouldReportHeldLocks) { auto opCtx = makeOperationContext(); const ResourceId dbId(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")); - const ResourceId collectionId(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection")); + const ResourceId collectionId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); // Take an exclusive lock on the collection. LockerImpl locker(opCtx->getServiceContext()); @@ -1057,8 +1079,9 @@ TEST_F(LockerImplTest, GetLockerInfoShouldReportPendingLocks) { auto opCtx = makeOperationContext(); const ResourceId dbId(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")); - const ResourceId collectionId(RESOURCE_COLLECTION, - NamespaceString(boost::none, "TestDB.collection")); + const ResourceId collectionId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); // Take an exclusive lock on the collection. LockerImpl successfulLocker(opCtx->getServiceContext()); @@ -1103,7 +1126,9 @@ TEST_F(LockerImplTest, GetLockerInfoShouldReportPendingLocks) { TEST_F(LockerImplTest, ReaquireLockPendingUnlock) { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(opCtx->getServiceContext()); locker.lockGlobal(opCtx.get(), MODE_IS); @@ -1133,7 +1158,9 @@ TEST_F(LockerImplTest, ReaquireLockPendingUnlock) { TEST_F(LockerImplTest, AcquireLockPendingUnlockWithCoveredMode) { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(opCtx->getServiceContext()); locker.lockGlobal(opCtx.get(), MODE_IS); @@ -1163,7 +1190,9 @@ TEST_F(LockerImplTest, AcquireLockPendingUnlockWithCoveredMode) { TEST_F(LockerImplTest, ConvertLockPendingUnlock) { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(opCtx->getServiceContext()); locker.lockGlobal(opCtx.get(), MODE_IS); @@ -1197,7 +1226,9 @@ TEST_F(LockerImplTest, ConvertLockPendingUnlock) { TEST_F(LockerImplTest, ConvertLockPendingUnlockAndUnlock) { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(opCtx->getServiceContext()); locker.lockGlobal(opCtx.get(), MODE_IS); @@ -1269,7 +1300,9 @@ DEATH_TEST_F(LockerImplTest, "Operation ending while holding locks.") { auto opCtx = makeOperationContext(); - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection")); LockerImpl locker(opCtx->getServiceContext()); locker.lockGlobal(opCtx.get(), MODE_IX); diff --git a/src/mongo/db/concurrency/lock_stats_test.cpp b/src/mongo/db/concurrency/lock_stats_test.cpp index 19f13672734..b1a32ddccb1 100644 --- a/src/mongo/db/concurrency/lock_stats_test.cpp +++ b/src/mongo/db/concurrency/lock_stats_test.cpp @@ -39,7 +39,9 @@ namespace mongo { class LockStatsTest : public ServiceContextTest {}; TEST_F(LockStatsTest, NoWait) { - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "LockStats.NoWait")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "LockStats.NoWait")); resetGlobalLockStats(); @@ -58,7 +60,9 @@ TEST_F(LockStatsTest, NoWait) { } TEST_F(LockStatsTest, Wait) { - const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "LockStats.Wait")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "LockStats.Wait")); resetGlobalLockStats(); @@ -92,8 +96,9 @@ TEST_F(LockStatsTest, Wait) { } TEST_F(LockStatsTest, Reporting) { - const ResourceId resId(RESOURCE_COLLECTION, - NamespaceString(boost::none, "LockStats.Reporting")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "LockStats.Reporting")); resetGlobalLockStats(); @@ -111,8 +116,9 @@ TEST_F(LockStatsTest, Reporting) { } TEST_F(LockStatsTest, Subtraction) { - const ResourceId resId(RESOURCE_COLLECTION, - NamespaceString(boost::none, "LockStats.Subtraction")); + const ResourceId resId( + RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "LockStats.Subtraction")); resetGlobalLockStats(); diff --git a/src/mongo/db/concurrency/resource_catalog_test.cpp b/src/mongo/db/concurrency/resource_catalog_test.cpp index 99752d3acd4..026e5cf587a 100644 --- a/src/mongo/db/concurrency/resource_catalog_test.cpp +++ b/src/mongo/db/concurrency/resource_catalog_test.cpp @@ -41,13 +41,16 @@ public: } protected: - NamespaceString firstCollection{boost::none, "1661880728"}; + NamespaceString firstCollection = + NamespaceString::createNamespaceString_forTest(boost::none, "1661880728"); ResourceId firstResourceId{RESOURCE_COLLECTION, firstCollection}; - NamespaceString secondCollection{boost::none, "1626936312"}; + NamespaceString secondCollection = + NamespaceString::createNamespaceString_forTest(boost::none, "1626936312"); ResourceId secondResourceId{RESOURCE_COLLECTION, secondCollection}; - NamespaceString thirdCollection{boost::none, "2930102946"}; + NamespaceString thirdCollection = + NamespaceString::createNamespaceString_forTest(boost::none, "2930102946"); ResourceId thirdResourceId{RESOURCE_COLLECTION, thirdCollection}; ResourceCatalog catalog; @@ -81,7 +84,8 @@ TEST_F(ResourceCatalogTest, RemoveTest) { catalog.add(thirdResourceId, thirdCollection); // This fails to remove the resource because of an invalid namespace. - catalog.remove(firstResourceId, NamespaceString(boost::none, "BadNamespace")); + catalog.remove(firstResourceId, + NamespaceString::createNamespaceString_forTest(boost::none, "BadNamespace")); auto resource = catalog.name(firstResourceId); ASSERT_EQ(firstCollection.toStringWithTenantId(), *resource); @@ -147,7 +151,7 @@ DEATH_TEST_F(ResourceCatalogTest, AddDatabaseInvalidResourceType, "invariant") { } DEATH_TEST_F(ResourceCatalogTest, AddCollectionInvalidResourceType, "invariant") { - catalog.add({RESOURCE_GLOBAL, 0}, NamespaceString{"db.coll"}); + catalog.add({RESOURCE_GLOBAL, 0}, NamespaceString::createNamespaceString_forTest("db.coll")); } } // namespace } // namespace mongo diff --git a/src/mongo/db/cst/cst_literals_test.cpp b/src/mongo/db/cst/cst_literals_test.cpp index 938d8226e8a..acffd400b20 100644 --- a/src/mongo/db/cst/cst_literals_test.cpp +++ b/src/mongo/db/cst/cst_literals_test.cpp @@ -52,7 +52,7 @@ namespace { using namespace std::string_literals; auto getExpCtx() { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); return boost::intrusive_ptr{new ExpressionContextForTest(nss)}; } diff --git a/src/mongo/db/cst/cst_match_translation_test.cpp b/src/mongo/db/cst/cst_match_translation_test.cpp index d9e84e93683..65257f9e21d 100644 --- a/src/mongo/db/cst/cst_match_translation_test.cpp +++ b/src/mongo/db/cst/cst_match_translation_test.cpp @@ -49,7 +49,7 @@ namespace mongo { namespace { auto getExpCtx() { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); return boost::intrusive_ptr{new ExpressionContextForTest(nss)}; } diff --git a/src/mongo/db/cst/cst_pipeline_translation_test.cpp b/src/mongo/db/cst/cst_pipeline_translation_test.cpp index 3d247af1e57..f2d11bbdcb6 100644 --- a/src/mongo/db/cst/cst_pipeline_translation_test.cpp +++ b/src/mongo/db/cst/cst_pipeline_translation_test.cpp @@ -58,7 +58,7 @@ namespace { using namespace std::string_literals; auto getExpCtx() { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); return boost::intrusive_ptr{new ExpressionContextForTest(nss)}; } diff --git a/src/mongo/db/cst/cst_set_operator_translation_test.cpp b/src/mongo/db/cst/cst_set_operator_translation_test.cpp index 7f5c3c4c76c..e7403a9d5d6 100644 --- a/src/mongo/db/cst/cst_set_operator_translation_test.cpp +++ b/src/mongo/db/cst/cst_set_operator_translation_test.cpp @@ -47,7 +47,7 @@ namespace mongo { namespace { auto getExpCtx() { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); return ExpressionContextForTest(nss); } diff --git a/src/mongo/db/cst/cst_sort_translation_test.cpp b/src/mongo/db/cst/cst_sort_translation_test.cpp index 3c0e69979cd..f35dccb7cf6 100644 --- a/src/mongo/db/cst/cst_sort_translation_test.cpp +++ b/src/mongo/db/cst/cst_sort_translation_test.cpp @@ -47,7 +47,7 @@ namespace mongo { namespace { auto getExpCtx() { - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); return boost::intrusive_ptr{new ExpressionContextForTest(nss)}; } diff --git a/src/mongo/db/curop_test.cpp b/src/mongo/db/curop_test.cpp index fc9e05e37c4..47c2289baae 100644 --- a/src/mongo/db/curop_test.cpp +++ b/src/mongo/db/curop_test.cpp @@ -206,8 +206,11 @@ TEST(CurOpTest, OptionalAdditiveMetricsNotDisplayedIfUninitialized) { BSONObj command = BSON("a" << 3); // Set dummy 'ns' and 'command'. - curop->setGenericOpRequestDetails( - opCtx.get(), NamespaceString("myDb.coll"), nullptr, command, NetworkOp::dbQuery); + curop->setGenericOpRequestDetails(opCtx.get(), + NamespaceString::createNamespaceString_forTest("myDb.coll"), + nullptr, + command, + NetworkOp::dbQuery); BSONObjBuilder builder; od.append(opCtx.get(), ls, {}, builder); diff --git a/src/mongo/db/db_raii_multi_collection_test.cpp b/src/mongo/db/db_raii_multi_collection_test.cpp index 8f3e4820c37..de2b9f20671 100644 --- a/src/mongo/db/db_raii_multi_collection_test.cpp +++ b/src/mongo/db/db_raii_multi_collection_test.cpp @@ -73,14 +73,18 @@ public: opCtx, _secondaryNssOtherDbNss, defaultCollectionOptions)); } - const NamespaceString _primaryNss = NamespaceString("db1.primary1"); - const NamespaceString _secondaryNss1 = NamespaceString("db1.secondary1"); - const NamespaceString _secondaryNss2 = NamespaceString("db1.secondary2"); + const NamespaceString _primaryNss = + NamespaceString::createNamespaceString_forTest("db1.primary1"); + const NamespaceString _secondaryNss1 = + NamespaceString::createNamespaceString_forTest("db1.secondary1"); + const NamespaceString _secondaryNss2 = + NamespaceString::createNamespaceString_forTest("db1.secondary2"); const std::vector _secondaryNssOrUUIDVec = { NamespaceStringOrUUID(_secondaryNss1), NamespaceStringOrUUID(_secondaryNss2)}; - const NamespaceString _secondaryNssOtherDbNss = NamespaceString("db2.secondary1"); + const NamespaceString _secondaryNssOtherDbNss = + NamespaceString::createNamespaceString_forTest("db2.secondary1"); const std::vector _secondaryNssOtherDbNssVec = { NamespaceStringOrUUID(_secondaryNssOtherDbNss)}; diff --git a/src/mongo/db/db_raii_test.cpp b/src/mongo/db/db_raii_test.cpp index 776afdfa0aa..ce6099b6b68 100644 --- a/src/mongo/db/db_raii_test.cpp +++ b/src/mongo/db/db_raii_test.cpp @@ -59,7 +59,7 @@ public: return std::make_pair(std::move(client), std::move(opCtx)); } - const NamespaceString nss = NamespaceString("test", "coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); const Milliseconds timeoutMs = Seconds(1); const ClientAndCtx client1 = makeClientWithLocker("client1"); const ClientAndCtx client2 = makeClientWithLocker("client2"); @@ -273,7 +273,8 @@ TEST_F(DBRAIITestFixture, // Simulate using a DBDirectClient to test this behavior for user reads. client2.first->setInDirectClient(true); - AutoGetCollectionForRead coll(client2.second.get(), NamespaceString("local.system.js")); + AutoGetCollectionForRead coll( + client2.second.get(), NamespaceString::createNamespaceString_forTest("local.system.js")); // Reading from an unreplicated collection does not change the ReadSource to kLastApplied. ASSERT_EQ(client2.second.get()->recoveryUnit()->getTimestampReadSource(), RecoveryUnit::ReadSource::kNoTimestamp); diff --git a/src/mongo/db/dbdirectclient_test.cpp b/src/mongo/db/dbdirectclient_test.cpp index b26f8b5d1d9..51a9cb78697 100644 --- a/src/mongo/db/dbdirectclient_test.cpp +++ b/src/mongo/db/dbdirectclient_test.cpp @@ -34,7 +34,7 @@ namespace mongo { namespace { -const NamespaceString kNs("a.b"); +const NamespaceString kNs = NamespaceString::createNamespaceString_forTest("a.b"); class DBDirectClientTest : public ServiceContextMongoDTest { protected: diff --git a/src/mongo/db/error_labels_test.cpp b/src/mongo/db/error_labels_test.cpp index 4607f6501dc..f0920b0085f 100644 --- a/src/mongo/db/error_labels_test.cpp +++ b/src/mongo/db/error_labels_test.cpp @@ -144,7 +144,8 @@ public: } private: - const NamespaceString _testNss{"test", "testing"}; + const NamespaceString _testNss = + NamespaceString::createNamespaceString_forTest("test", "testing"); ServiceContext::UniqueOperationContext _opCtx; }; diff --git a/src/mongo/db/exec/queued_data_stage_test.cpp b/src/mongo/db/exec/queued_data_stage_test.cpp index 37f895ebb6b..d0e65b6d742 100644 --- a/src/mongo/db/exec/queued_data_stage_test.cpp +++ b/src/mongo/db/exec/queued_data_stage_test.cpp @@ -49,7 +49,7 @@ namespace { using std::unique_ptr; -const static NamespaceString kNss("db.dummy"); +const static NamespaceString kNss = NamespaceString::createNamespaceString_forTest("db.dummy"); class QueuedDataStageTest : public ServiceContextMongoDTest { public: diff --git a/src/mongo/db/exec/sbe/abt/sbe_abt_test.cpp b/src/mongo/db/exec/sbe/abt/sbe_abt_test.cpp index eef9762af01..9b60634b0a8 100644 --- a/src/mongo/db/exec/sbe/abt/sbe_abt_test.cpp +++ b/src/mongo/db/exec/sbe/abt/sbe_abt_test.cpp @@ -390,8 +390,9 @@ TEST_F(NodeSBE, Lower1) { Metadata metadata{{}}; auto opCtx = makeOperationContext(); - auto pipeline = parsePipeline( - "[{$project:{'a.b.c.d':{$literal:'abc'}}}]", NamespaceString("test"), opCtx.get()); + auto pipeline = parsePipeline("[{$project:{'a.b.c.d':{$literal:'abc'}}}]", + NamespaceString::createNamespaceString_forTest("test"), + opCtx.get()); const auto [tag, val] = sbe::value::makeNewArray(); { @@ -605,7 +606,8 @@ TEST_F(NodeSBE, RequireRID) { Metadata metadata{{}}; auto opCtx = makeOperationContext(); - auto pipeline = parsePipeline("[{$match: {a: 2}}]", NamespaceString("test"), opCtx.get()); + auto pipeline = parsePipeline( + "[{$match: {a: 2}}]", NamespaceString::createNamespaceString_forTest("test"), opCtx.get()); const ProjectionName scanProjName = prefixId.getNextId("scan"); diff --git a/src/mongo/db/exec/sort_test.cpp b/src/mongo/db/exec/sort_test.cpp index 7266665304a..328484902f0 100644 --- a/src/mongo/db/exec/sort_test.cpp +++ b/src/mongo/db/exec/sort_test.cpp @@ -49,7 +49,7 @@ using namespace mongo; namespace { -static const NamespaceString kNss("db.dummy"); +static const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("db.dummy"); class SortStageDefaultTest : public ServiceContextMongoDTest { public: diff --git a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp index 35b676751e3..788ac47f272 100644 --- a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp +++ b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp @@ -51,7 +51,8 @@ const auto parallelWaitTimeoutMS = stdx::chrono::milliseconds(5 * 60 * 1000); // Obtain a pointer to the global system clock. Used to enforce timeouts in the parallel thread. auto* const clock = SystemClockSource::get(); -const NamespaceString testNSS{"exhaust_cursor_currentop.testColl"}; +const NamespaceString testNSS = + NamespaceString::createNamespaceString_forTest("exhaust_cursor_currentop.testColl"); const StringData testAppName = "curop_exhaust_cursor_test"; std::unique_ptr connect(StringData appName = testAppName) { diff --git a/src/mongo/db/fle_crud_test.cpp b/src/mongo/db/fle_crud_test.cpp index 0c2bb0c5292..a24ef102902 100644 --- a/src/mongo/db/fle_crud_test.cpp +++ b/src/mongo/db/fle_crud_test.cpp @@ -264,10 +264,10 @@ protected: TestKeyVault _keyVault; - NamespaceString _edcNs{"test.edc"}; - NamespaceString _escNs{"test.esc"}; - NamespaceString _eccNs{"test.ecc"}; - NamespaceString _ecocNs{"test.ecoc"}; + NamespaceString _edcNs = NamespaceString::createNamespaceString_forTest("test.edc"); + NamespaceString _escNs = NamespaceString::createNamespaceString_forTest("test.esc"); + NamespaceString _eccNs = NamespaceString::createNamespaceString_forTest("test.ecc"); + NamespaceString _ecocNs = NamespaceString::createNamespaceString_forTest("test.ecoc"); }; void FleCrudTest::setUp() { @@ -299,7 +299,9 @@ void FleCrudTest::createCollection(const NamespaceString& ns) { CollectionOptions collectionOptions; collectionOptions.uuid = UUID::gen(); auto statusCC = _storage->createCollection( - _opCtx.get(), NamespaceString(ns.db(), ns.coll()), collectionOptions); + _opCtx.get(), + NamespaceString::createNamespaceString_forTest(ns.dbName(), ns.coll()), + collectionOptions); ASSERT_OK(statusCC); } @@ -722,7 +724,7 @@ void FleCrudTest::doFindAndModify(write_ops::FindAndModifyCommandRequest& reques class CollectionReader : public FLEStateCollectionReader { public: CollectionReader(std::string&& coll, FLEQueryInterfaceMock& queryImpl) - : _coll(NamespaceString(coll)), _queryImpl(queryImpl) {} + : _coll(NamespaceString::createNamespaceString_forTest(coll)), _queryImpl(queryImpl) {} uint64_t getDocumentCount() const override { return _queryImpl.countDocuments(_coll); diff --git a/src/mongo/db/free_mon/free_mon_controller_test.cpp b/src/mongo/db/free_mon/free_mon_controller_test.cpp index cd8740054c2..92b2bbb9b59 100644 --- a/src/mongo/db/free_mon/free_mon_controller_test.cpp +++ b/src/mongo/db/free_mon/free_mon_controller_test.cpp @@ -435,7 +435,9 @@ void FreeMonControllerTest::setUp() { collectionOptions.uuid = UUID::gen(); auto statusCC = repl::StorageInterface::get(service)->createCollection( - _opCtx.get(), NamespaceString("admin", "system.version"), collectionOptions); + _opCtx.get(), + NamespaceString::createNamespaceString_forTest("admin", "system.version"), + collectionOptions); ASSERT_OK(statusCC); } diff --git a/src/mongo/db/free_mon/free_mon_storage_test.cpp b/src/mongo/db/free_mon/free_mon_storage_test.cpp index 89073a30b0e..e3040b3373e 100644 --- a/src/mongo/db/free_mon/free_mon_storage_test.cpp +++ b/src/mongo/db/free_mon/free_mon_storage_test.cpp @@ -116,7 +116,9 @@ TEST_F(FreeMonStorageTest, TestStorage) { CollectionOptions collectionOptions; collectionOptions.uuid = UUID::gen(); auto statusCC = _storage->createCollection( - _opCtx.get(), NamespaceString("admin", "system.version"), collectionOptions); + _opCtx.get(), + NamespaceString::createNamespaceString_forTest("admin", "system.version"), + collectionOptions); ASSERT_OK(statusCC); @@ -167,7 +169,9 @@ TEST_F(FreeMonStorageTest, TestSecondary) { CollectionOptions collectionOptions; collectionOptions.uuid = UUID::gen(); auto statusCC = _storage->createCollection( - _opCtx.get(), NamespaceString("admin", "system.version"), collectionOptions); + _opCtx.get(), + NamespaceString::createNamespaceString_forTest("admin", "system.version"), + collectionOptions); ASSERT_OK(statusCC); @@ -244,7 +248,8 @@ void insertDoc(OperationContext* optCtx, const NamespaceString nss, StringData i // Positive: Test local.clustermanager TEST_F(FreeMonStorageTest, TestClusterManagerStorage) { - const NamespaceString localClusterManagerNss("local.clustermanager"); + const NamespaceString localClusterManagerNss = + NamespaceString::createNamespaceString_forTest("local.clustermanager"); // Verify read of non-existent collection works ASSERT_FALSE(FreeMonStorage::readClusterManagerState(_opCtx.get()).has_value()); diff --git a/src/mongo/db/index/columns_access_method_test.cpp b/src/mongo/db/index/columns_access_method_test.cpp index bf5e10de1c7..1ed6ced7416 100644 --- a/src/mongo/db/index/columns_access_method_test.cpp +++ b/src/mongo/db/index/columns_access_method_test.cpp @@ -160,7 +160,7 @@ private: operationContext(), spec.getStringField(IndexDescriptor::kIndexNameFieldName))); } - NamespaceString _nss{"testDB.columns"}; + NamespaceString _nss = NamespaceString::createNamespaceString_forTest("testDB.columns"); boost::optional _coll; ColumnStoreAccessMethod* _accessMethod; diff --git a/src/mongo/db/index/index_build_interceptor_test.cpp b/src/mongo/db/index/index_build_interceptor_test.cpp index c8d44cf3e5a..b9129e16bde 100644 --- a/src/mongo/db/index/index_build_interceptor_test.cpp +++ b/src/mongo/db/index/index_build_interceptor_test.cpp @@ -90,7 +90,7 @@ protected: } private: - NamespaceString _nss{"testDB.interceptor"}; + NamespaceString _nss = NamespaceString::createNamespaceString_forTest("testDB.interceptor"); boost::optional _coll; }; diff --git a/src/mongo/db/index_builds_coordinator_mongod_test.cpp b/src/mongo/db/index_builds_coordinator_mongod_test.cpp index 6327f0c9b1a..3e21ecf6f33 100644 --- a/src/mongo/db/index_builds_coordinator_mongod_test.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod_test.cpp @@ -58,13 +58,15 @@ public: void createCollection(const NamespaceString& nss, UUID uuid); const UUID _testFooUUID = UUID::gen(); - const NamespaceString _testFooNss = NamespaceString("test.foo"); + const NamespaceString _testFooNss = NamespaceString::createNamespaceString_forTest("test.foo"); const UUID _testBarUUID = UUID::gen(); - const NamespaceString _testBarNss = NamespaceString("test.bar"); + const NamespaceString _testBarNss = NamespaceString::createNamespaceString_forTest("test.bar"); const UUID _othertestFooUUID = UUID::gen(); - const NamespaceString _othertestFooNss = NamespaceString("othertest.foo"); + const NamespaceString _othertestFooNss = + NamespaceString::createNamespaceString_forTest("othertest.foo"); const TenantId _tenantId{OID::gen()}; - const NamespaceString _testTenantFooNss{_tenantId, "test.test"}; + const NamespaceString _testTenantFooNss = + NamespaceString::createNamespaceString_forTest(_tenantId, "test.test"); const UUID _testFooTenantUUID = UUID::gen(); const IndexBuildsCoordinator::IndexBuildOptions _indexBuildOptions = { CommitQuorumOptions(CommitQuorumOptions::kDisabled)}; @@ -279,7 +281,7 @@ TEST_F(IndexBuildsCoordinatorMongodTest, SetCommitQuorumWithBadArguments) { ASSERT_EQUALS(ErrorCodes::IndexNotFound, status); // Use an invalid collection namespace. - NamespaceString nss("bad.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("bad.collection"); status = _indexBuildsCoord->setCommitQuorum( operationContext(), nss, {"a_1", "b_1"}, newCommitQuorum); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, status); diff --git a/src/mongo/db/index_builds_coordinator_test.cpp b/src/mongo/db/index_builds_coordinator_test.cpp index ceeff4178c4..d2298a70077 100644 --- a/src/mongo/db/index_builds_coordinator_test.cpp +++ b/src/mongo/db/index_builds_coordinator_test.cpp @@ -71,7 +71,8 @@ CollectionPtr coll(OperationContext* opCtx, const NamespaceString& nss) { TEST_F(IndexBuildsCoordinatorTest, ForegroundUniqueEnforce) { auto opCtx = operationContext(); - NamespaceString nss("IndexBuildsCoordinatorTest.ForegroundUniqueEnforce"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "IndexBuildsCoordinatorTest.ForegroundUniqueEnforce"); createCollectionWithDuplicateDocs(opCtx, nss); AutoGetCollection collection(opCtx, nss, MODE_X); @@ -92,7 +93,8 @@ TEST_F(IndexBuildsCoordinatorTest, ForegroundUniqueEnforce) { TEST_F(IndexBuildsCoordinatorTest, ForegroundUniqueRelax) { auto opCtx = operationContext(); - NamespaceString nss("IndexBuildsCoordinatorTest.ForegroundUniqueRelax"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "IndexBuildsCoordinatorTest.ForegroundUniqueRelax"); createCollectionWithDuplicateDocs(opCtx, nss); AutoGetCollection collection(opCtx, nss, MODE_X); @@ -111,7 +113,8 @@ TEST_F(IndexBuildsCoordinatorTest, ForegroundUniqueRelax) { TEST_F(IndexBuildsCoordinatorTest, ForegroundIndexAlreadyExists) { auto opCtx = operationContext(); - NamespaceString nss("IndexBuildsCoordinatorTest.ForegroundIndexAlreadyExists"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "IndexBuildsCoordinatorTest.ForegroundIndexAlreadyExists"); createCollectionWithDuplicateDocs(opCtx, nss); AutoGetCollection collection(opCtx, nss, MODE_X); @@ -135,7 +138,8 @@ TEST_F(IndexBuildsCoordinatorTest, ForegroundIndexAlreadyExists) { TEST_F(IndexBuildsCoordinatorTest, ForegroundIndexOptionsConflictEnforce) { auto opCtx = operationContext(); - NamespaceString nss("IndexBuildsCoordinatorTest.ForegroundIndexOptionsConflictEnforce"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "IndexBuildsCoordinatorTest.ForegroundIndexOptionsConflictEnforce"); createCollectionWithDuplicateDocs(opCtx, nss); AutoGetCollection collection(opCtx, nss, MODE_X); @@ -162,7 +166,8 @@ TEST_F(IndexBuildsCoordinatorTest, ForegroundIndexOptionsConflictEnforce) { TEST_F(IndexBuildsCoordinatorTest, ForegroundIndexOptionsConflictRelax) { auto opCtx = operationContext(); - NamespaceString nss("IndexBuildsCoordinatorTest.ForegroundIndexOptionsConflictRelax"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "IndexBuildsCoordinatorTest.ForegroundIndexOptionsConflictRelax"); createCollectionWithDuplicateDocs(opCtx, nss); AutoGetCollection collection(opCtx, nss, MODE_X); diff --git a/src/mongo/db/matcher/expression_optimize_test.cpp b/src/mongo/db/matcher/expression_optimize_test.cpp index b7137a3239b..204a2ed10ad 100644 --- a/src/mongo/db/matcher/expression_optimize_test.cpp +++ b/src/mongo/db/matcher/expression_optimize_test.cpp @@ -41,7 +41,8 @@ namespace mongo { namespace { -static const NamespaceString nss("testdb.testcoll"); +static const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("testdb.testcoll"); using unittest::assertGet; diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index fc451951373..cbab3d2c23c 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -370,6 +370,39 @@ public: // functionality to DatabaseNameUtil::parseDbNameFromStringExpectTenantIdInMultitenancyMode. static NamespaceString parseFromStringExpectTenantIdInMultitenancyMode(StringData ns); + /** + * These functions construct a NamespaceString without checking for presence of TenantId. + * + * MUST only be used for tests. + */ + static NamespaceString createNamespaceString_forTest(StringData ns) { + return NamespaceString(boost::none, ns); + } + + static NamespaceString createNamespaceString_forTest(const DatabaseName& dbName) { + return NamespaceString(dbName); + } + + static NamespaceString createNamespaceString_forTest(StringData db, StringData coll) { + return NamespaceString(boost::none, db, coll); + } + + static NamespaceString createNamespaceString_forTest(const DatabaseName& dbName, + StringData coll) { + return NamespaceString(dbName, coll); + } + + static NamespaceString createNamespaceString_forTest(const boost::optional& tenantId, + StringData ns) { + return NamespaceString(tenantId, ns); + } + + static NamespaceString createNamespaceString_forTest(const boost::optional& tenantId, + StringData db, + StringData coll) { + return NamespaceString(tenantId, db, coll); + } + /** * Constructs the namespace '.$cmd.aggregate', which we use as the namespace for * aggregation commands with the format {aggregate: 1}. diff --git a/src/mongo/db/namespace_string_test.cpp b/src/mongo/db/namespace_string_test.cpp index 736f024d3af..231c14f6083 100644 --- a/src/mongo/db/namespace_string_test.cpp +++ b/src/mongo/db/namespace_string_test.cpp @@ -166,7 +166,7 @@ TEST(NamespaceStringTest, MakeDropPendingNamespace) { repl::OpTime(Timestamp(Seconds(1234567), 8U), 9LL))); std::string collName(NamespaceString::MaxNsCollectionLen, 't'); - NamespaceString nss("test", collName); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", collName); ASSERT_EQUALS(NamespaceString{"test.system.drop.1234567i8t9." + collName}, nss.makeDropPendingNamespace(repl::OpTime(Timestamp(Seconds(1234567), 8U), 9LL))); } @@ -253,31 +253,31 @@ TEST(NamespaceStringTest, nsToDatabase1) { } TEST(NamespaceStringTest, NamespaceStringParse1) { - NamespaceString ns("a.b"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("a.b"); ASSERT_EQUALS(std::string("a"), ns.db()); ASSERT_EQUALS(std::string("b"), ns.coll()); } TEST(NamespaceStringTest, NamespaceStringParse2) { - NamespaceString ns("a.b.c"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("a.b.c"); ASSERT_EQUALS(std::string("a"), ns.db()); ASSERT_EQUALS(std::string("b.c"), ns.coll()); } TEST(NamespaceStringTest, NamespaceStringParse3) { - NamespaceString ns("abc"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("abc"); ASSERT_EQUALS(std::string("abc"), ns.db()); ASSERT_EQUALS(std::string(""), ns.coll()); } TEST(NamespaceStringTest, NamespaceStringParse4) { - NamespaceString ns("abc."); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("abc."); ASSERT_EQUALS(std::string("abc"), ns.db()); ASSERT(ns.coll().empty()); } TEST(NamespaceStringTest, NamespaceStringParse5) { - NamespaceString ns("abc", ""); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("abc", ""); ASSERT_EQUALS(std::string("abc"), ns.db()); ASSERT(ns.coll().empty()); } @@ -306,7 +306,7 @@ TEST(NamespaceStringTest, NSSWithTenantId) { TenantId tenantId(OID::gen()); std::string tenantNsStr = str::stream() << tenantId.toString() << "_foo.bar"; - NamespaceString nss(tenantId, "foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tenantId, "foo.bar"); ASSERT_EQ(nss.ns(), "foo.bar"); ASSERT_EQ(nss.toString(), "foo.bar"); ASSERT_EQ(nss.toStringWithTenantId(), tenantNsStr); @@ -314,7 +314,7 @@ TEST(NamespaceStringTest, NSSWithTenantId) { ASSERT_EQ(*nss.tenantId(), tenantId); DatabaseName dbName(tenantId, "foo"); - NamespaceString nss2(dbName, "bar"); + NamespaceString nss2 = NamespaceString::createNamespaceString_forTest(dbName, "bar"); ASSERT_EQ(nss2.ns(), "foo.bar"); ASSERT_EQ(nss2.toString(), "foo.bar"); ASSERT_EQ(nss2.toStringWithTenantId(), tenantNsStr); @@ -340,7 +340,7 @@ TEST(NamespaceStringTest, NSSNoCollectionWithTenantId) { TenantId tenantId(OID::gen()); std::string tenantNsStr = str::stream() << tenantId.toString() << "_foo"; - NamespaceString nss(tenantId, "foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tenantId, "foo"); ASSERT_EQ(nss.ns(), "foo"); ASSERT_EQ(nss.toString(), "foo"); ASSERT_EQ(nss.toStringWithTenantId(), tenantNsStr); @@ -348,7 +348,7 @@ TEST(NamespaceStringTest, NSSNoCollectionWithTenantId) { ASSERT_EQ(*nss.tenantId(), tenantId); DatabaseName dbName(tenantId, "foo"); - NamespaceString nss2(dbName, ""); + NamespaceString nss2 = NamespaceString::createNamespaceString_forTest(dbName, ""); ASSERT(nss2.tenantId()); ASSERT_EQ(*nss2.tenantId(), tenantId); diff --git a/src/mongo/db/op_observer/batched_write_context_test.cpp b/src/mongo/db/op_observer/batched_write_context_test.cpp index dc29da44e7e..88ed3d45f91 100644 --- a/src/mongo/db/op_observer/batched_write_context_test.cpp +++ b/src/mongo/db/op_observer/batched_write_context_test.cpp @@ -66,7 +66,8 @@ DEATH_TEST_REGEX_F(BatchedWriteContextTest, auto& bwc = BatchedWriteContext::get(opCtx); ASSERT(!bwc.writesAreBatched()); - const NamespaceString nss{boost::none, "test", "coll"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); auto op = repl::MutableOplogEntry::makeDeleteOperation(nss, UUID::gen(), BSON("_id" << 0)); bwc.addBatchedOperation(opCtx, op); } @@ -81,7 +82,8 @@ DEATH_TEST_REGEX_F(BatchedWriteContextTest, // Need to explicitly set writes are batched to simulate op observer starting batched write. bwc.setWritesAreBatched(true); - const NamespaceString nss{boost::none, "test", "coll"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); auto op = repl::MutableOplogEntry::makeDeleteOperation(nss, UUID::gen(), BSON("_id" << 0)); bwc.addBatchedOperation(opCtx, op); } @@ -97,7 +99,8 @@ DEATH_TEST_REGEX_F(BatchedWriteContextTest, // Need to explicitly set writes are batched to simulate op observer starting batched write. bwc.setWritesAreBatched(true); - const NamespaceString nss{NamespaceString(boost::none, "other", "coll")}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "other", "coll"); auto op = repl::MutableOplogEntry::makeCreateCommand(nss, CollectionOptions(), BSON("v" << 2)); bwc.addBatchedOperation(opCtx, op); } @@ -115,7 +118,8 @@ DEATH_TEST_REGEX_F(BatchedWriteContextTest, // Need to explicitly set writes are batched to simulate op observer starting batched write. bwc.setWritesAreBatched(true); - const NamespaceString nss{boost::none, "test", "coll"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); auto op = repl::MutableOplogEntry::makeDeleteOperation(nss, UUID::gen(), BSON("_id" << 0)); op.setChangeStreamPreImageRecordingMode( repl::ReplOperation::ChangeStreamPreImageRecordingMode::kPreImagesCollection); @@ -134,7 +138,8 @@ DEATH_TEST_REGEX_F(BatchedWriteContextTest, // Need to explicitly set writes are batched to simulate op observer starting batched write. bwc.setWritesAreBatched(true); - const NamespaceString nss{boost::none, "test", "coll"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); auto op = repl::MutableOplogEntry::makeDeleteOperation(nss, UUID::gen(), BSON("_id" << 0)); bwc.addBatchedOperation(opCtx, op); } @@ -152,7 +157,8 @@ DEATH_TEST_REGEX_F(BatchedWriteContextTest, // Need to explicitly set writes are batched to simulate op observer starting batched write. bwc.setWritesAreBatched(true); - const NamespaceString nss{boost::none, "test", "coll"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); auto op = repl::MutableOplogEntry::makeDeleteOperation(nss, UUID::gen(), BSON("_id" << 0)); bwc.addBatchedOperation(opCtx, op); } @@ -169,7 +175,8 @@ TEST_F(BatchedWriteContextTest, TestAcceptedBatchOperationsSucceeds) { BatchedWriteContext::BatchedOperations* ops = bwc.getBatchedOperations(opCtx); ASSERT(ops->isEmpty()); - const NamespaceString nss{boost::none, "test", "coll"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); auto op = repl::MutableOplogEntry::makeDeleteOperation(nss, UUID::gen(), BSON("_id" << 0)); bwc.addBatchedOperation(opCtx, op); ASSERT_FALSE(ops->isEmpty()); diff --git a/src/mongo/db/op_observer/op_observer_impl_test.cpp b/src/mongo/db/op_observer/op_observer_impl_test.cpp index 4ec02c5d27e..9f075e092db 100644 --- a/src/mongo/db/op_observer/op_observer_impl_test.cpp +++ b/src/mongo/db/op_observer/op_observer_impl_test.cpp @@ -334,13 +334,17 @@ protected: return ChangeStreamPreImage::parse(IDLParserContext("pre-image"), *container); } - const NamespaceString nss{TenantId(OID::gen()), "testDB", "testColl"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(TenantId(OID::gen()), "testDB", "testColl"); const UUID uuid{UUID::gen()}; - const NamespaceString nss1{TenantId(OID::gen()), "testDB1", "testColl1"}; + const NamespaceString nss1 = NamespaceString::createNamespaceString_forTest( + TenantId(OID::gen()), "testDB1", "testColl1"); const UUID uuid1{UUID::gen()}; - const NamespaceString nss2{TenantId(OID::gen()), "testDB2", "testColl2"}; + const NamespaceString nss2 = NamespaceString::createNamespaceString_forTest( + TenantId(OID::gen()), "testDB2", "testColl2"); const UUID uuid2{UUID::gen()}; - const NamespaceString nss3{boost::none, "testDB3", "testColl3"}; + const NamespaceString nss3 = + NamespaceString::createNamespaceString_forTest(boost::none, "testDB3", "testColl3"); const UUID uuid3{UUID::gen()}; const std::string kTenantId = OID::gen().toString(); @@ -364,7 +368,7 @@ TEST_F(OpObserverTest, StartIndexBuildExpectedOplogEntry) { OpObserverImpl opObserver(std::make_unique()); auto opCtx = cc().makeOperationContext(); auto uuid = UUID::gen(); - NamespaceString nss(boost::none, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "test.coll"); UUID indexBuildUUID = UUID::gen(); BSONObj specX = BSON("key" << BSON("x" << 1) << "name" @@ -404,7 +408,7 @@ TEST_F(OpObserverTest, CommitIndexBuildExpectedOplogEntry) { OpObserverImpl opObserver(std::make_unique()); auto opCtx = cc().makeOperationContext(); auto uuid = UUID::gen(); - NamespaceString nss(boost::none, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "test.coll"); UUID indexBuildUUID = UUID::gen(); BSONObj specX = BSON("key" << BSON("x" << 1) << "name" @@ -444,7 +448,7 @@ TEST_F(OpObserverTest, AbortIndexBuildExpectedOplogEntry) { OpObserverImpl opObserver(std::make_unique()); auto opCtx = cc().makeOperationContext(); auto uuid = UUID::gen(); - NamespaceString nss(boost::none, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "test.coll"); UUID indexBuildUUID = UUID::gen(); BSONObj specX = BSON("key" << BSON("x" << 1) << "name" @@ -495,7 +499,7 @@ TEST_F(OpObserverTest, CollModWithCollectionOptionsAndTTLInfo) { auto uuid = UUID::gen(); // Create 'collMod' command. - NamespaceString nss(boost::none, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "test.coll"); BSONObj collModCmd = BSON("collMod" << nss.coll() << "validationLevel" << "off" << "validationAction" @@ -555,7 +559,7 @@ TEST_F(OpObserverTest, CollModWithOnlyCollectionOptions) { auto uuid = UUID::gen(); // Create 'collMod' command. - NamespaceString nss(boost::none, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "test.coll"); BSONObj collModCmd = BSON("collMod" << nss.coll() << "validationLevel" << "off" << "validationAction" @@ -597,7 +601,7 @@ TEST_F(OpObserverTest, OnDropCollectionReturnsDropOpTime) { auto uuid = UUID::gen(); // Create 'drop' command. - NamespaceString nss(boost::none, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "test.coll"); auto dropCmd = BSON("drop" << nss.coll()); // Write to the oplog. @@ -631,7 +635,7 @@ TEST_F(OpObserverTest, OnDropCollectionInlcudesTenantId) { // Create 'drop' command. TenantId tid{TenantId(OID::gen())}; - NamespaceString nss(tid, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "test.coll"); auto dropCmd = BSON("drop" << nss.coll()); // Write to the oplog. @@ -655,8 +659,10 @@ TEST_F(OpObserverTest, OnRenameCollectionReturnsRenameOpTime) { auto uuid = UUID::gen(); auto dropTargetUuid = UUID::gen(); auto stayTemp = false; - NamespaceString sourceNss(boost::none, "test.foo"); - NamespaceString targetNss(boost::none, "test.bar"); + NamespaceString sourceNss = + NamespaceString::createNamespaceString_forTest(boost::none, "test.foo"); + NamespaceString targetNss = + NamespaceString::createNamespaceString_forTest(boost::none, "test.bar"); // Write to the oplog. repl::OpTime renameOpTime; @@ -693,8 +699,8 @@ TEST_F(OpObserverTest, OnRenameCollectionIncludesTenantIdFeatureFlagOff) { auto dropTargetUuid = UUID::gen(); auto stayTemp = false; auto tid{TenantId(OID::gen())}; // rename should not occur across tenants - NamespaceString sourceNss(tid, "test.foo"); - NamespaceString targetNss(tid, "test.bar"); + NamespaceString sourceNss = NamespaceString::createNamespaceString_forTest(tid, "test.foo"); + NamespaceString targetNss = NamespaceString::createNamespaceString_forTest(tid, "test.bar"); // Write to the oplog. { @@ -729,8 +735,8 @@ TEST_F(OpObserverTest, OnRenameCollectionIncludesTenantIdFeatureFlagOn) { auto dropTargetUuid = UUID::gen(); auto stayTemp = false; auto tid{TenantId(OID::gen())}; // rename should not occur across tenants - NamespaceString sourceNss(tid, "test.foo"); - NamespaceString targetNss(tid, "test.bar"); + NamespaceString sourceNss = NamespaceString::createNamespaceString_forTest(tid, "test.foo"); + NamespaceString targetNss = NamespaceString::createNamespaceString_forTest(tid, "test.bar"); // Write to the oplog. { @@ -761,8 +767,10 @@ TEST_F(OpObserverTest, OnRenameCollectionOmitsDropTargetFieldIfDropTargetUuidIsN auto uuid = UUID::gen(); auto stayTemp = true; - NamespaceString sourceNss(boost::none, "test.foo"); - NamespaceString targetNss(boost::none, "test.bar"); + NamespaceString sourceNss = + NamespaceString::createNamespaceString_forTest(boost::none, "test.foo"); + NamespaceString targetNss = + NamespaceString::createNamespaceString_forTest(boost::none, "test.bar"); // Write to the oplog. { @@ -802,7 +810,7 @@ TEST_F(OpObserverTest, ImportCollectionOplogEntry) { auto opCtx = cc().makeOperationContext(); auto importUUID = UUID::gen(); - NamespaceString nss(boost::none, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "test.coll"); long long numRecords = 1; long long dataSize = 2; // A dummy invalid catalog entry. We do not need a valid catalog entry for this test. @@ -845,7 +853,7 @@ TEST_F(OpObserverTest, ImportCollectionOplogEntryIncludesTenantId) { auto importUUID = UUID::gen(); TenantId tid{TenantId(OID::gen())}; - NamespaceString nss(tid, "test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "test.coll"); long long numRecords = 1; long long dataSize = 2; // A dummy invalid catalog entry. We do not need a valid catalog entry for this test. @@ -1010,7 +1018,8 @@ public: TEST_F(OpObserverSessionCatalogRollbackTest, OnRollbackDoesntInvalidateSessionCatalogIfNoSessionOpsRolledBack) { - const NamespaceString nss(boost::none, "testDB", "testColl"); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "testDB", "testColl"); auto sessionId = makeLogicalSessionIdForTest(); @@ -2050,7 +2059,8 @@ public: protected: void testRetryableFindAndModifyUpdateRequestingPostImageHasNeedsRetryImage() { - NamespaceString nss = {boost::none /* tenantId */, "test", "coll"}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + boost::none /* tenantId */, "test", "coll"); const auto criteria = BSON("_id" << 0); const auto preImageDoc = criteria; CollectionUpdateArgs updateArgs{preImageDoc}; @@ -2082,7 +2092,8 @@ protected: } void testRetryableFindAndModifyUpdateRequestingPreImageHasNeedsRetryImage() { - NamespaceString nss = {boost::none, "test", "coll"}; + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); const auto criteria = BSON("_id" << 0); const auto preImageDoc = BSON("_id" << 0 << "data" << "y"); @@ -2137,7 +2148,8 @@ protected: finish(); } - NamespaceString nss = {boost::none, "test", "coll"}; + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); UUID uuid = UUID::gen(); virtual void commit() = 0; @@ -2452,7 +2464,8 @@ protected: {kFaMPost, kChangeStreamImagesEnabled, kNotRetryable, 1}, {kFaMPost, kChangeStreamImagesEnabled, kRecordInSideCollection, 1}}; - const NamespaceString _nss{boost::none, "test", "coll"}; + const NamespaceString _nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); const UUID _uuid = UUID::gen(); const BSONObj kCriteria = BSON("_id" << 0); @@ -2694,8 +2707,10 @@ protected: // See maxNumberOfBatchedOperationsInSingleOplogEntry and // maxSizeOfBatchedOperationsInSingleOplogEntryBytes. static const int maxDeleteOpsInBatch = 202000; - const NamespaceString _nss{boost::none, "test", "coll"}; - const NamespaceString _nssWithTid{TenantId(OID::gen()), "test", "coll"}; + const NamespaceString _nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); + const NamespaceString _nssWithTid = + NamespaceString::createNamespaceString_forTest(TenantId(OID::gen()), "test", "coll"); }; // Verifies that a WriteUnitOfWork with groupOplogEntries=true replicates its writes as a single @@ -3149,7 +3164,8 @@ protected: {kChangeStreamImagesEnabled, kNotRetryable, 1}, {kChangeStreamImagesEnabled, kRecordInSideCollection, 1}}; - const NamespaceString _nss{boost::none, "test", "coll"}; + const NamespaceString _nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); const UUID _uuid = UUID::gen(); const BSONObj _deletedDoc = BSON("_id" << 0 << "valuePriorToDelete" << "marvelous"); diff --git a/src/mongo/db/op_observer/op_observer_registry_test.cpp b/src/mongo/db/op_observer/op_observer_registry_test.cpp index b7ac21be4f8..3f81f4219ff 100644 --- a/src/mongo/db/op_observer/op_observer_registry_test.cpp +++ b/src/mongo/db/op_observer/op_observer_registry_test.cpp @@ -103,7 +103,7 @@ struct ThrowingObserver : public TestObserver { }; struct OpObserverRegistryTest : public unittest::Test { - NamespaceString testNss = {"test", "coll"}; + NamespaceString testNss = NamespaceString::createNamespaceString_forTest("test", "coll"); std::unique_ptr unique1 = std::make_unique(); std::unique_ptr unique2 = std::make_unique(); TestObserver* observer1 = unique1.get(); diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp b/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp index cd57bf41085..72fd24a8e79 100644 --- a/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp +++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp @@ -60,14 +60,24 @@ public: auto replCoord = repl::ReplicationCoordinator::get(opCtx.get()); ASSERT_OK(replCoord->setFollowerMode(repl::MemberState::RS_PRIMARY)); - ASSERT_OK(createCollection(opCtx.get(), CreateCommand(NamespaceString("userDB.coll")))); - ASSERT_OK( - createCollection(opCtx.get(), CreateCommand(NamespaceString("userDB.system.profile")))); - ASSERT_OK(createCollection(opCtx.get(), CreateCommand(NamespaceString("admin.coll")))); - ASSERT_OK( - createCollection(opCtx.get(), CreateCommand(NamespaceString("admin.collForRename")))); - ASSERT_OK(createCollection(opCtx.get(), CreateCommand(NamespaceString("local.coll")))); - ASSERT_OK(createCollection(opCtx.get(), CreateCommand(NamespaceString("config.coll")))); + ASSERT_OK(createCollection( + opCtx.get(), + CreateCommand(NamespaceString::createNamespaceString_forTest("userDB.coll")))); + ASSERT_OK(createCollection(opCtx.get(), + CreateCommand(NamespaceString::createNamespaceString_forTest( + "userDB.system.profile")))); + ASSERT_OK(createCollection( + opCtx.get(), + CreateCommand(NamespaceString::createNamespaceString_forTest("admin.coll")))); + ASSERT_OK(createCollection( + opCtx.get(), + CreateCommand(NamespaceString::createNamespaceString_forTest("admin.collForRename")))); + ASSERT_OK(createCollection( + opCtx.get(), + CreateCommand(NamespaceString::createNamespaceString_forTest("local.coll")))); + ASSERT_OK(createCollection( + opCtx.get(), + CreateCommand(NamespaceString::createNamespaceString_forTest("config.coll")))); } protected: @@ -122,7 +132,8 @@ protected: runCUD(opCtx, nss, shouldSucceed, fromMigrate); UserWriteBlockModeOpObserver opObserver; auto uuid = UUID::gen(); - NamespaceString adminNss = NamespaceString("admin.collForRename"); + NamespaceString adminNss = + NamespaceString::createNamespaceString_forTest("admin.collForRename"); if (shouldSucceed) { try { @@ -209,10 +220,10 @@ TEST_F(UserWriteBlockModeOpObserverTest, WriteBlockingDisabledNoBypass) { ASSERT(!WriteBlockBypass::get(opCtx.get()).isWriteBlockBypassEnabled()); // Ensure writes succeed - runCheckedOps(opCtx.get(), NamespaceString("userDB.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("admin.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("local.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("config.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("userDB.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("admin.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("local.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("config.coll"), true); } TEST_F(UserWriteBlockModeOpObserverTest, WriteBlockingDisabledWithBypass) { @@ -229,10 +240,10 @@ TEST_F(UserWriteBlockModeOpObserverTest, WriteBlockingDisabledWithBypass) { ASSERT(WriteBlockBypass::get(opCtx.get()).isWriteBlockBypassEnabled()); // Ensure writes succeed - runCheckedOps(opCtx.get(), NamespaceString("userDB.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("admin.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("local.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("config.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("userDB.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("admin.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("local.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("config.coll"), true); } TEST_F(UserWriteBlockModeOpObserverTest, WriteBlockingEnabledNoBypass) { @@ -244,17 +255,21 @@ TEST_F(UserWriteBlockModeOpObserverTest, WriteBlockingEnabledNoBypass) { ASSERT(!WriteBlockBypass::get(opCtx.get()).isWriteBlockBypassEnabled()); // Ensure user writes now fail, while non-user writes still succeed - runCheckedOps(opCtx.get(), NamespaceString("userDB.coll"), false); - runCheckedOps(opCtx.get(), NamespaceString("admin.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("local.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("config.coll"), true); + runCheckedOps( + opCtx.get(), NamespaceString::createNamespaceString_forTest("userDB.coll"), false); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("admin.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("local.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("config.coll"), true); // Ensure that CUD ops from migrations succeed - runCUD(opCtx.get(), NamespaceString("userDB.coll"), true, true /* fromMigrate */); + runCUD(opCtx.get(), + NamespaceString::createNamespaceString_forTest("userDB.coll"), + true, + true /* fromMigrate */); // Ensure that writes to the .system.profile collections are always allowed runCUD(opCtx.get(), - NamespaceString("userDB.system.profile"), + NamespaceString::createNamespaceString_forTest("userDB.system.profile"), true /* shouldSucceed */, false /* fromMigrate */); } @@ -274,10 +289,10 @@ TEST_F(UserWriteBlockModeOpObserverTest, WriteBlockingEnabledWithBypass) { // Ensure user writes succeed - runCheckedOps(opCtx.get(), NamespaceString("userDB.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("admin.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("local.coll"), true); - runCheckedOps(opCtx.get(), NamespaceString("config.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("userDB.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("admin.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("local.coll"), true); + runCheckedOps(opCtx.get(), NamespaceString::createNamespaceString_forTest("config.coll"), true); } } // namespace diff --git a/src/mongo/db/ops/write_ops_document_stream_integration_test.cpp b/src/mongo/db/ops/write_ops_document_stream_integration_test.cpp index c1af25b192f..dbfb2d3889e 100644 --- a/src/mongo/db/ops/write_ops_document_stream_integration_test.cpp +++ b/src/mongo/db/ops/write_ops_document_stream_integration_test.cpp @@ -43,7 +43,7 @@ TEST(WriteOpsDocSeq, InsertDocStreamWorks) { uassertStatusOK(swConn.getStatus()); auto conn = std::move(swConn.getValue()); - NamespaceString ns("test", "doc_seq"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test", "doc_seq"); conn->dropCollection(ns); ASSERT_EQ(conn->count(ns), 0u); diff --git a/src/mongo/db/ops/write_ops_exec_test.cpp b/src/mongo/db/ops/write_ops_exec_test.cpp index 21cbaf485db..c5f646db73a 100644 --- a/src/mongo/db/ops/write_ops_exec_test.cpp +++ b/src/mongo/db/ops/write_ops_exec_test.cpp @@ -111,7 +111,8 @@ TEST_F(WriteOpsExecTest, TestDeleteSizeEstimationLogic) { } TEST_F(WriteOpsExecTest, PerformAtomicTimeseriesWritesWithTransform) { - NamespaceString ns{"db_write_ops_exec_test", "ts"}; + NamespaceString ns = + NamespaceString::createNamespaceString_forTest("db_write_ops_exec_test", "ts"); auto opCtx = operationContext(); ASSERT_OK(createCollection(opCtx, ns.dbName(), diff --git a/src/mongo/db/ops/write_ops_parsers_test.cpp b/src/mongo/db/ops/write_ops_parsers_test.cpp index a75bb2bd5b2..5b677720819 100644 --- a/src/mongo/db/ops/write_ops_parsers_test.cpp +++ b/src/mongo/db/ops/write_ops_parsers_test.cpp @@ -206,7 +206,7 @@ TEST(CommandWriteOpsParsers, BadArrayFiltersElementInUpdateDoc) { } TEST(CommandWriteOpsParsers, SingleInsert) { - const auto ns = NamespaceString("test", "foo"); + const auto ns = NamespaceString::createNamespaceString_forTest("test", "foo"); const BSONObj obj = BSON("x" << 1); auto cmd = BSON("insert" << ns.coll() << "documents" << BSON_ARRAY(obj)); for (bool seq : {false, true}) { @@ -221,7 +221,7 @@ TEST(CommandWriteOpsParsers, SingleInsert) { } TEST(CommandWriteOpsParsers, EmptyMultiInsertFails) { - const auto ns = NamespaceString("test", "foo"); + const auto ns = NamespaceString::createNamespaceString_forTest("test", "foo"); auto cmd = BSON("insert" << ns.coll() << "documents" << BSONArray()); for (bool seq : {false, true}) { auto request = toOpMsg(ns.db(), cmd, seq); @@ -230,7 +230,7 @@ TEST(CommandWriteOpsParsers, EmptyMultiInsertFails) { } TEST(CommandWriteOpsParsers, RealMultiInsert) { - const auto ns = NamespaceString("test", "foo"); + const auto ns = NamespaceString::createNamespaceString_forTest("test", "foo"); const BSONObj obj0 = BSON("x" << 0); const BSONObj obj1 = BSON("x" << 1); auto cmd = BSON("insert" << ns.coll() << "documents" << BSON_ARRAY(obj0 << obj1)); @@ -249,7 +249,7 @@ TEST(CommandWriteOpsParsers, RealMultiInsert) { } TEST(CommandWriteOpsParsers, MultiInsertWithStmtId) { - const auto ns = NamespaceString("test", "foo"); + const auto ns = NamespaceString::createNamespaceString_forTest("test", "foo"); const BSONObj obj0 = BSON("x" << 0); const BSONObj obj1 = BSON("x" << 1); auto cmd = @@ -269,7 +269,7 @@ TEST(CommandWriteOpsParsers, MultiInsertWithStmtId) { } TEST(CommandWriteOpsParsers, MultiInsertWithStmtIdsArray) { - const auto ns = NamespaceString("test", "foo"); + const auto ns = NamespaceString::createNamespaceString_forTest("test", "foo"); const BSONObj obj0 = BSON("x" << 0); const BSONObj obj1 = BSON("x" << 1); auto cmd = BSON("insert" << ns.coll() << "documents" << BSON_ARRAY(obj0 << obj1) << "stmtIds" @@ -289,7 +289,7 @@ TEST(CommandWriteOpsParsers, MultiInsertWithStmtIdsArray) { } TEST(CommandWriteOpsParsers, UpdateCommandRequest) { - const auto ns = NamespaceString("test", "foo"); + const auto ns = NamespaceString::createNamespaceString_forTest("test", "foo"); const BSONObj query = BSON("x" << 1); const BSONObj update = BSON("$inc" << BSON("x" << 1)); const BSONObj collation = BSON("locale" @@ -327,7 +327,7 @@ TEST(CommandWriteOpsParsers, UpdateCommandRequest) { } TEST(CommandWriteOpsParsers, UpdateWithPipeline) { - const auto ns = NamespaceString("test", "foo"); + const auto ns = NamespaceString::createNamespaceString_forTest("test", "foo"); const BSONObj query = BSON("q" << BSON("x" << 1)); std::vector pipeline{BSON("$addFields" << BSON("x" << 1))}; const BSONObj update = BSON("u" << pipeline); @@ -363,7 +363,7 @@ TEST(CommandWriteOpsParsers, UpdateWithPipeline) { } TEST(CommandWriteOpsParsers, Remove) { - const auto ns = NamespaceString("test", "foo"); + const auto ns = NamespaceString::createNamespaceString_forTest("test", "foo"); const BSONObj query = BSON("x" << 1); const BSONObj collation = BSON("locale" << "en_US"); diff --git a/src/mongo/db/ops/write_ops_retryability_test.cpp b/src/mongo/db/ops/write_ops_retryability_test.cpp index b0412b67e00..33ca336b7ab 100644 --- a/src/mongo/db/ops/write_ops_retryability_test.cpp +++ b/src/mongo/db/ops/write_ops_retryability_test.cpp @@ -129,16 +129,18 @@ TEST_F(WriteOpsRetryability, ParseOplogEntryForUpdate) { } TEST_F(WriteOpsRetryability, ParseOplogEntryForNestedUpdate) { - auto innerOplog = makeOplogEntry(repl::OpTime(Timestamp(50, 10), 1), // optime - repl::OpTypeEnum::kUpdate, // op type - NamespaceString("a.b"), // namespace - BSON("_id" << 1 << "x" << 5), // o - BSON("_id" << 1)); // o2 - auto updateOplog = makeOplogEntry(repl::OpTime(Timestamp(60, 10), 1), // optime - repl::OpTypeEnum::kNoop, // op type - NamespaceString("a.b"), // namespace - kNestedOplog, // o - innerOplog.getEntry().toBSON()); // o2 + auto innerOplog = + makeOplogEntry(repl::OpTime(Timestamp(50, 10), 1), // optime + repl::OpTypeEnum::kUpdate, // op type + NamespaceString::createNamespaceString_forTest("a.b"), // namespace + BSON("_id" << 1 << "x" << 5), // o + BSON("_id" << 1)); // o2 + auto updateOplog = + makeOplogEntry(repl::OpTime(Timestamp(60, 10), 1), // optime + repl::OpTypeEnum::kNoop, // op type + NamespaceString::createNamespaceString_forTest("a.b"), // namespace + kNestedOplog, // o + innerOplog.getEntry().toBSON()); // o2 auto res = parseOplogEntryForUpdate(updateOplog); @@ -163,15 +165,17 @@ TEST_F(WriteOpsRetryability, ParseOplogEntryForUpsert) { } TEST_F(WriteOpsRetryability, ParseOplogEntryForNestedUpsert) { - auto innerOplog = makeOplogEntry(repl::OpTime(Timestamp(50, 10), 1), // optime - repl::OpTypeEnum::kInsert, // op type - NamespaceString("a.b"), // namespace - BSON("_id" << 2)); // o - auto insertOplog = makeOplogEntry(repl::OpTime(Timestamp(60, 10), 1), /// optime - repl::OpTypeEnum::kNoop, // op type - NamespaceString("a.b"), // namespace - kNestedOplog, // o - innerOplog.getEntry().toBSON()); // o2 + auto innerOplog = + makeOplogEntry(repl::OpTime(Timestamp(50, 10), 1), // optime + repl::OpTypeEnum::kInsert, // op type + NamespaceString::createNamespaceString_forTest("a.b"), // namespace + BSON("_id" << 2)); // o + auto insertOplog = + makeOplogEntry(repl::OpTime(Timestamp(60, 10), 1), /// optime + repl::OpTypeEnum::kNoop, // op type + NamespaceString::createNamespaceString_forTest("a.b"), // namespace + kNestedOplog, // o + innerOplog.getEntry().toBSON()); // o2 auto res = parseOplogEntryForUpdate(insertOplog); @@ -181,10 +185,11 @@ TEST_F(WriteOpsRetryability, ParseOplogEntryForNestedUpsert) { } TEST_F(WriteOpsRetryability, ShouldFailIfParsingDeleteOplogForUpdate) { - auto deleteOplog = makeOplogEntry(repl::OpTime(Timestamp(50, 10), 1), // optime - repl::OpTypeEnum::kDelete, // op type - NamespaceString("a.b"), // namespace - BSON("_id" << 2)); // o + auto deleteOplog = + makeOplogEntry(repl::OpTime(Timestamp(50, 10), 1), // optime + repl::OpTypeEnum::kDelete, // op type + NamespaceString::createNamespaceString_forTest("a.b"), // namespace + BSON("_id" << 2)); // o ASSERT_THROWS(parseOplogEntryForUpdate(deleteOplog), AssertionException); } @@ -195,7 +200,8 @@ TEST_F(WriteOpsRetryability, PerformInsertsSuccess) { repl::UnreplicatedWritesBlock unreplicated(opCtxRaii.get()); setUpReplication(getServiceContext()); - write_ops::InsertCommandRequest insertOp(NamespaceString("foo.bar")); + write_ops::InsertCommandRequest insertOp( + NamespaceString::createNamespaceString_forTest("foo.bar")); insertOp.getWriteCommandRequestBase().setOrdered(true); insertOp.setDocuments({BSON("_id" << 0), BSON("_id" << 1)}); write_ops_exec::WriteResult result = write_ops_exec::performInserts(opCtxRaii.get(), insertOp); @@ -216,7 +222,8 @@ TEST_F(WriteOpsRetryability, PerformRetryableInsertsSuccess) { // Set up a retryable write where statements 1 and 2 have already executed. setUpTxnParticipant(opCtxRaii.get(), {1, 2}); - write_ops::InsertCommandRequest insertOp(NamespaceString("foo.bar")); + write_ops::InsertCommandRequest insertOp( + NamespaceString::createNamespaceString_forTest("foo.bar")); insertOp.getWriteCommandRequestBase().setOrdered(true); // Setup documents that cannot be successfully inserted to show that the retryable logic was // exercised. @@ -243,7 +250,8 @@ TEST_F(WriteOpsRetryability, PerformRetryableInsertsWithBatchedFailure) { // Set up a retryable write where statement 3 has already executed. setUpTxnParticipant(opCtxRaii.get(), {3}); - write_ops::InsertCommandRequest insertOp(NamespaceString("foo.bar")); + write_ops::InsertCommandRequest insertOp( + NamespaceString::createNamespaceString_forTest("foo.bar")); insertOp.getWriteCommandRequestBase().setOrdered(false); // Setup documents such that the second will fail insertion. insertOp.setDocuments({BSON("_id" << 0), BSON("_id" << 0), BSON("_id" << 1)}); @@ -267,7 +275,8 @@ TEST_F(WriteOpsRetryability, PerformOrderedInsertsStopsAtError) { repl::UnreplicatedWritesBlock unreplicated(opCtxRaii.get()); setUpReplication(getServiceContext()); - write_ops::InsertCommandRequest insertOp(NamespaceString("foo.bar")); + write_ops::InsertCommandRequest insertOp( + NamespaceString::createNamespaceString_forTest("foo.bar")); insertOp.getWriteCommandRequestBase().setOrdered(true); // Setup documents such that the second cannot be successfully inserted. insertOp.setDocuments({BSON("_id" << 0), BSON("_id" << 0), BSON("_id" << 1)}); @@ -288,7 +297,8 @@ TEST_F(WriteOpsRetryability, PerformOrderedInsertsStopsAtBadDoc) { repl::UnreplicatedWritesBlock unreplicated(opCtxRaii.get()); setUpReplication(getServiceContext()); - write_ops::InsertCommandRequest insertOp(NamespaceString("foo.bar")); + write_ops::InsertCommandRequest insertOp( + NamespaceString::createNamespaceString_forTest("foo.bar")); insertOp.getWriteCommandRequestBase().setOrdered(true); // Setup documents such that the second cannot be successfully inserted. @@ -320,7 +330,8 @@ TEST_F(WriteOpsRetryability, PerformUnorderedInsertsContinuesAtBadDoc) { repl::UnreplicatedWritesBlock unreplicated(opCtxRaii.get()); setUpReplication(getServiceContext()); - write_ops::InsertCommandRequest insertOp(NamespaceString("foo.bar")); + write_ops::InsertCommandRequest insertOp( + NamespaceString::createNamespaceString_forTest("foo.bar")); insertOp.getWriteCommandRequestBase().setOrdered(false); // Setup documents such that the second cannot be successfully inserted. @@ -347,7 +358,7 @@ TEST_F(WriteOpsRetryability, PerformUnorderedInsertsContinuesAtBadDoc) { using FindAndModifyRetryability = MockReplCoordServerFixture; -const NamespaceString kNs("test.user"); +const NamespaceString kNs = NamespaceString::createNamespaceString_forTest("test.user"); TEST_F(FindAndModifyRetryability, BasicUpsertReturnNew) { auto request = makeFindAndModifyRequest( diff --git a/src/mongo/db/persistent_task_store_test.cpp b/src/mongo/db/persistent_task_store_test.cpp index 0f711d0bffa..e463b9773d4 100644 --- a/src/mongo/db/persistent_task_store_test.cpp +++ b/src/mongo/db/persistent_task_store_test.cpp @@ -37,7 +37,7 @@ namespace mongo { namespace { -const NamespaceString kNss{"test.foo"}; +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.foo"); struct TestTask { std::string key; diff --git a/src/mongo/db/pipeline/abt/abt_optimization_test.cpp b/src/mongo/db/pipeline/abt/abt_optimization_test.cpp index 72546d6d83d..de36df51e8b 100644 --- a/src/mongo/db/pipeline/abt/abt_optimization_test.cpp +++ b/src/mongo/db/pipeline/abt/abt_optimization_test.cpp @@ -254,16 +254,17 @@ TEST_F(ABTOptimizationTest, OptimizePipelineTests) { std::string scanDefA = "collA"; std::string scanDefB = "collB"; Metadata metadata{{{scanDefA, {}}, {scanDefB, {}}}}; - testABTTranslationAndOptimization("optimized union", - "[{$unionWith: 'collB'}, {$match: {_id: 1}}]", - scanDefA, - {OptPhase::MemoSubstitutionPhase, - OptPhase::MemoExplorationPhase, - OptPhase::MemoImplementationPhase}, - metadata, - {}, - false, - {{NamespaceString("a." + scanDefB), {}}}); + testABTTranslationAndOptimization( + "optimized union", + "[{$unionWith: 'collB'}, {$match: {_id: 1}}]", + scanDefA, + {OptPhase::MemoSubstitutionPhase, + OptPhase::MemoExplorationPhase, + OptPhase::MemoImplementationPhase}, + metadata, + {}, + false, + {{NamespaceString::createNamespaceString_forTest("a." + scanDefB), {}}}); testABTTranslationAndOptimization( "optimized common expression elimination", diff --git a/src/mongo/db/pipeline/abt/abt_translation_test.cpp b/src/mongo/db/pipeline/abt/abt_translation_test.cpp index d7d9e021c43..5b315bcfe68 100644 --- a/src/mongo/db/pipeline/abt/abt_translation_test.cpp +++ b/src/mongo/db/pipeline/abt/abt_translation_test.cpp @@ -188,14 +188,15 @@ TEST_F(ABTTranslationTest, UnionTranslation) { std::string scanDefA = "collA"; std::string scanDefB = "collB"; Metadata metadataUnion{{{scanDefA, {}}, {scanDefB, {}}}}; - testABTTranslationAndOptimization("union", - "[{$unionWith: 'collB'}, {$match: {_id: 1}}]", - scanDefA, - {}, - metadataUnion, - {}, - false, - {{NamespaceString("a." + scanDefB), {}}}); + testABTTranslationAndOptimization( + "union", + "[{$unionWith: 'collB'}, {$match: {_id: 1}}]", + scanDefA, + {}, + metadataUnion, + {}, + false, + {{NamespaceString::createNamespaceString_forTest("a." + scanDefB), {}}}); } TEST_F(ABTTranslationTest, SortTranslation) { diff --git a/src/mongo/db/pipeline/aggregation_context_fixture.h b/src/mongo/db/pipeline/aggregation_context_fixture.h index 6dcbe083fb5..a5d14abf5c6 100644 --- a/src/mongo/db/pipeline/aggregation_context_fixture.h +++ b/src/mongo/db/pipeline/aggregation_context_fixture.h @@ -47,7 +47,8 @@ namespace mongo { class AggregationContextFixture : public ServiceContextTest { public: AggregationContextFixture() - : AggregationContextFixture(NamespaceString(boost::none, "unittests", "pipeline_test")) {} + : AggregationContextFixture(NamespaceString::createNamespaceString_forTest( + boost::none, "unittests", "pipeline_test")) {} AggregationContextFixture(NamespaceString nss) { auto service = getServiceContext(); @@ -88,8 +89,8 @@ struct DocumentSourceDeleter { class ServerlessAggregationContextFixture : public AggregationContextFixture { public: ServerlessAggregationContextFixture() - : AggregationContextFixture( - NamespaceString(TenantId(OID::gen()), "unittests", "pipeline_test")) {} + : AggregationContextFixture(NamespaceString::createNamespaceString_forTest( + TenantId(OID::gen()), "unittests", "pipeline_test")) {} const std::string _targetDb = "test"; const std::string _targetColl = "target_collection"; diff --git a/src/mongo/db/pipeline/aggregation_mongod_context_fixture.h b/src/mongo/db/pipeline/aggregation_mongod_context_fixture.h index 71d004cf548..f41e2695ef0 100644 --- a/src/mongo/db/pipeline/aggregation_mongod_context_fixture.h +++ b/src/mongo/db/pipeline/aggregation_mongod_context_fixture.h @@ -46,7 +46,8 @@ namespace mongo { class AggregationMongoDContextFixture : public ServiceContextMongoDTest { public: AggregationMongoDContextFixture() - : AggregationMongoDContextFixture(NamespaceString("unittests.pipeline_test")) {} + : AggregationMongoDContextFixture( + NamespaceString::createNamespaceString_forTest("unittests.pipeline_test")) {} AggregationMongoDContextFixture(NamespaceString nss) : _expCtx(new ExpressionContextForTest(_opCtx.get(), nss)) { diff --git a/src/mongo/db/pipeline/aggregation_request_test.cpp b/src/mongo/db/pipeline/aggregation_request_test.cpp index a300aa15128..1d5b5c89a9b 100644 --- a/src/mongo/db/pipeline/aggregation_request_test.cpp +++ b/src/mongo/db/pipeline/aggregation_request_test.cpp @@ -58,7 +58,7 @@ const Document kDefaultCursorOptionDocument{ TEST(AggregationRequestTest, ShouldParseAllKnownOptions) { // Using oplog namespace so that validation of $_requestReshardingResumeToken succeeds. - NamespaceString nss("local.oplog.rs"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.oplog.rs"); BSONObj inputBson = fromjson( "{aggregate: 'oplog.rs', pipeline: [{$match: {a: 'abc'}}], explain: false, allowDiskUse: " "true, fromMongos: true, " @@ -101,7 +101,7 @@ TEST(AggregationRequestTest, ShouldParseAllKnownOptions) { } TEST(AggregationRequestTest, ShouldParseExplicitRequestReshardingResumeTokenFalseForNonOplog) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj inputBson = fromjson( "{aggregate: 'collection', pipeline: [], $_requestReshardingResumeToken: false, cursor: " "{}, $db: 'a'}"); @@ -111,7 +111,7 @@ TEST(AggregationRequestTest, ShouldParseExplicitRequestReshardingResumeTokenFals } TEST(AggregationRequestTest, ShouldParseExplicitExplainTrue) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj inputBson = fromjson("{aggregate: 'collection', pipeline: [], explain: true, cursor: {}, $db: 'a'}"); auto request = @@ -121,7 +121,7 @@ TEST(AggregationRequestTest, ShouldParseExplicitExplainTrue) { } TEST(AggregationRequestTest, ShouldParseExplicitExplainFalseWithCursorOption) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj inputBson = fromjson( "{aggregate: 'collection', pipeline: [], explain: false, cursor: {batchSize: 10}, $db: " "'a'}"); @@ -134,7 +134,7 @@ TEST(AggregationRequestTest, ShouldParseExplicitExplainFalseWithCursorOption) { } TEST(AggregationRequestTest, ShouldParseWithSeparateQueryPlannerExplainModeArg) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj inputBson = fromjson("{aggregate: 'collection', pipeline: [], cursor: {}, $db: 'a'}"); auto request = unittest::assertGet(aggregation_request_helper::parseFromBSONForTests( @@ -144,7 +144,7 @@ TEST(AggregationRequestTest, ShouldParseWithSeparateQueryPlannerExplainModeArg) } TEST(AggregationRequestTest, ShouldParseWithSeparateQueryPlannerExplainModeArgAndCursorOption) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj inputBson = fromjson("{aggregate: 'collection', pipeline: [], cursor: {batchSize: 10}, $db: 'a'}"); auto request = unittest::assertGet(aggregation_request_helper::parseFromBSONForTests( @@ -157,7 +157,7 @@ TEST(AggregationRequestTest, ShouldParseWithSeparateQueryPlannerExplainModeArgAn } TEST(AggregationRequestTest, ShouldParseExplainFlagWithReadConcern) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); // Non-local readConcern should not be allowed with the explain flag, but this is checked // elsewhere to avoid having to parse the readConcern in AggregationCommand. const BSONObj inputBson = fromjson( @@ -176,7 +176,7 @@ TEST(AggregationRequestTest, ShouldParseExplainFlagWithReadConcern) { // TEST(AggregationRequestTest, ShouldOnlySerializeRequiredFieldsIfNoOptionalFieldsAreSpecified) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); AggregateCommandRequest request(nss, {}); auto expectedSerialization = @@ -188,7 +188,7 @@ TEST(AggregationRequestTest, ShouldOnlySerializeRequiredFieldsIfNoOptionalFields } TEST(AggregationRequestTest, ShouldSerializeOptionalValuesIfSet) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); AggregateCommandRequest request(nss, {}); request.setAllowDiskUse(true); request.setFromMongos(true); @@ -241,7 +241,7 @@ TEST(AggregationRequestTest, ShouldSerializeOptionalValuesIfSet) { } TEST(AggregationRequestTest, ShouldSerializeBatchSizeIfSetAndExplainFalse) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); AggregateCommandRequest request(nss, {}); SimpleCursorOptions cursor; cursor.setBatchSize(10); @@ -272,7 +272,7 @@ TEST(AggregationRequestTest, ShouldSerialiseAggregateFieldToOneIfCollectionIsAgg } TEST(AggregationRequestTest, ShouldSetBatchSizeToDefaultOnEmptyCursorObject) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj inputBson = fromjson( "{aggregate: 'collection', pipeline: [{$match: {a: 'abc'}}], cursor: {}, $db: 'a'}"); auto request = aggregation_request_helper::parseFromBSONForTests(nss, inputBson); @@ -283,7 +283,7 @@ TEST(AggregationRequestTest, ShouldSetBatchSizeToDefaultOnEmptyCursorObject) { } TEST(AggregationRequestTest, ShouldAcceptHintAsString) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj inputBson = fromjson( "{aggregate: 'collection', pipeline: [{$match: {a: 'abc'}}], hint: 'a_1', cursor: {}, $db: " "'a'}"); @@ -295,7 +295,7 @@ TEST(AggregationRequestTest, ShouldAcceptHintAsString) { } TEST(AggregationRequestTest, ShouldNotSerializeBatchSizeWhenExplainSet) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); AggregateCommandRequest request(nss, {}); SimpleCursorOptions cursor; cursor.setBatchSize(10); @@ -397,7 +397,7 @@ void parseNSHelper(const std::string& dbName, } TEST(AggregationRequestTest, ShouldRejectNonArrayPipeline) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson("{aggregate: 'collection', pipeline: [], cursor: {}, $db: 'a'}"); const BSONObj nonArrayPipeline = fromjson("{pipeline: {}}"); @@ -406,7 +406,7 @@ TEST(AggregationRequestTest, ShouldRejectNonArrayPipeline) { } TEST(AggregationRequestTest, ShouldRejectPipelineArrayIfAnElementIsNotAnObject) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection', pipeline: [{$match: {a: 'abc'}}], cursor: {}, $db: 'a'}"); BSONObj nonObjectPipelineElem = fromjson("{pipeline: [4]}"); @@ -419,7 +419,7 @@ TEST(AggregationRequestTest, ShouldRejectPipelineArrayIfAnElementIsNotAnObject) } TEST(AggregationRequestTest, ShouldRejectNonObjectCollation) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection', " "pipeline: [{$match: {a: 'abc'}}]," @@ -432,7 +432,7 @@ TEST(AggregationRequestTest, ShouldRejectNonObjectCollation) { } TEST(AggregationRequestTest, ShouldRejectNonStringNonObjectHint) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection', " "pipeline: [{$match: {a: 'abc'}}]," @@ -445,7 +445,7 @@ TEST(AggregationRequestTest, ShouldRejectNonStringNonObjectHint) { } TEST(AggregationRequestTest, ShouldRejectExplainIfNumber) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}]," @@ -458,7 +458,7 @@ TEST(AggregationRequestTest, ShouldRejectExplainIfNumber) { } TEST(AggregationRequestTest, ShouldRejectExplainIfObject) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}]," @@ -471,7 +471,7 @@ TEST(AggregationRequestTest, ShouldRejectExplainIfObject) { } TEST(AggregationRequestTest, ShouldRejectNonBoolFromMongos) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}]," @@ -484,7 +484,7 @@ TEST(AggregationRequestTest, ShouldRejectNonBoolFromMongos) { } TEST(AggregationRequestTest, ShouldRejectNonBoolNeedsMerge) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}], " @@ -498,7 +498,7 @@ TEST(AggregationRequestTest, ShouldRejectNonBoolNeedsMerge) { } TEST(AggregationRequestTest, ShouldRejectNeedsMergeIfFromMongosNotPresent) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}]," @@ -510,7 +510,7 @@ TEST(AggregationRequestTest, ShouldRejectNeedsMergeIfFromMongosNotPresent) { } TEST(AggregationRequestTest, ShouldRejectNonBoolAllowDiskUse) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}]," @@ -523,7 +523,7 @@ TEST(AggregationRequestTest, ShouldRejectNonBoolAllowDiskUse) { } TEST(AggregationRequestTest, ShouldRejectNonBoolIsMapReduceCommand) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}]," @@ -536,7 +536,7 @@ TEST(AggregationRequestTest, ShouldRejectNonBoolIsMapReduceCommand) { } TEST(AggregationRequestTest, ShouldRejectNoCursorNoExplain) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); // An aggregate with neither cursor nor explain should fail to parse. const BSONObj invalidRequest = fromjson( @@ -562,7 +562,7 @@ TEST(AggregationRequestTest, ShouldRejectNoCursorNoExplain) { } TEST(AggregationRequestTest, ShouldRejectNonObjectCursor) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}]," @@ -579,7 +579,7 @@ TEST(AggregationRequestTest, ShouldRejectNonObjectCursor) { } TEST(AggregationRequestTest, ShouldRejectExplainTrueWithSeparateExplainArg) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: []," @@ -594,7 +594,7 @@ TEST(AggregationRequestTest, ShouldRejectExplainTrueWithSeparateExplainArg) { } TEST(AggregationRequestTest, ShouldRejectExplainFalseWithSeparateExplainArg) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: []," @@ -609,7 +609,7 @@ TEST(AggregationRequestTest, ShouldRejectExplainFalseWithSeparateExplainArg) { } TEST(AggregationRequestTest, ShouldRejectExplainWithWriteConcernMajority) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson("{aggregate: 'collection', pipeline: [], explain: true, $db: 'a'}"); const BSONObj wcMajority = fromjson("{writeConcern: {w: 'majority'}}"); @@ -617,7 +617,7 @@ TEST(AggregationRequestTest, ShouldRejectExplainWithWriteConcernMajority) { } TEST(AggregationRequestTest, ShouldRejectExplainExecStatsVerbosityWithWriteConcernMajority) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson("{aggregate: 'collection', pipeline: [], cursor: {}, $db: 'a'}"); const BSONObj wcMajority = fromjson("{writeConcern: {w: 'majority'}}"); @@ -629,7 +629,7 @@ TEST(AggregationRequestTest, ShouldRejectExplainExecStatsVerbosityWithWriteConce } TEST(AggregationRequestTest, ShouldRejectRequestReshardingResumeTokenIfNonBooleanType) { - NamespaceString oplogNss("local.oplog.rs"); + NamespaceString oplogNss = NamespaceString::createNamespaceString_forTest("local.oplog.rs"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: []," @@ -643,7 +643,7 @@ TEST(AggregationRequestTest, ShouldRejectRequestReshardingResumeTokenIfNonBoolea } TEST(AggregationRequestTest, ShouldRejectRequestReshardingResumeTokenIfNonOplogNss) { - NamespaceString oplogNss("local.oplog.rs"); + NamespaceString oplogNss = NamespaceString::createNamespaceString_forTest("local.oplog.rs"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: []," @@ -653,7 +653,7 @@ TEST(AggregationRequestTest, ShouldRejectRequestReshardingResumeTokenIfNonOplogN ASSERT_OK( aggregation_request_helper::parseFromBSONForTests(oplogNss, validRequest).getStatus()); - NamespaceString nonOplogNss("a.collection"); + NamespaceString nonOplogNss = NamespaceString::createNamespaceString_forTest("a.collection"); auto status = aggregation_request_helper::parseFromBSONForTests(nonOplogNss, validRequest).getStatus(); ASSERT_NOT_OK(status); @@ -700,7 +700,7 @@ TEST(AggregationRequestTest, ParseFromBSONOverloadsShouldProduceIdenticalRequest const BSONObj inputBSON = fromjson( "{aggregate: 'collection', pipeline: [{$match: {}}, {$project: {}}], cursor: {}, $db: " "'a'}"); - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); auto aggReqDBName = unittest::assertGet( aggregation_request_helper::parseFromBSONForTests(nss.dbName(), inputBSON)); @@ -712,7 +712,7 @@ TEST(AggregationRequestTest, ParseFromBSONOverloadsShouldProduceIdenticalRequest } TEST(AggregationRequestTest, ShouldRejectExchangeNotObject) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection', " "pipeline: []," @@ -725,7 +725,7 @@ TEST(AggregationRequestTest, ShouldRejectExchangeNotObject) { } TEST(AggregationRequestTest, ShouldRejectExchangeInvalidSpec) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: []," @@ -739,7 +739,7 @@ TEST(AggregationRequestTest, ShouldRejectExchangeInvalidSpec) { } TEST(AggregationRequestTest, ShouldRejectInvalidWriteConcern) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection'," "pipeline: [{$match: {a: 'abc'}}]," @@ -751,7 +751,7 @@ TEST(AggregationRequestTest, ShouldRejectInvalidWriteConcern) { } TEST(AggregationRequestTest, ShouldRejectInvalidCollectionUUID) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); auto uuid = UUID::gen(); BSONObjBuilder validRequestBuilder( fromjson("{aggregate: 'collection', cursor: {}, pipeline: [{$match: {}}], $db: 'a'}")); @@ -767,7 +767,7 @@ TEST(AggregationRequestTest, ShouldRejectInvalidCollectionUUID) { // TEST(AggregationRequestTest, ShouldRejectUnknownField) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj validRequest = fromjson( "{aggregate: 'collection', " "pipeline: []," @@ -781,7 +781,7 @@ TEST(AggregationRequestTest, ShouldRejectUnknownField) { } TEST(AggregationRequestTest, ShouldIgnoreQueryOptions) { - NamespaceString nss("a.collection"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); const BSONObj inputBson = fromjson( "{aggregate: 'collection', pipeline: [{$match: {a: 'abc'}}], cursor: {}, $queryOptions: " "{}, $db: 'a'}"); diff --git a/src/mongo/db/pipeline/change_stream_event_transform_test.cpp b/src/mongo/db/pipeline/change_stream_event_transform_test.cpp index 56071871909..8f09356c895 100644 --- a/src/mongo/db/pipeline/change_stream_event_transform_test.cpp +++ b/src/mongo/db/pipeline/change_stream_event_transform_test.cpp @@ -102,7 +102,8 @@ TEST(ChangeStreamEventTransformTest, TestDefaultUpdateTransform) { TEST(ChangeStreamEventTransformTest, TestCreateViewTransform) { const NamespaceString systemViewNss = NamespaceString::makeSystemDotViewsNamespace({boost::none, "viewDB"}); - const NamespaceString viewNss(boost::none, "viewDB.view.name"); + const NamespaceString viewNss = + NamespaceString::createNamespaceString_forTest(boost::none, "viewDB.view.name"); const auto viewPipeline = Value(fromjson("[{$match: {field: 'value'}}, {$project: {field: 1}}]")); const auto opDescription = Document{{"viewOn", "baseColl"_sd}, {"pipeline", viewPipeline}}; @@ -136,7 +137,8 @@ TEST(ChangeStreamEventTransformTest, TestCreateViewTransform) { TEST(ChangeStreamEventTransformTest, TestCreateViewOnSingleCollection) { const NamespaceString systemViewNss = NamespaceString::makeSystemDotViewsNamespace({boost::none, "viewDB"}); - const NamespaceString viewNss(boost::none, "viewDB.view.name"); + const NamespaceString viewNss = + NamespaceString::createNamespaceString_forTest(boost::none, "viewDB.view.name"); const auto viewPipeline = Value(fromjson("[{$match: {field: 'value'}}, {$project: {field: 1}}]")); const auto document = BSON("_id" << viewNss.toString() << "viewOn" @@ -175,7 +177,8 @@ TEST(ChangeStreamEventTransformTest, TestUpdateTransformWithTenantId) { const auto documentKey = Document{{"x", 1}, {"y", 1}}; const auto tenantId = TenantId(OID::gen()); - NamespaceString nssWithTenant(tenantId, "unittests.serverless_change_stream"); + NamespaceString nssWithTenant = NamespaceString::createNamespaceString_forTest( + tenantId, "unittests.serverless_change_stream"); auto updateField = makeOplogEntry(repl::OpTypeEnum::kUpdate, // op type @@ -219,8 +222,10 @@ TEST(ChangeStreamEventTransformTest, TestRenameTransformWithTenantId) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); const auto tenantId = TenantId(OID::gen()); - NamespaceString renameFrom(tenantId, "unittests.serverless_change_stream"); - NamespaceString renameTo(tenantId, "unittests.rename_coll"); + NamespaceString renameFrom = NamespaceString::createNamespaceString_forTest( + tenantId, "unittests.serverless_change_stream"); + NamespaceString renameTo = + NamespaceString::createNamespaceString_forTest(tenantId, "unittests.rename_coll"); auto renameField = makeOplogEntry( repl::OpTypeEnum::kCommand, // op type @@ -278,7 +283,8 @@ TEST(ChangeStreamEventTransformTest, TestDropDatabaseTransformWithTenantId) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); const auto tenantId = TenantId(OID::gen()); - NamespaceString dbToDrop(tenantId, "unittests"); + NamespaceString dbToDrop = + NamespaceString::createNamespaceString_forTest(tenantId, "unittests"); auto dropDbField = makeOplogEntry(repl::OpTypeEnum::kCommand, // op type dbToDrop.getCommandNS(), // namespace @@ -316,7 +322,8 @@ TEST(ChangeStreamEventTransformTest, TestCreateTransformWithTenantId) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); const auto tenantId = TenantId(OID::gen()); - NamespaceString nssWithTenant(tenantId, "unittests.serverless_change_stream"); + NamespaceString nssWithTenant = NamespaceString::createNamespaceString_forTest( + tenantId, "unittests.serverless_change_stream"); auto createField = makeOplogEntry(repl::OpTypeEnum::kCommand, // op type nssWithTenant.getCommandNS(), // namespace @@ -358,7 +365,8 @@ TEST(ChangeStreamEventTransformTest, TestCreateViewTransformWithTenantId) { const NamespaceString systemViewNss = NamespaceString::makeSystemDotViewsNamespace({tenantId, "viewDB"}); - const NamespaceString viewNss(tenantId, "viewDB.view.name"); + const NamespaceString viewNss = + NamespaceString::createNamespaceString_forTest(tenantId, "viewDB.view.name"); const auto viewPipeline = Value(fromjson("[{$match: {field: 'value'}}, {$project: {field: 1}}]")); const auto opDescription = Document{{"viewOn", "baseColl"_sd}, {"pipeline", viewPipeline}}; diff --git a/src/mongo/db/pipeline/document_source_change_stream_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_test.cpp index 1c48b6fbf3e..eb7704a9cee 100644 --- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp +++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp @@ -394,7 +394,7 @@ public: std::unique_ptr buildTestPipeline( const std::vector& rawPipeline) { auto expCtx = getExpCtx(); - expCtx->ns = NamespaceString(boost::none, "a.collection"); + expCtx->ns = NamespaceString::createNamespaceString_forTest(boost::none, "a.collection"); expCtx->inMongos = true; auto pipeline = Pipeline::parse(rawPipeline, expCtx); @@ -601,7 +601,8 @@ TEST_F(ChangeStreamStageTestNoSetup, FailsWithNoReplicationCoordinator) { TEST_F(ChangeStreamStageTest, CannotCreateStageForSystemCollection) { auto expressionContext = getExpCtx(); - expressionContext->ns = NamespaceString{"db", "system.namespace"}; + expressionContext->ns = + NamespaceString::createNamespaceString_forTest("db", "system.namespace"); const auto spec = fromjson("{$changeStream: {allowToRunOnSystemNS: false}}"); ASSERT_THROWS_CODE(DocumentSourceChangeStream::createFromBson(spec.firstElement(), getExpCtx()), AssertionException, @@ -610,7 +611,8 @@ TEST_F(ChangeStreamStageTest, CannotCreateStageForSystemCollection) { TEST_F(ChangeStreamStageTest, CanCreateStageForSystemCollectionWhenAllowToRunOnSystemNSIsTrue) { auto expressionContext = getExpCtx(); - expressionContext->ns = NamespaceString{"db", "system.namespace"}; + expressionContext->ns = + NamespaceString::createNamespaceString_forTest("db", "system.namespace"); expressionContext->inMongos = false; const auto spec = fromjson("{$changeStream: {allowToRunOnSystemNS: true}}"); DocumentSourceChangeStream::createFromBson(spec.firstElement(), getExpCtx()); @@ -619,7 +621,8 @@ TEST_F(ChangeStreamStageTest, CanCreateStageForSystemCollectionWhenAllowToRunOnS TEST_F(ChangeStreamStageTest, CannotCreateStageForSystemCollectionWhenAllowToRunOnSystemNSIsTrueAndInMongos) { auto expressionContext = getExpCtx(); - expressionContext->ns = NamespaceString{"db", "system.namespace"}; + expressionContext->ns = + NamespaceString::createNamespaceString_forTest("db", "system.namespace"); expressionContext->inMongos = true; const auto spec = fromjson("{$changeStream: {allowToRunOnSystemNS: true}}"); ASSERT_THROWS_CODE(DocumentSourceChangeStream::createFromBson(spec.firstElement(), getExpCtx()), @@ -1188,7 +1191,7 @@ TEST_F(ChangeStreamStageTest, TransformCreate) { } TEST_F(ChangeStreamStageTest, TransformRename) { - NamespaceString otherColl("test.bar"); + NamespaceString otherColl = NamespaceString::createNamespaceString_forTest("test.bar"); OplogEntry rename = createCommand(BSON("renameCollection" << nss.ns() << "to" << otherColl.ns()), testUuid()); @@ -1219,7 +1222,7 @@ TEST_F(ChangeStreamStageTest, TransformRename) { } TEST_F(ChangeStreamStageTest, TransformRenameShowExpandedEvents) { - NamespaceString otherColl("test.bar"); + NamespaceString otherColl = NamespaceString::createNamespaceString_forTest("test.bar"); auto dropTarget = UUID::gen(); OplogEntry rename = createCommand(BSON("renameCollection" << nss.ns() << "to" << otherColl.ns() << "dropTarget" << dropTarget), @@ -1257,7 +1260,7 @@ TEST_F(ChangeStreamStageTest, TransformRenameShowExpandedEvents) { } TEST_F(ChangeStreamStageTest, TransformInvalidateFromMigrate) { - NamespaceString otherColl("test.bar"); + NamespaceString otherColl = NamespaceString::createNamespaceString_forTest("test.bar"); bool dropCollFromMigrate = true; OplogEntry dropColl = @@ -1276,7 +1279,7 @@ TEST_F(ChangeStreamStageTest, TransformInvalidateFromMigrate) { } TEST_F(ChangeStreamStageTest, TransformRenameTarget) { - NamespaceString otherColl("test.bar"); + NamespaceString otherColl = NamespaceString::createNamespaceString_forTest("test.bar"); OplogEntry rename = createCommand(BSON("renameCollection" << otherColl.ns() << "to" << nss.ns()), testUuid()); @@ -2474,7 +2477,7 @@ TEST_F(ChangeStreamStageTest, ClusterTimeMatchesOplogEntry) { checkTransformation(dropColl, expectedDrop); // Test the 'clusterTime' field is copied from the oplog entry for a collection rename. - NamespaceString otherColl("test.bar"); + NamespaceString otherColl = NamespaceString::createNamespaceString_forTest("test.bar"); OplogEntry rename = createCommand(BSON("renameCollection" << nss.ns() << "to" << otherColl.ns()), testUuid(), @@ -2871,7 +2874,8 @@ TEST_F(ChangeStreamStageTest, ResumeAfterFailsIfResumeTokenDoesNotContainUUID) { TEST_F(ChangeStreamStageTest, RenameFromSystemToUserCollectionShouldIncludeNotification) { // Renaming to a non-system collection will include a notification in the stream. - NamespaceString systemColl(nss.db() + ".system.users"); + NamespaceString systemColl = + NamespaceString::createNamespaceString_forTest(nss.dbName(), "system.users"); OplogEntry rename = createCommand(BSON("renameCollection" << systemColl.ns() << "to" << nss.ns()), testUuid()); @@ -2891,7 +2895,8 @@ TEST_F(ChangeStreamStageTest, RenameFromSystemToUserCollectionShouldIncludeNotif TEST_F(ChangeStreamStageTest, RenameFromUserToSystemCollectionShouldIncludeNotification) { // Renaming to a system collection will include a notification in the stream. - NamespaceString systemColl(nss.db() + ".system.users"); + NamespaceString systemColl = + NamespaceString::createNamespaceString_forTest(nss.dbName(), "system.users"); OplogEntry rename = createCommand(BSON("renameCollection" << nss.ns() << "to" << systemColl.ns()), testUuid()); @@ -3018,7 +3023,8 @@ TEST_F(ChangeStreamStageDBTest, TransformInsertShowExpandedEvents) { } TEST_F(ChangeStreamStageDBTest, InsertOnOtherCollections) { - NamespaceString otherNss("unittests.other_collection."); + NamespaceString otherNss = + NamespaceString::createNamespaceString_forTest("unittests.other_collection."); auto insertOtherColl = makeOplogEntry(OpTypeEnum::kInsert, otherNss, BSON("_id" << 1 << "x" << 2), @@ -3044,13 +3050,13 @@ TEST_F(ChangeStreamStageDBTest, InsertOnOtherCollections) { TEST_F(ChangeStreamStageDBTest, MatchFiltersChangesOnOtherDatabases) { std::set unmatchedNamespaces = { // Namespace starts with the db name, but is longer. - NamespaceString("unittests2.coll"), + NamespaceString::createNamespaceString_forTest("unittests2.coll"), // Namespace contains the db name, but not at the front. - NamespaceString("test.unittests"), + NamespaceString::createNamespaceString_forTest("test.unittests"), // Namespace contains the db name + dot. - NamespaceString("test.unittests.coll"), + NamespaceString::createNamespaceString_forTest("test.unittests.coll"), // Namespace contains the db name + dot but is followed by $. - NamespaceString("unittests.$cmd"), + NamespaceString::createNamespaceString_forTest("unittests.$cmd"), }; // Insert into another database. @@ -3061,28 +3067,28 @@ TEST_F(ChangeStreamStageDBTest, MatchFiltersChangesOnOtherDatabases) { } TEST_F(ChangeStreamStageDBTest, MatchFiltersAllSystemDotCollections) { - auto nss = NamespaceString("unittests.system.coll"); + auto nss = NamespaceString::createNamespaceString_forTest("unittests.system.coll"); auto insert = makeOplogEntry(OpTypeEnum::kInsert, nss, BSON("_id" << 1)); checkTransformation(insert, boost::none); - nss = NamespaceString("unittests.system.users"); + nss = NamespaceString::createNamespaceString_forTest("unittests.system.users"); insert = makeOplogEntry(OpTypeEnum::kInsert, nss, BSON("_id" << 1)); checkTransformation(insert, boost::none); - nss = NamespaceString("unittests.system.roles"); + nss = NamespaceString::createNamespaceString_forTest("unittests.system.roles"); insert = makeOplogEntry(OpTypeEnum::kInsert, nss, BSON("_id" << 1)); checkTransformation(insert, boost::none); - nss = NamespaceString("unittests.system.keys"); + nss = NamespaceString::createNamespaceString_forTest("unittests.system.keys"); insert = makeOplogEntry(OpTypeEnum::kInsert, nss, BSON("_id" << 1)); checkTransformation(insert, boost::none); } TEST_F(ChangeStreamStageDBTest, TransformsEntriesForLegalClientCollectionsWithSystem) { std::set allowedNamespaces = { - NamespaceString("unittests.coll.system"), - NamespaceString("unittests.coll.system.views"), - NamespaceString("unittests.systemx"), + NamespaceString::createNamespaceString_forTest("unittests.coll.system"), + NamespaceString::createNamespaceString_forTest("unittests.coll.system.views"), + NamespaceString::createNamespaceString_forTest("unittests.systemx"), }; for (auto& ns : allowedNamespaces) { @@ -3260,7 +3266,7 @@ TEST_F(ChangeStreamStageDBTest, TransformDrop) { } TEST_F(ChangeStreamStageDBTest, TransformRename) { - NamespaceString otherColl("test.bar"); + NamespaceString otherColl = NamespaceString::createNamespaceString_forTest("test.bar"); OplogEntry rename = createCommand(BSON("renameCollection" << nss.ns() << "to" << otherColl.ns()), testUuid()); @@ -3333,7 +3339,8 @@ TEST_F(ChangeStreamStageDBTest, TransformDropDatabaseShowExpandedEvents) { } TEST_F(ChangeStreamStageDBTest, MatchFiltersOperationsOnSystemCollections) { - NamespaceString systemColl(nss.db() + ".system.users"); + NamespaceString systemColl = + NamespaceString::createNamespaceString_forTest(nss.dbName(), "system.users"); OplogEntry insert = makeOplogEntry(OpTypeEnum::kInsert, systemColl, BSON("_id" << 1)); checkTransformation(insert, boost::none); @@ -3350,8 +3357,10 @@ TEST_F(ChangeStreamStageDBTest, MatchFiltersOperationsOnSystemCollections) { TEST_F(ChangeStreamStageDBTest, RenameFromSystemToUserCollectionShouldIncludeNotification) { // Renaming to a non-system collection will include a notification in the stream. - NamespaceString systemColl(nss.db() + ".system.users"); - NamespaceString renamedColl(nss.db() + ".non_system_coll"); + NamespaceString systemColl = + NamespaceString::createNamespaceString_forTest(nss.dbName(), "system.users"); + NamespaceString renamedColl = + NamespaceString::createNamespaceString_forTest(nss.dbName(), "non_system_coll"); OplogEntry rename = createCommand( BSON("renameCollection" << systemColl.ns() << "to" << renamedColl.ns()), testUuid()); @@ -3372,7 +3381,8 @@ TEST_F(ChangeStreamStageDBTest, RenameFromSystemToUserCollectionShouldIncludeNot TEST_F(ChangeStreamStageDBTest, RenameFromUserToSystemCollectionShouldIncludeNotification) { // Renaming to a system collection will include a notification in the stream. - NamespaceString systemColl(nss.db() + ".system.users"); + NamespaceString systemColl = + NamespaceString::createNamespaceString_forTest(nss.dbName(), "system.users"); OplogEntry rename = createCommand(BSON("renameCollection" << nss.ns() << "to" << systemColl.ns()), testUuid()); diff --git a/src/mongo/db/pipeline/document_source_current_op_test.cpp b/src/mongo/db/pipeline/document_source_current_op_test.cpp index 881f5e476b7..84084f0222f 100644 --- a/src/mongo/db/pipeline/document_source_current_op_test.cpp +++ b/src/mongo/db/pipeline/document_source_current_op_test.cpp @@ -109,7 +109,7 @@ TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfNotRunOnAdmin) { TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfNotRunWithAggregateOne) { const auto specObj = fromjson("{$currentOp:{}}"); - getExpCtx()->ns = NamespaceString("admin.foo"); + getExpCtx()->ns = NamespaceString::createNamespaceString_forTest("admin.foo"); ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()), AssertionException, ErrorCodes::InvalidNamespace); diff --git a/src/mongo/db/pipeline/document_source_exchange_test.cpp b/src/mongo/db/pipeline/document_source_exchange_test.cpp index 58d184a7a46..6063c252dbd 100644 --- a/src/mongo/db/pipeline/document_source_exchange_test.cpp +++ b/src/mongo/db/pipeline/document_source_exchange_test.cpp @@ -87,7 +87,8 @@ struct ThreadInfo { }; } // namespace -const NamespaceString kTestNss = NamespaceString("test.docSourceExchange"_sd); +const NamespaceString kTestNss = + NamespaceString::createNamespaceString_forTest("test.docSourceExchange"_sd); class DocumentSourceExchangeTest : public AggregationContextFixture { protected: diff --git a/src/mongo/db/pipeline/document_source_find_and_modify_image_lookup_test.cpp b/src/mongo/db/pipeline/document_source_find_and_modify_image_lookup_test.cpp index b2dae500011..df5624353a6 100644 --- a/src/mongo/db/pipeline/document_source_find_and_modify_image_lookup_test.cpp +++ b/src/mongo/db/pipeline/document_source_find_and_modify_image_lookup_test.cpp @@ -129,16 +129,17 @@ TEST_F(FindAndModifyImageLookupTest, NoopWhenEntryDoesNotHaveNeedsRetryImageFiel const auto stmtId = 1; const auto opTime = repl::OpTime(Timestamp(2, 1), 1); const auto preImageOpTime = repl::OpTime(Timestamp(1, 1), 1); - const auto oplogEntryBson = makeOplogEntry(opTime, - repl::OpTypeEnum::kNoop, - NamespaceString("test.foo"), - UUID::gen(), - BSON("a" << 1), - sessionInfo, - {stmtId}, - preImageOpTime) - .getEntry() - .toBSON(); + const auto oplogEntryBson = + makeOplogEntry(opTime, + repl::OpTypeEnum::kNoop, + NamespaceString::createNamespaceString_forTest("test.foo"), + UUID::gen(), + BSON("a" << 1), + sessionInfo, + {stmtId}, + preImageOpTime) + .getEntry() + .toBSON(); auto mock = DocumentSourceMock::createForTest(Document(oplogEntryBson), getExpCtx()); imageLookup->setSource(mock.get()); // Mock out the foreign collection. @@ -163,18 +164,19 @@ TEST_F(FindAndModifyImageLookupTest, ShouldNotForgeImageEntryWhenImageDocMissing sessionInfo.setTxnNumber(1); const auto stmtId = 1; const auto opTime = repl::OpTime(Timestamp(2, 1), 1); - const auto oplogEntryDoc = Document(makeOplogEntry(opTime, - repl::OpTypeEnum::kUpdate, - NamespaceString("test.foo"), - UUID::gen(), - BSON("a" << 1), - sessionInfo, - {stmtId}, - boost::none /* preImageOpTime */, - boost::none /* postImageOpTime */, - repl::RetryImageEnum::kPreImage) - .getEntry() - .toBSON()); + const auto oplogEntryDoc = + Document(makeOplogEntry(opTime, + repl::OpTypeEnum::kUpdate, + NamespaceString::createNamespaceString_forTest("test.foo"), + UUID::gen(), + BSON("a" << 1), + sessionInfo, + {stmtId}, + boost::none /* preImageOpTime */, + boost::none /* postImageOpTime */, + repl::RetryImageEnum::kPreImage) + .getEntry() + .toBSON()); auto mock = DocumentSourceMock::createForTest(oplogEntryDoc, getExpCtx()); imageLookup->setSource(mock.get()); @@ -204,18 +206,19 @@ TEST_F(FindAndModifyImageLookupTest, ShouldNotForgeImageEntryWhenImageDocHasDiff const auto stmtId = 1; const auto ts = Timestamp(2, 1); const auto opTime = repl::OpTime(ts, 1); - const auto oplogEntryDoc = Document(makeOplogEntry(opTime, - repl::OpTypeEnum::kUpdate, - NamespaceString("test.foo"), - UUID::gen(), - BSON("a" << 1), - sessionInfo, - {stmtId}, - boost::none /* preImageOpTime */, - boost::none /* postImageOpTime */, - repl::RetryImageEnum::kPreImage) - .getEntry() - .toBSON()); + const auto oplogEntryDoc = + Document(makeOplogEntry(opTime, + repl::OpTypeEnum::kUpdate, + NamespaceString::createNamespaceString_forTest("test.foo"), + UUID::gen(), + BSON("a" << 1), + sessionInfo, + {stmtId}, + boost::none /* preImageOpTime */, + boost::none /* postImageOpTime */, + repl::RetryImageEnum::kPreImage) + .getEntry() + .toBSON()); auto mock = DocumentSourceMock::createForTest(oplogEntryDoc, getExpCtx()); imageLookup->setSource(mock.get()); @@ -260,7 +263,7 @@ TEST_F(FindAndModifyImageLookupTest, ShouldForgeImageEntryWhenMatchingImageDocIs sessionInfo.setTxnNumber(txnNum); const auto ts = Timestamp(2, 1); const auto opTime = repl::OpTime(ts, 1); - const auto nss = NamespaceString("test.foo"); + const auto nss = NamespaceString::createNamespaceString_forTest("test.foo"); const auto uuid = UUID::gen(); // Define a findAndModify/update oplog entry with the 'needsRetryImage' field set. @@ -348,7 +351,7 @@ TEST_F(FindAndModifyImageLookupTest, ShouldForgeImageEntryWhenMatchingImageDocIs const auto applyOpsOpTime = repl::OpTime(applyOpsTs, 1); const auto commitTxnTs = Timestamp(3, 1); const auto commitTxnTsFieldName = CommitTransactionOplogObject::kCommitTimestampFieldName; - const auto nss = NamespaceString("test.foo"); + const auto nss = NamespaceString::createNamespaceString_forTest("test.foo"); const auto uuid = UUID::gen(); // Define an applyOps oplog entry containing a findAndModify/update operation entry with @@ -456,7 +459,7 @@ TEST_F(FindAndModifyImageLookupTest, const auto applyOpsOpTime = repl::OpTime(applyOpsTs, 1); const auto commitTxnTs = Timestamp(3, 1); const auto commitTxnTsFieldName = CommitTransactionOplogObject::kCommitTimestampFieldName; - const auto nss = NamespaceString("test.foo"); + const auto nss = NamespaceString::createNamespaceString_forTest("test.foo"); const auto uuid = UUID::gen(); // Define an applyOps oplog entry containing a findAndModify/update operation entry with diff --git a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp index 141d75926fa..cb577e05f97 100644 --- a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp +++ b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp @@ -85,7 +85,8 @@ private: TEST_F(DocumentSourceGraphLookUpTest, LookupReParseSerializedStageWithFromDBAndColl) { auto expCtx = getExpCtx(); // TODO SERVER-62491 Use system tenantId for nss 'local.system.tenantMigration.oplogView'. - NamespaceString fromNs("local", "system.tenantMigration.oplogView"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest("local", "system.tenantMigration.oplogView"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -128,7 +129,8 @@ TEST_F(DocumentSourceGraphLookUpTest, LookupReParseSerializedStageWithFromDBAndC // local.system.tenantMigration.oplogView. TEST_F(DocumentSourceGraphLookUpTest, RejectsPipelineFromDBAndCollNotLocalDBOrRsOplogView) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -146,7 +148,8 @@ TEST_F(DocumentSourceGraphLookUpTest, RejectsPipelineFromDBAndCollNotLocalDBOrRs // not "system.tenantMigration.oplogView". TEST_F(DocumentSourceGraphLookUpTest, RejectsPipelineFromDBAndCollNotRsOplogView) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "local", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "local", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -164,7 +167,8 @@ TEST_F(DocumentSourceGraphLookUpTest, RejectsPipelineFromDBAndCollNotRsOplogView // "system.tenantMigration.oplogView" but "db" is not "local". TEST_F(DocumentSourceGraphLookUpTest, RejectsPipelineFromDBAndCollNotLocalDB) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "system.tenantMigration.oplogView"); + NamespaceString fromNs = NamespaceString::createNamespaceString_forTest( + boost::none, "test", "system.tenantMigration.oplogView"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -187,7 +191,8 @@ TEST_F(DocumentSourceGraphLookUpTest, std::deque fromContents{Document{{"to", 0}}}; - NamespaceString fromNs(boost::none, "test", "graph_lookup"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "graph_lookup"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = std::make_shared(std::move(fromContents)); @@ -216,7 +221,8 @@ TEST_F(DocumentSourceGraphLookUpTest, std::deque fromContents{ Document{{"_id", "a"_sd}, {"to", 0}, {"from", 1}}, Document{{"to", 1}}}; - NamespaceString fromNs(boost::none, "test", "graph_lookup"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "graph_lookup"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = std::make_shared(std::move(fromContents)); @@ -245,7 +251,8 @@ TEST_F(DocumentSourceGraphLookUpTest, std::deque fromContents{Document{{"to", 0}}}; - NamespaceString fromNs(boost::none, "test", "graph_lookup"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "graph_lookup"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = std::make_shared(std::move(fromContents)); @@ -289,7 +296,8 @@ TEST_F(DocumentSourceGraphLookUpTest, std::deque fromContents{ Document(to1), Document(to2), Document(to0from1), Document(to0from2)}; - NamespaceString fromNs(boost::none, "test", "graph_lookup"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "graph_lookup"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = std::make_shared(std::move(fromContents)); @@ -353,7 +361,8 @@ TEST_F(DocumentSourceGraphLookUpTest, ShouldPropagatePauses) { std::deque fromContents{ Document{{"_id", "a"_sd}, {"to", 0}, {"from", 1}}, Document{{"_id", "b"_sd}, {"to", 1}}}; - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = std::make_shared(std::move(fromContents)); @@ -421,7 +430,8 @@ TEST_F(DocumentSourceGraphLookUpTest, ShouldPropagatePausesWhileUnwinding) { std::deque fromContents{ Document{{"_id", "a"_sd}, {"to", 0}, {"from", 1}}, Document{{"_id", "b"_sd}, {"to", 1}}}; - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -487,7 +497,8 @@ TEST_F(DocumentSourceGraphLookUpTest, ShouldPropagatePausesWhileUnwinding) { TEST_F(DocumentSourceGraphLookUpTest, GraphLookupShouldReportAsFieldIsModified) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = @@ -512,7 +523,8 @@ TEST_F(DocumentSourceGraphLookUpTest, GraphLookupShouldReportAsFieldIsModified) TEST_F(DocumentSourceGraphLookUpTest, GraphLookupShouldReportFieldsModifiedByAbsorbedUnwind) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = @@ -544,7 +556,8 @@ TEST_F(DocumentSourceGraphLookUpTest, GraphLookupWithComparisonExpressionForStar auto inputMock = DocumentSourceMock::createForTest(Document({{"_id", 0}, {"a", 1}, {"b", 2}}), expCtx); - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); std::deque fromContents{Document{{"_id", 0}, {"to", true}}, @@ -609,7 +622,8 @@ TEST_F(DocumentSourceGraphLookUpTest, ShouldExpandArraysAtEndOfConnectFromField) Document(middle3), Document(sinkDoc)}; - NamespaceString fromNs(boost::none, "test", "graph_lookup"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "graph_lookup"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = std::make_shared(std::move(fromContents)); @@ -682,7 +696,8 @@ TEST_F(DocumentSourceGraphLookUpTest, ShouldNotExpandArraysWithinArraysAtEndOfCo std::deque fromContents{ Document(startDoc), Document(target1), Document(target2), Document(soloDoc)}; - NamespaceString fromNs(boost::none, "test", "graph_lookup"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "graph_lookup"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); expCtx->mongoProcessInterface = std::make_shared(std::move(fromContents)); @@ -749,11 +764,11 @@ TEST_F(DocumentSourceGraphLookUpTest, IncrementNestedAggregateOpCounterOnCreateB ASSERT_EQ(countAfterCopy - countAfterCreate, 0); }; - testOpCounter(NamespaceString{"testDb", "testColl"}, 1); + testOpCounter(NamespaceString::createNamespaceString_forTest("testDb", "testColl"), 1); // $graphLookup against internal databases should not cause the counter to get incremented. - testOpCounter(NamespaceString{"config", "testColl"}, 0); - testOpCounter(NamespaceString{"admin", "testColl"}, 0); - testOpCounter(NamespaceString{"local", "testColl"}, 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("config", "testColl"), 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("admin", "testColl"), 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("local", "testColl"), 0); } @@ -773,12 +788,15 @@ TEST_F(DocumentSourceGraphLookupServerlessTest, << "as" << "connections")); - NamespaceString nss(expCtx->ns.dbName(), _targetColl); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), _targetColl); auto liteParsedLookup = DocumentSourceGraphLookUp::LiteParsed::parse(nss, originalBSON.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); ASSERT_EQ(1, namespaceSet.size()); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(expCtx->ns.dbName(), "foo"))); + ASSERT_EQ(1ul, + namespaceSet.count( + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "foo"))); } TEST_F( @@ -801,7 +819,8 @@ TEST_F( << "as" << "connections")); - NamespaceString nss(expCtx->ns.dbName(), _targetColl); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), _targetColl); for (bool flagStatus : {false, true}) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", @@ -840,7 +859,8 @@ TEST_F(DocumentSourceGraphLookupServerlessTest, flagStatus); // TODO SERVER-62491 Use system tenantId to construct nss. - NamespaceString nss(boost::none, expCtx->ns.dbName().toString(), _targetColl); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + boost::none, expCtx->ns.dbName().toString(), _targetColl); auto liteParsedLookup = DocumentSourceGraphLookUp::LiteParsed::parse(nss, originalBSON.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); diff --git a/src/mongo/db/pipeline/document_source_group_test.cpp b/src/mongo/db/pipeline/document_source_group_test.cpp index 9c8a800caae..d2404c38440 100644 --- a/src/mongo/db/pipeline/document_source_group_test.cpp +++ b/src/mongo/db/pipeline/document_source_group_test.cpp @@ -258,8 +258,9 @@ class Base : public ServiceContextTest { public: Base(GroupStageType groupStageType = GroupStageType::Default) : _opCtx(makeOperationContext()), - _ctx(new ExpressionContextForTest(_opCtx.get(), - AggregateCommandRequest(NamespaceString(ns), {}))), + _ctx(new ExpressionContextForTest( + _opCtx.get(), + AggregateCommandRequest(NamespaceString::createNamespaceString_forTest(ns), {}))), _tempDir("DocumentSourceGroupTest"), _groupStageType(groupStageType) {} @@ -298,7 +299,8 @@ protected: BSONElement specElement = namedSpec.firstElement(); intrusive_ptr expressionContext = new ExpressionContextForTest( - _opCtx.get(), AggregateCommandRequest(NamespaceString(ns), {})); + _opCtx.get(), + AggregateCommandRequest(NamespaceString::createNamespaceString_forTest(ns), {})); expressionContext->allowDiskUse = true; // For $group, 'inShard' implies 'fromMongos' and 'needsMerge'. expressionContext->fromMongos = expressionContext->needsMerge = inShard; diff --git a/src/mongo/db/pipeline/document_source_lookup_test.cpp b/src/mongo/db/pipeline/document_source_lookup_test.cpp index 49b340d1853..1682a375569 100644 --- a/src/mongo/db/pipeline/document_source_lookup_test.cpp +++ b/src/mongo/db/pipeline/document_source_lookup_test.cpp @@ -95,7 +95,8 @@ auto makeLookUpFromBson(BSONElement elem, const boost::intrusive_ptrsetResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -118,7 +119,8 @@ TEST_F(DocumentSourceLookUpTest, PreservesParentPipelineLetVariables) { TEST_F(DocumentSourceLookUpTest, AcceptsPipelineSyntax) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -136,7 +138,8 @@ TEST_F(DocumentSourceLookUpTest, AcceptsPipelineSyntax) { TEST_F(DocumentSourceLookUpTest, AcceptsPipelineWithLetSyntax) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -161,7 +164,8 @@ TEST_F(DocumentSourceLookUpTest, AcceptsPipelineWithLetSyntax) { TEST_F(DocumentSourceLookUpTest, LookupEmptyPipelineDoesntUseDiskAndIsOKInATransaction) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -183,7 +187,8 @@ TEST_F(DocumentSourceLookUpTest, LookupEmptyPipelineDoesntUseDiskAndIsOKInATrans TEST_F(DocumentSourceLookUpTest, LookupWithOutInPipelineNotAllowed) { auto ERROR_CODE_OUT_BANNED_IN_LOOKUP = 51047; auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); ASSERT_THROWS_CODE( @@ -216,19 +221,24 @@ TEST_F(DocumentSourceLookUpTest, LiteParsedDocumentSourceLookupContainsExpectedN << "as" << "lookup1")); - NamespaceString nss(boost::none, "test.test"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "test.test"); std::vector pipeline; auto liteParsedLookup = DocumentSourceLookUp::LiteParsed::parse(nss, stageSpec.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(boost::none, "test.namespace1"))); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(boost::none, "test.namespace2"))); + ASSERT_EQ(1ul, + namespaceSet.count( + NamespaceString::createNamespaceString_forTest(boost::none, "test.namespace1"))); + ASSERT_EQ(1ul, + namespaceSet.count( + NamespaceString::createNamespaceString_forTest(boost::none, "test.namespace2"))); ASSERT_EQ(2ul, namespaceSet.size()); } TEST_F(DocumentSourceLookUpTest, RejectLookupWhenDepthLimitIsExceeded) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -249,7 +259,8 @@ TEST_F(DocumentSourceLookUpTest, RejectLookupWhenDepthLimitIsExceeded) { TEST_F(ReplDocumentSourceLookUpTest, RejectsPipelineWithChangeStreamStage) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -265,7 +276,8 @@ TEST_F(ReplDocumentSourceLookUpTest, RejectsPipelineWithChangeStreamStage) { TEST_F(ReplDocumentSourceLookUpTest, RejectsSubPipelineWithChangeStreamStage) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -283,7 +295,8 @@ TEST_F(ReplDocumentSourceLookUpTest, RejectsSubPipelineWithChangeStreamStage) { TEST_F(DocumentSourceLookUpTest, AcceptsLocalFieldForeignFieldAndPipelineSyntax) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -310,7 +323,8 @@ TEST_F(DocumentSourceLookUpTest, AcceptsLocalFieldForeignFieldAndPipelineSyntax) TEST_F(DocumentSourceLookUpTest, AcceptsLocalFieldForeignFieldAndPipelineWithLetSyntax) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -343,7 +357,8 @@ TEST_F(DocumentSourceLookUpTest, AcceptsLocalFieldForeignFieldAndPipelineWithLet TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenLetIsSpecified) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -366,7 +381,8 @@ TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenLetIsSpecified TEST_F(DocumentSourceLookUpTest, RejectsInvalidLetVariableName) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -418,7 +434,8 @@ TEST_F(DocumentSourceLookUpTest, RejectsInvalidLetVariableName) { TEST_F(DocumentSourceLookUpTest, ShouldBeAbleToReParseSerializedStage) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -476,7 +493,8 @@ TEST_F(DocumentSourceLookUpTest, ShouldBeAbleToReParseSerializedStage) { TEST_F(DocumentSourceLookUpTest, ShouldBeAbleToReParseSerializedStageWithFieldsAndPipeline) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -543,7 +561,8 @@ TEST_F(DocumentSourceLookUpTest, ShouldBeAbleToReParseSerializedStageWithFieldsA // be round tripped. TEST_F(DocumentSourceLookUpTest, LookupReParseSerializedStageWithFromDBAndColl) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "config", "cache.chunks.test.foo"); + NamespaceString fromNs = NamespaceString::createNamespaceString_forTest( + boost::none, "config", "cache.chunks.test.foo"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -581,7 +600,8 @@ TEST_F(DocumentSourceLookUpTest, LookupReParseSerializedStageWithFromDBAndColl) // can be round tripped. TEST_F(DocumentSourceLookUpTest, LookupWithLetReParseSerializedStageWithFromDBAndColl) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "config", "cache.chunks.test.foo"); + NamespaceString fromNs = NamespaceString::createNamespaceString_forTest( + boost::none, "config", "cache.chunks.test.foo"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -620,7 +640,8 @@ TEST_F(DocumentSourceLookUpTest, LookupWithLetReParseSerializedStageWithFromDBAn // Tests that $lookup with 'collation' can be round tripped. TEST_F(DocumentSourceLookUpTest, LookupReParseSerializedStageWithCollation) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -669,7 +690,8 @@ TEST_F(DocumentSourceLookUpTest, LookupReParseSerializedStageWithCollation) { // config.cache.chunks*. TEST_F(DocumentSourceLookUpTest, RejectsPipelineFromDBAndCollWithBadDBAndColl) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -686,7 +708,8 @@ TEST_F(DocumentSourceLookUpTest, RejectsPipelineFromDBAndCollWithBadDBAndColl) { // "cache.chunks.*" but "db" is not "config". TEST_F(DocumentSourceLookUpTest, RejectsPipelineFromDBAndCollWithBadColl) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "config", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "config", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -703,7 +726,8 @@ TEST_F(DocumentSourceLookUpTest, RejectsPipelineFromDBAndCollWithBadColl) { // not "cache.chunks.*". TEST_F(DocumentSourceLookUpTest, RejectsPipelineFromDBAndCollWithBadDB) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "cache.chunks.test.foo"); + NamespaceString fromNs = NamespaceString::createNamespaceString_forTest( + boost::none, "test", "cache.chunks.test.foo"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -721,7 +745,8 @@ TEST_F(DocumentSourceLookUpTest, RejectsPipelineFromDBAndCollWithBadDB) { // syntax. TEST_F(DocumentSourceLookUpTest, FromDBAndCollDistributedPlanLogic) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "config", "cache.chunks.test.foo"); + NamespaceString fromNs = NamespaceString::createNamespaceString_forTest( + boost::none, "config", "cache.chunks.test.foo"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -746,7 +771,8 @@ TEST_F(DocumentSourceLookUpTest, FromDBAndCollDistributedPlanLogic) { // $lookup with from: syntax. TEST_F(DocumentSourceLookUpTest, LookupDistributedPlanLogic) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -852,7 +878,8 @@ private: TEST_F(DocumentSourceLookUpTest, ShouldPropagatePauses) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -900,7 +927,8 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePauses) { TEST_F(DocumentSourceLookUpTest, ShouldPropagatePausesWhileUnwinding) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -954,7 +982,8 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePausesWhileUnwinding) { TEST_F(DocumentSourceLookUpTest, LookupReportsAsFieldIsModified) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -975,7 +1004,8 @@ TEST_F(DocumentSourceLookUpTest, LookupReportsAsFieldIsModified) { TEST_F(DocumentSourceLookUpTest, LookupReportsFieldsModifiedByAbsorbedUnwind) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "foreign"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "foreign"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1007,7 +1037,8 @@ BSONObj sequentialCacheStageObj(const StringData status = "kBuilding"_sd, TEST_F(DocumentSourceLookUpTest, ShouldCacheNonCorrelatedSubPipelinePrefix) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1036,7 +1067,8 @@ TEST_F(DocumentSourceLookUpTest, ShouldCacheNonCorrelatedSubPipelinePrefix) { TEST_F(DocumentSourceLookUpTest, ShouldDiscoverVariablesReferencedInFacetPipelineAfterAnExhaustiveAllStage) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1078,7 +1110,8 @@ TEST_F(DocumentSourceLookUpTest, TEST_F(DocumentSourceLookUpTest, ExprEmbeddedInMatchExpressionShouldBeOptimized) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1118,7 +1151,8 @@ TEST_F(DocumentSourceLookUpTest, ExprEmbeddedInMatchExpressionShouldBeOptimized) TEST_F(DocumentSourceLookUpTest, ShouldIgnoreLocalVariablesShadowingLetVariablesWhenFindingNonCorrelatedPrefix) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1154,7 +1188,8 @@ TEST_F(DocumentSourceLookUpTest, TEST_F(DocumentSourceLookUpTest, ShouldInsertCacheBeforeCorrelatedNestedLookup) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1192,7 +1227,8 @@ TEST_F(DocumentSourceLookUpTest, ShouldInsertCacheBeforeCorrelatedNestedLookup) TEST_F(DocumentSourceLookUpTest, ShouldIgnoreNestedLookupLetVariablesShadowingOuterLookupLetVariablesWhenFindingPrefix) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1226,7 +1262,8 @@ TEST_F(DocumentSourceLookUpTest, TEST_F(DocumentSourceLookUpTest, ShouldCacheEntirePipelineIfNonCorrelated) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1259,7 +1296,8 @@ TEST_F(DocumentSourceLookUpTest, ShouldCacheEntirePipelineIfNonCorrelated) { TEST_F(DocumentSourceLookUpTest, ShouldReplaceNonCorrelatedPrefixWithCacheAfterFirstSubPipelineIteration) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1333,7 +1371,8 @@ TEST_F(DocumentSourceLookUpTest, TEST_F(DocumentSourceLookUpTest, ShouldAbandonCacheIfMaxSizeIsExceededAfterFirstSubPipelineIteration) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1399,7 +1438,8 @@ TEST_F(DocumentSourceLookUpTest, TEST_F(DocumentSourceLookUpTest, ShouldNotCacheIfCorrelatedStageIsAbsorbedIntoPlanExecutor) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1454,11 +1494,11 @@ TEST_F(DocumentSourceLookUpTest, IncrementNestedAggregateOpCounterOnCreateButNot ASSERT_EQ(countAfterCopy - countAfterCreate, 0); }; - testOpCounter(NamespaceString{"testDb", "testColl"}, 1); + testOpCounter(NamespaceString::createNamespaceString_forTest("testDb", "testColl"), 1); // $lookup against internal databases should not cause the counter to get incremented. - testOpCounter(NamespaceString{"config", "testColl"}, 0); - testOpCounter(NamespaceString{"admin", "testColl"}, 0); - testOpCounter(NamespaceString{"local", "testColl"}, 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("config", "testColl"), 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("admin", "testColl"), 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("local", "testColl"), 0); } using DocumentSourceLookUpServerlessTest = ServerlessAggregationContextFixture; @@ -1482,12 +1522,17 @@ TEST_F(DocumentSourceLookUpServerlessTest, << "as" << "lookup1")); - NamespaceString nss(expCtx->ns.dbName(), _targetColl); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), _targetColl); auto liteParsedLookup = DocumentSourceLookUp::LiteParsed::parse(nss, stageSpec.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(expCtx->ns.dbName(), "namespace1"))); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(expCtx->ns.dbName(), "namespace2"))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), + "namespace1"))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), + "namespace2"))); ASSERT_EQ(2ul, namespaceSet.size()); } @@ -1517,7 +1562,8 @@ TEST_F( << BSON_ARRAY(BSON("$match" << BSON("x" << 1)))))) << "as" << "lookup1")); - NamespaceString nss(expCtx->ns.dbName(), _targetColl); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), _targetColl); for (bool flagStatus : {false, true}) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", @@ -1558,7 +1604,8 @@ TEST_F(DocumentSourceLookUpServerlessTest, << "lookup1")); // TODO SERVER-62491 Use system tenantId to construct nss. - NamespaceString nss(boost::none, expCtx->ns.dbName().toString(), _targetColl); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + boost::none, expCtx->ns.dbName().toString(), _targetColl); for (bool flagStatus : {false, true}) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", @@ -1568,10 +1615,12 @@ TEST_F(DocumentSourceLookUpServerlessTest, DocumentSourceLookUp::LiteParsed::parse(nss, stageSpec.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); - ASSERT_EQ( - 1ul, - namespaceSet.count(NamespaceString(boost::none, "config", "cache.chunks.test.foo"))); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(boost::none, "local", "oplog.rs"))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest( + boost::none, "config", "cache.chunks.test.foo"))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest( + boost::none, "local", "oplog.rs"))); ASSERT_EQ(2ul, namespaceSet.size()); } } @@ -1580,7 +1629,8 @@ TEST_F(DocumentSourceLookUpServerlessTest, CreateFromBSONContainsExpectedNamespa auto expCtx = getExpCtx(); ASSERT(expCtx->ns.tenantId()); - NamespaceString fromNs(expCtx->ns.dbName(), "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -1593,7 +1643,8 @@ TEST_F(DocumentSourceLookUpServerlessTest, CreateFromBSONContainsExpectedNamespa expCtx); auto lookupStage = static_cast(docSource.get()); ASSERT(lookupStage); - ASSERT_EQ(lookupStage->getFromNs(), NamespaceString(expCtx->ns.dbName(), "coll")); + ASSERT_EQ(lookupStage->getFromNs(), + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "coll")); } } // namespace diff --git a/src/mongo/db/pipeline/document_source_merge_cursors_test.cpp b/src/mongo/db/pipeline/document_source_merge_cursors_test.cpp index 04bf762d340..b0c6fff8037 100644 --- a/src/mongo/db/pipeline/document_source_merge_cursors_test.cpp +++ b/src/mongo/db/pipeline/document_source_merge_cursors_test.cpp @@ -415,7 +415,8 @@ public: DocumentSourceMergeCursorsMultiTenancyTest() : _multitenancyController( std::make_unique("multitenancySupport", true)) { - _nss = NamespaceString(TenantId(OID::gen()), kMergeCursorNsStr); + _nss = + NamespaceString::createNamespaceString_forTest(TenantId(OID::gen()), kMergeCursorNsStr); } protected: diff --git a/src/mongo/db/pipeline/document_source_merge_test.cpp b/src/mongo/db/pipeline/document_source_merge_test.cpp index 288ea3c81e5..1cd0aa0dcd6 100644 --- a/src/mongo/db/pipeline/document_source_merge_test.cpp +++ b/src/mongo/db/pipeline/document_source_merge_test.cpp @@ -963,7 +963,8 @@ TEST_F(DocumentSourceMergeServerlessTest, flagStatus); auto tenantId = TenantId(OID::gen()); - NamespaceString nss(tenantId, _targetDb, "testColl"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, _targetDb, "testColl"); // Pass collection name as a string. auto stageSpec = BSON("$merge" << _targetColl); @@ -971,7 +972,9 @@ TEST_F(DocumentSourceMergeServerlessTest, DocumentSourceMerge::LiteParsed::parse(nss, stageSpec.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); ASSERT_EQ(1, namespaceSet.size()); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(tenantId, _targetDb, _targetColl))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest( + tenantId, _targetDb, _targetColl))); } } @@ -984,7 +987,8 @@ TEST_F(DocumentSourceMergeServerlessTest, flagStatus); auto tenantId = TenantId(OID::gen()); - NamespaceString nss(tenantId, _targetDb, "testColl"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, _targetDb, "testColl"); // Pass collection name as a db + coll object. auto stageSpec = @@ -993,7 +997,9 @@ TEST_F(DocumentSourceMergeServerlessTest, DocumentSourceMerge::LiteParsed::parse(nss, stageSpec.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); ASSERT_EQ(1, namespaceSet.size()); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(tenantId, _targetDb, _targetColl))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest( + tenantId, _targetDb, _targetColl))); } } @@ -1004,7 +1010,8 @@ TEST_F(DocumentSourceMergeServerlessTest, RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); auto tenantId = TenantId(OID::gen()); - NamespaceString nss(tenantId, _targetDb, "testColl"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, _targetDb, "testColl"); // Pass collection name as a db + coll object. auto stageSpec = @@ -1013,7 +1020,9 @@ TEST_F(DocumentSourceMergeServerlessTest, auto liteParsedLookup = DocumentSourceMerge::LiteParsed::parse(nss, stageSpec.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); ASSERT_EQ(1, namespaceSet.size()); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(tenantId, _targetDb, _targetColl))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest( + tenantId, _targetDb, _targetColl))); } TEST_F(DocumentSourceMergeServerlessTest, diff --git a/src/mongo/db/pipeline/document_source_out_test.cpp b/src/mongo/db/pipeline/document_source_out_test.cpp index abeb2ebca8d..af5ac5b568d 100644 --- a/src/mongo/db/pipeline/document_source_out_test.cpp +++ b/src/mongo/db/pipeline/document_source_out_test.cpp @@ -119,7 +119,8 @@ using DocumentSourceOutServerlessTest = ServerlessAggregationContextFixture; TEST_F(DocumentSourceOutServerlessTest, LiteParsedDocumentSourceLookupContainsExpectedNamespacesInServerless) { auto tenantId = TenantId(OID::gen()); - NamespaceString nss(tenantId, "test", "testColl"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, "test", "testColl"); std::vector pipeline; auto stageSpec = BSON("$out" @@ -127,7 +128,9 @@ TEST_F(DocumentSourceOutServerlessTest, auto liteParsedLookup = DocumentSourceOut::LiteParsed::parse(nss, stageSpec.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); ASSERT_EQ(1, namespaceSet.size()); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(tenantId, "test", "some_collection"))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest( + tenantId, "test", "some_collection"))); // The tenantId for the outputNs should be the same as that on the expCtx despite outputting // into different dbs. @@ -138,7 +141,9 @@ TEST_F(DocumentSourceOutServerlessTest, liteParsedLookup = DocumentSourceOut::LiteParsed::parse(nss, stageSpec.firstElement()); namespaceSet = liteParsedLookup->getInvolvedNamespaces(); ASSERT_EQ(1, namespaceSet.size()); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(tenantId, "target_db", "some_collection"))); + ASSERT_EQ(1ul, + namespaceSet.count(NamespaceString::createNamespaceString_forTest( + tenantId, "target_db", "some_collection"))); } TEST_F(DocumentSourceOutServerlessTest, CreateFromBSONContainsExpectedNamespacesInServerless) { @@ -151,7 +156,8 @@ TEST_F(DocumentSourceOutServerlessTest, CreateFromBSONContainsExpectedNamespaces auto outStage = DocumentSourceOut::createFromBson(spec.firstElement(), expCtx); auto outSource = static_cast(outStage.get()); ASSERT(outSource); - ASSERT_EQ(outSource->getOutputNs(), NamespaceString(defaultDb, targetColl)); + ASSERT_EQ(outSource->getOutputNs(), + NamespaceString::createNamespaceString_forTest(defaultDb, targetColl)); // Assert the tenantId is not included in the serialized namespace. auto serialized = outSource->serialize().getDocument(); diff --git a/src/mongo/db/pipeline/document_source_telemetry_test.cpp b/src/mongo/db/pipeline/document_source_telemetry_test.cpp index 9d8f2ad7e26..25e24164507 100644 --- a/src/mongo/db/pipeline/document_source_telemetry_test.cpp +++ b/src/mongo/db/pipeline/document_source_telemetry_test.cpp @@ -70,7 +70,7 @@ TEST_F(DocumentSourceTelemetryTest, ShouldFailToParseIfNotRunOnAdmin) { } TEST_F(DocumentSourceTelemetryTest, ShouldFailToParseIfNotRunWithAggregateOne) { - getExpCtx()->ns = NamespaceString("admin.foo"); + getExpCtx()->ns = NamespaceString::createNamespaceString_forTest("admin.foo"); ASSERT_THROWS_CODE(DocumentSourceTelemetry::createFromBson( fromjson("{$telemetry: {}}").firstElement(), getExpCtx()), AssertionException, diff --git a/src/mongo/db/pipeline/document_source_union_with_test.cpp b/src/mongo/db/pipeline/document_source_union_with_test.cpp index 50f9047bd0d..bb7461b8913 100644 --- a/src/mongo/db/pipeline/document_source_union_with_test.cpp +++ b/src/mongo/db/pipeline/document_source_union_with_test.cpp @@ -180,7 +180,8 @@ TEST_F(DocumentSourceUnionWithTest, UnionsWithNonEmptySubPipelines) { TEST_F(DocumentSourceUnionWithTest, SerializeAndParseWithPipeline) { auto expCtx = getExpCtx(); - NamespaceString nsToUnionWith(expCtx->ns.dbName(), "coll"); + NamespaceString nsToUnionWith = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "coll"); expCtx->setResolvedNamespaces(StringMap{ {nsToUnionWith.coll().toString(), {nsToUnionWith, std::vector()}}}); auto bson = @@ -200,7 +201,8 @@ TEST_F(DocumentSourceUnionWithTest, SerializeAndParseWithPipeline) { TEST_F(DocumentSourceUnionWithTest, SerializeAndParseWithoutPipeline) { auto expCtx = getExpCtx(); - NamespaceString nsToUnionWith(expCtx->ns.dbName(), "coll"); + NamespaceString nsToUnionWith = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "coll"); expCtx->setResolvedNamespaces(StringMap{ {nsToUnionWith.coll().toString(), {nsToUnionWith, std::vector()}}}); auto bson = BSON("$unionWith" << nsToUnionWith.coll()); @@ -219,7 +221,8 @@ TEST_F(DocumentSourceUnionWithTest, SerializeAndParseWithoutPipeline) { TEST_F(DocumentSourceUnionWithTest, SerializeAndParseWithoutPipelineExtraSubobject) { auto expCtx = getExpCtx(); - NamespaceString nsToUnionWith(expCtx->ns.dbName(), "coll"); + NamespaceString nsToUnionWith = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "coll"); expCtx->setResolvedNamespaces(StringMap{ {nsToUnionWith.coll().toString(), {nsToUnionWith, std::vector()}}}); auto bson = BSON("$unionWith" << BSON("coll" << nsToUnionWith.coll())); @@ -238,7 +241,8 @@ TEST_F(DocumentSourceUnionWithTest, SerializeAndParseWithoutPipelineExtraSubobje TEST_F(DocumentSourceUnionWithTest, ParseErrors) { auto expCtx = getExpCtx(); - NamespaceString nsToUnionWith(expCtx->ns.dbName(), "coll"); + NamespaceString nsToUnionWith = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "coll"); expCtx->setResolvedNamespaces(StringMap{ {nsToUnionWith.coll().toString(), {nsToUnionWith, std::vector()}}}); ASSERT_THROWS_CODE( @@ -397,7 +401,8 @@ TEST_F(DocumentSourceUnionWithTest, DependencyAnalysisReportsReferencedFieldsBef TEST_F(DocumentSourceUnionWithTest, RespectsViewDefinition) { auto expCtx = getExpCtx(); - NamespaceString nsToUnionWith(expCtx->ns.dbName(), "coll"); + NamespaceString nsToUnionWith = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "coll"); expCtx->setResolvedNamespaces(StringMap{ {nsToUnionWith.coll().toString(), {nsToUnionWith, std::vector{fromjson("{$match: {_id: {$mod: [2, 0]}}}")}}}}); @@ -427,8 +432,10 @@ TEST_F(DocumentSourceUnionWithTest, RespectsViewDefinition) { TEST_F(DocumentSourceUnionWithTest, ConcatenatesViewDefinitionToPipeline) { auto expCtx = getExpCtx(); - NamespaceString viewNsToUnionWith(expCtx->ns.dbName(), "view"); - NamespaceString nsToUnionWith(expCtx->ns.dbName(), "coll"); + NamespaceString viewNsToUnionWith = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "view"); + NamespaceString nsToUnionWith = + NamespaceString::createNamespaceString_forTest(expCtx->ns.dbName(), "coll"); expCtx->setResolvedNamespaces(StringMap{ {viewNsToUnionWith.coll().toString(), {nsToUnionWith, std::vector{fromjson("{$match: {_id: {$mod: [2, 0]}}}")}}}}); @@ -463,7 +470,8 @@ TEST_F(DocumentSourceUnionWithTest, ConcatenatesViewDefinitionToPipeline) { TEST_F(DocumentSourceUnionWithTest, RejectUnionWhenDepthLimitIsExceeded) { auto expCtx = getExpCtx(); - NamespaceString fromNs(boost::none, "test", "coll"); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest(boost::none, "test", "coll"); expCtx->setResolvedNamespaces(StringMap{ {fromNs.coll().toString(), {fromNs, std::vector()}}}); @@ -615,11 +623,11 @@ TEST_F(DocumentSourceUnionWithTest, IncrementNestedAggregateOpCounterOnCreateBut ASSERT_EQ(countAfterCopy - countAfterCreate, 0); }; - testOpCounter(NamespaceString{"testDb", "testColl"}, 1); + testOpCounter(NamespaceString::createNamespaceString_forTest("testDb", "testColl"), 1); // $unionWith against internal databases should not cause the counter to get incremented. - testOpCounter(NamespaceString{"config", "testColl"}, 0); - testOpCounter(NamespaceString{"admin", "testColl"}, 0); - testOpCounter(NamespaceString{"local", "testColl"}, 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("config", "testColl"), 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("admin", "testColl"), 0); + testOpCounter(NamespaceString::createNamespaceString_forTest("local", "testColl"), 0); } using DocumentSourceUnionWithServerlessTest = ServerlessAggregationContextFixture; @@ -627,7 +635,8 @@ using DocumentSourceUnionWithServerlessTest = ServerlessAggregationContextFixtur TEST_F(DocumentSourceUnionWithServerlessTest, LiteParsedDocumentSourceLookupContainsExpectedNamespacesInServerless) { auto tenantId = TenantId(OID::gen()); - NamespaceString nss(tenantId, "test", "testColl"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, "test", "testColl"); std::vector pipeline; auto stageSpec = BSON("$unionWith" @@ -636,7 +645,9 @@ TEST_F(DocumentSourceUnionWithServerlessTest, DocumentSourceUnionWith::LiteParsed::parse(nss, stageSpec.firstElement()); auto namespaceSet = liteParsedLookup->getInvolvedNamespaces(); ASSERT_EQ(1, namespaceSet.size()); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(tenantId, "test", "some_coll"))); + ASSERT_EQ(1ul, + namespaceSet.count( + NamespaceString::createNamespaceString_forTest(tenantId, "test", "some_coll"))); stageSpec = BSON("$unionWith" << BSON("coll" << "some_coll" @@ -644,7 +655,9 @@ TEST_F(DocumentSourceUnionWithServerlessTest, liteParsedLookup = DocumentSourceUnionWith::LiteParsed::parse(nss, stageSpec.firstElement()); namespaceSet = liteParsedLookup->getInvolvedNamespaces(); ASSERT_EQ(1, namespaceSet.size()); - ASSERT_EQ(1ul, namespaceSet.count(NamespaceString(tenantId, "test", "some_coll"))); + ASSERT_EQ(1ul, + namespaceSet.count( + NamespaceString::createNamespaceString_forTest(tenantId, "test", "some_coll"))); } TEST_F(DocumentSourceUnionWithServerlessTest, @@ -652,7 +665,8 @@ TEST_F(DocumentSourceUnionWithServerlessTest, auto expCtx = getExpCtx(); ASSERT(expCtx->ns.tenantId()); - NamespaceString unionWithNs(expCtx->ns.tenantId(), "test", "some_coll"); + NamespaceString unionWithNs = + NamespaceString::createNamespaceString_forTest(expCtx->ns.tenantId(), "test", "some_coll"); expCtx->setResolvedNamespaces(StringMap{ {unionWithNs.coll().toString(), {unionWithNs, std::vector()}}}); diff --git a/src/mongo/db/pipeline/document_source_unwind_test.cpp b/src/mongo/db/pipeline/document_source_unwind_test.cpp index 662ee79d24a..8eb021797af 100644 --- a/src/mongo/db/pipeline/document_source_unwind_test.cpp +++ b/src/mongo/db/pipeline/document_source_unwind_test.cpp @@ -70,8 +70,9 @@ public: CheckResultsBase() : _queryServiceContext(std::make_unique()), _opCtx(_queryServiceContext->makeOperationContext()), - _ctx(new ExpressionContextForTest(_opCtx.get(), - AggregateCommandRequest(NamespaceString(ns), {}))) {} + _ctx(new ExpressionContextForTest( + _opCtx.get(), + AggregateCommandRequest(NamespaceString::createNamespaceString_forTest(ns), {}))) {} virtual ~CheckResultsBase() {} diff --git a/src/mongo/db/pipeline/expression_context_test.cpp b/src/mongo/db/pipeline/expression_context_test.cpp index 2ff0ef20b1e..a8e93bb290d 100644 --- a/src/mongo/db/pipeline/expression_context_test.cpp +++ b/src/mongo/db/pipeline/expression_context_test.cpp @@ -50,61 +50,64 @@ TEST_F(ExpressionContextTest, ExpressionContextSummonsMissingTimeValues) { t1.addTicks(100); VectorClockMutable::get(opCtx->getServiceContext())->tickClusterTimeTo(t1); { - const auto expCtx = ExpressionContext{opCtx.get(), - {}, // explain - false, // fromMongos - false, // needsMerge - false, // allowDiskUse - false, // bypassDocumentValidation - false, // isMapReduce - NamespaceString{"test"_sd, "namespace"_sd}, - {}, // runtime constants - {}, // collator - std::make_shared(), - {}, // resolvedNamespaces - {}, // collUUID - {}, // let - false}; + const auto expCtx = ExpressionContext{ + opCtx.get(), + {}, // explain + false, // fromMongos + false, // needsMerge + false, // allowDiskUse + false, // bypassDocumentValidation + false, // isMapReduce + NamespaceString::createNamespaceString_forTest("test"_sd, "namespace"_sd), + {}, // runtime constants + {}, // collator + std::make_shared(), + {}, // resolvedNamespaces + {}, // collUUID + {}, // let + false}; ASSERT_DOES_NOT_THROW(static_cast(expCtx.variables.getValue(Variables::kNowId))); ASSERT_DOES_NOT_THROW( static_cast(expCtx.variables.getValue(Variables::kClusterTimeId))); } { - const auto expCtx = ExpressionContext{opCtx.get(), - {}, // explain - false, // fromMongos - false, // needsMerge - false, // allowDiskUse - false, // bypassDocumentValidation - false, // isMapReduce - NamespaceString{"test"_sd, "namespace"_sd}, - LegacyRuntimeConstants{Date_t::now(), {}}, - {}, // collator - std::make_shared(), - {}, // resolvedNamespaces - {}, // collUUID - {}, // let - false}; + const auto expCtx = ExpressionContext{ + opCtx.get(), + {}, // explain + false, // fromMongos + false, // needsMerge + false, // allowDiskUse + false, // bypassDocumentValidation + false, // isMapReduce + NamespaceString::createNamespaceString_forTest("test"_sd, "namespace"_sd), + LegacyRuntimeConstants{Date_t::now(), {}}, + {}, // collator + std::make_shared(), + {}, // resolvedNamespaces + {}, // collUUID + {}, // let + false}; ASSERT_DOES_NOT_THROW(static_cast(expCtx.variables.getValue(Variables::kNowId))); ASSERT_DOES_NOT_THROW( static_cast(expCtx.variables.getValue(Variables::kClusterTimeId))); } { - const auto expCtx = ExpressionContext{opCtx.get(), - {}, // explain - false, // fromMongos - false, // needsMerge - false, // allowDiskUse - false, // bypassDocumentValidation - false, // isMapReduce - NamespaceString{"test"_sd, "namespace"_sd}, - LegacyRuntimeConstants{{}, Timestamp(1, 0)}, - {}, // collator - std::make_shared(), - {}, // resolvedNamespaces - {}, // collUUID - {}, // let - false}; + const auto expCtx = ExpressionContext{ + opCtx.get(), + {}, // explain + false, // fromMongos + false, // needsMerge + false, // allowDiskUse + false, // bypassDocumentValidation + false, // isMapReduce + NamespaceString::createNamespaceString_forTest("test"_sd, "namespace"_sd), + LegacyRuntimeConstants{{}, Timestamp(1, 0)}, + {}, // collator + std::make_shared(), + {}, // resolvedNamespaces + {}, // collUUID + {}, // let + false}; ASSERT_DOES_NOT_THROW(static_cast(expCtx.variables.getValue(Variables::kNowId))); ASSERT_DOES_NOT_THROW( static_cast(expCtx.variables.getValue(Variables::kClusterTimeId))); @@ -113,21 +116,22 @@ TEST_F(ExpressionContextTest, ExpressionContextSummonsMissingTimeValues) { TEST_F(ExpressionContextTest, ParametersCanContainExpressionsWhichAreFolded) { auto opCtx = makeOperationContext(); - const auto expCtx = ExpressionContext{opCtx.get(), - {}, // explain - false, // fromMongos - false, // needsMerge - false, // allowDiskUse - false, // bypassDocumentValidation - false, // isMapReduce - NamespaceString{"test"_sd, "namespace"_sd}, - {}, // runtime constants - {}, // collator - std::make_shared(), - {}, // resolvedNamespaces - {}, // collUUID - BSON("atan2" << BSON("$atan2" << BSON_ARRAY(0 << 1))), - false}; + const auto expCtx = + ExpressionContext{opCtx.get(), + {}, // explain + false, // fromMongos + false, // needsMerge + false, // allowDiskUse + false, // bypassDocumentValidation + false, // isMapReduce + NamespaceString::createNamespaceString_forTest("test"_sd, "namespace"_sd), + {}, // runtime constants + {}, // collator + std::make_shared(), + {}, // resolvedNamespaces + {}, // collUUID + BSON("atan2" << BSON("$atan2" << BSON_ARRAY(0 << 1))), + false}; ASSERT_EQUALS( 0.0, expCtx.variables.getValue(expCtx.variablesParseState.getVariable("atan2")).getDouble()); @@ -135,45 +139,47 @@ TEST_F(ExpressionContextTest, ParametersCanContainExpressionsWhichAreFolded) { TEST_F(ExpressionContextTest, ParametersCanReferToAlreadyDefinedParameters) { auto opCtx = makeOperationContext(); - const auto expCtx = ExpressionContext{opCtx.get(), - {}, // explain - false, // fromMongos - false, // needsMerge - false, // allowDiskUse - false, // bypassDocumentValidation - false, // isMapReduce - NamespaceString{"test"_sd, "namespace"_sd}, - {}, // runtime constants - {}, // collator - std::make_shared(), - {}, // resolvedNamespaces - {}, // collUUID - BSON("a" << 12 << "b" - << "$$a" - << "c" - << "$$b"), - false}; + const auto expCtx = + ExpressionContext{opCtx.get(), + {}, // explain + false, // fromMongos + false, // needsMerge + false, // allowDiskUse + false, // bypassDocumentValidation + false, // isMapReduce + NamespaceString::createNamespaceString_forTest("test"_sd, "namespace"_sd), + {}, // runtime constants + {}, // collator + std::make_shared(), + {}, // resolvedNamespaces + {}, // collUUID + BSON("a" << 12 << "b" + << "$$a" + << "c" + << "$$b"), + false}; ASSERT_EQUALS( 12.0, expCtx.variables.getValue(expCtx.variablesParseState.getVariable("c")).getDouble()); } TEST_F(ExpressionContextTest, ParametersCanOverwriteInLeftToRightOrder) { auto opCtx = makeOperationContext(); - const auto expCtx = ExpressionContext{opCtx.get(), - {}, // explain - false, // fromMongos - false, // needsMerge - false, // allowDiskUse - false, // bypassDocumentValidation - false, // isMapReduce - NamespaceString{"test"_sd, "namespace"_sd}, - {}, // runtime constants - {}, // collator - std::make_shared(), - {}, // resolvedNamespaces - {}, // collUUID - BSON("x" << 12 << "b" << 10 << "x" << 20), - false}; + const auto expCtx = + ExpressionContext{opCtx.get(), + {}, // explain + false, // fromMongos + false, // needsMerge + false, // allowDiskUse + false, // bypassDocumentValidation + false, // isMapReduce + NamespaceString::createNamespaceString_forTest("test"_sd, "namespace"_sd), + {}, // runtime constants + {}, // collator + std::make_shared(), + {}, // resolvedNamespaces + {}, // collUUID + BSON("x" << 12 << "b" << 10 << "x" << 20), + false}; ASSERT_EQUALS( 20, expCtx.variables.getValue(expCtx.variablesParseState.getVariable("x")).getDouble()); } @@ -188,7 +194,8 @@ TEST_F(ExpressionContextTest, ParametersCauseGracefulFailuresIfNonConstant) { false, // allowDiskUse false, // bypassDocumentValidation false, // isMapReduce - NamespaceString{"test"_sd, "namespace"_sd}, + NamespaceString::createNamespaceString_forTest( + "test"_sd, "namespace"_sd), {}, // runtime constants {}, // collator std::make_shared(), @@ -204,21 +211,22 @@ TEST_F(ExpressionContextTest, ParametersCauseGracefulFailuresIfNonConstant) { TEST_F(ExpressionContextTest, ParametersCauseGracefulFailuresIfUppercase) { auto opCtx = makeOperationContext(); ASSERT_THROWS_CODE( - static_cast(ExpressionContext{opCtx.get(), - {}, // explain - false, // fromMongos - false, // needsMerge - false, // allowDiskUse - false, // bypassDocumentValidation - false, // isMapReduce - NamespaceString{"test"_sd, "namespace"_sd}, - {}, // runtime constants - {}, // collator - std::make_shared(), - {}, // resolvedNamespaces - {}, // collUUID - BSON("A" << 12), - false}), + static_cast(ExpressionContext{ + opCtx.get(), + {}, // explain + false, // fromMongos + false, // needsMerge + false, // allowDiskUse + false, // bypassDocumentValidation + false, // isMapReduce + NamespaceString::createNamespaceString_forTest("test"_sd, "namespace"_sd), + {}, // runtime constants + {}, // collator + std::make_shared(), + {}, // resolvedNamespaces + {}, // collUUID + BSON("A" << 12), + false}), DBException, ErrorCodes::FailedToParse); } diff --git a/src/mongo/db/pipeline/expression_walker_test.cpp b/src/mongo/db/pipeline/expression_walker_test.cpp index 36fbe505cc8..adc34141554 100644 --- a/src/mongo/db/pipeline/expression_walker_test.cpp +++ b/src/mongo/db/pipeline/expression_walker_test.cpp @@ -54,7 +54,8 @@ protected: ASSERT_EQUALS(inputBson["pipeline"].type(), BSONType::Array); auto rawPipeline = parsePipelineFromBSON(inputBson["pipeline"]); - NamespaceString testNss("test", "collection"); + NamespaceString testNss = + NamespaceString::createNamespaceString_forTest("test", "collection"); auto command = AggregateCommandRequest{testNss, rawPipeline}; return Pipeline::parse(command.getPipeline(), getExpCtx()); diff --git a/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp b/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp index 07a0016f119..c521c432597 100644 --- a/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp +++ b/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp @@ -68,7 +68,8 @@ protected: ASSERT_EQUALS(inputBson["pipeline"].type(), BSONType::Array); auto rawPipeline = parsePipelineFromBSON(inputBson["pipeline"]); - NamespaceString testNss("test", "collection"); + NamespaceString testNss = + NamespaceString::createNamespaceString_forTest("test", "collection"); AggregateCommandRequest request(testNss, rawPipeline); getExpCtx()->ns = testNss; @@ -84,7 +85,8 @@ protected: } void introduceCollection(StringData collectionName) { - NamespaceString fromNs("test", collectionName); + NamespaceString fromNs = + NamespaceString::createNamespaceString_forTest("test", collectionName); _resolvedNamespaces.insert({fromNs.coll().toString(), {fromNs, std::vector()}}); getExpCtx()->setResolvedNamespaces(_resolvedNamespaces); } @@ -117,7 +119,9 @@ TEST_F(PipelineMetadataTreeTest, LinearPipelinesConstructProperTrees) { ASSERT([&]() { auto pipePtr = jsonToPipeline("[{$project: {name: 1}}]"); return makeTree( - {{NamespaceString("test.collection"), initial}}, *pipePtr, ignoreDocumentSourceAddOne); + {{NamespaceString::createNamespaceString_forTest("test.collection"), initial}}, + *pipePtr, + ignoreDocumentSourceAddOne); }() .first.value() == Stage(TestThing{23}, {}, {})); @@ -126,7 +130,9 @@ TEST_F(PipelineMetadataTreeTest, LinearPipelinesConstructProperTrees) { "[{$project: {name: 1, status: 1}}, " "{$match: {status: \"completed\"}}]"); return makeTree( - {{NamespaceString("test.collection"), initial}}, *pipePtr, ignoreDocumentSourceAddOne); + {{NamespaceString::createNamespaceString_forTest("test.collection"), initial}}, + *pipePtr, + ignoreDocumentSourceAddOne); }() .first.value() == Stage(TestThing{24}, makeUniqueStage(TestThing{23}, {}, {}), {})); @@ -139,7 +145,9 @@ TEST_F(PipelineMetadataTreeTest, LinearPipelinesConstructProperTrees) { "{$match: {status: \"completed\"}}, " "{$match: {status: \"completed\"}}]"); return makeTree( - {{NamespaceString("test.collection"), initial}}, *pipePtr, ignoreDocumentSourceAddOne); + {{NamespaceString::createNamespaceString_forTest("test.collection"), initial}}, + *pipePtr, + ignoreDocumentSourceAddOne); }() .first.value() == Stage(TestThing{28}, @@ -233,12 +241,13 @@ TEST_F(PipelineMetadataTreeTest, BranchingPipelinesConstructProperTrees) { "{$unwind: \"$instr\"}, " "{$group: {_id: {PositionID: \"$trade.mvtident\", \"InstrumentReference\": " "\"$instr.libelle\"}, NumberOfSecurities: {$sum:\"$trade.quantite\"}}}]"); - return makeTree({{NamespaceString("test.collection"), {"1"}}, - {NamespaceString("test.folios"), {"2"}}, - {NamespaceString("test.trades"), {"2"}}, - {NamespaceString("test.instruments"), {"2"}}}, - *pipePtr, - buildRepresentativeString); + return makeTree( + {{NamespaceString::createNamespaceString_forTest("test.collection"), {"1"}}, + {NamespaceString::createNamespaceString_forTest("test.folios"), {"2"}}, + {NamespaceString::createNamespaceString_forTest("test.trades"), {"2"}}, + {NamespaceString::createNamespaceString_forTest("test.instruments"), {"2"}}}, + *pipePtr, + buildRepresentativeString); }() .first.value() == Stage(TestThing{"1mpxul[2m]ulu"}, @@ -275,7 +284,9 @@ TEST_F(PipelineMetadataTreeTest, BranchingPipelinesConstructProperTrees) { "\"categorizedByYears(Auto)\": [{$bucketAuto: {groupBy: \"$year\", buckets: 2}}]}}, " "{$limit: 12}]"); return makeTree( - {{NamespaceString("test.collection"), {""}}}, *pipePtr, buildRepresentativeString); + {{NamespaceString::createNamespaceString_forTest("test.collection"), {""}}}, + *pipePtr, + buildRepresentativeString); }() .first.value() == Stage(TestThing{"f[tugs, tmgs, tb]"}, @@ -349,12 +360,13 @@ TEST_F(PipelineMetadataTreeTest, ZipWalksAPipelineAndTreeInTandemAndInOrder) { "{$unwind: \"$instr\"}, " "{$group: {_id: {PositionID: \"$trade.mvtident\", \"InstrumentReference\": " "\"$instr.libelle\"}, NumberOfSecurities: {$sum:\"$trade.quantite\"}}}]"); - auto tree = makeTree({{NamespaceString("test.collection"), {}}, - {NamespaceString("test.folios"), {}}, - {NamespaceString("test.trades"), {}}, - {NamespaceString("test.instruments"), {}}}, - *pipePtr, - takeTypeInfo) + auto tree = makeTree( + {{NamespaceString::createNamespaceString_forTest("test.collection"), {}}, + {NamespaceString::createNamespaceString_forTest("test.folios"), {}}, + {NamespaceString::createNamespaceString_forTest("test.trades"), {}}, + {NamespaceString::createNamespaceString_forTest("test.instruments"), {}}}, + *pipePtr, + takeTypeInfo) .first; zip(&tree.value(), &*pipePtr, tookTypeInfoOrThrow); previousStack.pop(); @@ -369,10 +381,11 @@ TEST_F(PipelineMetadataTreeTest, ZipWalksAPipelineAndTreeInTandemAndInOrder) { "{$bucket: {groupBy: \"$year\", boundaries: [ 2000, 2010, 2015, 2020]}}], " "\"categorizedByYears(Auto)\": [{$bucketAuto: {groupBy: \"$year\", buckets: 2}}]}}, " "{$limit: 12}]"); - auto tree = makeTree({{NamespaceString("test.collection"), {}}, - {NamespaceString("test.collection"), {}}}, - *pipePtr, - takeTypeInfo) + auto tree = makeTree( + {{NamespaceString::createNamespaceString_forTest("test.collection"), {}}, + {NamespaceString::createNamespaceString_forTest("test.collection"), {}}}, + *pipePtr, + takeTypeInfo) .first; zip(&tree.value(), &*pipePtr, tookTypeInfoOrThrow); previousStack.pop(); @@ -381,12 +394,13 @@ TEST_F(PipelineMetadataTreeTest, ZipWalksAPipelineAndTreeInTandemAndInOrder) { TEST_F(PipelineMetadataTreeTest, MakeTreeWithEmptyPipeline) { auto pipeline = Pipeline::parse({}, getExpCtx()); - auto result = - makeTree({{NamespaceString("unittests.pipeline_test"), std::string("input")}}, - *pipeline, - [](const auto&, const auto&, const DocumentSource& source) { - return std::string("not called"); - }); + auto result = makeTree( + {{NamespaceString::createNamespaceString_forTest("unittests.pipeline_test"), + std::string("input")}}, + *pipeline, + [](const auto&, const auto&, const DocumentSource& source) { + return std::string("not called"); + }); ASSERT_FALSE(result.first); ASSERT_EQ(result.second, "input"_sd); } @@ -397,7 +411,8 @@ TEST_F(PipelineMetadataTreeTest, BranchingPipelineMissesInitialStageContents) { "[{$lookup: {from: \"trades\", as: \"trade\", let: {sp: \"sub_positions.ident\"}, " "pipeline: [{$match: {$expr: {$eq: [\"$$sp\", \"$opcvm\"]}}}]}}]"); ASSERT_THROWS_CODE( - makeTree({{NamespaceString("test.collection"), std::string("input")}}, + makeTree({{NamespaceString::createNamespaceString_forTest("test.collection"), + std::string("input")}}, *pipeline, [](const auto&, const auto&, const DocumentSource& source) { return std::string("not called"); diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp index ed4c9c4cc69..bfc12d09eb8 100644 --- a/src/mongo/db/pipeline/pipeline_test.cpp +++ b/src/mongo/db/pipeline/pipeline_test.cpp @@ -74,8 +74,9 @@ using boost::intrusive_ptr; using std::string; using std::vector; -const NamespaceString kTestNss = NamespaceString("a.collection"); -const NamespaceString kAdminCollectionlessNss = NamespaceString("admin.$cmd.aggregate"); +const NamespaceString kTestNss = NamespaceString::createNamespaceString_forTest("a.collection"); +const NamespaceString kAdminCollectionlessNss = + NamespaceString::createNamespaceString_forTest("admin.$cmd.aggregate"); constexpr size_t getChangeStreamStageSize() { return 6; @@ -139,8 +140,9 @@ void assertPipelineOptimizesAndSerializesTo(std::string inputPipeJson, // For $graphLookup and $lookup, we have to populate the resolvedNamespaces so that the // operations will be able to have a resolved view definition. - NamespaceString lookupCollNs("a", "lookupColl"); - NamespaceString unionCollNs("b", "unionColl"); + NamespaceString lookupCollNs = + NamespaceString::createNamespaceString_forTest("a", "lookupColl"); + NamespaceString unionCollNs = NamespaceString::createNamespaceString_forTest("b", "unionColl"); ctx->setResolvedNamespace(lookupCollNs, {lookupCollNs, std::vector{}}); ctx->setResolvedNamespace(unionCollNs, {unionCollNs, std::vector{}}); @@ -3383,7 +3385,7 @@ public: // Allows tests to override the default resolvedNamespaces. virtual NamespaceString getLookupCollNs() { - return NamespaceString("a", "lookupColl"); + return NamespaceString::createNamespaceString_forTest("a", "lookupColl"); } BSONObj pipelineFromJsonArray(const string& array) { @@ -4359,7 +4361,9 @@ TEST(PipelineInitialSource, GeoNearInitialQuery) { const std::vector rawPipeline = { fromjson("{$geoNear: {distanceField: 'd', near: [0, 0], query: {a: 1}}}")}; intrusive_ptr ctx = new ExpressionContextForTest( - &_opCtx, AggregateCommandRequest(NamespaceString("a.collection"), rawPipeline)); + &_opCtx, + AggregateCommandRequest(NamespaceString::createNamespaceString_forTest("a.collection"), + rawPipeline)); auto pipe = Pipeline::parse(rawPipeline, ctx); ASSERT_BSONOBJ_EQ(pipe->getInitialQuery(), BSON("a" << 1)); } @@ -4368,7 +4372,9 @@ TEST(PipelineInitialSource, MatchInitialQuery) { OperationContextNoop _opCtx; const std::vector rawPipeline = {fromjson("{$match: {'a': 4}}")}; intrusive_ptr ctx = new ExpressionContextForTest( - &_opCtx, AggregateCommandRequest(NamespaceString("a.collection"), rawPipeline)); + &_opCtx, + AggregateCommandRequest(NamespaceString::createNamespaceString_forTest("a.collection"), + rawPipeline)); auto pipe = Pipeline::parse(rawPipeline, ctx); ASSERT_BSONOBJ_EQ(pipe->getInitialQuery(), BSON("a" << 4)); @@ -4460,7 +4466,7 @@ TEST_F(PipelineValidateTest, ChangeStreamIsValidAsFirstStage) { const std::vector rawPipeline = {fromjson("{$changeStream: {}}")}; auto ctx = getExpCtx(); setMockReplicationCoordinatorOnOpCtx(ctx->opCtx); - ctx->ns = NamespaceString("a.collection"); + ctx->ns = NamespaceString::createNamespaceString_forTest("a.collection"); Pipeline::parse(rawPipeline, ctx); } @@ -4469,7 +4475,7 @@ TEST_F(PipelineValidateTest, ChangeStreamIsNotValidIfNotFirstStage) { fromjson("{$changeStream: {}}")}; auto ctx = getExpCtx(); setMockReplicationCoordinatorOnOpCtx(ctx->opCtx); - ctx->ns = NamespaceString("a.collection"); + ctx->ns = NamespaceString::createNamespaceString_forTest("a.collection"); ASSERT_THROWS_CODE(Pipeline::parse(rawPipeline, ctx), AssertionException, 40602); } @@ -4479,7 +4485,7 @@ TEST_F(PipelineValidateTest, ChangeStreamIsNotValidIfNotFirstStageInFacet) { auto ctx = getExpCtx(); setMockReplicationCoordinatorOnOpCtx(ctx->opCtx); - ctx->ns = NamespaceString("a.collection"); + ctx->ns = NamespaceString::createNamespaceString_forTest("a.collection"); ASSERT_THROWS_CODE(Pipeline::parse(rawPipeline, ctx), AssertionException, 40600); } @@ -5132,8 +5138,9 @@ TEST_F(InvolvedNamespacesTest, NoInvolvedNamespacesForMatchSortProject) { TEST_F(InvolvedNamespacesTest, IncludesLookupNamespace) { auto expCtx = getExpCtx(); - const NamespaceString lookupNss{"test", "foo"}; - const NamespaceString resolvedNss{"test", "bar"}; + const NamespaceString lookupNss = NamespaceString::createNamespaceString_forTest("test", "foo"); + const NamespaceString resolvedNss = + NamespaceString::createNamespaceString_forTest("test", "bar"); expCtx->setResolvedNamespace(lookupNss, {resolvedNss, vector{}}); auto lookupSpec = fromjson("{$lookup: {from: 'foo', as: 'x', localField: 'foo_id', foreignField: '_id'}}"); @@ -5149,8 +5156,9 @@ TEST_F(InvolvedNamespacesTest, IncludesLookupNamespace) { TEST_F(InvolvedNamespacesTest, IncludesGraphLookupNamespace) { auto expCtx = getExpCtx(); - const NamespaceString lookupNss{"test", "foo"}; - const NamespaceString resolvedNss{"test", "bar"}; + const NamespaceString lookupNss = NamespaceString::createNamespaceString_forTest("test", "foo"); + const NamespaceString resolvedNss = + NamespaceString::createNamespaceString_forTest("test", "bar"); expCtx->setResolvedNamespace(lookupNss, {resolvedNss, vector{}}); auto graphLookupSpec = fromjson( "{$graphLookup: {" @@ -5172,10 +5180,14 @@ TEST_F(InvolvedNamespacesTest, IncludesGraphLookupNamespace) { TEST_F(InvolvedNamespacesTest, IncludesLookupSubpipelineNamespaces) { auto expCtx = getExpCtx(); - const NamespaceString outerLookupNss{"test", "foo_outer"}; - const NamespaceString outerResolvedNss{"test", "bar_outer"}; - const NamespaceString innerLookupNss{"test", "foo_inner"}; - const NamespaceString innerResolvedNss{"test", "bar_inner"}; + const NamespaceString outerLookupNss = + NamespaceString::createNamespaceString_forTest("test", "foo_outer"); + const NamespaceString outerResolvedNss = + NamespaceString::createNamespaceString_forTest("test", "bar_outer"); + const NamespaceString innerLookupNss = + NamespaceString::createNamespaceString_forTest("test", "foo_inner"); + const NamespaceString innerResolvedNss = + NamespaceString::createNamespaceString_forTest("test", "bar_inner"); expCtx->setResolvedNamespace(outerLookupNss, {outerResolvedNss, vector{}}); expCtx->setResolvedNamespace(innerLookupNss, {innerResolvedNss, vector{}}); auto lookupSpec = fromjson( @@ -5197,10 +5209,14 @@ TEST_F(InvolvedNamespacesTest, IncludesLookupSubpipelineNamespaces) { TEST_F(InvolvedNamespacesTest, IncludesGraphLookupSubPipeline) { auto expCtx = getExpCtx(); - const NamespaceString outerLookupNss{"test", "foo_outer"}; - const NamespaceString outerResolvedNss{"test", "bar_outer"}; - const NamespaceString innerLookupNss{"test", "foo_inner"}; - const NamespaceString innerResolvedNss{"test", "bar_inner"}; + const NamespaceString outerLookupNss = + NamespaceString::createNamespaceString_forTest("test", "foo_outer"); + const NamespaceString outerResolvedNss = + NamespaceString::createNamespaceString_forTest("test", "bar_outer"); + const NamespaceString innerLookupNss = + NamespaceString::createNamespaceString_forTest("test", "foo_inner"); + const NamespaceString innerResolvedNss = + NamespaceString::createNamespaceString_forTest("test", "bar_inner"); expCtx->setResolvedNamespace(outerLookupNss, {outerResolvedNss, vector{}}); expCtx->setResolvedNamespace( outerLookupNss, @@ -5228,10 +5244,13 @@ TEST_F(InvolvedNamespacesTest, IncludesGraphLookupSubPipeline) { TEST_F(InvolvedNamespacesTest, IncludesAllCollectionsWhenResolvingViews) { auto expCtx = getExpCtx(); - const NamespaceString normalCollectionNss{"test", "collection"}; - const NamespaceString lookupNss{"test", "foo"}; - const NamespaceString resolvedNss{"test", "bar"}; - const NamespaceString nssIncludedInResolvedView{"test", "extra_backer_of_bar"}; + const NamespaceString normalCollectionNss = + NamespaceString::createNamespaceString_forTest("test", "collection"); + const NamespaceString lookupNss = NamespaceString::createNamespaceString_forTest("test", "foo"); + const NamespaceString resolvedNss = + NamespaceString::createNamespaceString_forTest("test", "bar"); + const NamespaceString nssIncludedInResolvedView = + NamespaceString::createNamespaceString_forTest("test", "extra_backer_of_bar"); expCtx->setResolvedNamespace( lookupNss, {resolvedNss, diff --git a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface_test.cpp b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface_test.cpp index 5c3f7eebf97..3a457d8112d 100644 --- a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface_test.cpp +++ b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface_test.cpp @@ -46,7 +46,8 @@ TEST_F(ShardedProcessInterfaceTest, TestInsert) { // Need a real locker for storage operations. getClient()->swapLockState(std::make_unique(expCtx()->opCtx->getServiceContext())); - const NamespaceString kOutNss = NamespaceString{"unittests-out", "sharded_agg_test"}; + const NamespaceString kOutNss = + NamespaceString::createNamespaceString_forTest("unittests-out", "sharded_agg_test"); auto outStage = DocumentSourceOut::create(kOutNss, expCtx()); // Attach a write concern, and make sure it is forwarded below. diff --git a/src/mongo/db/pipeline/sampling_based_initial_split_policy_test.cpp b/src/mongo/db/pipeline/sampling_based_initial_split_policy_test.cpp index 3918e6f390d..b1d2c223caf 100644 --- a/src/mongo/db/pipeline/sampling_based_initial_split_policy_test.cpp +++ b/src/mongo/db/pipeline/sampling_based_initial_split_policy_test.cpp @@ -321,7 +321,7 @@ TEST_F(SamplingBasedSplitPolicyTest, SamplingSucceedsWithLimitedMemoryForSortOpe const int numSamplesPerChunk = 2; auto shardKeyPattern = ShardKeyPattern(BSON("a" << 1)); - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); auto pipelineDocSource = SamplingBasedSplitPolicy::makePipelineDocumentSource_forTest(operationContext(), kTestAggregateNss, diff --git a/src/mongo/db/pipeline/semantic_analysis_test.cpp b/src/mongo/db/pipeline/semantic_analysis_test.cpp index 0b6e4d224bf..e86ad2cf2a8 100644 --- a/src/mongo/db/pipeline/semantic_analysis_test.cpp +++ b/src/mongo/db/pipeline/semantic_analysis_test.cpp @@ -730,7 +730,7 @@ TEST_F(SemanticAnalysisFindLongestViablePrefix, FindsLastPossibleStageWithCallba TEST_F(SemanticAnalysisFindLongestViablePrefix, CorrectlyAnswersReshardingUseCase) { auto expCtx = getExpCtx(); - auto lookupNss = NamespaceString{"config.cache.chunks.test"}; + auto lookupNss = NamespaceString::createNamespaceString_forTest("config.cache.chunks.test"); expCtx->setResolvedNamespace(lookupNss, ExpressionContext::ResolvedNamespace{lookupNss, {}}); auto pipeline = Pipeline::parse({fromjson("{$replaceWith: {original: '$$ROOT'}}"), diff --git a/src/mongo/db/pipeline/sharded_union_test.cpp b/src/mongo/db/pipeline/sharded_union_test.cpp index f932812c479..d7c82e12075 100644 --- a/src/mongo/db/pipeline/sharded_union_test.cpp +++ b/src/mongo/db/pipeline/sharded_union_test.cpp @@ -400,7 +400,8 @@ TEST_F(ShardedUnionTest, IncorporatesViewDefinitionAndRetriesWhenViewErrorReceiv auto shards = setupNShards(2); auto cm = loadRoutingTableWithTwoChunksAndTwoShards(kTestAggregateNss); - NamespaceString nsToUnionWith(expCtx()->ns.db(), "view"); + NamespaceString nsToUnionWith = + NamespaceString::createNamespaceString_forTest(expCtx()->ns.db(), "view"); // Mock out the view namespace as emtpy for now - this is what it would be when parsing in a // sharded cluster - only later would we learn the actual view definition. expCtx()->setResolvedNamespaces(StringMap{ diff --git a/src/mongo/db/query/canonical_query_encoder_test.cpp b/src/mongo/db/query/canonical_query_encoder_test.cpp index 12593f56490..969e31e5986 100644 --- a/src/mongo/db/query/canonical_query_encoder_test.cpp +++ b/src/mongo/db/query/canonical_query_encoder_test.cpp @@ -47,8 +47,10 @@ namespace { using std::unique_ptr; -static const NamespaceString nss("testdb.testcoll"); -static const NamespaceString foreignNss("testdb.foreigncoll"); +static const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("testdb.testcoll"); +static const NamespaceString foreignNss = + NamespaceString::createNamespaceString_forTest("testdb.foreigncoll"); unittest::GoldenTestConfig goldenTestConfig{"src/mongo/db/test_output/query"}; diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp index 2fb5614fd16..8fbb4eec5c3 100644 --- a/src/mongo/db/query/canonical_query_test.cpp +++ b/src/mongo/db/query/canonical_query_test.cpp @@ -44,7 +44,8 @@ using std::string; using std::unique_ptr; using unittest::assertGet; -static const NamespaceString nss("testdb.testcoll"); +static const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("testdb.testcoll"); /** * Helper function to parse the given BSON object as a MatchExpression, checks the status, diff --git a/src/mongo/db/query/classic_stage_builder_test.cpp b/src/mongo/db/query/classic_stage_builder_test.cpp index cb4efe466dc..0df26b56b02 100644 --- a/src/mongo/db/query/classic_stage_builder_test.cpp +++ b/src/mongo/db/query/classic_stage_builder_test.cpp @@ -40,7 +40,7 @@ namespace mongo { -const static NamespaceString kNss("db.dummy"); +const static NamespaceString kNss = NamespaceString::createNamespaceString_forTest("db.dummy"); class ClassicStageBuilderTest : public ServiceContextMongoDTest { public: diff --git a/src/mongo/db/query/collection_query_info_test.cpp b/src/mongo/db/query/collection_query_info_test.cpp index 142cbf9d48f..0bf1bef1093 100644 --- a/src/mongo/db/query/collection_query_info_test.cpp +++ b/src/mongo/db/query/collection_query_info_test.cpp @@ -183,7 +183,7 @@ std::unique_ptr makeIndexDescriptor(StringData indexName, TEST(CollectionQueryInfoTest, computeUpdateIndexDataForCompoundWildcardIndex) { RAIIServerParameterControllerForTest controller("featureFlagCompoundWildcardIndexes", true); - NamespaceString nss{"test"_sd}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test"_sd); CollectionOptions collOptions{}; DevNullKVEngine engine{}; auto sortedDataInterface = @@ -213,7 +213,7 @@ TEST(CollectionQueryInfoTest, computeUpdateIndexDataForCompoundWildcardIndex) { TEST(CollectionQueryInfoTest, computeUpdateIndexDataForCompoundWildcardIndex_ExcludeCase) { RAIIServerParameterControllerForTest controller("featureFlagCompoundWildcardIndexes", true); - NamespaceString nss{"test"_sd}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test"_sd); CollectionOptions collOptions{}; DevNullKVEngine engine{}; auto sortedDataInterface = diff --git a/src/mongo/db/query/cursor_response_test.cpp b/src/mongo/db/query/cursor_response_test.cpp index 23a513a177a..8d76e0d86d4 100644 --- a/src/mongo/db/query/cursor_response_test.cpp +++ b/src/mongo/db/query/cursor_response_test.cpp @@ -274,7 +274,7 @@ TEST(CursorResponseTest, roundTripThroughCursorResponseBuilderWithPartialResults CursorResponseBuilder crb(&builder, options); crb.append(testDoc); crb.setPartialResultsReturned(true); - crb.done(CursorId(123), NamespaceString(boost::none, "db.coll")); + crb.done(CursorId(123), NamespaceString::createNamespaceString_forTest(boost::none, "db.coll")); // Confirm that the resulting BSONObj response matches the expected body. auto msg = builder.done(); @@ -312,7 +312,7 @@ TEST(CursorResponseTest, CursorResponseBuilder::Options options; options.isInitialResponse = true; TenantId tid(OID::gen()); - NamespaceString nss(tid, "db.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "db.coll"); RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); @@ -382,7 +382,8 @@ TEST(CursorResponseTest, parseFromBSONHandleErrorResponse) { TEST(CursorResponseTest, toBSONInitialResponse) { std::vector batch = {BSON("_id" << 1), BSON("_id" << 2)}; - CursorResponse response(NamespaceString("testdb.testcoll"), CursorId(123), batch); + CursorResponse response( + NamespaceString::createNamespaceString_forTest("testdb.testcoll"), CursorId(123), batch); BSONObj responseObj = response.toBSON(CursorResponse::ResponseType::InitialResponse); BSONObj expectedResponse = BSON( "cursor" << BSON("id" << CursorId(123) << "ns" @@ -394,7 +395,8 @@ TEST(CursorResponseTest, toBSONInitialResponse) { TEST(CursorResponseTest, toBSONSubsequentResponse) { std::vector batch = {BSON("_id" << 1), BSON("_id" << 2)}; - CursorResponse response(NamespaceString("testdb.testcoll"), CursorId(123), batch); + CursorResponse response( + NamespaceString::createNamespaceString_forTest("testdb.testcoll"), CursorId(123), batch); BSONObj responseObj = response.toBSON(CursorResponse::ResponseType::SubsequentResponse); BSONObj expectedResponse = BSON( "cursor" << BSON("id" << CursorId(123) << "ns" @@ -406,7 +408,7 @@ TEST(CursorResponseTest, toBSONSubsequentResponse) { TEST(CursorResponseTest, toBSONPartialResultsReturned) { std::vector batch = {BSON("_id" << 1), BSON("_id" << 2)}; - CursorResponse response(NamespaceString("testdb.testcoll"), + CursorResponse response(NamespaceString::createNamespaceString_forTest("testdb.testcoll"), CursorId(123), batch, boost::none, @@ -427,7 +429,8 @@ TEST(CursorResponseTest, toBSONPartialResultsReturned) { TEST(CursorResponseTest, addToBSONInitialResponse) { std::vector batch = {BSON("_id" << 1), BSON("_id" << 2)}; - CursorResponse response(NamespaceString("testdb.testcoll"), CursorId(123), batch); + CursorResponse response( + NamespaceString::createNamespaceString_forTest("testdb.testcoll"), CursorId(123), batch); BSONObjBuilder builder; response.addToBSON(CursorResponse::ResponseType::InitialResponse, &builder); @@ -443,7 +446,8 @@ TEST(CursorResponseTest, addToBSONInitialResponse) { TEST(CursorResponseTest, addToBSONSubsequentResponse) { std::vector batch = {BSON("_id" << 1), BSON("_id" << 2)}; - CursorResponse response(NamespaceString("testdb.testcoll"), CursorId(123), batch); + CursorResponse response( + NamespaceString::createNamespaceString_forTest("testdb.testcoll"), CursorId(123), batch); BSONObjBuilder builder; response.addToBSON(CursorResponse::ResponseType::SubsequentResponse, &builder); @@ -459,7 +463,7 @@ TEST(CursorResponseTest, addToBSONSubsequentResponse) { TEST(CursorResponseTest, addToBSONInitialResponseWithTenantId) { TenantId tid(OID::gen()); - NamespaceString nss(tid, "testdb.testcoll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "testdb.testcoll"); RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); @@ -489,8 +493,11 @@ TEST(CursorResponseTest, serializePostBatchResumeToken) { ResumeToken::makeHighWaterMarkToken(Timestamp(1, 2), ResumeTokenData::kDefaultTokenVersion) .toDocument() .toBson(); - CursorResponse response( - NamespaceString("db.coll"), CursorId(123), batch, boost::none, postBatchResumeToken); + CursorResponse response(NamespaceString::createNamespaceString_forTest("db.coll"), + CursorId(123), + batch, + boost::none, + postBatchResumeToken); auto serialized = response.toBSON(CursorResponse::ResponseType::SubsequentResponse); ASSERT_BSONOBJ_EQ(serialized, BSON("cursor" << BSON("id" << CursorId(123) << "ns" diff --git a/src/mongo/db/query/get_executor_test.cpp b/src/mongo/db/query/get_executor_test.cpp index 431430259e8..f8954cdad4f 100644 --- a/src/mongo/db/query/get_executor_test.cpp +++ b/src/mongo/db/query/get_executor_test.cpp @@ -63,7 +63,8 @@ auto createProjectionExecutor(const BSONObj& spec, const ProjectionPolicies& pol using std::unique_ptr; -static const NamespaceString nss("test.collection"); +static const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("test.collection"); /** * Utility functions to create a CanonicalQuery diff --git a/src/mongo/db/query/killcursors_request_test.cpp b/src/mongo/db/query/killcursors_request_test.cpp index 75a248a29ab..c7e63d8eb3c 100644 --- a/src/mongo/db/query/killcursors_request_test.cpp +++ b/src/mongo/db/query/killcursors_request_test.cpp @@ -105,7 +105,7 @@ TEST(KillCursorsRequestTest, parseCursorFieldArrayWithNonCursorIdValue) { } TEST(KillCursorsRequestTest, toBSON) { - const NamespaceString nss("db.coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("db.coll"); std::vector cursorIds = {CursorId(123)}; KillCursorsCommandRequest request(nss, cursorIds); BSONObj requestObj = request.toBSON(BSONObj{}); diff --git a/src/mongo/db/query/parsed_distinct_test.cpp b/src/mongo/db/query/parsed_distinct_test.cpp index b9fd911f653..19b8f5539a8 100644 --- a/src/mongo/db/query/parsed_distinct_test.cpp +++ b/src/mongo/db/query/parsed_distinct_test.cpp @@ -41,7 +41,8 @@ namespace mongo { namespace { -static const NamespaceString testns("testdb.testcoll"); +static const NamespaceString testns = + NamespaceString::createNamespaceString_forTest("testdb.testcoll"); static const bool isExplain = true; TEST(ParsedDistinctTest, ConvertToAggregationNoQuery) { diff --git a/src/mongo/db/query/projection_test.cpp b/src/mongo/db/query/projection_test.cpp index 1b9bd564104..eec99455232 100644 --- a/src/mongo/db/query/projection_test.cpp +++ b/src/mongo/db/query/projection_test.cpp @@ -45,7 +45,8 @@ using namespace mongo; using projection_ast::Projection; -const NamespaceString kTestNss = NamespaceString("db.projection_test"); +const NamespaceString kTestNss = + NamespaceString::createNamespaceString_forTest("db.projection_test"); /** * Helper for creating projections. diff --git a/src/mongo/db/query/query_planner_options_test.cpp b/src/mongo/db/query/query_planner_options_test.cpp index 7f4cb9e3a1b..094686bc9f3 100644 --- a/src/mongo/db/query/query_planner_options_test.cpp +++ b/src/mongo/db/query/query_planner_options_test.cpp @@ -788,7 +788,8 @@ TEST_F(QueryPlannerTest, CacheDataFromTaggedTreeFailsOnBadInput) { // No relevant index matching the index tag. relevantIndices.push_back(buildSimpleIndexEntry(BSON("a" << 1), "a_1")); - auto findCommand = std::make_unique(NamespaceString("test.collection")); + auto findCommand = std::make_unique( + NamespaceString::createNamespaceString_forTest("test.collection")); findCommand->setFilter(BSON("a" << 3)); auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand)); ASSERT_OK(statusWithCQ.getStatus()); @@ -800,7 +801,7 @@ TEST_F(QueryPlannerTest, CacheDataFromTaggedTreeFailsOnBadInput) { } TEST_F(QueryPlannerTest, TagAccordingToCacheFailsOnBadInput) { - const NamespaceString nss("test.collection"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.collection"); auto findCommand = std::make_unique(nss); findCommand->setFilter(BSON("a" << 3)); diff --git a/src/mongo/db/query/query_planner_partialidx_test.cpp b/src/mongo/db/query/query_planner_partialidx_test.cpp index 46adc5869ab..88a806f2f63 100644 --- a/src/mongo/db/query/query_planner_partialidx_test.cpp +++ b/src/mongo/db/query/query_planner_partialidx_test.cpp @@ -36,7 +36,7 @@ namespace mongo { namespace { -const static NamespaceString kNs("db.dummyNs"); +const static NamespaceString kNs = NamespaceString::createNamespaceString_forTest("db.dummyNs"); TEST_F(QueryPlannerTest, PartialIndexEq) { params.options = QueryPlannerParams::NO_TABLE_SCAN; diff --git a/src/mongo/db/query/query_planner_pipeline_pushdown_test.cpp b/src/mongo/db/query/query_planner_pipeline_pushdown_test.cpp index f06de53dc16..535cfb232e2 100644 --- a/src/mongo/db/query/query_planner_pipeline_pushdown_test.cpp +++ b/src/mongo/db/query/query_planner_pipeline_pushdown_test.cpp @@ -63,7 +63,8 @@ protected: return Pipeline::parse(rawPipeline, expCtx); } - const NamespaceString kSecondaryNamespace{"test.other"}; + const NamespaceString kSecondaryNamespace = + NamespaceString::createNamespaceString_forTest("test.other"); const std::map secondaryCollMap{ {kSecondaryNamespace, SecondaryCollectionInfo()}}; }; diff --git a/src/mongo/db/query/query_request_test.cpp b/src/mongo/db/query/query_request_test.cpp index da0126a3d1d..15827a9be2f 100644 --- a/src/mongo/db/query/query_request_test.cpp +++ b/src/mongo/db/query/query_request_test.cpp @@ -422,7 +422,7 @@ TEST(QueryRequestTest, OplogReplayFlagIsAllowedButIgnored) { << "testns" << "oplogReplay" << true << "tailable" << true << "$db" << "test"); - const NamespaceString nss{"test.testns"}; + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.testns"); auto findCommand = query_request_helper::makeFromFindCommandForTests(cmdObj); // Verify that the 'oplogReplay' flag does not appear if we reserialize the request. @@ -1567,7 +1567,7 @@ TEST_F(QueryRequestTest, ParseFromUUID) { NamespaceStringOrUUID nssOrUUID("test", uuid); FindCommandRequest findCommand(nssOrUUID); - const NamespaceString nss("test.testns"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.testns"); // Ensure a call to refreshNSS succeeds. query_request_helper::refreshNSS(nss, &findCommand); ASSERT_EQ(nss, *findCommand.getNamespaceOrUUID().nss()); diff --git a/src/mongo/db/query/query_solution_test.cpp b/src/mongo/db/query/query_solution_test.cpp index 522c2e108b9..69e1d5614e6 100644 --- a/src/mongo/db/query/query_solution_test.cpp +++ b/src/mongo/db/query/query_solution_test.cpp @@ -809,8 +809,10 @@ TEST(QuerySolutionTest, IndexScanNodeHasFieldExcludesSimpleBoundsStringFieldWhen auto createMatchExprAndProjection(const BSONObj& query, const BSONObj& projObj) { QueryTestServiceContext serviceCtx; auto opCtx = serviceCtx.makeOperationContext(); - const boost::intrusive_ptr expCtx(new ExpressionContext( - opCtx.get(), std::unique_ptr(nullptr), NamespaceString("test.dummy"))); + const boost::intrusive_ptr expCtx( + new ExpressionContext(opCtx.get(), + std::unique_ptr(nullptr), + NamespaceString::createNamespaceString_forTest("test.dummy"))); StatusWithMatchExpression queryMatchExpr = MatchExpressionParser::parse(query, expCtx); ASSERT(queryMatchExpr.isOK()); projection_ast::Projection res = projection_ast::parseAndAnalyze( @@ -1103,8 +1105,10 @@ TEST(QuerySolutionTest, NodeIdsAssignedInPostOrderFashionStartingFromOne) { TEST(QuerySolutionTest, GroupNodeWithIndexScan) { QueryTestServiceContext serviceCtx; auto opCtx = serviceCtx.makeOperationContext(); - const boost::intrusive_ptr expCtx(new ExpressionContext( - opCtx.get(), std::unique_ptr(nullptr), NamespaceString("test.dummy"))); + const boost::intrusive_ptr expCtx( + new ExpressionContext(opCtx.get(), + std::unique_ptr(nullptr), + NamespaceString::createNamespaceString_forTest("test.dummy"))); auto scanNode = std::make_unique(buildSimpleIndexEntry(BSON("a" << 1 << "b" << 1))); scanNode->bounds.isSimpleRange = true; @@ -1134,7 +1138,7 @@ TEST(QuerySolutionTest, EqLookupNodeWithIndexScan) { scanNode->bounds.endKey = BSON("a" << 1 << "b" << 1); EqLookupNode node(std::move(scanNode), - NamespaceString("db.col"), + NamespaceString::createNamespaceString_forTest("db.col"), "local", "foreign", "as", @@ -1169,7 +1173,7 @@ TEST(QuerySolutionTest, EqLookupNodeWithIndexScanFieldOverwrite) { << "1"); EqLookupNode node(std::move(scanNode), - NamespaceString("db.col"), + NamespaceString::createNamespaceString_forTest("db.col"), "local", "foreign", "b", @@ -1241,8 +1245,8 @@ TEST(QuerySolutionTest, FieldAvailabilityOutputStreamOperator) { TEST(QuerySolutionTest, GetSecondaryNamespaceVectorOverSingleEqLookupNode) { auto scanNode = std::make_unique(buildSimpleIndexEntry(BSON("a" << 1))); - const NamespaceString mainNss("db.main"); - const NamespaceString foreignColl("db.col"); + const NamespaceString mainNss = NamespaceString::createNamespaceString_forTest("db.main"); + const NamespaceString foreignColl = NamespaceString::createNamespaceString_forTest("db.col"); auto root = std::make_unique(std::move(scanNode), foreignColl, "local", @@ -1263,7 +1267,7 @@ TEST(QuerySolutionTest, GetSecondaryNamespaceVectorOverSingleEqLookupNode) { TEST(QuerySolutionTest, GetSecondaryNamespaceVectorDeduplicatesMainNss) { auto scanNode = std::make_unique(buildSimpleIndexEntry(BSON("a" << 1))); - const NamespaceString mainNss("db.main"); + const NamespaceString mainNss = NamespaceString::createNamespaceString_forTest("db.main"); auto root = std::make_unique(std::move(scanNode), mainNss, "local", @@ -1285,9 +1289,9 @@ TEST(QuerySolutionTest, GetSecondaryNamespaceVectorDeduplicatesMainNss) { TEST(QuerySolutionTest, GetSecondaryNamespaceVectorOverNestedEqLookupNodes) { auto scanNode = std::make_unique(buildSimpleIndexEntry(BSON("a" << 1))); - const NamespaceString mainNss("db.main"); - const NamespaceString foreignCollOne("db.col"); - const NamespaceString foreignCollTwo("db.foo"); + const NamespaceString mainNss = NamespaceString::createNamespaceString_forTest("db.main"); + const NamespaceString foreignCollOne = NamespaceString::createNamespaceString_forTest("db.col"); + const NamespaceString foreignCollTwo = NamespaceString::createNamespaceString_forTest("db.foo"); auto childEqLookupNode = std::make_unique(std::move(scanNode), foreignCollOne, @@ -1320,8 +1324,8 @@ TEST(QuerySolutionTest, GetSecondaryNamespaceVectorOverNestedEqLookupNodes) { TEST(QuerySolutionTest, GetSecondaryNamespaceVectorDeduplicatesNestedEqLookupNodes) { auto scanNode = std::make_unique(buildSimpleIndexEntry(BSON("a" << 1))); - const NamespaceString mainNss("db.main"); - const NamespaceString foreignColl("db.col"); + const NamespaceString mainNss = NamespaceString::createNamespaceString_forTest("db.main"); + const NamespaceString foreignColl = NamespaceString::createNamespaceString_forTest("db.col"); auto childEqLookupNode = std::make_unique(std::move(scanNode), foreignColl, diff --git a/src/mongo/db/query/sbe_and_hash_test.cpp b/src/mongo/db/query/sbe_and_hash_test.cpp index 217696b3cdf..03533faf292 100644 --- a/src/mongo/db/query/sbe_and_hash_test.cpp +++ b/src/mongo/db/query/sbe_and_hash_test.cpp @@ -37,7 +37,8 @@ namespace mongo { -const NamespaceString kTestNss("TestDB", "TestColl"); +const NamespaceString kTestNss = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); class SbeAndHashTest : public SbeStageBuilderTestFixture { protected: diff --git a/src/mongo/db/query/sbe_and_sorted_test.cpp b/src/mongo/db/query/sbe_and_sorted_test.cpp index eada10cb8bf..dfdc2c13459 100644 --- a/src/mongo/db/query/sbe_and_sorted_test.cpp +++ b/src/mongo/db/query/sbe_and_sorted_test.cpp @@ -35,7 +35,8 @@ namespace mongo { -const NamespaceString kTestNss("TestDB", "TestColl"); +const NamespaceString kTestNss = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); class SbeAndSortedTest : public SbeStageBuilderTestFixture { protected: diff --git a/src/mongo/db/query/sbe_shard_filter_test.cpp b/src/mongo/db/query/sbe_shard_filter_test.cpp index a5d49bf4849..a2e55b6bc01 100644 --- a/src/mongo/db/query/sbe_shard_filter_test.cpp +++ b/src/mongo/db/query/sbe_shard_filter_test.cpp @@ -39,7 +39,8 @@ namespace mongo { -const NamespaceString kTestNss("TestDB", "TestColl"); +const NamespaceString kTestNss = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); class SbeShardFilterTest : public SbeStageBuilderTestFixture { protected: @@ -240,7 +241,7 @@ TEST_F(SbeShardFilterTest, CoveredShardFilterPlan) { BSON_ARRAY(BSON("a" << 3 << "b" << 3 << "c" << 3 << "d" << 3))}; auto expected = BSON_ARRAY(BSON("a" << 2 << "c" << 2) << BSON("a" << 3 << "c" << 3)); - auto nss = NamespaceString{"db", "coll"}; + auto nss = NamespaceString::createNamespaceString_forTest("db", "coll"); auto expCtx = make_intrusive(nss); auto emptyMatchExpression = unittest::assertGet(MatchExpressionParser::parse(BSONObj{}, expCtx)); diff --git a/src/mongo/db/query/sbe_stage_builder_lookup_test.cpp b/src/mongo/db/query/sbe_stage_builder_lookup_test.cpp index 2e3354a500e..0665799e84d 100644 --- a/src/mongo/db/query/sbe_stage_builder_lookup_test.cpp +++ b/src/mongo/db/query/sbe_stage_builder_lookup_test.cpp @@ -252,7 +252,8 @@ protected: EqLookupNode::LookupStrategy::kNestedLoopJoin, EqLookupNode::LookupStrategy::kHashJoin}; private: - const NamespaceString _foreignNss{"testdb.sbe_stage_builder_foreign"}; + const NamespaceString _foreignNss = + NamespaceString::createNamespaceString_forTest("testdb.sbe_stage_builder_foreign"); }; TEST_F(LookupStageBuilderTest, NestedLoopJoin_Basic) { diff --git a/src/mongo/db/query/sbe_stage_builder_test_fixture.h b/src/mongo/db/query/sbe_stage_builder_test_fixture.h index 610aa2104c6..a19ec93d1e7 100644 --- a/src/mongo/db/query/sbe_stage_builder_test_fixture.h +++ b/src/mongo/db/query/sbe_stage_builder_test_fixture.h @@ -99,7 +99,8 @@ public: } protected: - const NamespaceString _nss = NamespaceString{"testdb.sbe_stage_builder"}; + const NamespaceString _nss = + NamespaceString::createNamespaceString_forTest("testdb.sbe_stage_builder"); }; } // namespace mongo diff --git a/src/mongo/db/query/stats/stats_cache_loader_test.cpp b/src/mongo/db/query/stats/stats_cache_loader_test.cpp index f619fbc28de..c58c057341c 100644 --- a/src/mongo/db/query/stats/stats_cache_loader_test.cpp +++ b/src/mongo/db/query/stats/stats_cache_loader_test.cpp @@ -93,9 +93,9 @@ TEST_F(StatsCacheLoaderTest, VerifyStatsLoadsScalar) { auto serialized = stats::makeStatsPath(path, numDocs, sampleRate, ah); // Initalize stats collection. - NamespaceString nss("test", "stats"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "stats"); std::string statsColl(StatsCacheLoader::kStatsPrefix + "." + nss.coll()); - NamespaceString statsNss(nss.db(), statsColl); + NamespaceString statsNss = NamespaceString::createNamespaceString_forTest(nss.db(), statsColl); createStatsCollection(statsNss); // Write serialized stats path to collection. @@ -162,9 +162,9 @@ TEST_F(StatsCacheLoaderTest, VerifyStatsLoadsArray) { auto serialized = stats::makeStatsPath(path, numDocs, sampleRate, ah); // Initalize stats collection. - NamespaceString nss("test", "stats"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "stats"); std::string statsColl(StatsCacheLoader::kStatsPrefix + "." + nss.coll()); - NamespaceString statsNss(nss.db(), statsColl); + NamespaceString statsNss = NamespaceString::createNamespaceString_forTest(nss.db(), statsColl); createStatsCollection(statsNss); // Write serialized stats path to collection. diff --git a/src/mongo/db/query/stats/stats_cache_test.cpp b/src/mongo/db/query/stats/stats_cache_test.cpp index ca02a891e7e..14c859b8881 100644 --- a/src/mongo/db/query/stats/stats_cache_test.cpp +++ b/src/mongo/db/query/stats/stats_cache_test.cpp @@ -92,7 +92,9 @@ TEST_F(StatsCacheTest, KeyDoesNotExist) { auto cache = CacheWithThreadPool(getServiceContext(), std::move(cacheLoaderMock), 1); cache.getStatsCacheLoader()->setStatsReturnValueForTest( std::move(namespaceNotFoundErrorStatus)); - auto handle = cache.acquire(_opCtx, std::make_pair(NamespaceString("db", "coll"), "somePath")); + auto handle = cache.acquire( + _opCtx, + std::make_pair(NamespaceString::createNamespaceString_forTest("db", "coll"), "somePath")); ASSERT(!handle); } @@ -106,9 +108,8 @@ TEST_F(StatsCacheTest, LoadStats) { cache.getStatsCacheLoader()->setStatsReturnValueForTest(std::move(stats1)); - auto handle = cache.acquire(_opCtx, NamespaceString("db", "coll1")); - ASSERT(handle.isValid()); - ASSERT_EQ(1, handle->getCardinality()); + auto handle = cache.acquire(_opCtx, NamespaceString::createNamespaceString_forTest("db", +"coll1")); ASSERT(handle.isValid()); ASSERT_EQ(1, handle->getCardinality()); // Make all requests to StatsCacheLoader to throw an exception to ensre that test returns value // from cache. @@ -116,12 +117,12 @@ TEST_F(StatsCacheTest, LoadStats) { "Stats cache loader received unexpected request"}; cache.getStatsCacheLoader()->setStatsReturnValueForTest(std::move(internalErrorStatus)); - handle = cache.acquire(_opCtx, NamespaceString("db", "coll1")); + handle = cache.acquire(_opCtx, NamespaceString::createNamespaceString_forTest("db", "coll1")); ASSERT(handle.isValid()); ASSERT_EQ(1, handle->getCardinality()); cache.getStatsCacheLoader()->setStatsReturnValueForTest(std::move(stats2)); - handle = cache.acquire(_opCtx, NamespaceString("db", "coll2")); + handle = cache.acquire(_opCtx, NamespaceString::createNamespaceString_forTest("db", "coll2")); ASSERT(handle.isValid()); ASSERT_EQ(2, handle->getCardinality()); } diff --git a/src/mongo/db/query/view_response_formatter_test.cpp b/src/mongo/db/query/view_response_formatter_test.cpp index 274bcda50f1..f42ddd71898 100644 --- a/src/mongo/db/query/view_response_formatter_test.cpp +++ b/src/mongo/db/query/view_response_formatter_test.cpp @@ -41,7 +41,7 @@ namespace mongo { namespace { -static const NamespaceString testNss("db.col"); +static const NamespaceString testNss = NamespaceString::createNamespaceString_forTest("db.col"); static const CursorId testCursor(1); TEST(ViewResponseFormatter, FormatInitialCountResponseSuccessfully) { @@ -62,7 +62,8 @@ TEST(ViewResponseFormatter, FormatSubsequentCountResponseSuccessfully) { TEST(ViewResponseFormatter, FormatInitialCountResponseWithTenantIdSuccessfully) { const TenantId tenantId(OID::gen()); - const NamespaceString nss(tenantId, testNss.toString()); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, testNss.toString()); RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); @@ -119,7 +120,8 @@ TEST(ViewResponseFormatter, FormatSubsequentDistinctResponseSuccessfully) { TEST(ViewResponseFormatter, FormatInitialDistinctResponseWithTenantIdSuccessfully) { const TenantId tenantId(OID::gen()); - const NamespaceString nss(tenantId, testNss.toString()); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, testNss.toString()); RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); diff --git a/src/mongo/db/repl/apply_ops_test.cpp b/src/mongo/db/repl/apply_ops_test.cpp index 4d8c8d0cc16..d98cea10638 100644 --- a/src/mongo/db/repl/apply_ops_test.cpp +++ b/src/mongo/db/repl/apply_ops_test.cpp @@ -139,7 +139,7 @@ TEST_F(ApplyOpsTest, CommandInNestedApplyOpsReturnsSuccess) { auto opCtx = cc().makeOperationContext(); auto mode = OplogApplication::Mode::kApplyOpsCmd; BSONObjBuilder resultBuilder; - NamespaceString nss("test", "foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "foo"); auto innerCmdObj = BSON("op" << "c" @@ -172,7 +172,7 @@ BSONObj makeApplyOpsWithInsertOperation(const NamespaceString& nss, TEST_F(ApplyOpsTest, ApplyOpsInsertIntoNonexistentCollectionReturnsNamespaceNotFoundInResult) { auto opCtx = cc().makeOperationContext(); auto mode = OplogApplication::Mode::kApplyOpsCmd; - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto documentToInsert = BSON("_id" << 0); auto cmdObj = makeApplyOpsWithInsertOperation(nss, boost::none, documentToInsert); BSONObjBuilder resultBuilder; @@ -186,7 +186,7 @@ TEST_F(ApplyOpsTest, ApplyOpsInsertIntoNonexistentCollectionReturnsNamespaceNotF TEST_F(ApplyOpsTest, ApplyOpsInsertWithUuidIntoCollectionWithOtherUuid) { auto opCtx = cc().makeOperationContext(); auto mode = OplogApplication::Mode::kApplyOpsCmd; - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto applyOpsUuid = UUID::gen(); @@ -214,7 +214,7 @@ TEST_F(ApplyOpsTest, ApplyOpsPropagatesOplogApplicationMode) { // Test that the 'applyOps' function passes the oplog application mode through correctly to the // underlying op application functions. - NamespaceString nss("test.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.coll"); auto uuid = UUID::gen(); // Create a collection for us to insert documents into. @@ -254,18 +254,18 @@ TEST_F(ApplyOpsTest, ApplyOpsPropagatesOplogApplicationMode) { OplogEntry makeOplogEntry(OpTypeEnum opType, const BSONObj& oField, const std::vector& stmtIds = {}) { - return {DurableOplogEntry(OpTime(Timestamp(1, 1), 1), // optime - opType, // op type - NamespaceString("a.a"), // namespace - boost::none, // uuid - boost::none, // fromMigrate - OplogEntry::kOplogVersion, // version - oField, // o - boost::none, // o2 - {}, // sessionInfo - boost::none, // upsert - Date_t(), // wall clock time - stmtIds, // statement ids + return {DurableOplogEntry(OpTime(Timestamp(1, 1), 1), // optime + opType, // op type + NamespaceString::createNamespaceString_forTest("a.a"), // namespace + boost::none, // uuid + boost::none, // fromMigrate + OplogEntry::kOplogVersion, // version + oField, // o + boost::none, // o2 + {}, // sessionInfo + boost::none, // upsert + Date_t(), // wall clock time + stmtIds, // statement ids boost::none, // optime of previous write within same transaction boost::none, // pre-image optime boost::none, // post-image optime @@ -296,19 +296,19 @@ TEST_F(ApplyOpsTest, ExtractOperationsReturnsEmptyArrayIfApplyOpsContainsNoOpera } TEST_F(ApplyOpsTest, ExtractOperationsReturnsOperationsWithSameOpTimeAsApplyOps) { - NamespaceString ns1("test.a"); + NamespaceString ns1 = NamespaceString::createNamespaceString_forTest("test.a"); auto ui1 = UUID::gen(); auto op1 = BSON("op" << "i" << "ns" << ns1.ns() << "ui" << ui1 << "o" << BSON("_id" << 1)); - NamespaceString ns2("test.b"); + NamespaceString ns2 = NamespaceString::createNamespaceString_forTest("test.b"); auto ui2 = UUID::gen(); auto op2 = BSON("op" << "i" << "ns" << ns2.ns() << "ui" << ui2 << "o" << BSON("_id" << 2)); - NamespaceString ns3("test.c"); + NamespaceString ns3 = NamespaceString::createNamespaceString_forTest("test.c"); auto ui3 = UUID::gen(); auto op3 = BSON("op" << "u" @@ -371,13 +371,13 @@ TEST_F(ApplyOpsTest, ExtractOperationsReturnsOperationsWithSameOpTimeAsApplyOps) } TEST_F(ApplyOpsTest, ExtractOperationsFromApplyOpsMultiStmtIds) { - NamespaceString ns1("test.a"); + NamespaceString ns1 = NamespaceString::createNamespaceString_forTest("test.a"); auto ui1 = UUID::gen(); auto op1 = BSON("op" << "i" << "ns" << ns1.ns() << "ui" << ui1 << "o" << BSON("_id" << 1)); - NamespaceString ns2("test.b"); + NamespaceString ns2 = NamespaceString::createNamespaceString_forTest("test.b"); auto ui2 = UUID::gen(); auto op2 = BSON("op" << "u" @@ -431,7 +431,7 @@ TEST_F(ApplyOpsTest, ApplyOpsFailsToDropAdmin) { auto mode = OplogApplication::Mode::kApplyOpsCmd; // Create a collection on the admin database. - NamespaceString nss("admin.foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("admin.foo"); CollectionOptions options; options.uuid = UUID::gen(); ASSERT_OK(_storage->createCollection(opCtx.get(), nss, options)); diff --git a/src/mongo/db/repl/database_cloner_test.cpp b/src/mongo/db/repl/database_cloner_test.cpp index f103a5ccd30..d694c4f91fb 100644 --- a/src/mongo/db/repl/database_cloner_test.cpp +++ b/src/mongo/db/repl/database_cloner_test.cpp @@ -148,9 +148,9 @@ TEST_F(DatabaseClonerTest, ListCollections) { auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(2U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid1), collections[0].second.toBSON()); - ASSERT_EQ(NamespaceString(_dbName, "b"), collections[1].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), collections[1].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid2), collections[1].second.toBSON()); } @@ -189,9 +189,9 @@ TEST_F(DatabaseClonerTest, ListCollectionsAllowsExtraneousFields) { auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(2U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid1), collections[0].second.toBSON()); - ASSERT_EQ(NamespaceString(_dbName, "b"), collections[1].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), collections[1].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid2), collections[1].second.toBSON()); } @@ -387,12 +387,12 @@ TEST_F(DatabaseClonerTest, CreateCollections) { ASSERT_EQUALS(2U, _collections.size()); - auto collInfo = _collections[NamespaceString{_dbName, "a"}]; + auto collInfo = _collections[NamespaceString::createNamespaceString_forTest(_dbName, "a")]; auto stats = *collInfo.stats; ASSERT_EQUALS(0, stats.insertCount); ASSERT(stats.commitCalled); - collInfo = _collections[NamespaceString{_dbName, "b"}]; + collInfo = _collections[NamespaceString::createNamespaceString_forTest(_dbName, "b")]; stats = *collInfo.stats; ASSERT_EQUALS(0, stats.insertCount); ASSERT(stats.commitCalled); @@ -456,8 +456,10 @@ TEST_F(DatabaseClonerTest, DatabaseAndCollectionStats) { ASSERT_EQ(2, stats.collections); ASSERT_EQ(0, stats.clonedCollections); ASSERT_EQ(2, stats.collectionStats.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), stats.collectionStats[0].nss); - ASSERT_EQ(NamespaceString(_dbName, "b"), stats.collectionStats[1].nss); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), + stats.collectionStats[0].nss); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), + stats.collectionStats[1].nss); ASSERT_EQ(_clock.now(), stats.collectionStats[0].start); ASSERT_EQ(Date_t(), stats.collectionStats[0].end); ASSERT_EQ(Date_t(), stats.collectionStats[1].start); @@ -479,8 +481,10 @@ TEST_F(DatabaseClonerTest, DatabaseAndCollectionStats) { ASSERT_EQ(2, stats.collections); ASSERT_EQ(1, stats.clonedCollections); ASSERT_EQ(2, stats.collectionStats.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), stats.collectionStats[0].nss); - ASSERT_EQ(NamespaceString(_dbName, "b"), stats.collectionStats[1].nss); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), + stats.collectionStats[0].nss); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), + stats.collectionStats[1].nss); ASSERT_EQ(2, stats.collectionStats[0].indexes); ASSERT_EQ(0, stats.collectionStats[1].indexes); ASSERT_EQ(_clock.now(), stats.collectionStats[0].end); @@ -498,8 +502,10 @@ TEST_F(DatabaseClonerTest, DatabaseAndCollectionStats) { ASSERT_EQ(2, stats.collections); ASSERT_EQ(2, stats.clonedCollections); ASSERT_EQ(2, stats.collectionStats.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), stats.collectionStats[0].nss); - ASSERT_EQ(NamespaceString(_dbName, "b"), stats.collectionStats[1].nss); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), + stats.collectionStats[0].nss); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), + stats.collectionStats[1].nss); ASSERT_EQ(2, stats.collectionStats[0].indexes); ASSERT_EQ(1, stats.collectionStats[1].indexes); ASSERT_EQ(_clock.now(), stats.collectionStats[1].end); @@ -552,9 +558,9 @@ TEST_F(DatabaseClonerMultitenancyTest, ListCollectionsMultitenancySupport) { auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(2U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid1), collections[0].second.toBSON()); - ASSERT_EQ(NamespaceString(_dbName, "b"), collections[1].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), collections[1].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid2), collections[1].second.toBSON()); } @@ -585,9 +591,9 @@ TEST_F(DatabaseClonerMultitenancyTest, auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(2U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid1), collections[0].second.toBSON()); - ASSERT_EQ(NamespaceString(_dbName, "b"), collections[1].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), collections[1].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid2), collections[1].second.toBSON()); } diff --git a/src/mongo/db/repl/drop_pending_collection_reaper_test.cpp b/src/mongo/db/repl/drop_pending_collection_reaper_test.cpp index b6517b044d6..54bb65f0870 100644 --- a/src/mongo/db/repl/drop_pending_collection_reaper_test.cpp +++ b/src/mongo/db/repl/drop_pending_collection_reaper_test.cpp @@ -116,7 +116,8 @@ TEST_F(DropPendingCollectionReaperTest, GetEarliestDropOpTimeReturnsBoostNoneOnE TEST_F(DropPendingCollectionReaperTest, AddDropPendingNamespaceAcceptsNullDropOpTime) { OpTime nullDropOpTime; - auto dpns = NamespaceString("test.foo").makeDropPendingNamespace(nullDropOpTime); + auto dpns = NamespaceString::createNamespaceString_forTest("test.foo") + .makeDropPendingNamespace(nullDropOpTime); DropPendingCollectionReaper reaper(_storageInterface.get()); reaper.addDropPendingNamespace(makeOpCtx().get(), nullDropOpTime, dpns); ASSERT_EQUALS(nullDropOpTime, *reaper.getEarliestDropOpTime()); @@ -133,11 +134,14 @@ TEST_F(DropPendingCollectionReaperTest, DropPendingCollectionReaper reaper(&storageInterfaceMock); OpTime opTime({Seconds(100), 0}, 1LL); - auto dpns = NamespaceString("test.foo").makeDropPendingNamespace(opTime); + auto dpns = + NamespaceString::createNamespaceString_forTest("test.foo").makeDropPendingNamespace(opTime); auto opCtx = makeOpCtx(); reaper.addDropPendingNamespace(opCtx.get(), opTime, dpns); - reaper.addDropPendingNamespace( - opCtx.get(), opTime, NamespaceString("test.bar").makeDropPendingNamespace(opTime)); + reaper.addDropPendingNamespace(opCtx.get(), + opTime, + NamespaceString::createNamespaceString_forTest("test.bar") + .makeDropPendingNamespace(opTime)); // Drop all collections managed by reaper and confirm number of drops. reaper.dropCollectionsOlderThan(opCtx.get(), opTime); @@ -148,7 +152,8 @@ DEATH_TEST_F(DropPendingCollectionReaperTest, AddDropPendingNamespaceTerminatesOnDuplicateDropOpTimeAndNamespace, "Failed to add drop-pending collection") { OpTime opTime({Seconds(100), 0}, 1LL); - auto dpns = NamespaceString("test.foo").makeDropPendingNamespace(opTime); + auto dpns = + NamespaceString::createNamespaceString_forTest("test.foo").makeDropPendingNamespace(opTime); DropPendingCollectionReaper reaper(_storageInterface.get()); auto opCtx = makeOpCtx(); reaper.addDropPendingNamespace(opCtx.get(), opTime, dpns); @@ -167,7 +172,8 @@ TEST_F(DropPendingCollectionReaperTest, NamespaceString dpns[n]; for (int i = 0; i < n; ++i) { opTime[i] = OpTime({Seconds((i + 1) * 10), 0}, 1LL); - ns[i] = NamespaceString("test", str::stream() << "coll" << i); + ns[i] = + NamespaceString::createNamespaceString_forTest("test", str::stream() << "coll" << i); dpns[i] = ns[i].makeDropPendingNamespace(opTime[i]); _storageInterface->createCollection(opCtx.get(), dpns[i], generateOptionsWithUuid()) .transitional_ignore(); @@ -212,7 +218,7 @@ TEST_F(DropPendingCollectionReaperTest, TEST_F(DropPendingCollectionReaperTest, DropCollectionsOlderThanHasNoEffectIfCollectionIsMissing) { OpTime optime({Seconds{1}, 0}, 1LL); - NamespaceString ns("test.foo"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.foo"); auto dpns = ns.makeDropPendingNamespace(optime); DropPendingCollectionReaper reaper(_storageInterface.get()); @@ -224,7 +230,7 @@ TEST_F(DropPendingCollectionReaperTest, DropCollectionsOlderThanHasNoEffectIfCol TEST_F(DropPendingCollectionReaperTest, DropCollectionsOlderThanLogsDropCollectionError) { OpTime optime({Seconds{1}, 0}, 1LL); - NamespaceString ns("test.foo"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.foo"); auto dpns = ns.makeDropPendingNamespace(optime); // StorageInterfaceMock::dropCollection() returns IllegalOperation. @@ -245,7 +251,7 @@ TEST_F(DropPendingCollectionReaperTest, DropCollectionsOlderThanLogsDropCollecti TEST_F(DropPendingCollectionReaperTest, DropCollectionsOlderThanDisablesReplicatedWritesWhenDroppingCollection) { OpTime optime({Seconds{1}, 0}, 1LL); - NamespaceString ns("test.foo"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("test.foo"); auto dpns = ns.makeDropPendingNamespace(optime); // Override dropCollection to confirm that writes are not replicated when dropping the @@ -281,7 +287,8 @@ TEST_F(DropPendingCollectionReaperTest, RollBackDropPendingCollection) { NamespaceString dpns[n]; for (int i = 0; i < n; ++i) { opTime[i] = OpTime({Seconds((i + 1) * 10), 0}, 1LL); - ns[i] = NamespaceString("test", str::stream() << "coll" << i); + ns[i] = + NamespaceString::createNamespaceString_forTest("test", str::stream() << "coll" << i); dpns[i] = ns[i].makeDropPendingNamespace(opTime[i]); ASSERT_OK( _storageInterface->createCollection(opCtx.get(), dpns[i], generateOptionsWithUuid())); @@ -317,7 +324,7 @@ TEST_F(DropPendingCollectionReaperTest, RollBackDropPendingCollection) { // Rolling back collection that has the same opTime as another drop-pending collection // only removes a single collection from the list of drop-pending namespaces - NamespaceString ns4 = NamespaceString("test", "coll4"); + NamespaceString ns4 = NamespaceString::createNamespaceString_forTest("test", "coll4"); NamespaceString dpns4 = ns4.makeDropPendingNamespace(opTime[1]); ASSERT_OK(_storageInterface->createCollection(opCtx.get(), dpns4, generateOptionsWithUuid())); reaper.addDropPendingNamespace(opCtx.get(), opTime[1], dpns4); diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index 8fde4801165..0245fe9b5c8 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -636,18 +636,18 @@ OplogEntry makeOplogEntry(int t, oField = BSON("dropIndexes" << "a_1"); } - return {DurableOplogEntry(OpTime(Timestamp(t, 1), 1), // optime - opType, // op type - NamespaceString("a.a"), // namespace - boost::none, // uuid - boost::none, // fromMigrate - version, // version - oField, // o - boost::none, // o2 - {}, // sessionInfo - boost::none, // upsert - Date_t() + Seconds(t), // wall clock time - {}, // statement ids + return {DurableOplogEntry(OpTime(Timestamp(t, 1), 1), // optime + opType, // op type + NamespaceString::createNamespaceString_forTest("a.a"), // namespace + boost::none, // uuid + boost::none, // fromMigrate + version, // version + oField, // o + boost::none, // o2 + {}, // sessionInfo + boost::none, // upsert + Date_t() + Seconds(t), // wall clock time + {}, // statement ids boost::none, // optime of previous write within same transaction boost::none, // pre-image optime boost::none, // post-image optime @@ -3582,7 +3582,7 @@ TEST_F(InitialSyncerTest, LastOpTimeShouldBeSetEvenIfNoOperationsAreAppliedAfter // Instead of fast forwarding to AllDatabaseCloner completion by returning an empty list of // database names, we'll simulate copying a single database with a single collection on the // sync source. We must do this setup before responding to the FCV, to avoid a race. - NamespaceString nss("a.a"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.a"); _mockServer->setCommandReply("listDatabases", makeListDatabasesResponse({nss.db().toString()})); @@ -4266,7 +4266,7 @@ TEST_F(InitialSyncerTest, // Instead of fast forwarding to AllDatabaseCloner completion by returning an empty list of // database names, we'll simulate copying a single database with a single collection on the // sync source. We must do this setup before responding to the FCV, to avoid a race. - NamespaceString nss("a.a"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.a"); _mockServer->setCommandReply("listDatabases", makeListDatabasesResponse({nss.db().toString()})); @@ -4431,7 +4431,7 @@ TEST_F(InitialSyncerTest, TestRemainingInitialSyncEstimatedMillisMetric) { const auto dbSize = 10000; const auto numDocs = 5; const auto avgObjSize = dbSize / numDocs; - NamespaceString nss("a.a"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.a"); auto hangDuringCloningFailPoint = globalFailPointRegistry().find("initialSyncHangDuringCollectionClone"); @@ -4718,7 +4718,7 @@ TEST_F(InitialSyncerTest, GetInitialSyncProgressReturnsCorrectProgress) { // Set up the successful cloner run. // listDatabases: a - NamespaceString nss("a.a"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.a"); _mockServer->setCommandReply("listDatabases", makeListDatabasesResponse({nss.db().toString()})); // The AllDatabaseCloner post stage calls dbStats to record initial sync progress metrics. @@ -5095,7 +5095,7 @@ TEST_F(InitialSyncerTest, GetInitialSyncProgressOmitsClonerStatsIfClonerStatsExc // Set up the cloner data. This must be done before providing the FCV to avoid races. // listDatabases - NamespaceString nss("a.a"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.a"); _mockServer->setCommandReply("listDatabases", makeListDatabasesResponse({nss.db().toString()})); diff --git a/src/mongo/db/repl/multiapplier_test.cpp b/src/mongo/db/repl/multiapplier_test.cpp index 2afd59376fb..5119f14a85d 100644 --- a/src/mongo/db/repl/multiapplier_test.cpp +++ b/src/mongo/db/repl/multiapplier_test.cpp @@ -66,18 +66,18 @@ void MultiApplierTest::setUp() { * Generates oplog entries with the given number used for the timestamp. */ OplogEntry makeOplogEntry(int ts) { - return {DurableOplogEntry(OpTime(Timestamp(ts, 1), 1), // optime - OpTypeEnum::kNoop, // op type - NamespaceString("a.a"), // namespace - boost::none, // uuid - boost::none, // fromMigrate - OplogEntry::kOplogVersion, // version - BSONObj(), // o - boost::none, // o2 - {}, // sessionInfo - boost::none, // upsert - Date_t(), // wall clock time - {}, // statement ids + return {DurableOplogEntry(OpTime(Timestamp(ts, 1), 1), // optime + OpTypeEnum::kNoop, // op type + NamespaceString::createNamespaceString_forTest("a.a"), // namespace + boost::none, // uuid + boost::none, // fromMigrate + OplogEntry::kOplogVersion, // version + BSONObj(), // o + boost::none, // o2 + {}, // sessionInfo + boost::none, // upsert + Date_t(), // wall clock time + {}, // statement ids boost::none, // optime of previous write within same transaction boost::none, // pre-image optime boost::none, // post-image optime diff --git a/src/mongo/db/repl/oplog_applier_impl_test.cpp b/src/mongo/db/repl/oplog_applier_impl_test.cpp index c6024eee876..42e978295a7 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test.cpp @@ -123,7 +123,7 @@ typedef SetSteadyStateConstraints OplogApplierImplTestEnableSteadyStateConstraints; TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentDatabaseMissing) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto op = makeOplogEntry(OpTypeEnum::kInsert, nss, {}); ASSERT_THROWS(_applyOplogEntryOrGroupedInsertsWrapper( _opCtx.get(), ApplierOperation{&op}, OplogApplication::Mode::kSecondary), @@ -133,8 +133,9 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentDataba TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteDocumentDatabaseMissing) { - const NamespaceString nss(boost::none, "test.t"); - NamespaceString otherNss("test.othername"); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(boost::none, "test.t"); + NamespaceString otherNss = NamespaceString::createNamespaceString_forTest("test.othername"); auto op = makeOplogEntry(OpTypeEnum::kDelete, otherNss, {}); int prevDeleteFromMissing = replOpCounters.getDeleteFromMissingNamespace()->load(); _testApplyOplogEntryOrGroupedInsertsCrudOperation(ErrorCodes::OK, op, nss, false); @@ -150,7 +151,7 @@ TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteDocumentDatabaseMissing) { - NamespaceString otherNss("test.othername"); + NamespaceString otherNss = NamespaceString::createNamespaceString_forTest("test.othername"); auto op = makeOplogEntry(OpTypeEnum::kDelete, otherNss, {}); ASSERT_THROWS(_applyOplogEntryOrGroupedInsertsWrapper( _opCtx.get(), ApplierOperation{&op}, OplogApplication::Mode::kSecondary), @@ -159,9 +160,10 @@ TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentCollectionLookupByUUIDFails) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); createDatabase(_opCtx.get(), nss.db()); - NamespaceString otherNss(nss.getSisterNS("othername")); + NamespaceString otherNss = + NamespaceString::createNamespaceString_forTest(nss.getSisterNS("othername")); auto op = makeOplogEntry(OpTypeEnum::kInsert, otherNss, kUuid); ASSERT_THROWS(_applyOplogEntryOrGroupedInsertsWrapper( _opCtx.get(), ApplierOperation{&op}, OplogApplication::Mode::kSecondary), @@ -170,9 +172,10 @@ TEST_F(OplogApplierImplTest, TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteDocumentCollectionLookupByUUIDFails) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); createDatabase(_opCtx.get(), nss.db()); - NamespaceString otherNss(nss.getSisterNS("othername")); + NamespaceString otherNss = + NamespaceString::createNamespaceString_forTest(nss.getSisterNS("othername")); auto op = makeOplogEntry(OpTypeEnum::kDelete, otherNss, kUuid); int prevDeleteFromMissing = replOpCounters.getDeleteFromMissingNamespace()->load(); _testApplyOplogEntryOrGroupedInsertsCrudOperation(ErrorCodes::OK, op, nss, false); @@ -188,9 +191,10 @@ TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteDocumentCollectionLookupByUUIDFails) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); createDatabase(_opCtx.get(), nss.db()); - NamespaceString otherNss(nss.getSisterNS("othername")); + NamespaceString otherNss = + NamespaceString::createNamespaceString_forTest(nss.getSisterNS("othername")); auto op = makeOplogEntry(OpTypeEnum::kDelete, otherNss, kUuid); ASSERT_THROWS(_applyOplogEntryOrGroupedInsertsWrapper( _opCtx.get(), ApplierOperation{&op}, OplogApplication::Mode::kSecondary), @@ -198,7 +202,7 @@ TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, } TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentCollectionMissing) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); createDatabase(_opCtx.get(), nss.db()); // Even though the collection doesn't exist, this is handled in the actual application function, // which in the case of this test just ignores such errors. This tests mostly that we don't @@ -212,7 +216,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentCollec TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteDocumentCollectionMissing) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); createDatabase(_opCtx.get(), nss.db()); // Even though the collection doesn't exist, this is handled in the actual application function, // which in the case of this test just ignores such errors. This tests mostly that we don't @@ -233,7 +237,7 @@ TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteDocumentCollectionMissing) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); createDatabase(_opCtx.get(), nss.db()); // With steady state constraints enabled, attempting to delete from a missing collection is an // error. @@ -244,7 +248,7 @@ TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, } TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentCollectionExists) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); repl::createCollection(_opCtx.get(), nss, {}); auto op = makeOplogEntry(OpTypeEnum::kInsert, nss, {}); _testApplyOplogEntryOrGroupedInsertsCrudOperation(ErrorCodes::OK, op, nss, true); @@ -252,7 +256,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentCollec TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteDocumentDocMissing) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); repl::createCollection(_opCtx.get(), nss, {}); auto op = makeOplogEntry(OpTypeEnum::kDelete, nss, {}); int prevDeleteWasEmpty = replOpCounters.getDeleteWasEmpty()->load(); @@ -269,7 +273,7 @@ TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteDocumentDocMissing) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); repl::createCollection(_opCtx.get(), nss, {}); auto op = makeOplogEntry(OpTypeEnum::kDelete, nss, {}); ASSERT_THROWS(_applyOplogEntryOrGroupedInsertsWrapper( @@ -281,7 +285,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsDeleteDocumentCollec // Setup the pre-images collection. ChangeStreamPreImagesCollectionManager::createPreImagesCollection(_opCtx.get(), boost::none /* tenantId */); - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); createCollection( _opCtx.get(), nss, createRecordChangeStreamPreAndPostImagesCollectionOptions()); ASSERT_OK(getStorageInterface()->insertDocument(_opCtx.get(), nss, {BSON("_id" << 0)}, 0)); @@ -291,7 +295,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsDeleteDocumentCollec TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsInsertExistingDocument) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); ASSERT_OK(getStorageInterface()->insertDocument(_opCtx.get(), nss, {BSON("_id" << 0)}, 0)); auto op = makeOplogEntry(OpTypeEnum::kInsert, nss, uuid); @@ -309,7 +313,7 @@ TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsInsertExistingDocument) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); ASSERT_OK(getStorageInterface()->insertDocument(_opCtx.get(), nss, {BSON("_id" << 0)}, 0)); auto op = makeOplogEntry(OpTypeEnum::kInsert, nss, uuid); @@ -318,7 +322,7 @@ TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsUpdateMissingDocument) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto op = makeOplogEntry(repl::OpTypeEnum::kUpdate, nss, @@ -340,7 +344,7 @@ TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsUpdateMissingDocument) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto op = makeOplogEntry(repl::OpTypeEnum::kUpdate, nss, @@ -353,23 +357,25 @@ TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, } TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentCollectionLockedByUUID) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); // Test that the collection to lock is determined by the UUID and not the 'ns' field. - NamespaceString otherNss(nss.getSisterNS("othername")); + NamespaceString otherNss = + NamespaceString::createNamespaceString_forTest(nss.getSisterNS("othername")); auto op = makeOplogEntry(OpTypeEnum::kInsert, otherNss, uuid); _testApplyOplogEntryOrGroupedInsertsCrudOperation(ErrorCodes::OK, op, nss, true); } TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteMissingDocCollectionLockedByUUID) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.uuid = kUuid; createCollection(_opCtx.get(), nss, options); // Test that the collection to lock is determined by the UUID and not the 'ns' field. - NamespaceString otherNss(nss.getSisterNS("othername")); + NamespaceString otherNss = + NamespaceString::createNamespaceString_forTest(nss.getSisterNS("othername")); auto op = makeOplogEntry(OpTypeEnum::kDelete, otherNss, options.uuid); int prevDeleteWasEmpty = replOpCounters.getDeleteWasEmpty()->load(); _testApplyOplogEntryOrGroupedInsertsCrudOperation(ErrorCodes::OK, op, nss, false); @@ -385,12 +391,13 @@ TEST_F(OplogApplierImplTestDisableSteadyStateConstraints, TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, applyOplogEntryOrGroupedInsertsDeleteMissingDocCollectionLockedByUUID) { - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.uuid = kUuid; createCollection(_opCtx.get(), nss, options); - NamespaceString otherNss(nss.getSisterNS("othername")); + NamespaceString otherNss = + NamespaceString::createNamespaceString_forTest(nss.getSisterNS("othername")); auto op = makeOplogEntry(OpTypeEnum::kDelete, otherNss, options.uuid); ASSERT_THROWS(_applyOplogEntryOrGroupedInsertsWrapper( _opCtx.get(), ApplierOperation{&op}, OplogApplication::Mode::kSecondary), @@ -401,7 +408,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsDeleteDocumentCollec // Setup the pre-images collection. ChangeStreamPreImagesCollectionManager::createPreImagesCollection(_opCtx.get(), boost::none /* tenantId */); - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options = createRecordChangeStreamPreAndPostImagesCollectionOptions(); options.uuid = kUuid; createCollection(_opCtx.get(), nss, options); @@ -410,7 +417,8 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsDeleteDocumentCollec ASSERT_OK(getStorageInterface()->insertDocument(_opCtx.get(), nss, {BSON("_id" << 0)}, 0)); // Test that the collection to lock is determined by the UUID and not the 'ns' field. - NamespaceString otherNss(nss.getSisterNS("othername")); + NamespaceString otherNss = + NamespaceString::createNamespaceString_forTest(nss.getSisterNS("othername")); auto op = makeOplogEntry(OpTypeEnum::kDelete, otherNss, options.uuid); _testApplyOplogEntryOrGroupedInsertsCrudOperation(ErrorCodes::OK, op, nss, true); } @@ -421,7 +429,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryToRecordChangeStreamPreImages) { boost::none /* tenantId */); // Create the collection. - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); CollectionOptions options; options.uuid = kUuid; options.changeStreamPreAndPostImagesOptions.setEnabled(true); @@ -515,7 +523,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryToRecordChangeStreamPreImages) { } TEST_F(OplogApplierImplTest, CreateCollectionCommand) { - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto op = BSON("op" << "c" @@ -544,7 +552,7 @@ TEST_F(OplogApplierImplTest, CreateCollectionCommandMultitenant) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); auto tid{TenantId(OID::gen())}; - NamespaceString nss(tid, "test.foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "test.foo"); auto op = BSON("create" << nss.coll()); bool applyCmdCalled = false; @@ -573,7 +581,7 @@ TEST_F(OplogApplierImplTest, CreateCollectionCommandMultitenantRequireTenantIDFa RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); auto tid{TenantId(OID::gen())}; - NamespaceString nss(tid, "test.foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "test.foo"); auto op = BSON("op" @@ -610,8 +618,10 @@ TEST_F(OplogApplierImplTest, CreateCollectionCommandMultitenantAlreadyExists) { auto tid1{TenantId(OID::gen())}; auto tid2{TenantId(OID::gen())}; std::string commonNamespace("test.foo"); - NamespaceString nssTenant1(tid1, commonNamespace); - NamespaceString nssTenant2(tid2, commonNamespace); + NamespaceString nssTenant1 = + NamespaceString::createNamespaceString_forTest(tid1, commonNamespace); + NamespaceString nssTenant2 = + NamespaceString::createNamespaceString_forTest(tid2, commonNamespace); ASSERT_NE(tid1, tid2); CollectionOptions options; @@ -666,8 +676,10 @@ TEST_F(OplogApplierImplTest, RenameCollectionCommandMultitenant) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); auto tid{TenantId(OID::gen())}; // rename should not occur across tenants - const NamespaceString sourceNss(tid, "test.foo"); - const NamespaceString targetNss(tid, "test.bar"); + const NamespaceString sourceNss = + NamespaceString::createNamespaceString_forTest(tid, "test.foo"); + const NamespaceString targetNss = + NamespaceString::createNamespaceString_forTest(tid, "test.bar"); auto oRename = BSON("renameCollection" << sourceNss.toString() << "to" << targetNss.toString() << "tid" << tid); @@ -692,8 +704,10 @@ TEST_F(OplogApplierImplTest, RenameCollectionCommandMultitenantRequireTenantIDFa RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); auto tid{TenantId(OID::gen())}; // rename should not occur across tenants - const NamespaceString sourceNss(tid, "test.foo"); - const NamespaceString targetNss(tid, "test.bar"); + const NamespaceString sourceNss = + NamespaceString::createNamespaceString_forTest(tid, "test.foo"); + const NamespaceString targetNss = + NamespaceString::createNamespaceString_forTest(tid, "test.bar"); auto oRename = BSON("renameCollection" << sourceNss.toStringWithTenantId() << "to" << targetNss.toStringWithTenantId()); @@ -719,9 +733,12 @@ TEST_F(OplogApplierImplTest, RenameCollectionCommandMultitenantAcrossTenantsRequ auto tid{TenantId(OID::gen())}; auto wrongTid{TenantId(OID::gen())}; // rename should not occur across tenants - const NamespaceString sourceNss(tid, "test.foo"); - const NamespaceString targetNss(tid, "test.bar"); - const NamespaceString wrongTargetNss(wrongTid, targetNss.toString()); + const NamespaceString sourceNss = + NamespaceString::createNamespaceString_forTest(tid, "test.foo"); + const NamespaceString targetNss = + NamespaceString::createNamespaceString_forTest(tid, "test.bar"); + const NamespaceString wrongTargetNss = + NamespaceString::createNamespaceString_forTest(wrongTid, targetNss.toString()); ASSERT_NE(sourceNss, wrongTargetNss); @@ -750,7 +767,7 @@ TEST_F(IdempotencyTest, CollModCommandMultitenant) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); auto tid{TenantId(OID::gen())}; - const NamespaceString nss(tid, "test.foo"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "test.foo"); setNss(nss); // IdempotencyTest keeps nss state, update with tid @@ -790,8 +807,10 @@ TEST_F(IdempotencyTest, CollModCommandMultitenantWrongTenant) { auto tid1{TenantId(OID::gen())}; auto tid2{TenantId(OID::gen())}; std::string commonNamespace("test.foo"); - NamespaceString nssTenant1(tid1, commonNamespace); - NamespaceString nssTenant2(tid2, commonNamespace); + NamespaceString nssTenant1 = + NamespaceString::createNamespaceString_forTest(tid1, commonNamespace); + NamespaceString nssTenant2 = + NamespaceString::createNamespaceString_forTest(tid2, commonNamespace); ASSERT_NE(tid1, tid2); setNss(nssTenant1); // IdempotencyTest keeps nss state, update with tid of the created nss @@ -913,7 +932,8 @@ bool _testOplogEntryIsForCappedCollection(OperationContext* opCtx, TEST_F( OplogApplierImplTest, MultiApplyDoesNotSetOplogEntryIsForCappedCollectionWhenProcessingNonCappedCollectionInsertOperation) { - NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "local." + _agent.getSuiteName() + "_" + _agent.getTestName()); ASSERT_FALSE(_testOplogEntryIsForCappedCollection(_opCtx.get(), ReplicationCoordinator::get(_opCtx.get()), getConsistencyMarkers(), @@ -924,7 +944,8 @@ TEST_F( TEST_F(OplogApplierImplTest, MultiApplySetsOplogEntryIsForCappedCollectionWhenProcessingCappedCollectionInsertOperation) { - NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "local." + _agent.getSuiteName() + "_" + _agent.getTestName()); ASSERT_TRUE(_testOplogEntryIsForCappedCollection(_opCtx.get(), ReplicationCoordinator::get(_opCtx.get()), getConsistencyMarkers(), @@ -935,7 +956,8 @@ TEST_F(OplogApplierImplTest, TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncUsesApplyOplogEntryOrGroupedInsertsToApplyOperation) { - NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "local." + _agent.getSuiteName() + "_" + _agent.getTestName()); auto op = makeCreateCollectionOplogEntry({Timestamp(Seconds(1), 0), 1LL}, nss); std::vector ops = {ApplierOperation{&op}}; @@ -1005,7 +1027,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentInclud RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); const TenantId tid(OID::gen()); - const NamespaceString nss(tid, "test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "test.t"); BSONObj doc = BSON("_id" << 0); repl::createCollection(_opCtx.get(), nss, {}); @@ -1023,8 +1045,10 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsInsertDocumentIncorr const auto commonNss("test.t"_sd); const TenantId tid1(OID::gen()); const TenantId tid2(OID::gen()); - const NamespaceString nssTenant1(tid1, commonNss); - const NamespaceString nssTenant2(tid2, commonNss); + const NamespaceString nssTenant1 = + NamespaceString::createNamespaceString_forTest(tid1, commonNss); + const NamespaceString nssTenant2 = + NamespaceString::createNamespaceString_forTest(tid2, commonNss); BSONObj doc = BSON("_id" << 0); repl::createCollection(_opCtx.get(), nssTenant1, {}); @@ -1047,7 +1071,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsDeleteDocumentInclud ChangeStreamPreImagesCollectionManager::createPreImagesCollection(_opCtx.get(), tid); RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); - const NamespaceString nss(tid, "test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "test.t"); BSONObj doc = BSON("_id" << 0); // this allows us to set deleteArgs.deletedDoc needed by the onDeleteFn validation function in @@ -1072,8 +1096,10 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsDeleteDocumentIncorr const auto commonNss("test.t"_sd); const TenantId tid1(OID::gen()); const TenantId tid2(OID::gen()); - const NamespaceString nssTenant1(tid1, commonNss); - const NamespaceString nssTenant2(tid2, commonNss); + const NamespaceString nssTenant1 = + NamespaceString::createNamespaceString_forTest(tid1, commonNss); + const NamespaceString nssTenant2 = + NamespaceString::createNamespaceString_forTest(tid2, commonNss); BSONObj doc = BSON("_id" << 0); repl::createCollection(_opCtx.get(), nssTenant1, {}); @@ -1098,8 +1124,10 @@ TEST_F(OplogApplierImplTestEnableSteadyStateConstraints, const auto commonNss("test.t"_sd); const TenantId tid1(OID::gen()); const TenantId tid2(OID::gen()); - const NamespaceString nssTenant1(tid1, commonNss); - const NamespaceString nssTenant2(tid2, commonNss); + const NamespaceString nssTenant1 = + NamespaceString::createNamespaceString_forTest(tid1, commonNss); + const NamespaceString nssTenant2 = + NamespaceString::createNamespaceString_forTest(tid2, commonNss); BSONObj doc = BSON("_id" << 0); auto uuid1 = createCollectionWithUuid(_opCtx.get(), nssTenant1); @@ -1122,7 +1150,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsUpdateDocumentInclud RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); const TenantId tid(OID::gen()); - const NamespaceString nss(tid, "test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "test.t"); BSONObj doc = BSON("_id" << 0); createCollection(_opCtx.get(), nss, {}); @@ -1149,8 +1177,10 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsUpdateDocumentIncorr const auto commonNss("test.t"_sd); const TenantId tid1(OID::gen()); const TenantId tid2(OID::gen()); - const NamespaceString nssTenant1(tid1, commonNss); - const NamespaceString nssTenant2(tid2, commonNss); + const NamespaceString nssTenant1 = + NamespaceString::createNamespaceString_forTest(tid1, commonNss); + const NamespaceString nssTenant2 = + NamespaceString::createNamespaceString_forTest(tid2, commonNss); BSONObj doc = BSON("_id" << 0); createCollection(_opCtx.get(), nssTenant1, {}); @@ -1181,7 +1211,8 @@ public: protected: void setUp() override { OplogApplierImplTest::setUp(); - const NamespaceString cmdNss{"admin", "$cmd"}; + const NamespaceString cmdNss = + NamespaceString::createNamespaceString_forTest("admin", "$cmd"); _uuid1 = createCollectionWithUuid(_opCtx.get(), _nss1); _uuid2 = createCollectionWithUuid(_opCtx.get(), _nss2); @@ -1377,7 +1408,7 @@ TEST_F(MultiOplogEntryOplogApplierImplTest, MultiApplyUnpreparedTransactionTwoBa std::vector insertOps; std::vector insertDocs; - const NamespaceString cmdNss{"admin", "$cmd"}; + const NamespaceString cmdNss = NamespaceString::createNamespaceString_forTest("admin", "$cmd"); for (int i = 0; i < 4; i++) { insertDocs.push_back(BSON("_id" << i)); insertOps.push_back(makeCommandOplogEntryWithSessionInfoAndStmtIds( @@ -1457,7 +1488,7 @@ TEST_F(MultiOplogEntryOplogApplierImplTest, MultiApplyTwoTransactionsOneBatch) { std::vector insertOps1, insertOps2; - const NamespaceString cmdNss{"admin", "$cmd"}; + const NamespaceString cmdNss = NamespaceString::createNamespaceString_forTest("admin", "$cmd"); insertOps1.push_back(makeCommandOplogEntryWithSessionInfoAndStmtIds( {Timestamp(Seconds(1), 1), 1LL}, cmdNss, @@ -2385,7 +2416,8 @@ TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncAddsWorkerMultikeyPathInf ASSERT_OK( ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_SECONDARY)); - NamespaceString nss("test." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName()); { auto op = makeCreateCollectionOplogEntry( @@ -2410,7 +2442,8 @@ TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncAddsMultipleWorkerMultike ASSERT_OK( ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_SECONDARY)); - NamespaceString nss("test." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName()); { auto op = makeCreateCollectionOplogEntry( @@ -2453,7 +2486,8 @@ TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncDoesNotAddWorkerMultikeyPathInfoOnCreateIndex) { ASSERT_OK( ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_RECOVERING)); - NamespaceString nss("test." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName()); { auto op = makeCreateCollectionOplogEntry( @@ -2484,7 +2518,8 @@ TEST_F(OplogApplierImplTest, TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncFailsWhenCollectionCreationTriesToMakeUUID) { ASSERT_OK( ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_SECONDARY)); - NamespaceString nss("foo." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "foo." + _agent.getSuiteName() + "_" + _agent.getTestName()); auto op = makeCreateCollectionOplogEntry({Timestamp(Seconds(1), 0), 1LL}, nss); @@ -2499,7 +2534,8 @@ TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncFailsWhenCollectionCreati TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncDisablesDocumentValidationWhileApplyingOperations) { - NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "local." + _agent.getSuiteName() + "_" + _agent.getTestName()); bool onInsertsCalled = false; _opObserver->onInsertsFn = [&](OperationContext* opCtx, const NamespaceString&, const std::vector&) { @@ -2518,7 +2554,8 @@ TEST_F(OplogApplierImplTest, TEST_F( OplogApplierImplTest, OplogApplicationThreadFuncPassesThroughApplyOplogEntryOrGroupedInsertsErrorAfterFailingToApplyOperation) { - NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "local." + _agent.getSuiteName() + "_" + _agent.getTestName()); // Delete operation without _id in 'o' field. auto op = makeDeleteDocumentOplogEntry({Timestamp(Seconds(1), 0), 1LL}, nss, {}); ASSERT_EQUALS(ErrorCodes::NoSuchKey, runOpSteadyState(op)); @@ -2526,7 +2563,8 @@ TEST_F( TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncPassesThroughApplyOplogEntryOrGroupedInsertsException) { - NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "local." + _agent.getSuiteName() + "_" + _agent.getTestName()); bool onInsertsCalled = false; _opObserver->onInsertsFn = [&](OperationContext* opCtx, const NamespaceString&, const std::vector&) { @@ -2542,9 +2580,9 @@ TEST_F(OplogApplierImplTest, TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncSortsOperationsStablyByNamespaceBeforeApplying) { - NamespaceString nss1("test.t1"); - NamespaceString nss2("test.t2"); - NamespaceString nss3("test.t3"); + NamespaceString nss1 = NamespaceString::createNamespaceString_forTest("test.t1"); + NamespaceString nss2 = NamespaceString::createNamespaceString_forTest("test.t2"); + NamespaceString nss3 = NamespaceString::createNamespaceString_forTest("test.t3"); const Seconds s(1); unsigned int i = 1; @@ -2593,8 +2631,10 @@ TEST_F(OplogApplierImplTest, auto t = seconds++; return makeInsertDocumentOplogEntry({Timestamp(Seconds(t), 0), 1LL}, nss, BSON("_id" << t)); }; - NamespaceString nss1("test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_1"); - NamespaceString nss2("test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_2"); + NamespaceString nss1 = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_1"); + NamespaceString nss2 = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_2"); auto createOp1 = makeCreateCollectionOplogEntry({Timestamp(Seconds(seconds++), 0), 1LL}, nss1); auto createOp2 = makeCreateCollectionOplogEntry({Timestamp(Seconds(seconds++), 0), 1LL}, nss2); auto insertOp1a = makeOp(nss1); @@ -2635,7 +2675,8 @@ TEST_F(OplogApplierImplTest, auto t = seconds++; return makeInsertDocumentOplogEntry({Timestamp(Seconds(t), 0), 1LL}, nss, BSON("_id" << t)); }; - NamespaceString nss("test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_1"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_1"); auto createOp = makeCreateCollectionOplogEntry({Timestamp(Seconds(seconds++), 0), 1LL}, nss); // Generate operations to apply: @@ -2687,7 +2728,8 @@ OplogEntry makeSizedInsertOp(const NamespaceString& nss, int size, int id) { TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncLimitsBatchSizeWhenGroupingInsertOperations) { int seconds = 1; - NamespaceString nss("test." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName()); auto createOp = makeCreateCollectionOplogEntry({Timestamp(Seconds(seconds++), 0), 1LL}, nss); // Create a sequence of insert ops that are too large to fit in one group. @@ -2737,7 +2779,8 @@ TEST_F(OplogApplierImplTest, TEST_F(OplogApplierImplTest, OplogApplicationThreadFuncAppliesOpIndividuallyWhenOpIndividuallyExceedsBatchSize) { int seconds = 1; - NamespaceString nss("test." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName()); auto createOp = makeCreateCollectionOplogEntry({Timestamp(Seconds(seconds++), 0), 1LL}, nss); int maxBatchSize = write_ops::insertVectorMaxBytes; @@ -2781,9 +2824,10 @@ TEST_F(OplogApplierImplTest, // Create a sequence of 3 'insert' ops that can't be grouped because they are from different // namespaces. - std::vector operationsToApply = {makeOp(NamespaceString(testNs + "_1")), - makeOp(NamespaceString(testNs + "_2")), - makeOp(NamespaceString(testNs + "_3"))}; + std::vector operationsToApply = { + makeOp(NamespaceString::createNamespaceString_forTest(testNs + "_1")), + makeOp(NamespaceString::createNamespaceString_forTest(testNs + "_2")), + makeOp(NamespaceString::createNamespaceString_forTest(testNs + "_3"))}; for (const auto& oplogEntry : operationsToApply) { createCollectionWithUuid(_opCtx.get(), oplogEntry.getNss()); @@ -2816,7 +2860,8 @@ TEST_F(OplogApplierImplTest, auto t = seconds++; return makeInsertDocumentOplogEntry({Timestamp(Seconds(t), 0), 1LL}, nss, BSON("_id" << t)); }; - NamespaceString nss("test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_1"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_1"); auto createOp = makeCreateCollectionOplogEntry({Timestamp(Seconds(seconds++), 0), 1LL}, nss); // Generate operations to apply: @@ -2865,7 +2910,7 @@ TEST_F(OplogApplierImplTest, TEST_F(OplogApplierImplTest, ApplyGroupIgnoresUpdateOperationIfDocumentIsMissingFromSyncSource) { TestApplyOplogGroupApplier oplogApplier( nullptr, nullptr, OplogApplier::Options(OplogApplication::Mode::kInitialSync)); - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); { Lock::GlobalWrite globalLock(_opCtx.get()); bool justCreated = false; @@ -2892,8 +2937,10 @@ TEST_F(OplogApplierImplTest, BSONObj emptyDoc; TestApplyOplogGroupApplier oplogApplier( nullptr, nullptr, OplogApplier::Options(OplogApplication::Mode::kInitialSync)); - NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); - NamespaceString badNss("local." + _agent.getSuiteName() + "_" + _agent.getTestName() + "bad"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "local." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString badNss = NamespaceString::createNamespaceString_forTest( + "local." + _agent.getSuiteName() + "_" + _agent.getTestName() + "bad"); auto doc1 = BSON("_id" << 1); auto doc2 = BSON("_id" << 2); auto doc3 = BSON("_id" << 3); @@ -2923,7 +2970,8 @@ TEST_F(OplogApplierImplTest, BSONObj emptyDoc; TestApplyOplogGroupApplier oplogApplier( nullptr, nullptr, OplogApplier::Options(OplogApplication::Mode::kInitialSync)); - NamespaceString nss("test." + _agent.getSuiteName() + "_" + _agent.getTestName()); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test." + _agent.getSuiteName() + "_" + _agent.getTestName()); NamespaceString badNss("test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "bad"); auto doc1 = BSON("_id" << 1); auto keyPattern = BSON("a" << 1); @@ -3229,8 +3277,9 @@ TEST_F(IdempotencyTest, CreateCollectionWithView) { ASSERT_OK( runOpInitialSync(makeCreateCollectionOplogEntry(nextOpTime(), viewNss, options.toBSON()))); - auto viewDoc = BSON("_id" << NamespaceString(_nss.db(), "view").ns() << "viewOn" << _nss.coll() - << "pipeline" << fromjson("[ { '$project' : { 'x' : 1 } } ]")); + auto viewDoc = BSON( + "_id" << NamespaceString::createNamespaceString_forTest(_nss.db(), "view").ns() << "viewOn" + << _nss.coll() << "pipeline" << fromjson("[ { '$project' : { 'x' : 1 } } ]")); auto insertViewOp = makeInsertDocumentOplogEntry(nextOpTime(), viewNss, viewDoc); auto dropColl = makeCommandOplogEntry(nextOpTime(), _nss, BSON("drop" << _nss.coll())); @@ -3315,7 +3364,7 @@ TEST_F(IdempotencyTest, InsertToFCVCollectionBesidesFCVDocumentSucceeds) { TEST_F(IdempotencyTest, DropDatabaseSucceeds) { // Choose `system.profile` so the storage engine doesn't expect the drop to be timestamped. - auto ns = NamespaceString("foo.system.profile"); + auto ns = NamespaceString::createNamespaceString_forTest("foo.system.profile"); ::mongo::repl::createCollection(_opCtx.get(), ns, CollectionOptions()); ASSERT_OK( ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_RECOVERING)); @@ -3326,7 +3375,7 @@ TEST_F(IdempotencyTest, DropDatabaseSucceeds) { TEST_F(OplogApplierImplTest, DropDatabaseSucceedsInRecovering) { // Choose `system.profile` so the storage engine doesn't expect the drop to be timestamped. - auto ns = NamespaceString("foo.system.profile"); + auto ns = NamespaceString::createNamespaceString_forTest("foo.system.profile"); ::mongo::repl::createCollection(_opCtx.get(), ns, CollectionOptions()); ASSERT_OK( ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_RECOVERING)); @@ -3340,7 +3389,7 @@ TEST_F(OplogApplierImplWithFastAutoAdvancingClockTest, LogSlowOpApplicationWhenS auto applyDuration = serverGlobalParams.slowMS.load() * 10; // We are inserting into an existing collection. - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); repl::createCollection(_opCtx.get(), nss, {}); auto entry = makeOplogEntry(OpTypeEnum::kInsert, nss, {}); @@ -3364,7 +3413,7 @@ TEST_F(OplogApplierImplWithFastAutoAdvancingClockTest, DoNotLogSlowOpApplication auto applyDuration = serverGlobalParams.slowMS.load() * 10; // We are trying to insert into a non-existing database. - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); auto entry = makeOplogEntry(OpTypeEnum::kInsert, nss, {}); startCapturingLogMessages(); @@ -3386,7 +3435,7 @@ TEST_F(OplogApplierImplWithSlowAutoAdvancingClockTest, DoNotLogNonSlowOpApplicat auto applyDuration = serverGlobalParams.slowMS.load() / 10; // We are inserting into an existing collection. - const NamespaceString nss("test.t"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); repl::createCollection(_opCtx.get(), nss, {}); auto entry = makeOplogEntry(OpTypeEnum::kInsert, nss, {}); @@ -3511,7 +3560,8 @@ private: static const NamespaceString kNs; }; -const NamespaceString OplogApplierImplTxnTableTest::kNs("test.foo"); +const NamespaceString OplogApplierImplTxnTableTest::kNs = + NamespaceString::createNamespaceString_forTest("test.foo"); TEST_F(OplogApplierImplTxnTableTest, SimpleWriteWithTxn) { const auto sessionId = makeLogicalSessionIdForTest(); @@ -3684,7 +3734,7 @@ TEST_F(OplogApplierImplTxnTableTest, InterleavedWriteWithTxnMixedWithDirectUpdat } TEST_F(OplogApplierImplTxnTableTest, RetryableWriteThenMultiStatementTxnWriteOnSameSession) { - const NamespaceString cmdNss{"admin", "$cmd"}; + const NamespaceString cmdNss = NamespaceString::createNamespaceString_forTest("admin", "$cmd"); const auto sessionId = makeLogicalSessionIdForTest(); OperationSessionInfo sessionInfo; sessionInfo.setSessionId(sessionId); @@ -3755,7 +3805,7 @@ TEST_F(OplogApplierImplTxnTableTest, RetryableWriteThenMultiStatementTxnWriteOnS } TEST_F(OplogApplierImplTxnTableTest, MultiStatementTxnWriteThenRetryableWriteOnSameSession) { - const NamespaceString cmdNss{"admin", "$cmd"}; + const NamespaceString cmdNss = NamespaceString::createNamespaceString_forTest("admin", "$cmd"); const auto sessionId = makeLogicalSessionIdForTest(); OperationSessionInfo sessionInfo; sessionInfo.setSessionId(sessionId); @@ -3826,10 +3876,10 @@ TEST_F(OplogApplierImplTxnTableTest, MultiStatementTxnWriteThenRetryableWriteOnS TEST_F(OplogApplierImplTxnTableTest, MultiApplyUpdatesTheTransactionTable) { - NamespaceString ns0("test.0"); - NamespaceString ns1("test.1"); - NamespaceString ns2("test.2"); - NamespaceString ns3("test.3"); + NamespaceString ns0 = NamespaceString::createNamespaceString_forTest("test.0"); + NamespaceString ns1 = NamespaceString::createNamespaceString_forTest("test.1"); + NamespaceString ns2 = NamespaceString::createNamespaceString_forTest("test.2"); + NamespaceString ns3 = NamespaceString::createNamespaceString_forTest("test.3"); DBDirectClient client(_opCtx.get()); BSONObj result; @@ -4150,7 +4200,7 @@ TEST_F(IdempotencyTestTxns, CommitUnpreparedTransactionDataPartiallyApplied) { auto lsid = makeLogicalSessionId(_opCtx.get()); TxnNumber txnNum(0); - NamespaceString nss2("test.coll2"); + NamespaceString nss2 = NamespaceString::createNamespaceString_forTest("test.coll2"); auto uuid2 = createCollectionWithUuid(_opCtx.get(), nss2); auto commitOp = commitUnprepared(lsid, @@ -4214,7 +4264,7 @@ TEST_F(IdempotencyTestTxns, CommitPreparedTransactionDataPartiallyApplied) { auto lsid = makeLogicalSessionId(_opCtx.get()); TxnNumber txnNum(0); - NamespaceString nss2("test.coll2"); + NamespaceString nss2 = NamespaceString::createNamespaceString_forTest("test.coll2"); auto uuid2 = createCollectionWithUuid(_opCtx.get(), nss2); auto prepareOp = prepare(lsid, @@ -4926,7 +4976,7 @@ protected: auto makeApplyOpsForGlobalIndexCrudBatch(const std::vector& batch) { BSONArrayBuilder arrBuilder; - NamespaceString nss("system"_sd); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("system"_sd); for (const auto& op : batch) { if (op.type == GlobalIndexCrudOp::Type::Insert) { arrBuilder << MutableOplogEntry::makeInsertGlobalIndexKeyOperation( diff --git a/src/mongo/db/repl/oplog_applier_test.cpp b/src/mongo/db/repl/oplog_applier_test.cpp index a6f6d6474d2..cc7bb212759 100644 --- a/src/mongo/db/repl/oplog_applier_test.cpp +++ b/src/mongo/db/repl/oplog_applier_test.cpp @@ -113,8 +113,10 @@ constexpr auto dbName = "test"_sd; TEST_F(OplogApplierTest, GetNextApplierBatchGroupsCrudOps) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "foo"))); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = unittest::assertGet(_applier->getNextApplierBatch(opCtx(), _limits)); @@ -126,7 +128,8 @@ TEST_F(OplogApplierTest, GetNextApplierBatchGroupsCrudOps) { TEST_F(OplogApplierTest, GetNextApplierBatchReturnsPreparedApplyOpsOpInOwnBatch) { std::vector srcOps; srcOps.push_back(makeApplyOpsOplogEntry(1, true)); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = unittest::assertGet(_applier->getNextApplierBatch(opCtx(), _limits)); @@ -137,7 +140,8 @@ TEST_F(OplogApplierTest, GetNextApplierBatchReturnsPreparedApplyOpsOpInOwnBatch) TEST_F(OplogApplierTest, GetNextApplierBatchGroupsUnpreparedApplyOpsOpWithOtherOps) { std::vector srcOps; srcOps.push_back(makeApplyOpsOplogEntry(1, false)); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = unittest::assertGet(_applier->getNextApplierBatch(opCtx(), _limits)); @@ -149,7 +153,8 @@ TEST_F(OplogApplierTest, GetNextApplierBatchGroupsUnpreparedApplyOpsOpWithOtherO TEST_F(OplogApplierTest, GetNextApplierBatchReturnsSystemDotViewsOpInOwnBatch) { std::vector srcOps; srcOps.push_back(makeInsertOplogEntry(1, NamespaceString::makeSystemDotViewsNamespace(dbName))); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = unittest::assertGet(_applier->getNextApplierBatch(opCtx(), _limits)); @@ -160,7 +165,8 @@ TEST_F(OplogApplierTest, GetNextApplierBatchReturnsSystemDotViewsOpInOwnBatch) { TEST_F(OplogApplierTest, GetNextApplierBatchReturnsServerConfigurationOpInOwnBatch) { std::vector srcOps; srcOps.push_back(makeInsertOplogEntry(1, NamespaceString::kServerConfigurationNamespace)); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = unittest::assertGet(_applier->getNextApplierBatch(opCtx(), _limits)); @@ -171,7 +177,8 @@ TEST_F(OplogApplierTest, GetNextApplierBatchReturnsServerConfigurationOpInOwnBat TEST_F(OplogApplierTest, GetNextApplierBatchReturnsConfigReshardingDonorOpInOwnBatch) { std::vector srcOps; srcOps.push_back(makeInsertOplogEntry(1, NamespaceString::kDonorReshardingOperationsNamespace)); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = unittest::assertGet(_applier->getNextApplierBatch(opCtx(), _limits)); @@ -182,7 +189,8 @@ TEST_F(OplogApplierTest, GetNextApplierBatchReturnsConfigReshardingDonorOpInOwnB TEST_F(OplogApplierTest, GetNextApplierBatchReturnsPreparedCommitTransactionOpInOwnBatch) { std::vector srcOps; srcOps.push_back(makeCommitTransactionOplogEntry(1, dbName, true, 3)); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = unittest::assertGet(_applier->getNextApplierBatch(opCtx(), _limits)); @@ -193,7 +201,8 @@ TEST_F(OplogApplierTest, GetNextApplierBatchReturnsPreparedCommitTransactionOpIn TEST_F(OplogApplierTest, GetNextApplierBatchGroupsUnpreparedCommitTransactionOpWithOtherOps) { std::vector srcOps; srcOps.push_back(makeCommitTransactionOplogEntry(1, dbName, false, 3)); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = unittest::assertGet(_applier->getNextApplierBatch(opCtx(), _limits)); @@ -204,11 +213,16 @@ TEST_F(OplogApplierTest, GetNextApplierBatchGroupsUnpreparedCommitTransactionOpW TEST_F(OplogApplierTest, GetNextApplierBatchChecksBatchLimitsForNumberOfOperations) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar"))); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "bar"))); - srcOps.push_back(makeInsertOplogEntry(4, NamespaceString(dbName, "bar"))); - srcOps.push_back(makeInsertOplogEntry(5, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(4, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(5, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); // Set batch limits so that each batch contains a maximum of 'BatchLimit::ops'. @@ -230,9 +244,12 @@ TEST_F(OplogApplierTest, GetNextApplierBatchChecksBatchLimitsForNumberOfOperatio TEST_F(OplogApplierTest, GetNextApplierBatchChecksBatchLimitsForSizeOfOperations) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar"))); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); // Set batch limits so that only the first two operations can fit into the first batch. @@ -254,9 +271,11 @@ TEST_F(OplogApplierTest, GetNextApplierBatchChecksBatchLimitsForSizeOfOperations TEST_F(OplogApplierTest, GetNextApplierBatchChecksBatchLimitsUsingEmbededCountInUnpreparedCommitTransactionOp1) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); srcOps.push_back(makeCommitTransactionOplogEntry(2, dbName, false, 3)); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); // Set batch limits so that commit transaction entry has to go into next batch as the only entry @@ -277,10 +296,13 @@ TEST_F(OplogApplierTest, TEST_F(OplogApplierTest, GetNextApplierBatchChecksBatchLimitsUsingEmbededCountInUnpreparedCommitTransactionOp2) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar"))); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); srcOps.push_back(makeCommitTransactionOplogEntry(3, dbName, false, 3)); - srcOps.push_back(makeInsertOplogEntry(4, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(4, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); // Set batch limits so that commit transaction entry has to go into next batch after taking into @@ -303,9 +325,11 @@ TEST_F(OplogApplierTest, TEST_F(OplogApplierTest, GetNextApplierBatchChecksBatchLimitsUsingEmbededCountInUnpreparedCommitTransactionOp3) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); srcOps.push_back(makeCommitTransactionOplogEntry(2, dbName, false, 5)); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); // Set batch limits so that commit transaction entry goes into its own batch because its @@ -325,7 +349,8 @@ TEST_F(OplogApplierTest, TEST_F(OplogApplierTest, LastOpInLargeTransactionIsProcessedIndividually) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); // Makes entries with ts from range [2, 5). std::vector multiEntryTransaction = @@ -336,7 +361,8 @@ TEST_F(OplogApplierTest, LastOpInLargeTransactionIsProcessedIndividually) { // Push one extra operation to ensure that the last oplog entry of a large transaction // is processed by itself. - srcOps.push_back(makeInsertOplogEntry(5, NamespaceString(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(5, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); @@ -427,9 +453,12 @@ TEST_F(OplogApplierDelayTest, GetNextApplierBatchReturnsEmptyBatchImmediately) { TEST_F(OplogApplierDelayTest, GetNextApplierBatchReturnsFullBatchImmediately) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "foo"))); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "baz"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "baz"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); auto batch = @@ -439,7 +468,8 @@ TEST_F(OplogApplierDelayTest, GetNextApplierBatchReturnsFullBatchImmediately) { TEST_F(OplogApplierDelayTest, GetNextApplierBatchWaitsForBatchToFill) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "foo"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); stdx::thread insertThread([this, &srcOps] { @@ -447,14 +477,16 @@ TEST_F(OplogApplierDelayTest, GetNextApplierBatchWaitsForBatchToFill) { { FailPointEnableBlock peekFailPoint("oplogBatcherPauseAfterSuccessfulPeek"); srcOps.clear(); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back(makeInsertOplogEntry( + 2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); peekFailPoint->waitForTimesEntered(peekFailPoint.initialTimesEntered() + 1); _mockClock->advance(Milliseconds(5)); } ASSERT(waitForWait()); srcOps.clear(); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "baz"))); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "baz"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); }); auto batch = @@ -466,7 +498,8 @@ TEST_F(OplogApplierDelayTest, GetNextApplierBatchWaitsForBatchToFill) { TEST_F(OplogApplierDelayTest, GetNextApplierBatchWaitsForBatchToTimeout) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "foo"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); stdx::thread insertThread([this, &srcOps] { @@ -474,7 +507,8 @@ TEST_F(OplogApplierDelayTest, GetNextApplierBatchWaitsForBatchToTimeout) { { FailPointEnableBlock peekFailPoint("oplogBatcherPauseAfterSuccessfulPeek"); srcOps.clear(); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back(makeInsertOplogEntry( + 2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); peekFailPoint->waitForTimesEntered(peekFailPoint.initialTimesEntered() + 1); _mockClock->advance(Milliseconds(5)); @@ -493,7 +527,8 @@ TEST_F(OplogApplierDelayTest, GetNextApplierBatchWaitsForBatchToTimeout) { // but does not throw or lose any data. TEST_F(OplogApplierDelayTest, GetNextApplierBatchInterrupted) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "foo"))); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); stdx::thread insertThread([this, &srcOps] { @@ -501,7 +536,8 @@ TEST_F(OplogApplierDelayTest, GetNextApplierBatchInterrupted) { { FailPointEnableBlock peekFailPoint("oplogBatcherPauseAfterSuccessfulPeek"); srcOps.clear(); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar"))); + srcOps.push_back(makeInsertOplogEntry( + 2, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); _applier->enqueue(opCtx(), srcOps.cbegin(), srcOps.cend()); peekFailPoint->waitForTimesEntered(peekFailPoint.initialTimesEntered() + 1); _mockClock->advance(Milliseconds(5)); diff --git a/src/mongo/db/repl/oplog_batcher_test_fixture.cpp b/src/mongo/db/repl/oplog_batcher_test_fixture.cpp index c4f244af6a1..e62e07bbae7 100644 --- a/src/mongo/db/repl/oplog_batcher_test_fixture.cpp +++ b/src/mongo/db/repl/oplog_batcher_test_fixture.cpp @@ -255,7 +255,8 @@ OplogEntry makeNoopOplogEntry(int t, const StringData& msg) { * Generates an applyOps oplog entry with the given number used for the timestamp. */ OplogEntry makeApplyOpsOplogEntry(int t, bool prepare, const std::vector& innerOps) { - auto nss = NamespaceString(NamespaceString::kAdminDb).getCommandNS(); + auto nss = + NamespaceString::createNamespaceString_forTest(NamespaceString::kAdminDb).getCommandNS(); BSONObjBuilder oField; BSONArrayBuilder applyOpsBuilder = oField.subarrayStart("applyOps"); for (const auto& op : innerOps) { @@ -290,7 +291,7 @@ OplogEntry makeApplyOpsOplogEntry(int t, bool prepare, const std::vector innerOps) { // TODO SERVER-62491: Replace TenantId with kSystemTenantId. - auto nss = NamespaceString(NamespaceString::kAdminDb).getCommandNS(); + auto nss = + NamespaceString::createNamespaceString_forTest(NamespaceString::kAdminDb).getCommandNS(); OpTime prevWriteOpTime = isFirst ? OpTime() : OpTime(Timestamp(t - 1, 1), 1); BSONObj oField; if (isLast && prepared) { diff --git a/src/mongo/db/repl/oplog_buffer_collection_test.cpp b/src/mongo/db/repl/oplog_buffer_collection_test.cpp index a320cc56acc..6d6c0b8d1a3 100644 --- a/src/mongo/db/repl/oplog_buffer_collection_test.cpp +++ b/src/mongo/db/repl/oplog_buffer_collection_test.cpp @@ -102,7 +102,8 @@ Client* OplogBufferCollectionTest::getClient() const { */ template NamespaceString makeNamespace(const T& t, const char* suffix = "") { - return NamespaceString("local." + t.getSuiteName() + "_" + t.getTestName() + suffix); + return NamespaceString::createNamespaceString_forTest("local." + t.getSuiteName() + "_" + + t.getTestName() + suffix); } /** @@ -150,7 +151,9 @@ TEST_F(OplogBufferCollectionTest, StartupWithUserProvidedNamespaceCreatesCollect TEST_F(OplogBufferCollectionTest, StartupWithOplogNamespaceTriggersUassert) { ASSERT_THROWS_CODE(testStartupCreatesCollection( - _opCtx.get(), _storageInterface, NamespaceString("local.oplog.Z")), + _opCtx.get(), + _storageInterface, + NamespaceString::createNamespaceString_forTest("local.oplog.Z")), DBException, 28838); } diff --git a/src/mongo/db/repl/oplog_entry_test.cpp b/src/mongo/db/repl/oplog_entry_test.cpp index 6d4021bcc33..12a43a08b35 100644 --- a/src/mongo/db/repl/oplog_entry_test.cpp +++ b/src/mongo/db/repl/oplog_entry_test.cpp @@ -39,7 +39,7 @@ namespace repl { namespace { const OpTime entryOpTime{Timestamp(3, 4), 5}; -const NamespaceString nss{"foo", "bar"}; +const NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo", "bar"); const int docId = 17; TEST(OplogEntryTest, Update) { @@ -145,7 +145,7 @@ TEST(OplogEntryTest, InsertIncludesTidField) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); const BSONObj doc = BSON("_id" << docId << "a" << 5); TenantId tid(OID::gen()); - NamespaceString nss(tid, "foo", "bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tid, "foo", "bar"); const auto entry = makeOplogEntry(entryOpTime, OpTypeEnum::kInsert, nss, doc, boost::none, {}, Date_t::now()); @@ -162,7 +162,8 @@ TEST(OplogEntryTest, ParseMutableOplogEntryIncludesTidField) { const TenantId tid(OID::gen()); - const NamespaceString nssWithTid{tid, nss.ns()}; + const NamespaceString nssWithTid = + NamespaceString::createNamespaceString_forTest(tid, nss.ns()); const BSONObj oplogBson = [&] { BSONObjBuilder bob; @@ -187,7 +188,8 @@ TEST(OplogEntryTest, ParseDurableOplogEntryIncludesTidField) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); const TenantId tid(OID::gen()); - const NamespaceString nssWithTid{tid, nss.ns()}; + const NamespaceString nssWithTid = + NamespaceString::createNamespaceString_forTest(tid, nss.ns()); const BSONObj oplogBson = [&] { BSONObjBuilder bob; @@ -214,7 +216,7 @@ TEST(OplogEntryTest, ParseReplOperationIncludesTidField) { UUID uuid(UUID::gen()); TenantId tid(OID::gen()); - NamespaceString nssWithTid(tid, nss.ns()); + NamespaceString nssWithTid = NamespaceString::createNamespaceString_forTest(tid, nss.ns()); auto op = repl::DurableOplogEntry::makeInsertOperation( nssWithTid, diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp index b5bbb5be64a..e05f0db9ff4 100644 --- a/src/mongo/db/repl/oplog_fetcher_test.cpp +++ b/src/mongo/db/repl/oplog_fetcher_test.cpp @@ -54,7 +54,7 @@ using namespace mongo::repl; using namespace unittest; HostAndPort source("localhost:12345"); -NamespaceString nss("local.oplog.rs"); +NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.oplog.rs"); ReplSetConfig _createConfig() { BSONObjBuilder bob; @@ -83,25 +83,25 @@ BSONObj concatenate(BSONObj a, const BSONObj& b) { } BSONObj makeNoopOplogEntry(OpTime opTime) { - auto oplogEntry = - repl::DurableOplogEntry(opTime, // optime - OpTypeEnum ::kNoop, // opType - NamespaceString("test.t"), // namespace - boost::none, // uuid - boost::none, // fromMigrate - repl::OplogEntry::kOplogVersion, // version - BSONObj(), // o - boost::none, // o2 - {}, // sessionInfo - boost::none, // upsert - Date_t(), // wall clock time - {}, // statement ids - boost::none, // optime of previous write within same transaction - boost::none, // pre-image optime - boost::none, // post-image optime - boost::none, // ShardId of resharding recipient - boost::none, // _id - boost::none); // needsRetryImage + auto oplogEntry = repl::DurableOplogEntry( + opTime, // optime + OpTypeEnum ::kNoop, // opType + NamespaceString::createNamespaceString_forTest("test.t"), // namespace + boost::none, // uuid + boost::none, // fromMigrate + repl::OplogEntry::kOplogVersion, // version + BSONObj(), // o + boost::none, // o2 + {}, // sessionInfo + boost::none, // upsert + Date_t(), // wall clock time + {}, // statement ids + boost::none, // optime of previous write within same transaction + boost::none, // pre-image optime + boost::none, // post-image optime + boost::none, // ShardId of resharding recipient + boost::none, // _id + boost::none); // needsRetryImage return oplogEntry.toBSON(); } diff --git a/src/mongo/db/repl/oplog_test.cpp b/src/mongo/db/repl/oplog_test.cpp index d4e5a2295dd..1b187845291 100644 --- a/src/mongo/db/repl/oplog_test.cpp +++ b/src/mongo/db/repl/oplog_test.cpp @@ -88,7 +88,7 @@ OplogEntry _getSingleOplogEntry(OperationContext* opCtx) { TEST_F(OplogTest, LogOpReturnsOpTimeOnSuccessfulInsertIntoOplogCollection) { auto opCtx = cc().makeOperationContext(); - const NamespaceString nss("test.coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.coll"); auto msgObj = BSON("msg" << "hello, world!"); @@ -163,8 +163,8 @@ void _testConcurrentLogOp(const F& makeTaskFunction, // test thread can proceed with shutting the thread pool down. auto mtx = MONGO_MAKE_LATCH(); unittest::Barrier barrier(3U); - const NamespaceString nss1("test1.coll"); - const NamespaceString nss2("test2.coll"); + const NamespaceString nss1 = NamespaceString::createNamespaceString_forTest("test1.coll"); + const NamespaceString nss2 = NamespaceString::createNamespaceString_forTest("test2.coll"); pool.schedule([&](auto status) mutable { ASSERT_OK(status) << "Failed to schedule logOp() task for namespace " << nss1; makeTaskFunction(nss1, &mtx, opTimeNssMap, &barrier)(); @@ -354,7 +354,7 @@ TEST_F(OplogTest, MigrationIdAddedToOplog) { auto migrationUuid = UUID::gen(); tenantMigrationInfo(opCtx.get()) = boost::make_optional(migrationUuid); - const NamespaceString nss("test.coll"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.coll"); auto msgObj = BSON("msg" << "hello, world!"); diff --git a/src/mongo/db/repl/primary_only_service_test.cpp b/src/mongo/db/repl/primary_only_service_test.cpp index 2b019c61879..908a9bcd6f5 100644 --- a/src/mongo/db/repl/primary_only_service_test.cpp +++ b/src/mongo/db/repl/primary_only_service_test.cpp @@ -79,7 +79,7 @@ public: } NamespaceString getStateDocumentsNS() const override { - return NamespaceString("admin", "test_service"); + return NamespaceString::createNamespaceString_forTest("admin", "test_service"); } ThreadPool::Limits getThreadPoolLimits() const override { @@ -318,8 +318,8 @@ public: _service = _registry->lookupServiceByName("TestService"); ASSERT(_service); - auto serviceByNamespace = - _registry->lookupServiceByNamespace(NamespaceString("admin.test_service")); + auto serviceByNamespace = _registry->lookupServiceByNamespace( + NamespaceString::createNamespaceString_forTest("admin.test_service")); ASSERT_EQ(_service, serviceByNamespace); _testExecutor = makeTestExecutor(); diff --git a/src/mongo/db/repl/primary_only_service_util_test.cpp b/src/mongo/db/repl/primary_only_service_util_test.cpp index 6392ae9c67e..02f98550380 100644 --- a/src/mongo/db/repl/primary_only_service_util_test.cpp +++ b/src/mongo/db/repl/primary_only_service_util_test.cpp @@ -67,7 +67,7 @@ private: // Create a global instance of the 'PrimaryOnlyServiceStateStore' to store the state document. PrimaryOnlyServiceStateStore gStateDocStore{ - NamespaceString{kTestPrimaryOnlyServiceStateDocumentNss}}; + NamespaceString::createNamespaceString_forTest(kTestPrimaryOnlyServiceStateDocumentNss)}; /** * Test class for the 'DefaultPrimaryOnlyServiceInstance'. @@ -124,7 +124,8 @@ public: } NamespaceString getStateDocumentsNS() const final { - return NamespaceString(kTestPrimaryOnlyServiceStateDocumentNss); + return NamespaceString::createNamespaceString_forTest( + kTestPrimaryOnlyServiceStateDocumentNss); } ThreadPool::Limits getThreadPoolLimits() const final { diff --git a/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp b/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp index 6247c389c74..cf24bb49a4c 100644 --- a/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp +++ b/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp @@ -55,9 +55,12 @@ namespace { using namespace mongo::repl; -NamespaceString kMinValidNss("local", "replset.minvalid"); -NamespaceString kOplogTruncateAfterPointNss("local", "replset.oplogTruncateAfterPoint"); -NamespaceString kInitialSyncIdNss("local", "replset.initialSyncId"); +NamespaceString kMinValidNss = + NamespaceString::createNamespaceString_forTest("local", "replset.minvalid"); +NamespaceString kOplogTruncateAfterPointNss = + NamespaceString::createNamespaceString_forTest("local", "replset.oplogTruncateAfterPoint"); +NamespaceString kInitialSyncIdNss = + NamespaceString::createNamespaceString_forTest("local", "replset.initialSyncId"); /** * Returns min valid document. diff --git a/src/mongo/db/repl/replication_recovery_test.cpp b/src/mongo/db/repl/replication_recovery_test.cpp index 5556d64628b..4bd2d39bad6 100644 --- a/src/mongo/db/repl/replication_recovery_test.cpp +++ b/src/mongo/db/repl/replication_recovery_test.cpp @@ -431,7 +431,9 @@ TEST_F(ReplicationRecoveryTest, RecoveryWithNoOplogSucceeds) { // Create the database. ASSERT_OK(getStorageInterface()->createCollection( - opCtx, NamespaceString("local.other"), generateOptionsWithUuid())); + opCtx, + NamespaceString::createNamespaceString_forTest("local.other"), + generateOptionsWithUuid())); recovery.recoverFromOplog(opCtx, boost::none); @@ -445,7 +447,9 @@ TEST_F(ReplicationRecoveryTest, RecoveryWithNoOplogSucceedsWithStableTimestamp) // Create the database. ASSERT_OK(getStorageInterface()->createCollection( - opCtx, NamespaceString("local.other"), generateOptionsWithUuid())); + opCtx, + NamespaceString::createNamespaceString_forTest("local.other"), + generateOptionsWithUuid())); Timestamp stableTimestamp(3, 3); recovery.recoverFromOplog(opCtx, stableTimestamp); diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp index cf4d25cc65f..e586e013e40 100644 --- a/src/mongo/db/repl/storage_interface_impl_test.cpp +++ b/src/mongo/db/repl/storage_interface_impl_test.cpp @@ -78,9 +78,10 @@ BSONObj makeIdIndexSpec(const NamespaceString& nss) { */ template NamespaceString makeNamespace(const T& t, const std::string& suffix = "") { - return NamespaceString(std::string("local." + t.getSuiteName() + "_" + t.getTestName()) - .substr(0, NamespaceString::MaxNsCollectionLen - suffix.length()) + - suffix); + return NamespaceString::createNamespaceString_forTest( + std::string("local." + t.getSuiteName() + "_" + t.getTestName()) + .substr(0, NamespaceString::MaxNsCollectionLen - suffix.length()) + + suffix); } /** @@ -258,7 +259,9 @@ TEST_F(StorageInterfaceImplTest, InitializeRollbackIDReturnsNamespaceExistsOnExi StorageInterfaceImpl storage; auto opCtx = getOperationContext(); - createCollection(opCtx, NamespaceString(StorageInterfaceImpl::kDefaultRollbackIdNamespace)); + createCollection(opCtx, + NamespaceString::createNamespaceString_forTest( + StorageInterfaceImpl::kDefaultRollbackIdNamespace)); ASSERT_EQUALS(ErrorCodes::NamespaceExists, storage.initializeRollbackID(opCtx)); } @@ -300,7 +303,8 @@ void _assertDocumentsInCollectionEquals(OperationContext* opCtx, void _assertRollbackIDDocument(OperationContext* opCtx, int id) { _assertDocumentsInCollectionEquals( opCtx, - NamespaceString(StorageInterfaceImpl::kDefaultRollbackIdNamespace), + NamespaceString::createNamespaceString_forTest( + StorageInterfaceImpl::kDefaultRollbackIdNamespace), {BSON("_id" << StorageInterfaceImpl::kRollbackIdDocumentId << StorageInterfaceImpl::kRollbackIdFieldName << id)}); } @@ -333,7 +337,8 @@ TEST_F(StorageInterfaceImplTest, RollbackIdInitializesIncrementsAndReadsProperly TEST_F(StorageInterfaceImplTest, IncrementRollbackIDRollsToOneWhenExceedingMaxInt) { StorageInterfaceImpl storage; auto opCtx = getOperationContext(); - NamespaceString nss(StorageInterfaceImpl::kDefaultRollbackIdNamespace); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + StorageInterfaceImpl::kDefaultRollbackIdNamespace); createCollection(opCtx, nss); TimestampedBSONObj maxDoc = {BSON("_id" << StorageInterfaceImpl::kRollbackIdDocumentId << StorageInterfaceImpl::kRollbackIdFieldName @@ -361,7 +366,8 @@ TEST_F(StorageInterfaceImplTest, IncrementRollbackIDRollsToOneWhenExceedingMaxIn TEST_F(StorageInterfaceImplTest, GetRollbackIDReturnsBadStatusIfDocumentHasBadField) { StorageInterfaceImpl storage; auto opCtx = getOperationContext(); - NamespaceString nss(StorageInterfaceImpl::kDefaultRollbackIdNamespace); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + StorageInterfaceImpl::kDefaultRollbackIdNamespace); createCollection(opCtx, nss); @@ -376,7 +382,8 @@ TEST_F(StorageInterfaceImplTest, GetRollbackIDReturnsBadStatusIfDocumentHasBadFi TEST_F(StorageInterfaceImplTest, GetRollbackIDReturnsBadStatusIfRollbackIDIsNotInt) { StorageInterfaceImpl storage; auto opCtx = getOperationContext(); - NamespaceString nss(StorageInterfaceImpl::kDefaultRollbackIdNamespace); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + StorageInterfaceImpl::kDefaultRollbackIdNamespace); createCollection(opCtx, nss); @@ -653,7 +660,7 @@ TEST_F(StorageInterfaceImplTest, TEST_F(StorageInterfaceImplTest, CreateCollectionThatAlreadyExistsFails) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("test.foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.foo"); createCollection(opCtx, nss); const CollectionOptions opts = generateOptionsWithUuid(); @@ -666,7 +673,7 @@ TEST_F(StorageInterfaceImplTest, CreateCollectionThatAlreadyExistsFails) { TEST_F(StorageInterfaceImplTest, CreateOplogCreateCappedCollection) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("local.oplog.X"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.oplog.X"); { AutoGetCollectionForReadCommand autoColl(opCtx, nss); ASSERT_FALSE(autoColl.getCollection()); @@ -684,7 +691,7 @@ TEST_F(StorageInterfaceImplTest, CreateCollectionReturnsUserExceptionAsStatusIfCollectionCreationThrows) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("local.oplog.Y"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.oplog.Y"); { AutoGetCollectionForReadCommand autoColl(opCtx, nss); ASSERT_FALSE(autoColl.getCollection()); @@ -747,7 +754,7 @@ TEST_F(StorageInterfaceImplTest, DropCollectionWorksWithMissingCollection) { } TEST_F(StorageInterfaceImplTest, DropCollectionWorksWithSystemCollection) { - NamespaceString nss("local.system.mysyscoll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.system.mysyscoll"); ASSERT_TRUE(nss.isSystem()); // If we can create a system collection using the StorageInterface, we should be able to drop it @@ -766,7 +773,7 @@ TEST_F(StorageInterfaceImplTest, RenameCollectionWorksWhenCollectionExists) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto toNss = NamespaceString("local.toNs"); + auto toNss = NamespaceString::createNamespaceString_forTest("local.toNs"); createCollection(opCtx, nss); ASSERT_OK(storage.renameCollection(opCtx, nss, toNss, false)); @@ -782,7 +789,7 @@ TEST_F(StorageInterfaceImplTest, RenameCollectionWithStayTempFalseMakesItNotTemp auto opCtx = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto toNss = NamespaceString("local.toNs"); + auto toNss = NamespaceString::createNamespaceString_forTest("local.toNs"); CollectionOptions opts = generateOptionsWithUuid(); opts.temp = true; createCollection(opCtx, nss, opts); @@ -801,7 +808,7 @@ TEST_F(StorageInterfaceImplTest, RenameCollectionWithStayTempTrueMakesItTemp) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto toNss = NamespaceString("local.toNs"); + auto toNss = NamespaceString::createNamespaceString_forTest("local.toNs"); CollectionOptions opts = generateOptionsWithUuid(); opts.temp = true; createCollection(opCtx, nss, opts); @@ -820,7 +827,7 @@ TEST_F(StorageInterfaceImplTest, RenameCollectionFailsBetweenDatabases) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto toNss = NamespaceString("notLocal.toNs"); + auto toNss = NamespaceString::createNamespaceString_forTest("notLocal.toNs"); createCollection(opCtx, nss); ASSERT_EQ(ErrorCodes::InvalidNamespace, storage.renameCollection(opCtx, nss, toNss, false)); @@ -836,7 +843,7 @@ TEST_F(StorageInterfaceImplTest, RenameCollectionFailsWhenToCollectionAlreadyExi auto opCtx = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto toNss = NamespaceString("local.toNs"); + auto toNss = NamespaceString::createNamespaceString_forTest("local.toNs"); createCollection(opCtx, nss); createCollection(opCtx, toNss); @@ -853,7 +860,7 @@ TEST_F(StorageInterfaceImplTest, RenameCollectionFailsWhenFromCollectionDoesNotE auto opCtx = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto toNss = NamespaceString("local.toNs"); + auto toNss = NamespaceString::createNamespaceString_forTest("local.toNs"); ASSERT_EQ(ErrorCodes::NamespaceNotFound, storage.renameCollection(opCtx, nss, toNss, false)); @@ -2336,16 +2343,17 @@ TEST_F(StorageInterfaceImplTest, TEST_F(StorageInterfaceImplTest, FindSingletonReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("nosuchdb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("nosuchdb.coll"); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, storage.findSingleton(opCtx, nss).getStatus()); } TEST_F(StorageInterfaceImplTest, FindSingletonReturnsNamespaceNotFoundWhenCollectionDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("db.coll1"); - ASSERT_OK( - storage.createCollection(opCtx, NamespaceString("db.coll2"), generateOptionsWithUuid())); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("db.coll1"); + ASSERT_OK(storage.createCollection(opCtx, + NamespaceString::createNamespaceString_forTest("db.coll2"), + generateOptionsWithUuid())); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, storage.findSingleton(opCtx, nss).getStatus()); } @@ -2386,7 +2394,7 @@ TEST_F(StorageInterfaceImplTest, FindSingletonReturnsDocumentWhenSingletonDocume TEST_F(StorageInterfaceImplTest, PutSingletonReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("nosuchdb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("nosuchdb.coll"); TimestampedBSONObj update; update.obj = BSON("$set" << BSON("_id" << 0 << "x" << 1)); @@ -2398,7 +2406,7 @@ TEST_F(StorageInterfaceImplTest, PutSingletonReturnsNamespaceNotFoundWhenDatabas TEST_F(StorageInterfaceImplTest, PutSingletonReturnsNamespaceNotFoundWhenCollectionDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("db.coll1"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("db.coll1"); ASSERT_OK(storage.createCollection(opCtx, nss, generateOptionsWithUuid())); TimestampedBSONObj update; @@ -2406,7 +2414,8 @@ TEST_F(StorageInterfaceImplTest, PutSingletonReturnsNamespaceNotFoundWhenCollect update.timestamp = Timestamp(); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, - storage.putSingleton(opCtx, NamespaceString("db.coll2"), update)); + storage.putSingleton( + opCtx, NamespaceString::createNamespaceString_forTest("db.coll2"), update)); } TEST_F(StorageInterfaceImplTest, PutSingletonUpsertsDocumentsWhenCollectionIsEmpty) { @@ -2511,7 +2520,7 @@ TEST_F(StorageInterfaceImplTest, FindByIdThrowsIfUUIDNotInCatalog) { TEST_F(StorageInterfaceImplTest, FindByIdReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("nosuchdb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("nosuchdb.coll"); auto doc = BSON("_id" << 0 << "x" << 0); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, storage.findById(opCtx, nss, doc["_id"]).getStatus()); @@ -2603,7 +2612,7 @@ TEST_F(StorageInterfaceImplTest, DeleteByIdThrowsIfUUIDNotInCatalog) { TEST_F(StorageInterfaceImplTest, DeleteByIdReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("nosuchdb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("nosuchdb.coll"); auto doc = BSON("_id" << 0 << "x" << 0); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, storage.deleteById(opCtx, nss, doc["_id"]).getStatus()); @@ -2678,7 +2687,7 @@ TEST_F(StorageInterfaceImplTest, UpsertSingleDocumentReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("nosuchdb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("nosuchdb.coll"); auto doc = BSON("_id" << 0 << "x" << 1); auto status = storage.upsertById(opCtx, nss, doc["_id"], doc); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, status); @@ -2688,7 +2697,7 @@ TEST_F(StorageInterfaceImplTest, UpsertSingleDocumentReturnsNamespaceNotFoundWhenCollectionDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("mydb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("mydb.coll"); NamespaceString wrongColl(nss.db(), "wrongColl"_sd); ASSERT_OK(storage.createCollection(opCtx, nss, generateOptionsWithUuid())); auto doc = BSON("_id" << 0 << "x" << 1); @@ -2771,7 +2780,8 @@ TEST_F(StorageInterfaceImplTest, UpsertSingleDocumentReplacesExistingDocumentInIllegalClientSystemNamespace) { // Checks that we can update collections with namespaces not considered "legal client system" // namespaces. - NamespaceString nss("local.system.rollback.docs"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("local.system.rollback.docs"); ASSERT_FALSE(nss.isLegalClientSystemNS(serverGlobalParams.featureCompatibility)); auto opCtx = getOperationContext(); @@ -2872,7 +2882,7 @@ TEST_F(StorageInterfaceImplTest, TEST_F(StorageInterfaceImplTest, DeleteByFilterReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("nosuchdb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("nosuchdb.coll"); auto filter = BSON("x" << 1); auto status = storage.deleteByFilter(opCtx, nss, filter); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, status); @@ -2914,7 +2924,7 @@ TEST_F( DeleteByFilterReturnsPrimarySteppedDownWhenCurrentMemberStateIsRollbackAndReplicatedWritesAreEnabled) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("mydb.mycoll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("mydb.mycoll"); ASSERT_OK(storage.createCollection(opCtx, nss, generateOptionsWithUuid())); auto doc = BSON("_id" << 0 << "x" << 0); @@ -2940,7 +2950,7 @@ TEST_F( DeleteByFilterReturnsPrimarySteppedDownWhenReplicationCoordinatorCannotAcceptWritesAndReplicatedWritesAreEnabled) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("mydb.mycoll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("mydb.mycoll"); ASSERT_OK(storage.createCollection(opCtx, nss, generateOptionsWithUuid())); auto doc = BSON("_id" << 0 << "x" << 0); @@ -2964,7 +2974,7 @@ TEST_F( TEST_F(StorageInterfaceImplTest, DeleteByFilterReturnsNamespaceNotFoundWhenCollectionDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("mydb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("mydb.coll"); NamespaceString wrongColl(nss.db(), "wrongColl"_sd); ASSERT_OK(storage.createCollection(opCtx, nss, generateOptionsWithUuid())); auto filter = BSON("x" << 1); @@ -3063,7 +3073,8 @@ TEST_F(StorageInterfaceImplTest, DeleteByFilterUsesIdHackIfFilterContainsIdField TEST_F(StorageInterfaceImplTest, DeleteByFilterRemovesDocumentsInIllegalClientSystemNamespace) { // Checks that we can remove documents from collections with namespaces not considered "legal // client system" namespaces. - NamespaceString nss("local.system.rollback.docs"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("local.system.rollback.docs"); ASSERT_FALSE(nss.isLegalClientSystemNS(serverGlobalParams.featureCompatibility)); auto opCtx = getOperationContext(); @@ -3124,7 +3135,7 @@ TEST_F(StorageInterfaceImplTest, GetCollectionCountReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("nosuchdb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("nosuchdb.coll"); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, storage.getCollectionCount(opCtx, nss).getStatus()); } @@ -3168,7 +3179,7 @@ TEST_F(StorageInterfaceImplTest, SetCollectionCountReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) { auto opCtx = getOperationContext(); StorageInterfaceImpl storage; - NamespaceString nss("nosuchdb.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("nosuchdb.coll"); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, storage.setCollectionCount(opCtx, nss, 3)); } diff --git a/src/mongo/db/repl/storage_timestamp_test.cpp b/src/mongo/db/repl/storage_timestamp_test.cpp index 33d35d4a884..768f6e23616 100644 --- a/src/mongo/db/repl/storage_timestamp_test.cpp +++ b/src/mongo/db/repl/storage_timestamp_test.cpp @@ -104,7 +104,7 @@ Status createIndexFromSpec(OperationContext* opCtx, VectorClockMutable* clock, StringData ns, const BSONObj& spec) { - NamespaceString nss(ns); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(ns); // Make sure we haven't already locked this namespace. An AutoGetCollection already instantiated // on this namespace would have a dangling Collection pointer after this function has run. @@ -118,7 +118,7 @@ Status createIndexFromSpec(OperationContext* opCtx, if (!coll) { auto db = autoDb.ensureDbExists(opCtx); invariant(db); - coll = db->createCollection(opCtx, NamespaceString(ns)); + coll = db->createCollection(opCtx, NamespaceString::createNamespaceString_forTest(ns)); } invariant(coll); wunit.commit(); @@ -813,7 +813,8 @@ TEST_F(StorageTimestampTest, SecondaryInsertTimes) { repl::UnreplicatedWritesBlock uwb(_opCtx); // Create a new collection. - NamespaceString nss("unittests.timestampedUpdates"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampedUpdates"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX); @@ -859,7 +860,8 @@ TEST_F(StorageTimestampTest, SecondaryArrayInsertTimes) { DisableDocumentValidation validationDisabler(_opCtx); // Create a new collection. - NamespaceString nss("unittests.timestampedUpdates"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampedUpdates"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX); @@ -916,7 +918,8 @@ TEST_F(StorageTimestampTest, SecondaryDeleteTimes) { repl::UnreplicatedWritesBlock uwb(_opCtx); // Create a new collection. - NamespaceString nss("unittests.timestampedDeletes"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampedDeletes"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX); @@ -961,7 +964,8 @@ TEST_F(StorageTimestampTest, SecondaryUpdateTimes) { repl::UnreplicatedWritesBlock uwb(_opCtx); // Create a new collection. - NamespaceString nss("unittests.timestampedUpdates"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampedUpdates"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX); @@ -1036,7 +1040,8 @@ TEST_F(StorageTimestampTest, SecondaryInsertToUpsert) { repl::UnreplicatedWritesBlock uwb(_opCtx); // Create a new collection. - NamespaceString nss("unittests.insertToUpsert"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.insertToUpsert"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX); @@ -1085,7 +1090,8 @@ TEST_F(StorageTimestampTest, SecondaryCreateCollection) { // In order for applyOps to assign timestamps, we must be in non-replicated mode. repl::UnreplicatedWritesBlock uwb(_opCtx); - NamespaceString nss("unittests.secondaryCreateCollection"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.secondaryCreateCollection"); ASSERT_OK(repl::StorageInterface::get(_opCtx)->dropCollection(_opCtx, nss)); { ASSERT_FALSE(AutoGetCollectionForReadCommand(_opCtx, nss).getCollection()); } @@ -1114,8 +1120,10 @@ TEST_F(StorageTimestampTest, SecondaryCreateTwoCollections) { repl::UnreplicatedWritesBlock uwb(_opCtx); std::string dbName = "unittest"; - NamespaceString nss1(dbName, "secondaryCreateTwoCollections1"); - NamespaceString nss2(dbName, "secondaryCreateTwoCollections2"); + NamespaceString nss1 = + NamespaceString::createNamespaceString_forTest(dbName, "secondaryCreateTwoCollections1"); + NamespaceString nss2 = + NamespaceString::createNamespaceString_forTest(dbName, "secondaryCreateTwoCollections2"); ASSERT_OK(repl::StorageInterface::get(_opCtx)->dropCollection(_opCtx, nss1)); ASSERT_OK(repl::StorageInterface::get(_opCtx)->dropCollection(_opCtx, nss2)); @@ -1161,8 +1169,10 @@ TEST_F(StorageTimestampTest, SecondaryCreateCollectionBetweenInserts) { repl::UnreplicatedWritesBlock uwb(_opCtx); std::string dbName = "unittest"; - NamespaceString nss1(dbName, "secondaryCreateCollectionBetweenInserts1"); - NamespaceString nss2(dbName, "secondaryCreateCollectionBetweenInserts2"); + NamespaceString nss1 = NamespaceString::createNamespaceString_forTest( + dbName, "secondaryCreateCollectionBetweenInserts1"); + NamespaceString nss2 = NamespaceString::createNamespaceString_forTest( + dbName, "secondaryCreateCollectionBetweenInserts2"); BSONObj doc1 = BSON("_id" << 1 << "field" << 1); BSONObj doc2 = BSON("_id" << 2 << "field" << 2); @@ -1234,7 +1244,8 @@ TEST_F(StorageTimestampTest, SecondaryCreateCollectionBetweenInserts) { } TEST_F(StorageTimestampTest, PrimaryCreateCollectionInApplyOps) { - NamespaceString nss("unittests.primaryCreateCollectionInApplyOps"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "unittests.primaryCreateCollectionInApplyOps"); ASSERT_OK(repl::StorageInterface::get(_opCtx)->dropCollection(_opCtx, nss)); { ASSERT_FALSE(AutoGetCollectionForReadCommand(_opCtx, nss).getCollection()); } @@ -1272,7 +1283,8 @@ TEST_F(StorageTimestampTest, SecondarySetIndexMultikeyOnInsert) { // Pretend to be a secondary. repl::UnreplicatedWritesBlock uwb(_opCtx); - NamespaceString nss("unittests.SecondarySetIndexMultikeyOnInsert"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "unittests.SecondarySetIndexMultikeyOnInsert"); create(nss); UUID uuid = UUID::gen(); { @@ -1337,7 +1349,8 @@ TEST_F(StorageTimestampTest, SecondarySetWildcardIndexMultikeyOnInsert) { // Pretend to be a secondary. repl::UnreplicatedWritesBlock uwb(_opCtx); - NamespaceString nss("unittests.SecondarySetWildcardIndexMultikeyOnInsert"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "unittests.SecondarySetWildcardIndexMultikeyOnInsert"); // Use a capped collection to prevent the batch applier from grouping insert operations // together in the same WUOW. This test attempts to apply operations out of order, but the // storage engine does not allow an operation to set out-of-order timestamps in the same @@ -1440,7 +1453,8 @@ TEST_F(StorageTimestampTest, SecondarySetWildcardIndexMultikeyOnUpdate) { // Pretend to be a secondary. repl::UnreplicatedWritesBlock uwb(_opCtx); - NamespaceString nss("unittests.SecondarySetWildcardIndexMultikeyOnUpdate"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "unittests.SecondarySetWildcardIndexMultikeyOnUpdate"); create(nss); UUID uuid = UUID::gen(); { @@ -1535,7 +1549,8 @@ TEST_F(StorageTimestampTest, SecondarySetWildcardIndexMultikeyOnUpdate) { } TEST_F(StorageTimestampTest, PrimarySetIndexMultikeyOnInsert) { - NamespaceString nss("unittests.PrimarySetIndexMultikeyOnInsert"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.PrimarySetIndexMultikeyOnInsert"); create(nss); auto indexName = "a_1"; @@ -1561,7 +1576,8 @@ TEST_F(StorageTimestampTest, PrimarySetIndexMultikeyOnInsert) { TEST_F(StorageTimestampTest, PrimarySetIndexMultikeyOnInsertUnreplicated) { // Use an unreplicated collection. repl::UnreplicatedWritesBlock noRep(_opCtx); - NamespaceString nss("unittests.system.profile"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.system.profile"); create(nss); auto indexName = "a_1"; @@ -1591,7 +1607,8 @@ TEST_F(StorageTimestampTest, PrimarySetsMultikeyInsideMultiDocumentTransaction) auto mongoDSessionCatalog = MongoDSessionCatalog::get(_opCtx); mongoDSessionCatalog->onStepUp(_opCtx); - NamespaceString nss("unittests.PrimarySetsMultikeyInsideMultiDocumentTransaction"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "unittests.PrimarySetsMultikeyInsideMultiDocumentTransaction"); create(nss); auto indexName = "a_1"; @@ -1669,7 +1686,8 @@ TEST_F(StorageTimestampTest, PrimarySetsMultikeyInsideMultiDocumentTransaction) } TEST_F(StorageTimestampTest, InitializeMinValid) { - NamespaceString nss(repl::ReplicationConsistencyMarkersImpl::kDefaultMinValidNamespace); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + repl::ReplicationConsistencyMarkersImpl::kDefaultMinValidNamespace); create(nss); repl::ReplicationConsistencyMarkersImpl consistencyMarkers(repl::StorageInterface::get(_opCtx)); @@ -1686,7 +1704,8 @@ TEST_F(StorageTimestampTest, InitializeMinValid) { } TEST_F(StorageTimestampTest, SetMinValidInitialSyncFlag) { - NamespaceString nss(repl::ReplicationConsistencyMarkersImpl::kDefaultMinValidNamespace); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + repl::ReplicationConsistencyMarkersImpl::kDefaultMinValidNamespace); create(nss); repl::ReplicationConsistencyMarkersImpl consistencyMarkers(repl::StorageInterface::get(_opCtx)); @@ -1711,7 +1730,8 @@ TEST_F(StorageTimestampTest, SetMinValidInitialSyncFlag) { } TEST_F(StorageTimestampTest, SetMinValidAppliedThrough) { - NamespaceString nss(repl::ReplicationConsistencyMarkersImpl::kDefaultMinValidNamespace); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + repl::ReplicationConsistencyMarkersImpl::kDefaultMinValidNamespace); create(nss); repl::ReplicationConsistencyMarkersImpl consistencyMarkers(repl::StorageInterface::get(_opCtx)); @@ -1765,7 +1785,8 @@ public: // This test drops collections piece-wise instead of having the "drop database" algorithm // perform this walk. Defensively operate on a separate DB from the other tests to ensure // no leftover collections carry-over. - const NamespaceString nss("unittestsDropDB.kvDropDatabase"); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittestsDropDB.kvDropDatabase"); const NamespaceString sysProfile("unittestsDropDB.system.profile"); std::string collIdent; @@ -1889,7 +1910,8 @@ public: auto storageEngine = _opCtx->getServiceContext()->getStorageEngine(); auto durableCatalog = storageEngine->getCatalog(); - NamespaceString nss("unittests.timestampIndexBuilds"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampIndexBuilds"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X); @@ -2034,7 +2056,8 @@ TEST_F(StorageTimestampTest, TimestampMultiIndexBuilds) { NamespaceString::kIndexBuildEntryNamespace.dbName(), BSON("create" << NamespaceString::kIndexBuildEntryNamespace.coll()))); - NamespaceString nss("unittests.timestampMultiIndexBuilds"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampMultiIndexBuilds"); create(nss); std::vector origIdents; @@ -2138,7 +2161,8 @@ TEST_F(StorageTimestampTest, TimestampMultiIndexBuildsDuringRename) { auto storageEngine = _opCtx->getServiceContext()->getStorageEngine(); auto durableCatalog = storageEngine->getCatalog(); - NamespaceString nss("unittests.timestampMultiIndexBuildsDuringRename"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "unittests.timestampMultiIndexBuildsDuringRename"); create(nss); { @@ -2202,7 +2226,7 @@ TEST_F(StorageTimestampTest, TimestampMultiIndexBuildsDuringRename) { << "b_1")); const auto tmpCollName = createIndexesDocument.getObjectField("o").getStringField("createIndexes"); - tmpName = NamespaceString(renamedNss.db(), tmpCollName); + tmpName = NamespaceString::createNamespaceString_forTest(renamedNss.db(), tmpCollName); indexCommitTs = createIndexesDocument["ts"].timestamp(); const Timestamp indexCreateInitTs = queryOplog(BSON("op" << "c" @@ -2252,7 +2276,8 @@ TEST_F(StorageTimestampTest, TimestampAbortIndexBuild) { NamespaceString::kIndexBuildEntryNamespace.dbName(), BSON("create" << NamespaceString::kIndexBuildEntryNamespace.coll()))); - NamespaceString nss("unittests.timestampAbortIndexBuild"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampAbortIndexBuild"); create(nss); std::vector origIdents; @@ -2355,7 +2380,8 @@ TEST_F(StorageTimestampTest, TimestampIndexDropsWildcard) { auto storageEngine = _opCtx->getServiceContext()->getStorageEngine(); auto durableCatalog = storageEngine->getCatalog(); - NamespaceString nss("unittests.timestampIndexDrops"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampIndexDrops"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X); @@ -2426,7 +2452,8 @@ TEST_F(StorageTimestampTest, TimestampIndexDropsListed) { auto storageEngine = _opCtx->getServiceContext()->getStorageEngine(); auto durableCatalog = storageEngine->getCatalog(); - NamespaceString nss("unittests.timestampIndexDrops"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampIndexDrops"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X); @@ -2568,7 +2595,8 @@ Status SecondaryReadsDuringBatchApplicationAreAllowedApplier::applyOplogBatchPer } TEST_F(StorageTimestampTest, IndexBuildsResolveErrorsDuringStateChangeToPrimary) { - NamespaceString nss("unittests.timestampIndexBuilds"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampIndexBuilds"); create(nss); AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X); @@ -2721,7 +2749,8 @@ TEST_F(StorageTimestampTest, IndexBuildsResolveErrorsDuringStateChangeToPrimary) TEST_F(StorageTimestampTest, SecondaryReadsDuringBatchApplicationAreAllowed) { ASSERT(_opCtx->getServiceContext()->getStorageEngine()->supportsReadConcernSnapshot()); - NamespaceString ns("unittest.secondaryReadsDuringBatchApplicationAreAllowed"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest( + "unittest.secondaryReadsDuringBatchApplicationAreAllowed"); create(ns); UUID uuid = UUID::gen(); { @@ -2812,7 +2841,8 @@ TEST_F(StorageTimestampTest, TimestampIndexOplogApplicationOnPrimary) { DisableDocumentValidation validationDisabler(_opCtx); std::string dbName = "unittest"; - NamespaceString nss(dbName, "oplogApplicationOnPrimary"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(dbName, "oplogApplicationOnPrimary"); BSONObj doc = BSON("_id" << 1 << "field" << 1); const LogicalTime setupStart = _clock->tickClusterTime(1); @@ -2925,7 +2955,8 @@ TEST_F(StorageTimestampTest, ViewCreationSeparateTransaction) { const NamespaceString backingCollNss("unittests.backingColl"); create(backingCollNss); - const NamespaceString viewNss("unittests.view"); + const NamespaceString viewNss = + NamespaceString::createNamespaceString_forTest("unittests.view"); const NamespaceString systemViewsNss = NamespaceString::makeSystemDotViewsNamespace({boost::none, "unittests"}); @@ -2970,7 +3001,7 @@ TEST_F(StorageTimestampTest, ViewCreationSeparateTransaction) { } TEST_F(StorageTimestampTest, CreateCollectionWithSystemIndex) { - NamespaceString nss("admin.system.users"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("admin.system.users"); { ASSERT_FALSE(AutoGetCollectionForReadCommand(_opCtx, nss).getCollection()); } @@ -3050,7 +3081,8 @@ TEST_F(StorageTimestampTest, MultipleTimestampsForMultikeyWrites) { NamespaceString::kIndexBuildEntryNamespace.dbName(), BSON("create" << NamespaceString::kIndexBuildEntryNamespace.coll()))); - NamespaceString nss("unittests.timestampVectoredInsertMultikey"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.timestampVectoredInsertMultikey"); create(nss); { diff --git a/src/mongo/db/repl/sync_source_resolver_test.cpp b/src/mongo/db/repl/sync_source_resolver_test.cpp index 2b7a822ec05..45b0a05a1ea 100644 --- a/src/mongo/db/repl/sync_source_resolver_test.cpp +++ b/src/mongo/db/repl/sync_source_resolver_test.cpp @@ -127,7 +127,7 @@ std::unique_ptr SyncSourceResolverTest::_makeResolver( [this](const SyncSourceResolverResponse& response) { _onCompletion(response); }); } -const NamespaceString nss("local.oplog.rs"); +const NamespaceString nss = NamespaceString::createNamespaceString_forTest("local.oplog.rs"); const OpTime requiredOpTime(Timestamp(200, 1U), 1LL); class SyncSourceResolverRequiredOpTimeTest : public SyncSourceResolverTest { @@ -311,18 +311,18 @@ void _scheduleFirstOplogEntryFetcherResponse(executor::NetworkInterfaceMock* net * Generates oplog entries with the given optime. */ BSONObj _makeOplogEntry(Timestamp ts, long long term) { - return DurableOplogEntry(OpTime(ts, term), // optime - OpTypeEnum::kNoop, // op type - NamespaceString("a.a"), // namespace - boost::none, // uuid - boost::none, // fromMigrate - repl::OplogEntry::kOplogVersion, // version - BSONObj(), // o - boost::none, // o2 - {}, // sessionInfo - boost::none, // upsert - Date_t(), // wall clock time - {}, // statement ids + return DurableOplogEntry(OpTime(ts, term), // optime + OpTypeEnum::kNoop, // op type + NamespaceString::createNamespaceString_forTest("a.a"), // namespace + boost::none, // uuid + boost::none, // fromMigrate + repl::OplogEntry::kOplogVersion, // version + BSONObj(), // o + boost::none, // o2 + {}, // sessionInfo + boost::none, // upsert + Date_t(), // wall clock time + {}, // statement ids boost::none, // optime of previous write within same transaction boost::none, // pre-image optime boost::none, // post-image optime diff --git a/src/mongo/db/repl/tenant_all_database_cloner_test.cpp b/src/mongo/db/repl/tenant_all_database_cloner_test.cpp index f601d8cb5fe..03712296681 100644 --- a/src/mongo/db/repl/tenant_all_database_cloner_test.cpp +++ b/src/mongo/db/repl/tenant_all_database_cloner_test.cpp @@ -363,7 +363,8 @@ TEST_F(TenantAllDatabaseClonerTest, ListDatabasesRecordsCorrectOperationTime) { TEST_F(TenantAllDatabaseClonerTest, TenantDatabasesAlreadyExist) { // Test that cloner should fail if tenant databases already exist on the recipient prior to // starting cloning phase of the migration. - ASSERT_OK(createCollection(NamespaceString(_tenantDbA, "coll"), CollectionOptions())); + ASSERT_OK(createCollection(NamespaceString::createNamespaceString_forTest(_tenantDbA, "coll"), + CollectionOptions())); auto listDatabasesReply = "{ok:1, databases:[{name:'" + _tenantDbA + "'}, {name:'" + _tenantDbAAB + "'}]}"; @@ -377,8 +378,8 @@ TEST_F(TenantAllDatabaseClonerTest, TenantDatabasesAlreadyExist) { TEST_F(TenantAllDatabaseClonerTest, ResumingFromLastClonedDb) { // Test that all databases cloner correctly resumes from the last cloned database. - auto nssDbA = NamespaceString(_tenantDbA, "coll"); - auto nssDbAAb = NamespaceString(_tenantDbAAB, "coll"); + auto nssDbA = NamespaceString::createNamespaceString_forTest(_tenantDbA, "coll"); + auto nssDbAAb = NamespaceString::createNamespaceString_forTest(_tenantDbAAB, "coll"); ASSERT_OK(createCollection(nssDbA, CollectionOptions())); ASSERT_OK(createCollection(nssDbAAb, CollectionOptions())); @@ -425,7 +426,7 @@ TEST_F(TenantAllDatabaseClonerTest, LastClonedDbDeleted_AllGreater) { // Test that we correctly resume from next database compared greater than the last cloned // database if the last cloned database is dropped. This tests the case when all databases in // the latest listDatabases result are compared greater than the last cloned database. - auto nssDbA = NamespaceString(_tenantDbA, "coll"); + auto nssDbA = NamespaceString::createNamespaceString_forTest(_tenantDbA, "coll"); ASSERT_OK(createCollection(nssDbA, CollectionOptions())); long long size = 0; @@ -469,8 +470,8 @@ TEST_F(TenantAllDatabaseClonerTest, LastClonedDbDeleted_SomeGreater) { // database if the last cloned database is dropped. This tests the case when some but not all // databases in the latest listDatabases result are compared greater than the last cloned // database. - auto nssDbA = NamespaceString(_tenantDbA, "coll"); - auto nssDbAAb = NamespaceString(_tenantDbAAB, "coll"); + auto nssDbA = NamespaceString::createNamespaceString_forTest(_tenantDbA, "coll"); + auto nssDbAAb = NamespaceString::createNamespaceString_forTest(_tenantDbAAB, "coll"); ASSERT_OK(createCollection(nssDbA, CollectionOptions())); ASSERT_OK(createCollection(nssDbAAb, CollectionOptions())); @@ -524,9 +525,9 @@ TEST_F(TenantAllDatabaseClonerTest, LastClonedDbDeleted_AllLess) { // Test that we correctly resume from next database compared greater than the last cloned // database if the last cloned database is dropped. This tests the case when all databases in // the latest listDatabases result are compared less than the last cloned database. - auto nssDbA = NamespaceString(_tenantDbA, "coll"); - auto nssDbAAb = NamespaceString(_tenantDbAAB, "coll"); - auto nssDbABC = NamespaceString(_tenantDbABC, "coll"); + auto nssDbA = NamespaceString::createNamespaceString_forTest(_tenantDbA, "coll"); + auto nssDbAAb = NamespaceString::createNamespaceString_forTest(_tenantDbAAB, "coll"); + auto nssDbABC = NamespaceString::createNamespaceString_forTest(_tenantDbABC, "coll"); ASSERT_OK(createCollection(nssDbA, CollectionOptions())); ASSERT_OK(createCollection(nssDbAAb, CollectionOptions())); diff --git a/src/mongo/db/repl/tenant_collection_cloner_test.cpp b/src/mongo/db/repl/tenant_collection_cloner_test.cpp index 376c2aa2acf..b67586bd5e7 100644 --- a/src/mongo/db/repl/tenant_collection_cloner_test.cpp +++ b/src/mongo/db/repl/tenant_collection_cloner_test.cpp @@ -204,7 +204,8 @@ protected: << "a_1"), BSON("v" << 1 << "key" << BSON("b" << 1) << "name" << "b_1")}; - const NamespaceString _nss = {_tenantId + "_testDb", "testcoll"}; + const NamespaceString _nss = + NamespaceString::createNamespaceString_forTest(_tenantId + "_testDb", "testcoll"); }; TEST_F(TenantCollectionClonerTest, CountStage) { @@ -964,7 +965,8 @@ TEST_F(TenantCollectionClonerTest, ResumeFromRenamedCollection) { auto cloner = makeCollectionCloner(CollectionOptions(), &resumingSharedData); // Simulate that the collection already exists under a different name with no index and no data. - const NamespaceString oldNss = {_nss.db(), "testcoll_old"}; + const NamespaceString oldNss = + NamespaceString::createNamespaceString_forTest(_nss.db(), "testcoll_old"); ASSERT_OK(createCollection(oldNss, _options)); _mockServer->setCommandReply("count", createCountResponse(1)); diff --git a/src/mongo/db/repl/tenant_database_cloner_test.cpp b/src/mongo/db/repl/tenant_database_cloner_test.cpp index 5e59d0fcc1e..9f0d0ef7a3b 100644 --- a/src/mongo/db/repl/tenant_database_cloner_test.cpp +++ b/src/mongo/db/repl/tenant_database_cloner_test.cpp @@ -169,9 +169,9 @@ TEST_F(TenantDatabaseClonerTest, ListCollections) { auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(2U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid1), collections[0].second.toBSON()); - ASSERT_EQ(NamespaceString(_dbName, "b"), collections[1].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), collections[1].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid2), collections[1].second.toBSON()); } @@ -212,9 +212,9 @@ TEST_F(TenantDatabaseClonerTest, ListCollectionsAllowsExtraneousFields) { auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(2U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "a"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "a"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid1), collections[0].second.toBSON()); - ASSERT_EQ(NamespaceString(_dbName, "b"), collections[1].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), collections[1].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid2), collections[1].second.toBSON()); } @@ -522,11 +522,11 @@ TEST_F(TenantDatabaseClonerTest, CreateCollections) { ASSERT_EQUALS(2U, _collections.size()); - auto collInfo = _collections[NamespaceString{_dbName, "a"}]; + auto collInfo = _collections[NamespaceString::createNamespaceString_forTest(_dbName, "a")]; ASSERT(collInfo.collCreated); ASSERT_EQUALS(0, collInfo.numDocsInserted); - collInfo = _collections[NamespaceString{_dbName, "b"}]; + collInfo = _collections[NamespaceString::createNamespaceString_forTest(_dbName, "b")]; ASSERT(collInfo.collCreated); ASSERT_EQUALS(0, collInfo.numDocsInserted); } @@ -641,7 +641,8 @@ TEST_F(TenantDatabaseClonerTest, TenantCollectionsAlreadyExist) { CollectionOptions options; options.uuid = uuid; - ASSERT_OK(createCollection(NamespaceString(_dbName, "a"), options)); + ASSERT_OK( + createCollection(NamespaceString::createNamespaceString_forTest(_dbName, "a"), options)); auto cloner = makeDatabaseCloner(); cloner->setStopAfterStage_forTest("listExistingCollections"); @@ -666,8 +667,8 @@ TEST_F(TenantDatabaseClonerTest, ResumingFromLastClonedCollection) { uuid.push_back(UUID::gen()); std::sort(uuid.begin(), uuid.end()); - auto aNss = NamespaceString(_dbName, "a"); - auto bNss = NamespaceString(_dbName, "b"); + auto aNss = NamespaceString::createNamespaceString_forTest(_dbName, "a"); + auto bNss = NamespaceString::createNamespaceString_forTest(_dbName, "b"); CollectionOptions options; options.uuid = uuid[0]; ASSERT_OK(createCollection(aNss, options)); @@ -720,7 +721,7 @@ TEST_F(TenantDatabaseClonerTest, ResumingFromLastClonedCollection) { auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(1U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "b"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid[1]), collections[0].second.toBSON()); auto stats = cloner->getStats(); @@ -739,7 +740,7 @@ TEST_F(TenantDatabaseClonerTest, LastClonedCollectionDeleted_AllGreater) { uuid.push_back(UUID::gen()); std::sort(uuid.begin(), uuid.end()); - auto aNss = NamespaceString(_dbName, "a"); + auto aNss = NamespaceString::createNamespaceString_forTest(_dbName, "a"); CollectionOptions options; options.uuid = uuid[0]; ASSERT_OK(createCollection(aNss, options)); @@ -784,9 +785,9 @@ TEST_F(TenantDatabaseClonerTest, LastClonedCollectionDeleted_AllGreater) { auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(2U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "b"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "b"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid[1]), collections[0].second.toBSON()); - ASSERT_EQ(NamespaceString(_dbName, "c"), collections[1].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "c"), collections[1].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid[2]), collections[1].second.toBSON()); auto stats = cloner->getStats(); @@ -805,8 +806,8 @@ TEST_F(TenantDatabaseClonerTest, LastClonedCollectionDeleted_SomeGreater) { uuid.push_back(UUID::gen()); std::sort(uuid.begin(), uuid.end()); - auto aNss = NamespaceString(_dbName, "a"); - auto bNss = NamespaceString(_dbName, "b"); + auto aNss = NamespaceString::createNamespaceString_forTest(_dbName, "a"); + auto bNss = NamespaceString::createNamespaceString_forTest(_dbName, "b"); CollectionOptions options; options.uuid = uuid[0]; ASSERT_OK(createCollection(aNss, options)); @@ -863,7 +864,7 @@ TEST_F(TenantDatabaseClonerTest, LastClonedCollectionDeleted_SomeGreater) { auto collections = getCollectionsFromCloner(cloner.get()); ASSERT_EQUALS(1U, collections.size()); - ASSERT_EQ(NamespaceString(_dbName, "c"), collections[0].first); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest(_dbName, "c"), collections[0].first); ASSERT_BSONOBJ_EQ(BSON("uuid" << uuid[2]), collections[0].second.toBSON()); auto stats = cloner->getStats(); @@ -882,9 +883,9 @@ TEST_F(TenantDatabaseClonerTest, LastClonedCollectionDeleted_AllLess) { uuid.push_back(UUID::gen()); std::sort(uuid.begin(), uuid.end()); - auto aNss = NamespaceString(_dbName, "a"); - auto bNss = NamespaceString(_dbName, "b"); - auto cNss = NamespaceString(_dbName, "c"); + auto aNss = NamespaceString::createNamespaceString_forTest(_dbName, "a"); + auto bNss = NamespaceString::createNamespaceString_forTest(_dbName, "b"); + auto cNss = NamespaceString::createNamespaceString_forTest(_dbName, "c"); CollectionOptions options; options.uuid = uuid[0]; ASSERT_OK(createCollection(aNss, options)); diff --git a/src/mongo/db/repl/tenant_migration_access_blocker_util_test.cpp b/src/mongo/db/repl/tenant_migration_access_blocker_util_test.cpp index f90159472a6..29eea68119c 100644 --- a/src/mongo/db/repl/tenant_migration_access_blocker_util_test.cpp +++ b/src/mongo/db/repl/tenant_migration_access_blocker_util_test.cpp @@ -222,29 +222,38 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, TestValidateNssBeingMigrated) { // No tenantId should work for an adminDB. tenant_migration_access_blocker::validateNssIsBeingMigrated( - boost::none, NamespaceString{NamespaceString::kAdminDb, "test"}, UUID::gen()); + boost::none, + NamespaceString::createNamespaceString_forTest(NamespaceString::kAdminDb, "test"), + UUID::gen()); // No tenantId will throw if it's not an adminDB. ASSERT_THROWS_CODE(tenant_migration_access_blocker::validateNssIsBeingMigrated( - boost::none, NamespaceString{"foo", "test"}, migrationId), + boost::none, + NamespaceString::createNamespaceString_forTest("foo", "test"), + migrationId), DBException, ErrorCodes::InvalidTenantId); // A different tenantId will throw. ASSERT_THROWS_CODE(tenant_migration_access_blocker::validateNssIsBeingMigrated( - TenantId(OID::gen()), NamespaceString{"foo", "test"}, migrationId), + TenantId(OID::gen()), + NamespaceString::createNamespaceString_forTest("foo", "test"), + migrationId), DBException, ErrorCodes::InvalidTenantId); // A different migrationId will throw. - ASSERT_THROWS_CODE(tenant_migration_access_blocker::validateNssIsBeingMigrated( - kTenantId, NamespaceString{"foo", "test"}, UUID::gen()), - DBException, - ErrorCodes::InvalidTenantId); + ASSERT_THROWS_CODE( + tenant_migration_access_blocker::validateNssIsBeingMigrated( + kTenantId, NamespaceString::createNamespaceString_forTest("foo", "test"), UUID::gen()), + DBException, + ErrorCodes::InvalidTenantId); // Finally everything works. tenant_migration_access_blocker::validateNssIsBeingMigrated( - kTenantId, NamespaceString{NamespaceString::kAdminDb, "test"}, migrationId); + kTenantId, + NamespaceString::createNamespaceString_forTest(NamespaceString::kAdminDb, "test"), + migrationId); } class RecoverAccessBlockerTest : public ServiceContextMongoDTest { diff --git a/src/mongo/db/repl/tenant_migration_recipient_service_shard_merge_test.cpp b/src/mongo/db/repl/tenant_migration_recipient_service_shard_merge_test.cpp index 658f7e50bf3..4ff527d62c9 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service_shard_merge_test.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service_shard_merge_test.cpp @@ -522,7 +522,8 @@ TEST_F(TenantMigrationRecipientServiceShardMergeTestInsert, TEST_F(TenantMigrationRecipientServiceShardMergeTest, CannotCreateServiceWithoutTenants) { const UUID migrationUUID = UUID::gen(); - const NamespaceString aggregateNs = NamespaceString("admin.$cmd.aggregate"); + const NamespaceString aggregateNs = + NamespaceString::createNamespaceString_forTest("admin.$cmd.aggregate"); MockReplicaSet replSet("donorSet", 3, true /* hasPrimary */, true /* dollarPrefixHosts */); @@ -547,7 +548,8 @@ TEST_F(TenantMigrationRecipientServiceShardMergeTest, OpenBackupCursorSuccessful stopFailPointEnableBlock fp("fpBeforeAdvancingStableTimestamp"); const UUID migrationUUID = UUID::gen(); const CursorId backupCursorId = 12345; - const NamespaceString aggregateNs = NamespaceString("admin.$cmd.aggregate"); + const NamespaceString aggregateNs = + NamespaceString::createNamespaceString_forTest("admin.$cmd.aggregate"); auto taskFp = globalFailPointRegistry().find("hangBeforeTaskCompletion"); auto initialTimesEntered = taskFp->setMode(FailPoint::alwaysOn); @@ -616,7 +618,8 @@ TEST_F(TenantMigrationRecipientServiceShardMergeTest, OpenBackupCursorAndRetries stopFailPointEnableBlock fp("fpBeforeAdvancingStableTimestamp"); const UUID migrationUUID = UUID::gen(); const CursorId backupCursorId = 12345; - const NamespaceString aggregateNs = NamespaceString("admin.$cmd.aggregate"); + const NamespaceString aggregateNs = + NamespaceString::createNamespaceString_forTest("admin.$cmd.aggregate"); auto taskFp = globalFailPointRegistry().find("hangBeforeTaskCompletion"); auto initialTimesEntered = taskFp->setMode(FailPoint::alwaysOn); diff --git a/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp b/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp index 9dd5bb422b0..091856b2654 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp @@ -1686,14 +1686,15 @@ TEST_F(TenantMigrationRecipientServiceTest, OplogFetcherResumesFromTopOfOplogBuf const auto oplogBuffer = getDonorOplogBuffer(instance.get()); OplogBuffer::Batch batch1; const OpTime resumeOpTime(Timestamp(2, 1), initialOpTime.getTerm()); - auto resumeOplogBson = makeOplogEntry(resumeOpTime, - OpTypeEnum::kInsert, - NamespaceString(tenantId + "_foo.bar"), - UUID::gen(), - BSON("doc" << 2), - boost::none /* o2 */) - .getEntry() - .toBSON(); + auto resumeOplogBson = + makeOplogEntry(resumeOpTime, + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"), + UUID::gen(), + BSON("doc" << 2), + boost::none /* o2 */) + .getEntry() + .toBSON(); batch1.push_back(resumeOplogBson); oplogBuffer->push(opCtx.get(), batch1.cbegin(), batch1.cend()); ASSERT_EQUALS(oplogBuffer->getCount(), 1); @@ -1719,12 +1720,13 @@ TEST_F(TenantMigrationRecipientServiceTest, OplogFetcherResumesFromTopOfOplogBuf hangAfterStartingOplogApplier->setMode(FailPoint::off); // Feed the oplog fetcher the last doc required for us to be considered consistent. - auto dataConsistentOplogEntry = makeOplogEntry(dataConsistentOpTime, - OpTypeEnum::kInsert, - NamespaceString(tenantId + "_foo.bar"), - UUID::gen(), - BSON("doc" << 3), - boost::none /* o2 */); + auto dataConsistentOplogEntry = + makeOplogEntry(dataConsistentOpTime, + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"), + UUID::gen(), + BSON("doc" << 3), + boost::none /* o2 */); oplogFetcher->receiveBatch( 1, {dataConsistentOplogEntry.getEntry().toBSON()}, dataConsistentOpTime.getTimestamp()); @@ -1817,7 +1819,7 @@ TEST_F(TenantMigrationRecipientServiceTest, OplogFetcherNoDocInBufferToResumeFro OplogFetcher::StartingPoint::kEnqueueFirstDoc); // Feed the oplog fetcher the last doc required for the recipient to be considered consistent. - const auto tenantNss = NamespaceString(tenantId + "_foo.bar"); + const auto tenantNss = NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"); auto resumeFetchingOplogEntry = makeOplogEntry(resumeFetchingOpTime, OpTypeEnum::kInsert, tenantNss, @@ -1911,7 +1913,7 @@ TEST_F(TenantMigrationRecipientServiceTest, OplogApplierResumesFromLastNoOpOplog } // Create and insert two tenant migration no-op entries into the oplog. The oplog applier should // resume from the no-op entry with the most recent donor opTime. - const auto insertNss = NamespaceString(tenantId + "_foo.bar"); + const auto insertNss = NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"); const auto earlierOplogBson = makeOplogEntry(earlierThanResumeOpTime, OpTypeEnum::kInsert, insertNss, @@ -2057,7 +2059,7 @@ TEST_F(TenantMigrationRecipientServiceTest, // 'fromTenantMigrate' field. This oplog entry does not satisfy the conditions // for the oplog applier to resume applying from so we default to apply from // 'startDonorApplyingOpTime'. - const auto insertNss = NamespaceString(tenantId + "_foo.bar"); + const auto insertNss = NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"); const auto beforeStartApplyingOpTime = OpTime(Timestamp(1, 1), 1); const auto entryBeforeStartApplyingOpTime = makeOplogEntry( beforeStartApplyingOpTime, @@ -2129,12 +2131,13 @@ TEST_F(TenantMigrationRecipientServiceTest, hangBeforeCreatingOplogApplier->setMode(FailPoint::off); hangAfterStartingOplogApplier->waitForTimesEntered(initialTimesEntered + 1); - auto dataConsistentOplogEntry = makeOplogEntry(dataConsistentOpTime, - OpTypeEnum::kInsert, - NamespaceString(tenantId + "_foo.bar"), - UUID::gen(), - BSON("doc" << 3), - boost::none /* o2 */); + auto dataConsistentOplogEntry = + makeOplogEntry(dataConsistentOpTime, + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"), + UUID::gen(), + BSON("doc" << 3), + boost::none /* o2 */); auto oplogFetcher = getDonorOplogFetcher(instance.get()); // Feed the oplog fetcher the last doc required for the recipient to be considered consistent. @@ -2221,7 +2224,7 @@ TEST_F(TenantMigrationRecipientServiceTest, OplogApplierResumesFromStartDonorApp // 'fromTenantMigrate' field. This oplog entry does not satisfy the conditions // for the oplog applier to resume applying from so we default to applying and // batching from the start of the buffer collection. - const auto insertNss = NamespaceString(tenantId + "_foo.bar"); + const auto insertNss = NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"); const auto afterStartApplyingOpTime = OpTime(Timestamp(3, 1), 1); const auto entryAfterStartApplyingOpTime = makeOplogEntry( afterStartApplyingOpTime, @@ -2276,12 +2279,13 @@ TEST_F(TenantMigrationRecipientServiceTest, OplogApplierResumesFromStartDonorApp hangAfterStartingOplogApplier->waitForTimesEntered(initialTimesEntered + 1); - auto dataConsistentOplogEntry = makeOplogEntry(dataConsistentOpTime, - OpTypeEnum::kInsert, - NamespaceString(tenantId + "_foo.bar"), - UUID::gen(), - BSON("doc" << 3), - boost::none /* o2 */); + auto dataConsistentOplogEntry = + makeOplogEntry(dataConsistentOpTime, + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"), + UUID::gen(), + BSON("doc" << 3), + boost::none /* o2 */); auto oplogFetcher = getDonorOplogFetcher(instance.get()); // Feed the oplog fetcher the last doc required for the recipient to be considered consistent. @@ -2364,23 +2368,25 @@ TEST_F(TenantMigrationRecipientServiceTest, // should know to skip this document on service restart. const auto oplogBuffer = getDonorOplogBuffer(instance.get()); OplogBuffer::Batch batch1; - batch1.push_back(makeOplogEntry(startFetchingOpTime, - OpTypeEnum::kInsert, - NamespaceString(tenantId + "_foo.bar"), - UUID::gen(), - BSON("doc" << 2), - boost::none /* o2 */) - .getEntry() - .toBSON()); + batch1.push_back( + makeOplogEntry(startFetchingOpTime, + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"), + UUID::gen(), + BSON("doc" << 2), + boost::none /* o2 */) + .getEntry() + .toBSON()); oplogBuffer->push(opCtx.get(), batch1.cbegin(), batch1.cend()); ASSERT_EQUALS(oplogBuffer->getCount(), 1); - auto dataConsistentOplogEntry = makeOplogEntry(dataConsistentOpTime, - OpTypeEnum::kInsert, - NamespaceString(tenantId + "_foo.bar"), - UUID::gen(), - BSON("doc" << 3), - boost::none /* o2 */); + auto dataConsistentOplogEntry = + makeOplogEntry(dataConsistentOpTime, + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest(tenantId + "_foo.bar"), + UUID::gen(), + BSON("doc" << 3), + boost::none /* o2 */); // Continue the recipient service to hang before starting the oplog applier. const auto hangAfterStartingOplogApplier = globalFailPointRegistry().find("fpAfterStartingOplogApplierMigrationRecipientInstance"); @@ -2475,13 +2481,14 @@ TEST_F(TenantMigrationRecipientServiceTest, OplogApplierFails) { ASSERT_TRUE(oplogFetcher->isActive()); // Send an oplog entry not from our tenant, which should cause the oplog applier to assert. - auto oplogEntry = makeOplogEntry(injectedEntryOpTime, - OpTypeEnum::kInsert, - NamespaceString("admin.bogus"), - UUID::gen(), - BSON("_id" - << "bad insert"), - boost::none /* o2 */); + auto oplogEntry = + makeOplogEntry(injectedEntryOpTime, + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest("admin.bogus"), + UUID::gen(), + BSON("_id" + << "bad insert"), + boost::none /* o2 */); oplogFetcher->receiveBatch( 1LL, {oplogEntry.getEntry().toBSON()}, injectedEntryOpTime.getTimestamp()); } @@ -2598,22 +2605,24 @@ TEST_F(TenantMigrationRecipientServiceTest, TenantMigrationRecipientAddResumeTok // Feed the oplog fetcher a resume token. auto oplogFetcher = getDonorOplogFetcher(instance.get()); const auto resumeToken1 = topOfOplogOpTime.getTimestamp(); - auto oplogEntry1 = makeOplogEntry(topOfOplogOpTime, - OpTypeEnum::kInsert, - NamespaceString("foo.bar") /* namespace */, - UUID::gen() /* uuid */, - BSON("doc" << 2) /* o */, - boost::none /* o2 */); + auto oplogEntry1 = + makeOplogEntry(topOfOplogOpTime, + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest("foo.bar") /* namespace */, + UUID::gen() /* uuid */, + BSON("doc" << 2) /* o */, + boost::none /* o2 */); oplogFetcher->receiveBatch(17, {oplogEntry1.getEntry().toBSON()}, resumeToken1); const Timestamp oplogEntryTS2 = Timestamp(6, 2); const Timestamp resumeToken2 = Timestamp(7, 3); - auto oplogEntry2 = makeOplogEntry(OpTime(oplogEntryTS2, topOfOplogOpTime.getTerm()), - OpTypeEnum::kInsert, - NamespaceString("foo.bar") /* namespace */, - UUID::gen() /* uuid */, - BSON("doc" << 3) /* o */, - boost::none /* o2 */); + auto oplogEntry2 = + makeOplogEntry(OpTime(oplogEntryTS2, topOfOplogOpTime.getTerm()), + OpTypeEnum::kInsert, + NamespaceString::createNamespaceString_forTest("foo.bar") /* namespace */, + UUID::gen() /* uuid */, + BSON("doc" << 3) /* o */, + boost::none /* o2 */); oplogFetcher->receiveBatch(17, {oplogEntry2.getEntry().toBSON()}, resumeToken2); // Receive an empty batch. @@ -2644,7 +2653,7 @@ TEST_F(TenantMigrationRecipientServiceTest, TenantMigrationRecipientAddResumeTok ASSERT_TRUE(noopEntry.getOpType() == OpTypeEnum::kNoop); ASSERT_EQUALS(noopEntry.getTimestamp(), resumeToken2); ASSERT_EQUALS(noopEntry.getTerm().value(), -1); - ASSERT_EQUALS(noopEntry.getNss(), NamespaceString("")); + ASSERT_EQUALS(noopEntry.getNss(), NamespaceString::createNamespaceString_forTest("")); } ASSERT_TRUE(oplogBuffer->isEmpty()); diff --git a/src/mongo/db/repl/tenant_oplog_applier_test.cpp b/src/mongo/db/repl/tenant_oplog_applier_test.cpp index 46cd336395f..cb1cef8c6cd 100644 --- a/src/mongo/db/repl/tenant_oplog_applier_test.cpp +++ b/src/mongo/db/repl/tenant_oplog_applier_test.cpp @@ -212,9 +212,13 @@ private: TEST_F(TenantOplogApplierTest, NoOpsForSingleBatch) { std::vector srcOps; srcOps.push_back(makeInsertOplogEntry( - 1, NamespaceString(_dbName.toStringWithTenantId(), "foo"), UUID::gen())); + 1, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "foo"), + UUID::gen())); srcOps.push_back(makeInsertOplogEntry( - 2, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen())); + 2, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen())); pushOps(srcOps); auto writerPool = makeTenantMigrationWriterPool(); @@ -246,7 +250,9 @@ TEST_F(TenantOplogApplierTest, NoOpsForLargeBatch) { // This should be big enough to use several threads to do the writing for (int i = 0; i < 64; i++) { srcOps.push_back(makeInsertOplogEntry( - i + 1, NamespaceString(_dbName.toStringWithTenantId(), "foo"), UUID::gen())); + i + 1, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "foo"), + UUID::gen())); } pushOps(srcOps); @@ -278,13 +284,21 @@ TEST_F(TenantOplogApplierTest, NoOpsForLargeBatch) { TEST_F(TenantOplogApplierTest, NoOpsForMultipleBatches) { std::vector srcOps; srcOps.push_back(makeInsertOplogEntry( - 1, NamespaceString(_dbName.toStringWithTenantId(), "foo"), UUID::gen())); + 1, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "foo"), + UUID::gen())); srcOps.push_back(makeInsertOplogEntry( - 2, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen())); + 2, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen())); srcOps.push_back(makeInsertOplogEntry( - 3, NamespaceString(_dbName.toStringWithTenantId(), "baz"), UUID::gen())); + 3, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "baz"), + UUID::gen())); srcOps.push_back(makeInsertOplogEntry( - 4, NamespaceString(_dbName.toStringWithTenantId(), "bif"), UUID::gen())); + 4, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bif"), + UUID::gen())); auto writerPool = makeTenantMigrationWriterPool(); @@ -321,19 +335,31 @@ TEST_F(TenantOplogApplierTest, NoOpsForMultipleBatches) { TEST_F(TenantOplogApplierTest, NoOpsForLargeTransaction) { std::vector innerOps1; innerOps1.push_back(makeInsertOplogEntry( - 11, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen())); + 11, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen())); innerOps1.push_back(makeInsertOplogEntry( - 12, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen())); + 12, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen())); std::vector innerOps2; innerOps2.push_back(makeInsertOplogEntry( - 21, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen())); + 21, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen())); innerOps2.push_back(makeInsertOplogEntry( - 22, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen())); + 22, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen())); std::vector innerOps3; innerOps3.push_back(makeInsertOplogEntry( - 31, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen())); + 31, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen())); innerOps3.push_back(makeInsertOplogEntry( - 32, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen())); + 32, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen())); // Makes entries with ts from range [2, 5). std::vector srcOps = makeMultiEntryTransactionOplogEntries( @@ -374,7 +400,8 @@ TEST_F(TenantOplogApplierTest, CommitUnpreparedTransaction_DataPartiallyApplied) client.createIndexes(NamespaceString::kSessionTransactionsTableNamespace, {MongoDSessionCatalog::getConfigTxnPartialIndexSpec()}); } - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto lsid = makeLogicalSessionId(_opCtx.get()); TxnNumber txnNum(0); @@ -433,7 +460,9 @@ TEST_F(TenantOplogApplierTest, CommitUnpreparedTransaction_DataPartiallyApplied) TEST_F(TenantOplogApplierTest, ApplyInsert_DatabaseMissing) { auto entry = makeInsertOplogEntry( - 1, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen()); + 1, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen()); bool onInsertsCalled = false; _opObserver->onInsertsFn = [&](OperationContext* opCtx, const NamespaceString&, @@ -462,7 +491,9 @@ TEST_F(TenantOplogApplierTest, ApplyInsert_DatabaseMissing) { TEST_F(TenantOplogApplierTest, ApplyInsert_CollectionMissing) { createDatabase(_opCtx.get(), _dbName.toString()); auto entry = makeInsertOplogEntry( - 1, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen()); + 1, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen()); bool onInsertsCalled = false; _opObserver->onInsertsFn = [&](OperationContext* opCtx, const NamespaceString&, @@ -489,7 +520,8 @@ TEST_F(TenantOplogApplierTest, ApplyInsert_CollectionMissing) { } TEST_F(TenantOplogApplierTest, ApplyInsert_InsertExisting) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); ASSERT_OK(getStorageInterface()->insertDocument(_opCtx.get(), nss, @@ -527,7 +559,8 @@ TEST_F(TenantOplogApplierTest, ApplyInsert_InsertExisting) { } TEST_F(TenantOplogApplierTest, ApplyInsert_UniqueKey_InsertExisting) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); // Create unique key index on the collection. @@ -568,7 +601,8 @@ TEST_F(TenantOplogApplierTest, ApplyInsert_UniqueKey_InsertExisting) { } TEST_F(TenantOplogApplierTest, ApplyInsert_Success) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto entry = makeInsertOplogEntry(1, nss, uuid); bool onInsertsCalled = false; @@ -607,8 +641,10 @@ TEST_F(TenantOplogApplierTest, ApplyInserts_Grouped) { // TODO(SERVER-50256): remove nss_workaround, which is used to work around a bug where // the first operation assigned to a worker cannot be grouped. NamespaceString nss_workaround(_dbName.toStringWithTenantId(), "a"); - NamespaceString nss1(_dbName.toStringWithTenantId(), "bar"); - NamespaceString nss2(_dbName.toStringWithTenantId(), "baz"); + NamespaceString nss1 = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss2 = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "baz"); auto uuid1 = createCollectionWithUuid(_opCtx.get(), nss1); auto uuid2 = createCollectionWithUuid(_opCtx.get(), nss2); std::vector entries; @@ -666,7 +702,8 @@ TEST_F(TenantOplogApplierTest, ApplyInserts_Grouped) { } TEST_F(TenantOplogApplierTest, ApplyUpdate_MissingDocument) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto entry = makeOplogEntry(repl::OpTypeEnum::kUpdate, nss, @@ -705,7 +742,8 @@ TEST_F(TenantOplogApplierTest, ApplyUpdate_MissingDocument) { } TEST_F(TenantOplogApplierTest, ApplyUpdate_Success) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); ASSERT_OK(getStorageInterface()->insertDocument(_opCtx.get(), nss, {BSON("_id" << 0)}, 0)); auto entry = makeOplogEntry(repl::OpTypeEnum::kUpdate, @@ -742,7 +780,9 @@ TEST_F(TenantOplogApplierTest, ApplyUpdate_Success) { TEST_F(TenantOplogApplierTest, ApplyDelete_DatabaseMissing) { auto entry = makeOplogEntry( - OpTypeEnum::kDelete, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen()); + OpTypeEnum::kDelete, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen()); bool onDeleteCalled = false; _opObserver->onDeleteFn = [&](OperationContext* opCtx, const CollectionPtr&, StmtId, const OplogDeleteEntryArgs&) { @@ -772,7 +812,9 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_DatabaseMissing) { TEST_F(TenantOplogApplierTest, ApplyDelete_CollectionMissing) { createDatabase(_opCtx.get(), _dbName.toString()); auto entry = makeOplogEntry( - OpTypeEnum::kDelete, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen()); + OpTypeEnum::kDelete, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"), + UUID::gen()); bool onDeleteCalled = false; _opObserver->onDeleteFn = [&](OperationContext* opCtx, const CollectionPtr&, StmtId, const OplogDeleteEntryArgs&) { @@ -800,7 +842,8 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_CollectionMissing) { } TEST_F(TenantOplogApplierTest, ApplyDelete_DocumentMissing) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto entry = makeOplogEntry(OpTypeEnum::kDelete, nss, uuid, BSON("_id" << 0)); bool onDeleteCalled = false; @@ -830,7 +873,8 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_DocumentMissing) { } TEST_F(TenantOplogApplierTest, ApplyDelete_Success) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); ASSERT_OK(getStorageInterface()->insertDocument(_opCtx.get(), nss, {BSON("_id" << 0)}, 0)); auto entry = makeOplogEntry(OpTypeEnum::kDelete, nss, uuid, BSON("_id" << 0)); @@ -872,7 +916,8 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_Success) { } TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_CollExisting) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto op = BSON("op" << "c" @@ -907,8 +952,10 @@ TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_CollExisting) { } TEST_F(TenantOplogApplierTest, ApplyRenameCollCommand_CollExisting) { - NamespaceString nss1(_dbName.toStringWithTenantId(), "foo"); - NamespaceString nss2(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss1 = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "foo"); + NamespaceString nss2 = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss2); auto op = BSON("op" @@ -947,7 +994,8 @@ TEST_F(TenantOplogApplierTest, ApplyRenameCollCommand_CollExisting) { } TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_Success) { - NamespaceString nss(_dbName.toStringWithTenantId(), "t"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "t"); auto op = BSON("op" << "c" @@ -987,7 +1035,8 @@ TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_Success) { } TEST_F(TenantOplogApplierTest, ApplyCreateIndexesCommand_Success) { - NamespaceString nss(_dbName.toStringWithTenantId(), "t"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "t"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto op = BSON("op" @@ -1034,7 +1083,8 @@ TEST_F(TenantOplogApplierTest, ApplyCreateIndexesCommand_Success) { } TEST_F(TenantOplogApplierTest, ApplyStartIndexBuildCommand_Failure) { - NamespaceString nss(_dbName.toStringWithTenantId(), "t"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "t"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto op = BSON("op" << "c" @@ -1065,7 +1115,7 @@ TEST_F(TenantOplogApplierTest, ApplyStartIndexBuildCommand_Failure) { TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_WrongNSS) { // Should not be able to apply a command in the wrong namespace. - NamespaceString nss("notmytenant", "t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("notmytenant", "t"); auto op = BSON("op" << "c" @@ -1100,7 +1150,7 @@ TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_WrongNSS) { TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_WrongNSS_Merge) { // Should not be able to apply a command in the wrong namespace. - NamespaceString nss("noTenantDB", "t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("noTenantDB", "t"); auto op = BSON("op" << "c" @@ -1133,7 +1183,8 @@ TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_WrongNSS_Merge) { } TEST_F(TenantOplogApplierTest, ApplyDropIndexesCommand_IndexNotFound) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto op = BSON("op" << "c" @@ -1171,7 +1222,8 @@ TEST_F(TenantOplogApplierTest, ApplyDropIndexesCommand_IndexNotFound) { } TEST_F(TenantOplogApplierTest, ApplyCollModCommand_IndexNotFound) { - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto op = BSON("op" << "c" @@ -1215,7 +1267,8 @@ TEST_F(TenantOplogApplierTest, ApplyCollModCommand_IndexNotFound) { TEST_F(TenantOplogApplierTest, ApplyCollModCommand_CollectionMissing) { createDatabase(_opCtx.get(), _dbName.toString()); - NamespaceString nss(_dbName.toStringWithTenantId(), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "bar"); UUID uuid(UUID::gen()); auto op = BSON("op" << "c" @@ -1259,7 +1312,7 @@ TEST_F(TenantOplogApplierTest, ApplyCollModCommand_CollectionMissing) { TEST_F(TenantOplogApplierTest, ApplyCRUD_WrongNSS) { // Should not be able to apply a CRUD operation to a namespace not belonging to us. - NamespaceString nss("notmytenant", "bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("notmytenant", "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto entry = makeInsertOplogEntry(1, nss, uuid); bool onInsertsCalled = false; @@ -1290,7 +1343,8 @@ TEST_F(TenantOplogApplierTest, ApplyCRUD_WrongNSS_Merge) { auto invalidTenant = TenantId(OID::gen()); // Should not be able to apply a CRUD operation to a namespace not belonging to us. - NamespaceString nss(DatabaseName(invalidTenant, "test"), "bar"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest(DatabaseName(invalidTenant, "test"), "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto entry = makeInsertOplogEntry(1, nss, uuid); bool onInsertsCalled = false; @@ -1319,8 +1373,8 @@ TEST_F(TenantOplogApplierTest, ApplyCRUD_WrongNSS_Merge) { TEST_F(TenantOplogApplierTest, ApplyCRUD_WrongUUID) { // Should not be able to apply a CRUD operation to a namespace not belonging to us, even if // we claim it does in the nss field. - NamespaceString nss("notmytenant", "bar"); - NamespaceString nss_to_apply(_dbName, "bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("notmytenant", "bar"); + NamespaceString nss_to_apply = NamespaceString::createNamespaceString_forTest(_dbName, "bar"); auto uuid = createCollectionWithUuid(_opCtx.get(), nss); auto entry = makeInsertOplogEntry(1, nss_to_apply, uuid); bool onInsertsCalled = false; @@ -1410,7 +1464,9 @@ TEST_F(TenantOplogApplierTest, ApplyResumeTokenNoop_Success) { TEST_F(TenantOplogApplierTest, ApplyInsertThenResumeTokenNoopInDifferentBatch_Success) { std::vector srcOps; srcOps.push_back(makeInsertOplogEntry( - 1, NamespaceString(_dbName.toStringWithTenantId(), "foo"), UUID::gen())); + 1, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "foo"), + UUID::gen())); srcOps.push_back(makeNoopOplogEntry(2, TenantMigrationRecipientService::kNoopMsg)); pushOps(srcOps); auto writerPool = makeTenantMigrationWriterPool(); @@ -1448,7 +1504,9 @@ TEST_F(TenantOplogApplierTest, ApplyResumeTokenNoopThenInsertInSameBatch_Success std::vector srcOps; srcOps.push_back(makeNoopOplogEntry(1, TenantMigrationRecipientService::kNoopMsg)); srcOps.push_back(makeInsertOplogEntry( - 2, NamespaceString(_dbName.toStringWithTenantId(), "foo"), UUID::gen())); + 2, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "foo"), + UUID::gen())); pushOps(srcOps); auto writerPool = makeTenantMigrationWriterPool(); @@ -1480,7 +1538,9 @@ TEST_F(TenantOplogApplierTest, ApplyResumeTokenNoopThenInsertInSameBatch_Success TEST_F(TenantOplogApplierTest, ApplyResumeTokenInsertThenNoopSameTimestamp_Success) { std::vector srcOps; srcOps.push_back(makeInsertOplogEntry( - 1, NamespaceString(_dbName.toStringWithTenantId(), "foo"), UUID::gen())); + 1, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "foo"), + UUID::gen())); srcOps.push_back(makeNoopOplogEntry(1, TenantMigrationRecipientService::kNoopMsg)); pushOps(srcOps); ASSERT_EQ(srcOps[0].getOpTime(), srcOps[1].getOpTime()); @@ -1514,7 +1574,9 @@ TEST_F(TenantOplogApplierTest, ApplyResumeTokenInsertThenNoopSameTimestamp_Succe TEST_F(TenantOplogApplierTest, ApplyResumeTokenInsertThenNoop_Success) { std::vector srcOps; srcOps.push_back(makeInsertOplogEntry( - 1, NamespaceString(_dbName.toStringWithTenantId(), "foo"), UUID::gen())); + 1, + NamespaceString::createNamespaceString_forTest(_dbName.toStringWithTenantId(), "foo"), + UUID::gen())); srcOps.push_back(makeNoopOplogEntry(2, TenantMigrationRecipientService::kNoopMsg)); pushOps(srcOps); auto writerPool = makeTenantMigrationWriterPool(); diff --git a/src/mongo/db/repl/tenant_oplog_batcher_test.cpp b/src/mongo/db/repl/tenant_oplog_batcher_test.cpp index 970c444cdd0..4ba7173aba3 100644 --- a/src/mongo/db/repl/tenant_oplog_batcher_test.cpp +++ b/src/mongo/db/repl/tenant_oplog_batcher_test.cpp @@ -125,8 +125,14 @@ TEST_F(TenantOplogBatcherTest, OplogBatcherGroupsCrudOps) { // We just started, no batch should be available. ASSERT(!batchFuture.isReady()); std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "foo")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar")).getEntry().toBSON()); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "foo")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); _oplogBuffer.push(nullptr, srcOps.cbegin(), srcOps.cend()); auto batch = batchFuture.get(); @@ -185,10 +191,15 @@ static DurableReplOperation stripB(const DurableReplOperation& withB) { TEST_F(TenantOplogBatcherTest, GetNextApplierBatchGroupsUnpreparedApplyOpsOpWithOtherOps) { std::vector innerOps; std::vector srcOps; - innerOps.push_back(makeInsertOplogEntry(10, NamespaceString(dbName, "foo"))); - innerOps.push_back(makeInsertOplogEntry(11, NamespaceString(dbName, "foo"))); + innerOps.push_back( + makeInsertOplogEntry(10, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); + innerOps.push_back( + makeInsertOplogEntry(11, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); srcOps.push_back(makeApplyOpsOplogEntry(1, false, innerOps).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar")).getEntry().toBSON()); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); auto batcher = std::make_shared( _migrationUuid, &_oplogBuffer, _executor, Timestamp(), OpTime()); @@ -217,10 +228,14 @@ TEST_F(TenantOplogBatcherTest, GetNextApplierBatchGroupsMultipleTransactions) { std::vector innerOps1; std::vector innerOps2; std::vector srcOps; - innerOps1.push_back(makeInsertOplogEntry(10, NamespaceString(dbName, "foo"))); - innerOps1.push_back(makeInsertOplogEntry(11, NamespaceString(dbName, "foo"))); - innerOps2.push_back(makeInsertOplogEntry(20, NamespaceString(dbName, "foo"))); - innerOps2.push_back(makeInsertOplogEntry(21, NamespaceString(dbName, "foo"))); + innerOps1.push_back( + makeInsertOplogEntry(10, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); + innerOps1.push_back( + makeInsertOplogEntry(11, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); + innerOps2.push_back( + makeInsertOplogEntry(20, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); + innerOps2.push_back( + makeInsertOplogEntry(21, NamespaceString::createNamespaceString_forTest(dbName, "foo"))); srcOps.push_back(makeApplyOpsOplogEntry(1, false, innerOps1).getEntry().toBSON()); srcOps.push_back(makeApplyOpsOplogEntry(2, false, innerOps2).getEntry().toBSON()); @@ -258,11 +273,26 @@ TEST_F(TenantOplogBatcherTest, GetNextApplierBatchGroupsMultipleTransactions) { TEST_F(TenantOplogBatcherTest, GetNextApplierBatchChecksBatchLimitsForNumberOfOperations) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(4, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(5, NamespaceString(dbName, "bar")).getEntry().toBSON()); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(4, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(5, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); _oplogBuffer.push(nullptr, srcOps.cbegin(), srcOps.cend()); // Set batch limits so that each batch contains a maximum of 'BatchLimit::ops'. @@ -292,9 +322,18 @@ TEST_F(TenantOplogBatcherTest, GetNextApplierBatchChecksBatchLimitsForNumberOfOp TEST_F(TenantOplogBatcherTest, GetNextApplierBatchChecksBatchLimitsForSizeOfOperations) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "bar")).getEntry().toBSON()); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); _oplogBuffer.push(nullptr, srcOps.cbegin(), srcOps.cend()); // Set batch limits so that only the first two operations can fit into the first batch. @@ -322,16 +361,25 @@ TEST_F(TenantOplogBatcherTest, GetNextApplierBatchChecksBatchLimitsForSizeOfOper TEST_F(TenantOplogBatcherTest, LargeTransactionProcessedIndividuallyAndExpanded) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar")).getEntry().toBSON()); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); std::vector innerOps1; - innerOps1.push_back(makeInsertOplogEntry(11, NamespaceString(dbName, "bar"))); - innerOps1.push_back(makeInsertOplogEntry(12, NamespaceString(dbName, "bar"))); + innerOps1.push_back( + makeInsertOplogEntry(11, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + innerOps1.push_back( + makeInsertOplogEntry(12, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); std::vector innerOps2; - innerOps2.push_back(makeInsertOplogEntry(21, NamespaceString(dbName, "bar"))); - innerOps2.push_back(makeInsertOplogEntry(22, NamespaceString(dbName, "bar"))); + innerOps2.push_back( + makeInsertOplogEntry(21, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + innerOps2.push_back( + makeInsertOplogEntry(22, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); std::vector innerOps3; - innerOps3.push_back(makeInsertOplogEntry(31, NamespaceString(dbName, "bar"))); - innerOps3.push_back(makeInsertOplogEntry(32, NamespaceString(dbName, "bar"))); + innerOps3.push_back( + makeInsertOplogEntry(31, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); + innerOps3.push_back( + makeInsertOplogEntry(32, NamespaceString::createNamespaceString_forTest(dbName, "bar"))); // Makes entries with ts from range [2, 5). std::vector multiEntryTransaction = makeMultiEntryTransactionOplogEntries( @@ -342,7 +390,10 @@ TEST_F(TenantOplogBatcherTest, LargeTransactionProcessedIndividuallyAndExpanded) // Push one extra operation to ensure that the last oplog entry of a large transaction // is processed by itself. - srcOps.push_back(makeInsertOplogEntry(5, NamespaceString(dbName, "bar")).getEntry().toBSON()); + srcOps.push_back( + makeInsertOplogEntry(5, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); _oplogBuffer.push(nullptr, srcOps.cbegin(), srcOps.cend()); @@ -407,9 +458,15 @@ TEST_F(TenantOplogBatcherTest, OplogBatcherRetreivesPreImageOutOfOrder) { ASSERT(!batchFuture.isReady()); std::vector srcOps; srcOps.push_back(makeNoopOplogEntry(1, "preImage").getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "foo")).getEntry().toBSON()); srcOps.push_back( - makeUpdateOplogEntry(3, NamespaceString(dbName, "bar"), UUID::gen(), OpTime({1, 1}, 1)) + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "foo")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeUpdateOplogEntry(3, + NamespaceString::createNamespaceString_forTest(dbName, "bar"), + UUID::gen(), + OpTime({1, 1}, 1)) .getEntry() .toBSON()); @@ -442,14 +499,18 @@ TEST_F(TenantOplogBatcherTest, OplogBatcherRetreivesPostImageOutOfOrder) { ASSERT(!batchFuture.isReady()); std::vector srcOps; srcOps.push_back(makeNoopOplogEntry(1, "postImage").getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "foo")).getEntry().toBSON()); - srcOps.push_back(makeUpdateOplogEntry(3, - NamespaceString(dbName, "bar"), - UUID::gen(), - boost::none /* preImageOpTime */, - OpTime({1, 1}, 1)) - .getEntry() - .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "foo")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeUpdateOplogEntry(3, + NamespaceString::createNamespaceString_forTest(dbName, "bar"), + UUID::gen(), + boost::none /* preImageOpTime */, + OpTime({1, 1}, 1)) + .getEntry() + .toBSON()); _oplogBuffer.push(nullptr, srcOps.cbegin(), srcOps.cend()); @@ -491,7 +552,10 @@ TEST_F(TenantOplogBatcherTest, OplogBatcherRetreivesPreImageBeforeBatchStart) { std::vector srcOps; srcOps.push_back(makeNoopOplogEntry(1, "preImage").getEntry().toBSON()); srcOps.push_back( - makeUpdateOplogEntry(2, NamespaceString(dbName, "bar"), UUID::gen(), OpTime({1, 1}, 1)) + makeUpdateOplogEntry(2, + NamespaceString::createNamespaceString_forTest(dbName, "bar"), + UUID::gen(), + OpTime({1, 1}, 1)) .getEntry() .toBSON()); @@ -521,13 +585,14 @@ TEST_F(TenantOplogBatcherTest, OplogBatcherRetreivesPostImageBeforeBatchStart) { ASSERT_OK(batcher->startup()); std::vector srcOps; srcOps.push_back(makeNoopOplogEntry(1, "postImage").getEntry().toBSON()); - srcOps.push_back(makeUpdateOplogEntry(2, - NamespaceString(dbName, "bar"), - UUID::gen(), - boost::none /* preImageOpTime */, - OpTime({1, 1}, 1)) - .getEntry() - .toBSON()); + srcOps.push_back( + makeUpdateOplogEntry(2, + NamespaceString::createNamespaceString_forTest(dbName, "bar"), + UUID::gen(), + boost::none /* preImageOpTime */, + OpTime({1, 1}, 1)) + .getEntry() + .toBSON()); _oplogBuffer.push(nullptr, srcOps.cbegin(), srcOps.cend()); // Pull the postImage off the buffer. @@ -564,11 +629,26 @@ TEST_F(TenantOplogBatcherTest, GetNextApplierBatchRejectsZeroBatchSizeLimits) { TEST_F(TenantOplogBatcherTest, ResumeOplogBatcherFromTimestamp) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(1, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(2, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(3, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(4, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(5, NamespaceString(dbName, "bar")).getEntry().toBSON()); + srcOps.push_back( + makeInsertOplogEntry(1, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(2, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(3, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(4, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(5, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); _oplogBuffer.push(nullptr, srcOps.cbegin(), srcOps.cend()); auto batcher = std::make_shared( @@ -587,8 +667,14 @@ TEST_F(TenantOplogBatcherTest, ResumeOplogBatcherFromTimestamp) { TEST_F(TenantOplogBatcherTest, ResumeOplogBatcherFromNonExistentTimestamp) { std::vector srcOps; - srcOps.push_back(makeInsertOplogEntry(4, NamespaceString(dbName, "bar")).getEntry().toBSON()); - srcOps.push_back(makeInsertOplogEntry(5, NamespaceString(dbName, "bar")).getEntry().toBSON()); + srcOps.push_back( + makeInsertOplogEntry(4, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); + srcOps.push_back( + makeInsertOplogEntry(5, NamespaceString::createNamespaceString_forTest(dbName, "bar")) + .getEntry() + .toBSON()); _oplogBuffer.push(nullptr, srcOps.cbegin(), srcOps.cend()); auto batcher = std::make_shared( diff --git a/src/mongo/db/s/active_migrations_registry_test.cpp b/src/mongo/db/s/active_migrations_registry_test.cpp index acdd2bfaf38..3cdaa0a021a 100644 --- a/src/mongo/db/s/active_migrations_registry_test.cpp +++ b/src/mongo/db/s/active_migrations_registry_test.cpp @@ -71,7 +71,9 @@ ShardsvrMoveRange createMoveRangeRequest(const NamespaceString& nss, TEST_F(MoveChunkRegistration, ScopedDonateChunkMoveConstructorAndAssignment) { auto originalScopedDonateChunk = assertGet(_registry.registerDonateChunk( - _opCtx, createMoveRangeRequest(NamespaceString("TestDB", "TestColl")))); + _opCtx, + createMoveRangeRequest( + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl")))); ASSERT(originalScopedDonateChunk.mustExecute()); ScopedDonateChunk movedScopedDonateChunk(std::move(originalScopedDonateChunk)); @@ -87,7 +89,8 @@ TEST_F(MoveChunkRegistration, ScopedDonateChunkMoveConstructorAndAssignment) { TEST_F(MoveChunkRegistration, GetActiveMigrationNamespace) { ASSERT(!_registry.getActiveDonateChunkNss()); - const NamespaceString nss("TestDB", "TestColl"); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); auto originalScopedDonateChunk = assertGet(_registry.registerDonateChunk(operationContext(), createMoveRangeRequest(nss))); @@ -100,10 +103,14 @@ TEST_F(MoveChunkRegistration, GetActiveMigrationNamespace) { TEST_F(MoveChunkRegistration, SecondMigrationReturnsConflictingOperationInProgress) { auto originalScopedDonateChunk = assertGet(_registry.registerDonateChunk( - operationContext(), createMoveRangeRequest(NamespaceString("TestDB", "TestColl1")))); + operationContext(), + createMoveRangeRequest( + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl1")))); auto secondScopedDonateChunkStatus = _registry.registerDonateChunk( - operationContext(), createMoveRangeRequest(NamespaceString("TestDB", "TestColl2"))); + operationContext(), + createMoveRangeRequest( + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl2"))); ASSERT_EQ(ErrorCodes::ConflictingOperationInProgress, secondScopedDonateChunkStatus.getStatus()); @@ -116,14 +123,17 @@ TEST_F(MoveChunkRegistration, SecondMigrationWithSameArgumentsJoinsFirst) { auto swOriginalScopedDonateChunkPtr = std::make_unique>(_registry.registerDonateChunk( operationContext(), - createMoveRangeRequest(NamespaceString("TestDB", "TestColl"), epoch))); + createMoveRangeRequest( + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"), epoch))); ASSERT_OK(swOriginalScopedDonateChunkPtr->getStatus()); auto& originalScopedDonateChunk = swOriginalScopedDonateChunkPtr->getValue(); ASSERT(originalScopedDonateChunk.mustExecute()); auto secondScopedDonateChunk = assertGet(_registry.registerDonateChunk( - operationContext(), createMoveRangeRequest(NamespaceString("TestDB", "TestColl"), epoch))); + operationContext(), + createMoveRangeRequest(NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"), + epoch))); ASSERT(!secondScopedDonateChunk.mustExecute()); originalScopedDonateChunk.signalComplete({ErrorCodes::InternalError, "Test error"}); @@ -177,7 +187,9 @@ TEST_F(MoveChunkRegistration, TestBlockingDonateChunk) { // 6. Now that we're woken up by the registry thread, let's attempt to start to donate. // This will block and call the lambda set on the baton above. auto scopedDonateChunk = _registry.registerDonateChunk( - opCtx.get(), createMoveRangeRequest(NamespaceString("TestDB", "TestColl"))); + opCtx.get(), + createMoveRangeRequest( + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"))); ASSERT_OK(scopedDonateChunk.getStatus()); scopedDonateChunk.getValue().signalComplete(Status::OK()); @@ -238,12 +250,12 @@ TEST_F(MoveChunkRegistration, TestBlockingReceiveChunk) { // 6. Now that we're woken up by the registry thread, let's attempt to start to receive. // This will block and call the lambda set on the baton above. - auto scopedReceiveChunk = - _registry.registerReceiveChunk(opCtx.get(), - NamespaceString("TestDB", "TestColl"), - ChunkRange(BSON("Key" << -100), BSON("Key" << 100)), - ShardId("shard0001"), - false); + auto scopedReceiveChunk = _registry.registerReceiveChunk( + opCtx.get(), + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"), + ChunkRange(BSON("Key" << -100), BSON("Key" << 100)), + ShardId("shard0001"), + false); ASSERT_OK(scopedReceiveChunk.getStatus()); @@ -273,7 +285,9 @@ TEST_F(MoveChunkRegistration, TestBlockingWhileDonateInProgress) { auto result = stdx::async(stdx::launch::async, [&] { // 2. Start a migration so that the registry lock will block when acquired. auto scopedDonateChunk = _registry.registerDonateChunk( - operationContext(), createMoveRangeRequest(NamespaceString("TestDB", "TestColl"))); + operationContext(), + createMoveRangeRequest( + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"))); ASSERT_OK(scopedDonateChunk.getStatus()); // 3. Signal the registry locking thread that the registry is ready to be locked. @@ -334,12 +348,12 @@ TEST_F(MoveChunkRegistration, TestBlockingWhileReceiveInProgress) { // Migration thread. auto result = stdx::async(stdx::launch::async, [&] { // 2. Start a migration so that the registry lock will block when acquired. - auto scopedReceiveChunk = - _registry.registerReceiveChunk(operationContext(), - NamespaceString("TestDB", "TestColl"), - ChunkRange(BSON("Key" << -100), BSON("Key" << 100)), - ShardId("shard0001"), - false); + auto scopedReceiveChunk = _registry.registerReceiveChunk( + operationContext(), + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"), + ChunkRange(BSON("Key" << -100), BSON("Key" << 100)), + ShardId("shard0001"), + false); ASSERT_OK(scopedReceiveChunk.getStatus()); // 3. Signal the registry locking thread that the registry is ready to be locked. diff --git a/src/mongo/db/s/analyze_shard_key_read_write_distribution_test.cpp b/src/mongo/db/s/analyze_shard_key_read_write_distribution_test.cpp index c52e5328e3a..b7174a3f0df 100644 --- a/src/mongo/db/s/analyze_shard_key_read_write_distribution_test.cpp +++ b/src/mongo/db/s/analyze_shard_key_read_write_distribution_test.cpp @@ -282,7 +282,8 @@ protected: assertWriteMetrics(writeDistributionCalculator, expectedMetrics); } - const NamespaceString nss{"testDb", "testColl"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("testDb", "testColl"); const UUID collUuid = UUID::gen(); // Define two set of ChunkSplintInfo's for testing. diff --git a/src/mongo/db/s/auto_split_vector_test.cpp b/src/mongo/db/s/auto_split_vector_test.cpp index dcc9b06ced7..ae7f4b006cd 100644 --- a/src/mongo/db/s/auto_split_vector_test.cpp +++ b/src/mongo/db/s/auto_split_vector_test.cpp @@ -45,7 +45,7 @@ namespace mongo { namespace { -const NamespaceString kNss = NamespaceString("autosplitDB", "coll"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("autosplitDB", "coll"); const std::string kPattern = "_id"; /* @@ -135,14 +135,15 @@ class AutoSplitVectorTest10MB : public AutoSplitVectorTest { // Throw exception upon calling autoSplitVector on dropped/unexisting collection TEST_F(AutoSplitVectorTest, NoCollection) { - ASSERT_THROWS_CODE(autoSplitVector(operationContext(), - NamespaceString("dummy", "collection"), - BSON(kPattern << 1) /* shard key pattern */, - BSON(kPattern << kMinBSONKey) /* min */, - BSON(kPattern << kMaxBSONKey) /* max */, - 1 * 1024 * 1024 /* max chunk size in bytes*/), - DBException, - ErrorCodes::NamespaceNotFound); + ASSERT_THROWS_CODE( + autoSplitVector(operationContext(), + NamespaceString::createNamespaceString_forTest("dummy", "collection"), + BSON(kPattern << 1) /* shard key pattern */, + BSON(kPattern << kMinBSONKey) /* min */, + BSON(kPattern << kMaxBSONKey) /* max */, + 1 * 1024 * 1024 /* max chunk size in bytes*/), + DBException, + ErrorCodes::NamespaceNotFound); } TEST_F(AutoSplitVectorTest, EmptyCollection) { diff --git a/src/mongo/db/s/balancer/balance_stats_test.cpp b/src/mongo/db/s/balancer/balance_stats_test.cpp index 1b1222e9b92..911188c8363 100644 --- a/src/mongo/db/s/balancer/balance_stats_test.cpp +++ b/src/mongo/db/s/balancer/balance_stats_test.cpp @@ -71,7 +71,7 @@ public: } private: - const NamespaceString _nss{"foo.bar"}; + const NamespaceString _nss = NamespaceString::createNamespaceString_forTest("foo.bar"); const UUID _uuid = UUID::gen(); const OID _epoch{OID::gen()}; const Timestamp _timestamp{Timestamp(1, 1)}; diff --git a/src/mongo/db/s/balancer/balancer_commands_scheduler_test.cpp b/src/mongo/db/s/balancer/balancer_commands_scheduler_test.cpp index 2c096547669..f7312baba99 100644 --- a/src/mongo/db/s/balancer/balancer_commands_scheduler_test.cpp +++ b/src/mongo/db/s/balancer/balancer_commands_scheduler_test.cpp @@ -51,8 +51,9 @@ public: ShardType(kShardId0.toString(), kShardHost0.toString()), ShardType(kShardId1.toString(), kShardHost1.toString())}; - const NamespaceString kNss{"testDb.testColl"}; - const NamespaceString kNssWithCustomizedSize{"testDb.testCollCustomized"}; + const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("testDb.testColl"); + const NamespaceString kNssWithCustomizedSize = + NamespaceString::createNamespaceString_forTest("testDb.testCollCustomized"); const UUID kUuid = UUID::gen(); diff --git a/src/mongo/db/s/balancer/balancer_defragmentation_policy_test.cpp b/src/mongo/db/s/balancer/balancer_defragmentation_policy_test.cpp index 0ffb8b256d2..953b6c95b5c 100644 --- a/src/mongo/db/s/balancer/balancer_defragmentation_policy_test.cpp +++ b/src/mongo/db/s/balancer/balancer_defragmentation_policy_test.cpp @@ -40,7 +40,7 @@ using ShardStatistics = ClusterStatistics::ShardStatistics; class BalancerDefragmentationPolicyTest : public ConfigServerTestFixture { protected: - const NamespaceString kNss{"testDb.testColl"}; + const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("testDb.testColl"); const UUID kUuid = UUID::gen(); const ShardId kShardId0 = ShardId("shard0"); const ShardId kShardId1 = ShardId("shard1"); diff --git a/src/mongo/db/s/balancer/cluster_chunks_resize_policy_test.cpp b/src/mongo/db/s/balancer/cluster_chunks_resize_policy_test.cpp index d08b453d4b5..f8d1870ff36 100644 --- a/src/mongo/db/s/balancer/cluster_chunks_resize_policy_test.cpp +++ b/src/mongo/db/s/balancer/cluster_chunks_resize_policy_test.cpp @@ -36,7 +36,7 @@ namespace { class ClusterChunksResizePolicyTest : public ConfigServerTestFixture { protected: - const NamespaceString kNss{"testDb.testColl"}; + const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("testDb.testColl"); const UUID kUuid = UUID::gen(); const ChunkVersion kCollectionVersion = ChunkVersion({OID::gen(), Timestamp(10)}, {1, 1}); diff --git a/src/mongo/db/s/collection_metadata_filtering_test.cpp b/src/mongo/db/s/collection_metadata_filtering_test.cpp index d1342eef868..017cc3362c1 100644 --- a/src/mongo/db/s/collection_metadata_filtering_test.cpp +++ b/src/mongo/db/s/collection_metadata_filtering_test.cpp @@ -37,7 +37,7 @@ namespace mongo { namespace { -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); class CollectionMetadataFilteringTest : public ShardServerTestFixture { protected: diff --git a/src/mongo/db/s/collection_metadata_test.cpp b/src/mongo/db/s/collection_metadata_test.cpp index e0afa83dcaa..18114ec79a4 100644 --- a/src/mongo/db/s/collection_metadata_test.cpp +++ b/src/mongo/db/s/collection_metadata_test.cpp @@ -39,7 +39,7 @@ namespace { using unittest::assertGet; -const NamespaceString kNss("test.foo"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.foo"); const ShardId kThisShard("thisShard"); const ShardId kOtherShard("otherShard"); diff --git a/src/mongo/db/s/collection_sharding_runtime_test.cpp b/src/mongo/db/s/collection_sharding_runtime_test.cpp index 109db73844d..76443bdc7eb 100644 --- a/src/mongo/db/s/collection_sharding_runtime_test.cpp +++ b/src/mongo/db/s/collection_sharding_runtime_test.cpp @@ -53,7 +53,8 @@ namespace mongo { namespace { -const NamespaceString kTestNss("TestDB", "TestColl"); +const NamespaceString kTestNss = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); const std::string kShardKey = "_id"; const BSONObj kShardKeyPattern = BSON(kShardKey << 1); @@ -205,7 +206,8 @@ TEST_F(CollectionShardingRuntimeTest, } TEST_F(CollectionShardingRuntimeTest, ReturnUnshardedMetadataInServerlessMode) { - const NamespaceString testNss("TestDBForServerless", "TestColl"); + const NamespaceString testNss = + NamespaceString::createNamespaceString_forTest("TestDBForServerless", "TestColl"); OperationContext* opCtx = operationContext(); // Enable serverless mode in global settings. @@ -257,7 +259,7 @@ TEST_F(CollectionShardingRuntimeTest, ReturnUnshardedMetadataInServerlessMode) { class CollectionShardingRuntimeTestWithMockedLoader : public ShardServerTestFixture { public: - const NamespaceString kNss{"test.foo"}; + const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.foo"); const UUID kCollUUID = UUID::gen(); const std::string kShardKey = "x"; const HostAndPort kConfigHostAndPort{"DummyConfig", 12345}; diff --git a/src/mongo/db/s/config/index_on_config_test.cpp b/src/mongo/db/s/config/index_on_config_test.cpp index 2e7920bb914..a3e1cad8fef 100644 --- a/src/mongo/db/s/config/index_on_config_test.cpp +++ b/src/mongo/db/s/config/index_on_config_test.cpp @@ -81,7 +81,7 @@ TEST_F(ConfigIndexTest, IncompatibleIndexAlreadyExists) { } TEST_F(ConfigIndexTest, CreateIndex) { - NamespaceString nss("config.foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("config.foo"); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, getIndexes(operationContext(), nss).getStatus()); @@ -111,7 +111,7 @@ TEST_F(ConfigIndexTest, CreateIndex) { } TEST_F(ConfigIndexTest, CreateIndexNonEmptyCollection) { - NamespaceString nss("config.foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("config.foo"); ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, getIndexes(operationContext(), nss).getStatus()); diff --git a/src/mongo/db/s/config/initial_split_policy_test.cpp b/src/mongo/db/s/config/initial_split_policy_test.cpp index 4003e43e1ca..4db00e91978 100644 --- a/src/mongo/db/s/config/initial_split_policy_test.cpp +++ b/src/mongo/db/s/config/initial_split_policy_test.cpp @@ -251,7 +251,7 @@ public: } private: - const NamespaceString _nss{"test.foo"}; + const NamespaceString _nss = NamespaceString::createNamespaceString_forTest("test.foo"); const UUID _uuid{UUID::gen()}; const ShardKeyPattern _shardKeyPattern = ShardKeyPattern(BSON("x" << "hashed")); @@ -1785,7 +1785,7 @@ public: }; TEST_F(SamplingBasedInitSplitTest, NoZones) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1)); std::vector shardList; @@ -1826,7 +1826,7 @@ TEST_F(SamplingBasedInitSplitTest, NoZones) { } TEST_F(SamplingBasedInitSplitTest, HashedShardKey) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << "hashed")); @@ -1868,7 +1868,7 @@ TEST_F(SamplingBasedInitSplitTest, HashedShardKey) { } TEST_F(SamplingBasedInitSplitTest, SingleInitialChunk) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1)); std::vector shardList; @@ -1900,7 +1900,7 @@ TEST_F(SamplingBasedInitSplitTest, SingleInitialChunk) { } TEST_F(SamplingBasedInitSplitTest, ZonesCoversEntireDomainButInsufficient) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1)); std::vector shardList; @@ -1945,7 +1945,7 @@ TEST_F(SamplingBasedInitSplitTest, ZonesCoversEntireDomainButInsufficient) { } TEST_F(SamplingBasedInitSplitTest, SamplesCoincidingWithZones) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1)); std::vector shardList; @@ -1993,7 +1993,7 @@ TEST_F(SamplingBasedInitSplitTest, SamplesCoincidingWithZones) { } TEST_F(SamplingBasedInitSplitTest, ZoneWithHoles) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1)); std::vector shardList; @@ -2039,7 +2039,7 @@ TEST_F(SamplingBasedInitSplitTest, ZoneWithHoles) { } TEST_F(SamplingBasedInitSplitTest, UnsortedZoneWithHoles) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1)); std::vector shardList; @@ -2085,7 +2085,7 @@ TEST_F(SamplingBasedInitSplitTest, UnsortedZoneWithHoles) { } TEST_F(SamplingBasedInitSplitTest, ZonesIsPrefixOfShardKey) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1 << "z" << 1)); std::vector shardList; @@ -2128,7 +2128,7 @@ TEST_F(SamplingBasedInitSplitTest, ZonesIsPrefixOfShardKey) { } TEST_F(SamplingBasedInitSplitTest, ZonesHasIncompatibleShardKey) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1 << "z" << 1)); std::vector shardList; @@ -2161,7 +2161,7 @@ TEST_F(SamplingBasedInitSplitTest, ZonesHasIncompatibleShardKey) { } TEST_F(SamplingBasedInitSplitTest, InsufficientSamples) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1)); std::vector shardList; @@ -2193,7 +2193,7 @@ TEST_F(SamplingBasedInitSplitTest, InsufficientSamples) { } TEST_F(SamplingBasedInitSplitTest, ZeroInitialChunks) { - const NamespaceString ns("foo", "bar"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("foo", "bar"); const ShardKeyPattern shardKey(BSON("y" << 1)); std::vector shardList; diff --git a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp index a5f1703688f..bf758421ab9 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp @@ -349,13 +349,13 @@ protected: << BSON("level" << "majority"))); auto cursorRes = - CursorResponse( - NamespaceString(DatabaseName(request.dbname), - NamespaceString::kClusterParametersNamespace.coll()), - 0, - {BSON("_id" - << "testStrClusterParameter" - << "strData" << request.dbname)}); + CursorResponse(NamespaceString::createNamespaceString_forTest( + DatabaseName(request.dbname), + NamespaceString::kClusterParametersNamespace.coll()), + 0, + {BSON("_id" + << "testStrClusterParameter" + << "strData" << request.dbname)}); return cursorRes.toBSON(CursorResponse::ResponseType::InitialResponse); }); } @@ -522,7 +522,7 @@ protected: operationContext(), ReadPreferenceSetting{ReadPreference::PrimaryOnly}, repl::ReadConcernLevel::kLocalReadConcern, - NamespaceString("config.changelog"), + NamespaceString::createNamespaceString_forTest("config.changelog"), BSON("what" << "addShard" << "details.name" << addedShard.getName()), @@ -620,7 +620,8 @@ TEST_F(AddShardTest, StandaloneBasicSuccess) { BSON("name" << discoveredDB1.getName() << "sizeOnDisk" << 2000), BSON("name" << discoveredDB2.getName() << "sizeOnDisk" << 5000)}); - expectCollectionDrop(shardTarget, NamespaceString("config", "system.sessions")); + expectCollectionDrop( + shardTarget, NamespaceString::createNamespaceString_forTest("config", "system.sessions")); // The shard receives the _addShard command expectAddShardCmdReturnSuccess(shardTarget, expectedShardName); @@ -706,7 +707,8 @@ TEST_F(AddShardTest, StandaloneBasicPushSuccess) { BSON("name" << discoveredDB1.getName() << "sizeOnDisk" << 2000), BSON("name" << discoveredDB2.getName() << "sizeOnDisk" << 5000)}); - expectCollectionDrop(shardTarget, NamespaceString("config", "system.sessions")); + expectCollectionDrop( + shardTarget, NamespaceString::createNamespaceString_forTest("config", "system.sessions")); // The shard receives the _addShard command expectAddShardCmdReturnSuccess(shardTarget, expectedShardName); @@ -786,7 +788,8 @@ TEST_F(AddShardTest, StandaloneMultitenantPullSuccess) { BSON("name" << discoveredDB1.getName() << "sizeOnDisk" << 2000), BSON("name" << discoveredDB2.getName() << "sizeOnDisk" << 5000)}); - expectCollectionDrop(shardTarget, NamespaceString("config", "system.sessions")); + expectCollectionDrop( + shardTarget, NamespaceString::createNamespaceString_forTest("config", "system.sessions")); // The shard receives the _addShard command expectAddShardCmdReturnSuccess(shardTarget, expectedShardName); @@ -888,7 +891,8 @@ TEST_F(AddShardTest, StandaloneMultitenantPushSuccess) { BSON("name" << discoveredDB1.getName() << "sizeOnDisk" << 2000), BSON("name" << discoveredDB2.getName() << "sizeOnDisk" << 5000)}); - expectCollectionDrop(shardTarget, NamespaceString("config", "system.sessions")); + expectCollectionDrop( + shardTarget, NamespaceString::createNamespaceString_forTest("config", "system.sessions")); // The shard receives the _addShard command expectAddShardCmdReturnSuccess(shardTarget, expectedShardName); @@ -978,7 +982,8 @@ TEST_F(AddShardTest, StandaloneGenerateName) { BSON("name" << discoveredDB1.getName() << "sizeOnDisk" << 2000), BSON("name" << discoveredDB2.getName() << "sizeOnDisk" << 5000)}); - expectCollectionDrop(shardTarget, NamespaceString("config", "system.sessions")); + expectCollectionDrop( + shardTarget, NamespaceString::createNamespaceString_forTest("config", "system.sessions")); // The shard receives the _addShard command expectAddShardCmdReturnSuccess(shardTarget, expectedShardName); @@ -1377,7 +1382,8 @@ TEST_F(AddShardTest, SuccessfullyAddReplicaSet) { // Get databases list from new shard expectListDatabases(shardTarget, std::vector{BSON("name" << discoveredDB.getName())}); - expectCollectionDrop(shardTarget, NamespaceString("config", "system.sessions")); + expectCollectionDrop( + shardTarget, NamespaceString::createNamespaceString_forTest("config", "system.sessions")); // The shard receives the _addShard command expectAddShardCmdReturnSuccess(shardTarget, expectedShardName); @@ -1449,7 +1455,8 @@ TEST_F(AddShardTest, ReplicaSetExtraHostsDiscovered) { // Get databases list from new shard expectListDatabases(shardTarget, std::vector{BSON("name" << discoveredDB.getName())}); - expectCollectionDrop(shardTarget, NamespaceString("config", "system.sessions")); + expectCollectionDrop( + shardTarget, NamespaceString::createNamespaceString_forTest("config", "system.sessions")); // The shard receives the _addShard command expectAddShardCmdReturnSuccess(shardTarget, expectedShardName); @@ -1534,7 +1541,8 @@ TEST_F(AddShardTest, AddShardSucceedsEvenIfAddingDBsFromNewShardFails) { BSON("name" << discoveredDB1.getName() << "sizeOnDisk" << 2000), BSON("name" << discoveredDB2.getName() << "sizeOnDisk" << 5000)}); - expectCollectionDrop(shardTarget, NamespaceString("config", "system.sessions")); + expectCollectionDrop( + shardTarget, NamespaceString::createNamespaceString_forTest("config", "system.sessions")); // The shard receives the _addShard command expectAddShardCmdReturnSuccess(shardTarget, expectedShardName); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_assign_key_range_to_zone_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_assign_key_range_to_zone_test.cpp index 297a4aa04d8..377d17292ff 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_assign_key_range_to_zone_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_assign_key_range_to_zone_test.cpp @@ -117,11 +117,11 @@ public: } NamespaceString shardedNS() const { - return NamespaceString("test.foo"); + return NamespaceString::createNamespaceString_forTest("test.foo"); } NamespaceString unshardedNS() const { - return NamespaceString("unsharded.coll"); + return NamespaceString::createNamespaceString_forTest("unsharded.coll"); } std::string zoneName() const { @@ -258,7 +258,7 @@ TEST_F(AssignKeyRangeToZoneTestFixture, RemoveZoneWithDollarPrefixedShardKeysSho } TEST_F(AssignKeyRangeToZoneTestFixture, MinThatIsAShardKeyPrefixShouldConvertToFullShardKey) { - NamespaceString ns("compound.shard"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("compound.shard"); CollectionType shardedCollection( ns, OID::gen(), Timestamp(1, 1), Date_t::now(), UUID::gen(), BSON("x" << 1 << "y" << 1)); @@ -275,7 +275,7 @@ TEST_F(AssignKeyRangeToZoneTestFixture, MinThatIsAShardKeyPrefixShouldConvertToF } TEST_F(AssignKeyRangeToZoneTestFixture, MaxThatIsAShardKeyPrefixShouldConvertToFullShardKey) { - NamespaceString ns("compound.shard"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("compound.shard"); CollectionType shardedCollection( ns, OID::gen(), Timestamp(1, 1), Date_t::now(), UUID::gen(), BSON("x" << 1 << "y" << 1)); @@ -327,7 +327,7 @@ TEST_F(AssignKeyRangeToZoneTestFixture, MinMaxThatIsNotAShardKeyPrefixShouldFail } TEST_F(AssignKeyRangeToZoneTestFixture, MinMaxThatIsAShardKeyPrefixShouldSucceed) { - NamespaceString ns("compound.shard"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("compound.shard"); CollectionType shardedCollection( ns, OID::gen(), Timestamp(1, 1), Date_t::now(), UUID::gen(), BSON("x" << 1 << "y" << 1)); @@ -365,7 +365,8 @@ TEST_F(AssignKeyRangeToZoneTestFixture, PrefixIsNotAllowedOnUnshardedColl) { } TEST_F(AssignKeyRangeToZoneTestFixture, TimeseriesCollMustHaveTimeKeyRangeMinKey) { - const NamespaceString ns("test.system.buckets.timeseries"); + const NamespaceString ns = + NamespaceString::createNamespaceString_forTest("test.system.buckets.timeseries"); const StringData metaField = "meta"_sd; const StringData timeField = "time"_sd; const std::string controlTimeField = @@ -525,7 +526,7 @@ TEST_F(AssignKeyRangeWithOneRangeFixture, NewRangeOverlappingInsideExistingShoul * 0123456789 */ TEST_F(AssignKeyRangeWithOneRangeFixture, NewRangeOverlappingWithDifferentNSShouldSucceed) { - CollectionType shardedCollection(NamespaceString("other.coll"), + CollectionType shardedCollection(NamespaceString::createNamespaceString_forTest("other.coll"), OID::gen(), Timestamp(1, 1), Date_t::now(), @@ -749,7 +750,7 @@ TEST_F(AssignKeyRangeWithOneRangeFixture, RemoveWithInvalidMaxShardKeyShouldFail } TEST_F(AssignKeyRangeWithOneRangeFixture, RemoveWithPartialMinPrefixShouldRemoveRange) { - NamespaceString ns("compound.shard"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("compound.shard"); CollectionType shardedCollection( ns, OID::gen(), Timestamp(1, 1), Date_t::now(), UUID::gen(), BSON("x" << 1 << "y" << 1)); @@ -772,7 +773,7 @@ TEST_F(AssignKeyRangeWithOneRangeFixture, RemoveWithPartialMinPrefixShouldRemove } TEST_F(AssignKeyRangeWithOneRangeFixture, RemoveWithPartialMaxPrefixShouldRemoveRange) { - NamespaceString ns("compound.shard"); + NamespaceString ns = NamespaceString::createNamespaceString_forTest("compound.shard"); CollectionType shardedCollection( ns, OID::gen(), Timestamp(1, 1), Date_t::now(), UUID::gen(), BSON("x" << 1 << "y" << 1)); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_bump_collection_version_and_change_metadata_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_bump_collection_version_and_change_metadata_test.cpp index a98c5ca938d..dc18b3ba28e 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_bump_collection_version_and_change_metadata_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_bump_collection_version_and_change_metadata_test.cpp @@ -44,7 +44,7 @@ namespace mongo { namespace { -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); const KeyPattern kKeyPattern(BSON("a" << 1)); const ShardType kShard0("shard0000", "shard0000:1234"); const ShardType kShard1("shard0001", "shard0001:1234"); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_clear_jumbo_flag_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_clear_jumbo_flag_test.cpp index 9f883997a3d..26294c605d2 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_clear_jumbo_flag_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_clear_jumbo_flag_test.cpp @@ -88,8 +88,10 @@ protected: } const std::string _shardName = "shard"; - const NamespaceString _nss1{"TestDB.TestColl1"}; - const NamespaceString _nss2{"TestDB.TestColl2"}; + const NamespaceString _nss1 = + NamespaceString::createNamespaceString_forTest("TestDB.TestColl1"); + const NamespaceString _nss2 = + NamespaceString::createNamespaceString_forTest("TestDB.TestColl2"); }; TEST_F(ClearJumboFlagTest, ClearJumboShouldBumpVersion) { diff --git a/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp index 57be3e8c40d..9fcdf428a83 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp @@ -351,7 +351,9 @@ TEST_F(ConfigInitializationTest, InizializePlacementHistory) { chunks1.push_back(c2); } - setupCollection(NamespaceString("db1.coll1"), BSON("x" << 1 << "y" << 1), chunks1); + setupCollection(NamespaceString::createNamespaceString_forTest("db1.coll1"), + BSON("x" << 1 << "y" << 1), + chunks1); // generate coll2 and its chunk: // 10 chunks: from shard6 to shard10 @@ -379,7 +381,9 @@ TEST_F(ConfigInitializationTest, InizializePlacementHistory) { chunks2.push_back(c1); } - setupCollection(NamespaceString("db1.coll2"), BSON("x" << 1 << "y" << 1), chunks2); + setupCollection(NamespaceString::createNamespaceString_forTest("db1.coll2"), + BSON("x" << 1 << "y" << 1), + chunks2); // Ensure that the vector clock is able to return an up-to-date config time to both the // ShardingCatalogManager and this test. @@ -400,7 +404,10 @@ TEST_F(ConfigInitializationTest, InizializePlacementHistory) { NamespaceString::kConfigsvrPlacementHistoryNamespace, BSON("nss" << "db1")); - assertPlacementType(db1Entry, NamespaceString("db1"), configTimeAtInitialization, {"shard1"}); + assertPlacementType(db1Entry, + NamespaceString::createNamespaceString_forTest("db1"), + configTimeAtInitialization, + {"shard1"}); // check db2 auto db2Entry = findOneOnConfigCollection( @@ -408,7 +415,10 @@ TEST_F(ConfigInitializationTest, InizializePlacementHistory) { NamespaceString::kConfigsvrPlacementHistoryNamespace, BSON("nss" << "db2")); - assertPlacementType(db2Entry, NamespaceString("db2"), configTimeAtInitialization, {"shard2"}); + assertPlacementType(db2Entry, + NamespaceString::createNamespaceString_forTest("db2"), + configTimeAtInitialization, + {"shard2"}); // check db3 auto db3Entry = findOneOnConfigCollection( @@ -416,7 +426,10 @@ TEST_F(ConfigInitializationTest, InizializePlacementHistory) { NamespaceString::kConfigsvrPlacementHistoryNamespace, BSON("nss" << "db3")); - assertPlacementType(db3Entry, NamespaceString("db3"), configTimeAtInitialization, {"shard3"}); + assertPlacementType(db3Entry, + NamespaceString::createNamespaceString_forTest("db3"), + configTimeAtInitialization, + {"shard3"}); // check coll1 auto coll1Entry = findOneOnConfigCollection( @@ -425,7 +438,7 @@ TEST_F(ConfigInitializationTest, InizializePlacementHistory) { BSON("nss" << "db1.coll1")); assertPlacementType(coll1Entry, - NamespaceString("db1.coll1"), + NamespaceString::createNamespaceString_forTest("db1.coll1"), configTimeAtInitialization, {"shard1", "shard2", "shard3", "shard4", "shard5"}); @@ -436,7 +449,7 @@ TEST_F(ConfigInitializationTest, InizializePlacementHistory) { BSON("nss" << "db1.coll2")); assertPlacementType(coll2Entry, - NamespaceString("db1.coll2"), + NamespaceString::createNamespaceString_forTest("db1.coll2"), configTimeAtInitialization, {"shard6", "shard7", "shard8", "shard9", "shard10"}); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_merge_chunks_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_merge_chunks_test.cpp index 2e3604af525..7f64439bda2 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_merge_chunks_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_merge_chunks_test.cpp @@ -75,8 +75,10 @@ protected: } const ShardId _shardId{_shardName}; - const NamespaceString _nss1{"TestDB.TestColl1"}; - const NamespaceString _nss2{"TestDB.TestColl2"}; + const NamespaceString _nss1 = + NamespaceString::createNamespaceString_forTest("TestDB.TestColl1"); + const NamespaceString _nss2 = + NamespaceString::createNamespaceString_forTest("TestDB.TestColl2"); const KeyPattern _keyPattern{BSON("x" << 1)}; }; @@ -467,13 +469,14 @@ TEST_F(MergeChunkTest, NonExistingNamespace) { setupCollection(_nss1, _keyPattern, {chunk, chunk2}); ASSERT_THROWS(ShardingCatalogManager::get(operationContext()) - ->commitChunksMerge(operationContext(), - NamespaceString("TestDB.NonExistingColl"), - collEpoch, - collTimestamp, - collUuidAtRequest, - rangeToBeMerged, - _shardId), + ->commitChunksMerge( + operationContext(), + NamespaceString::createNamespaceString_forTest("TestDB.NonExistingColl"), + collEpoch, + collTimestamp, + collUuidAtRequest, + rangeToBeMerged, + _shardId), DBException); } @@ -920,7 +923,7 @@ protected: inline const static auto _shards = std::vector{ShardType{"shard0", "host0:123"}, ShardType{"shard1", "host1:123"}}; - const NamespaceString _nss{"test.coll"}; + const NamespaceString _nss = NamespaceString::createNamespaceString_forTest("test.coll"); const UUID _collUuid = UUID::gen(); const OID _epoch = OID::gen(); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_from_zone_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_from_zone_test.cpp index 60327f62be5..fa0b28e547b 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_from_zone_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_from_zone_test.cpp @@ -109,7 +109,7 @@ TEST_F(RemoveShardFromZoneTest, RemoveLastZoneFromShardShouldSucceedWhenNoChunks // Insert a chunk range document referring to a different zone TagsType tagDoc; - tagDoc.setNS(NamespaceString("test.foo")); + tagDoc.setNS(NamespaceString::createNamespaceString_forTest("test.foo")); tagDoc.setMinKey(BSON("x" << 0)); tagDoc.setMaxKey(BSON("x" << 10)); tagDoc.setTag("y"); @@ -149,7 +149,7 @@ TEST_F(RemoveShardFromZoneTest, RemoveLastZoneFromShardShouldFailWhenAChunkRefer setupShards({shardA, shardB}); TagsType tagDoc; - tagDoc.setNS(NamespaceString("test.foo")); + tagDoc.setNS(NamespaceString::createNamespaceString_forTest("test.foo")); tagDoc.setMinKey(BSON("x" << 0)); tagDoc.setMaxKey(BSON("x" << 10)); tagDoc.setTag("z"); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_test.cpp index e0904146c32..e7ea22d1dd0 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_test.cpp @@ -230,7 +230,7 @@ TEST_F(RemoveShardTest, RemoveShardStillDrainingChunksRemaining) { setupShards(std::vector{shard1, shard2}); setupDatabase("testDB", shard1.getName()); - setupCollection(NamespaceString("testDB.testColl"), + setupCollection(NamespaceString::createNamespaceString_forTest("testDB.testColl"), kKeyPattern, std::vector{chunk1, chunk2, chunk3}); @@ -313,7 +313,7 @@ TEST_F(RemoveShardTest, RemoveShardCompletion) { setupShards(std::vector{shard1, shard2}); setupDatabase("testDB", shard2.getName()); - setupCollection(NamespaceString("testDB.testColl"), + setupCollection(NamespaceString::createNamespaceString_forTest("testDB.testColl"), kKeyPattern, std::vector{chunk1, chunk2, chunk3}); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_collection_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_collection_test.cpp index 545a7d2c15b..fb7c1bef681 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_shard_collection_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_collection_test.cpp @@ -81,7 +81,7 @@ protected: } const ShardId testPrimaryShard{"shard0"}; - const NamespaceString kNamespace{"db1.foo"}; + const NamespaceString kNamespace = NamespaceString::createNamespaceString_forTest("db1.foo"); private: const HostAndPort configHost{"configHost1"}; diff --git a/src/mongo/db/s/config/sharding_catalog_manager_split_chunk_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_split_chunk_test.cpp index 231cd8e12e1..04dc4f2d605 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_split_chunk_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_split_chunk_test.cpp @@ -66,8 +66,10 @@ protected: ConfigServerTestFixture::tearDown(); } - const NamespaceString _nss1{"TestDB", "TestColl1"}; - const NamespaceString _nss2{"TestDB", "TestColl2"}; + const NamespaceString _nss1 = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl1"); + const NamespaceString _nss2 = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl2"); const KeyPattern _keyPattern{BSON("a" << 1)}; }; @@ -385,7 +387,8 @@ TEST_F(SplitChunkTest, NonExisingNamespaceErrors) { ASSERT_EQUALS(ShardingCatalogManager::get(operationContext()) ->commitChunkSplit(operationContext(), - NamespaceString("TestDB.NonExistingColl"), + NamespaceString::createNamespaceString_forTest( + "TestDB.NonExistingColl"), collEpoch, Timestamp{50, 0}, ChunkRange(chunkMin, chunkMax), diff --git a/src/mongo/db/s/global_index/global_index_cloner_fetcher_test.cpp b/src/mongo/db/s/global_index/global_index_cloner_fetcher_test.cpp index 2bb94e9dbd8..0573b1834cd 100644 --- a/src/mongo/db/s/global_index/global_index_cloner_fetcher_test.cpp +++ b/src/mongo/db/s/global_index/global_index_cloner_fetcher_test.cpp @@ -103,7 +103,7 @@ public: } private: - const NamespaceString _ns{"test", "user"}; + const NamespaceString _ns = NamespaceString::createNamespaceString_forTest("test", "user"); const UUID _indexUUID{UUID::gen()}; const UUID _collUUID{UUID::gen()}; const ShardId _shard{"shardA"}; diff --git a/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp b/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp index 4f4306c19c6..2ff81e17895 100644 --- a/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp +++ b/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp @@ -62,7 +62,8 @@ using PauseDuringStateTransitions = resharding_service_test_helpers::PauseDuringStateTransitions; const ShardId kRecipientShardId{"myShardId"}; -const NamespaceString kSourceNss{"sourcedb", "sourcecollection"}; +const NamespaceString kSourceNss = + NamespaceString::createNamespaceString_forTest("sourcedb", "sourcecollection"); constexpr auto kSourceShardKey = "key"_sd; class GlobalIndexExternalStateForTest : public GlobalIndexCloningService::CloningExternalState { diff --git a/src/mongo/db/s/global_index/global_index_inserter_test.cpp b/src/mongo/db/s/global_index/global_index_inserter_test.cpp index dc5d399eeb0..c65ca491f74 100644 --- a/src/mongo/db/s/global_index/global_index_inserter_test.cpp +++ b/src/mongo/db/s/global_index/global_index_inserter_test.cpp @@ -130,7 +130,7 @@ private: return executor; } - const NamespaceString _nss{"test", "user"}; + const NamespaceString _nss = NamespaceString::createNamespaceString_forTest("test", "user"); const std::string _indexName{"global_x"}; const UUID _indexUUID{UUID::gen()}; const RAIIServerParameterControllerForTest _enableFeature{"featureFlagGlobalIndexes", true}; diff --git a/src/mongo/db/s/implicit_collection_creation_test.cpp b/src/mongo/db/s/implicit_collection_creation_test.cpp index f7c501f0a6f..ae1016e4644 100644 --- a/src/mongo/db/s/implicit_collection_creation_test.cpp +++ b/src/mongo/db/s/implicit_collection_creation_test.cpp @@ -44,7 +44,8 @@ namespace { class ImplicitCollectionCreationTest : public ShardServerTestFixture {}; TEST_F(ImplicitCollectionCreationTest, ImplicitCreateDisallowedByDefault) { - NamespaceString nss("ImplicitCreateDisallowedByDefaultDB.TestColl"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "ImplicitCreateDisallowedByDefaultDB.TestColl"); AutoGetCollection autoColl(operationContext(), nss, MODE_IX); auto db = autoColl.ensureDbExists(operationContext()); WriteUnitOfWork wuow(operationContext()); @@ -56,7 +57,8 @@ TEST_F(ImplicitCollectionCreationTest, ImplicitCreateDisallowedByDefault) { } TEST_F(ImplicitCollectionCreationTest, AllowImplicitCollectionCreate) { - NamespaceString nss("AllowImplicitCollectionCreateDB.TestColl"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("AllowImplicitCollectionCreateDB.TestColl"); OperationShardingState::ScopedAllowImplicitCollectionCreate_UNSAFE unsafeCreateCollection( operationContext()); AutoGetCollection autoColl(operationContext(), nss, MODE_IX); diff --git a/src/mongo/db/s/metadata_manager_test.cpp b/src/mongo/db/s/metadata_manager_test.cpp index f66649eae29..0f1c9ab2de9 100644 --- a/src/mongo/db/s/metadata_manager_test.cpp +++ b/src/mongo/db/s/metadata_manager_test.cpp @@ -56,7 +56,7 @@ namespace { using unittest::assertGet; -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); const std::string kPattern = "key"; const KeyPattern kShardKeyPattern(BSON(kPattern << 1)); const std::string kThisShard{"thisShard"}; diff --git a/src/mongo/db/s/migration_batch_fetcher_test.cpp b/src/mongo/db/s/migration_batch_fetcher_test.cpp index d9ec8c84069..b47a190d00a 100644 --- a/src/mongo/db/s/migration_batch_fetcher_test.cpp +++ b/src/mongo/db/s/migration_batch_fetcher_test.cpp @@ -172,7 +172,7 @@ auto getOnMigrateCloneCommandCb(BSONObj ret) { } TEST_F(MigrationBatchFetcherTestFixture, BasicEmptyFetchingTest) { - NamespaceString nss{"test", "foo"}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "foo"); ShardId fromShard{"Donor"}; auto msid = MigrationSessionId::generate(fromShard, "Recipient"); auto outerOpCtx = operationContext(); @@ -218,7 +218,7 @@ TEST_F(MigrationBatchFetcherTestFixture, BasicEmptyFetchingTest) { } TEST_F(MigrationBatchFetcherTestFixture, BasicFetching) { - NamespaceString nss{"test", "foo"}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "foo"); ShardId fromShard{"Donor"}; auto msid = MigrationSessionId::generate(fromShard, "Recipient"); diff --git a/src/mongo/db/s/migration_destination_manager_test.cpp b/src/mongo/db/s/migration_destination_manager_test.cpp index 1ee95dc8508..aeec60b57d4 100644 --- a/src/mongo/db/s/migration_destination_manager_test.cpp +++ b/src/mongo/db/s/migration_destination_manager_test.cpp @@ -172,7 +172,7 @@ using MigrationDestinationManagerNetworkTest = CatalogCacheTestFixture; // manager and won't include a read concern without afterClusterTime. TEST_F(MigrationDestinationManagerNetworkTest, MigrationDestinationManagerGetIndexesAndCollectionsNoVersionsOrReadConcern) { - const NamespaceString nss("db.foo"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("db.foo"); // Shard nss by _id with chunks [minKey, 0), [0, maxKey] on shards "0" and "1" respectively. // ShardId("1") is the primary shard for the database. diff --git a/src/mongo/db/s/migration_util_test.cpp b/src/mongo/db/s/migration_util_test.cpp index 84254dad0cd..70a01534d56 100644 --- a/src/mongo/db/s/migration_util_test.cpp +++ b/src/mongo/db/s/migration_util_test.cpp @@ -104,9 +104,15 @@ TEST_F(MigrationUtilsTest, TestOverlappingRangeQueryWithIntegerShardKey) { const auto uuid = UUID::gen(); PersistentTaskStore store(NamespaceString::kRangeDeletionNamespace); - store.add(opCtx, createDeletionTask(opCtx, NamespaceString{"one"}, uuid, 0, 10)); - store.add(opCtx, createDeletionTask(opCtx, NamespaceString{"two"}, uuid, 10, 20)); - store.add(opCtx, createDeletionTask(opCtx, NamespaceString{"three"}, uuid, 40, 50)); + store.add(opCtx, + createDeletionTask( + opCtx, NamespaceString::createNamespaceString_forTest("one"), uuid, 0, 10)); + store.add(opCtx, + createDeletionTask( + opCtx, NamespaceString::createNamespaceString_forTest("two"), uuid, 10, 20)); + store.add(opCtx, + createDeletionTask( + opCtx, NamespaceString::createNamespaceString_forTest("three"), uuid, 40, 50)); ASSERT_EQ(store.count(opCtx), 3); @@ -162,17 +168,17 @@ TEST_F(MigrationUtilsTest, TestOverlappingRangeQueryWithCompoundShardKeyWhereFir auto deletionTasks = { createDeletionTask(opCtx, - NamespaceString{"one"}, + NamespaceString::createNamespaceString_forTest("one"), uuid, BSON("a" << 0 << "b" << 0), BSON("a" << 0 << "b" << 10)), createDeletionTask(opCtx, - NamespaceString{"two"}, + NamespaceString::createNamespaceString_forTest("two"), uuid, BSON("a" << 0 << "b" << 10), BSON("a" << 0 << "b" << 20)), createDeletionTask(opCtx, - NamespaceString{"one"}, + NamespaceString::createNamespaceString_forTest("one"), uuid, BSON("a" << 0 << "b" << 40), BSON("a" << 0 << "b" << 50)), @@ -245,17 +251,17 @@ TEST_F(MigrationUtilsTest, auto deletionTasks = { createDeletionTask(opCtx, - NamespaceString{"one"}, + NamespaceString::createNamespaceString_forTest("one"), uuid, BSON("a" << 0 << "b" << 0), BSON("a" << 10 << "b" << 0)), createDeletionTask(opCtx, - NamespaceString{"two"}, + NamespaceString::createNamespaceString_forTest("two"), uuid, BSON("a" << 10 << "b" << 0), BSON("a" << 20 << "b" << 0)), createDeletionTask(opCtx, - NamespaceString{"one"}, + NamespaceString::createNamespaceString_forTest("one"), uuid, BSON("a" << 40 << "b" << 0), BSON("a" << 50 << "b" << 0)), @@ -325,9 +331,15 @@ TEST_F(MigrationUtilsTest, TestInvalidUUID) { const auto uuid = UUID::gen(); PersistentTaskStore store(NamespaceString::kRangeDeletionNamespace); - store.add(opCtx, createDeletionTask(opCtx, NamespaceString{"one"}, uuid, 0, 10)); - store.add(opCtx, createDeletionTask(opCtx, NamespaceString{"two"}, uuid, 10, 20)); - store.add(opCtx, createDeletionTask(opCtx, NamespaceString{"three"}, uuid, 40, 50)); + store.add(opCtx, + createDeletionTask( + opCtx, NamespaceString::createNamespaceString_forTest("one"), uuid, 0, 10)); + store.add(opCtx, + createDeletionTask( + opCtx, NamespaceString::createNamespaceString_forTest("two"), uuid, 10, 20)); + store.add(opCtx, + createDeletionTask( + opCtx, NamespaceString::createNamespaceString_forTest("three"), uuid, 40, 50)); ASSERT_EQ(store.count(opCtx), 3); diff --git a/src/mongo/db/s/op_observer_sharding_test.cpp b/src/mongo/db/s/op_observer_sharding_test.cpp index c5611006c8d..1b5f2ee340d 100644 --- a/src/mongo/db/s/op_observer_sharding_test.cpp +++ b/src/mongo/db/s/op_observer_sharding_test.cpp @@ -45,7 +45,8 @@ namespace mongo { namespace { -const NamespaceString kTestNss("TestDB", "TestColl"); +const NamespaceString kTestNss = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); const NamespaceString kUnshardedNss("TestDB", "UnshardedColl"); void setCollectionFilteringMetadata(OperationContext* opCtx, CollectionMetadata metadata) { diff --git a/src/mongo/db/s/persistent_task_queue_test.cpp b/src/mongo/db/s/persistent_task_queue_test.cpp index 62547d046f5..d9dd6e3562c 100644 --- a/src/mongo/db/s/persistent_task_queue_test.cpp +++ b/src/mongo/db/s/persistent_task_queue_test.cpp @@ -38,7 +38,7 @@ namespace mongo { namespace { -const NamespaceString kNss = NamespaceString("test", "foo"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test", "foo"); struct TestTask { std::string key; diff --git a/src/mongo/db/s/query_analysis_coordinator_test.cpp b/src/mongo/db/s/query_analysis_coordinator_test.cpp index b15f0e81f8b..58cdad04509 100644 --- a/src/mongo/db/s/query_analysis_coordinator_test.cpp +++ b/src/mongo/db/s/query_analysis_coordinator_test.cpp @@ -143,9 +143,12 @@ protected: } } - const NamespaceString nss0{"testDb", "testColl0"}; - const NamespaceString nss1{"testDb", "testColl1"}; - const NamespaceString nss2{"testDb", "testColl2"}; + const NamespaceString nss0 = + NamespaceString::createNamespaceString_forTest("testDb", "testColl0"); + const NamespaceString nss1 = + NamespaceString::createNamespaceString_forTest("testDb", "testColl1"); + const NamespaceString nss2 = + NamespaceString::createNamespaceString_forTest("testDb", "testColl2"); const UUID collUuid0 = UUID::gen(); const UUID collUuid1 = UUID::gen(); diff --git a/src/mongo/db/s/query_analysis_writer_test.cpp b/src/mongo/db/s/query_analysis_writer_test.cpp index 9c7487ca539..c954511f605 100644 --- a/src/mongo/db/s/query_analysis_writer_test.cpp +++ b/src/mongo/db/s/query_analysis_writer_test.cpp @@ -434,8 +434,10 @@ protected: assertBsonObjEqualUnordered(parsedDiffDoc.getDiff(), expectedDiff); } - const NamespaceString nss0{"testDb", "testColl0"}; - const NamespaceString nss1{"testDb", "testColl1"}; + const NamespaceString nss0 = + NamespaceString::createNamespaceString_forTest("testDb", "testColl0"); + const NamespaceString nss1 = + NamespaceString::createNamespaceString_forTest("testDb", "testColl1"); // Test with both empty and non-empty filter and collation to verify that the // QueryAnalysisWriter doesn't require filter or collation to be non-empty. diff --git a/src/mongo/db/s/range_deletion_util_test.cpp b/src/mongo/db/s/range_deletion_util_test.cpp index 0fc18ca7a84..6f7e7ee5c4d 100644 --- a/src/mongo/db/s/range_deletion_util_test.cpp +++ b/src/mongo/db/s/range_deletion_util_test.cpp @@ -49,7 +49,7 @@ namespace mongo { namespace { -const NamespaceString kNss = NamespaceString("foo", "bar"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("foo", "bar"); const std::string kShardKey = "_id"; const BSONObj kShardKeyPattern = BSON(kShardKey << 1); @@ -141,7 +141,8 @@ private: */ class RenameRangeDeletionsTest : public RangeDeleterTest { public: - const NamespaceString kToNss = NamespaceString(kNss.db(), "toColl"); + const NamespaceString kToNss = + NamespaceString::createNamespaceString_forTest(kNss.db(), "toColl"); void setUp() override { RangeDeleterTest::setUp(); @@ -357,7 +358,8 @@ TEST_F(RangeDeleterTest, TEST_F(RangeDeleterTest, RemoveDocumentsInRangeThrowsErrorWhenCollectionDoesNotExist) { auto queriesComplete = SemiFuture::makeReady(); - const auto notExistingNss = NamespaceString("someFake.namespace"); + const auto notExistingNss = + NamespaceString::createNamespaceString_forTest("someFake.namespace"); const auto notExistingCollectionUUID = UUID::gen(); const auto range = ChunkRange(BSON(kShardKey << 0), BSON(kShardKey << 10)); auto task = diff --git a/src/mongo/db/s/resharding/resharding_collection_cloner_test.cpp b/src/mongo/db/s/resharding/resharding_collection_cloner_test.cpp index aa35eef0774..8e8f1c79b6b 100644 --- a/src/mongo/db/s/resharding/resharding_collection_cloner_test.cpp +++ b/src/mongo/db/s/resharding/resharding_collection_cloner_test.cpp @@ -185,7 +185,8 @@ protected: } protected: - const NamespaceString _sourceNss = NamespaceString("test"_sd, "collection_being_resharded"_sd); + const NamespaceString _sourceNss = + NamespaceString::createNamespaceString_forTest("test"_sd, "collection_being_resharded"_sd); const NamespaceString tempNss = resharding::constructTemporaryReshardingNss(_sourceNss.db(), _sourceUUID); const UUID _sourceUUID = UUID::gen(); diff --git a/src/mongo/db/s/resharding/resharding_collection_test.cpp b/src/mongo/db/s/resharding/resharding_collection_test.cpp index b44cac4d093..8ebb4287055 100644 --- a/src/mongo/db/s/resharding/resharding_collection_test.cpp +++ b/src/mongo/db/s/resharding/resharding_collection_test.cpp @@ -84,11 +84,12 @@ TEST_F(ReshardingCollectionTest, TestWritesToTempReshardingCollection) { SimpleClient client(operationContext()); auto uuid = UUID::gen(); - auto tempNss = NamespaceString{"{}.system.resharding.{}"_format("test", uuid.toString())}; + auto tempNss = NamespaceString::createNamespaceString_forTest( + "{}.system.resharding.{}"_format("test", uuid.toString())); ASSERT_OK(client.insert(tempNss, BSON("x" << 5))); - auto chunksNss = NamespaceString{ - "config.cache.chunks.{}.system.resharding.{}"_format("test", uuid.toString())}; + auto chunksNss = NamespaceString::createNamespaceString_forTest( + "config.cache.chunks.{}.system.resharding.{}"_format("test", uuid.toString())); ASSERT_OK(client.insert(chunksNss, BSON("X" << 5))); } @@ -108,12 +109,12 @@ TEST_F(ReshardingCollectionTest, TestWritesToTempReshardingCollectionStressTest) SimpleClient client(opCtx.get()); auto uuid = UUID::gen(); - auto tempNss = - NamespaceString{"{}.system.resharding.{}"_format("test", uuid.toString())}; + auto tempNss = NamespaceString::createNamespaceString_forTest( + "{}.system.resharding.{}"_format("test", uuid.toString())); ASSERT_OK(client.insert(tempNss, BSON("x" << 5))); - auto chunksNss = NamespaceString{ - "config.cache.chunks.{}.system.resharding.{}"_format("test", uuid.toString())}; + auto chunksNss = NamespaceString::createNamespaceString_forTest( + "config.cache.chunks.{}.system.resharding.{}"_format("test", uuid.toString())); ASSERT_OK(client.insert(chunksNss, BSON("X" << 5))); iterations.increment(); } diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp index b181acc1fbd..ecc7a928002 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp @@ -632,12 +632,13 @@ public: repl::PrimaryOnlyServiceRegistry* _registry = nullptr; - NamespaceString _originalNss = NamespaceString("db.foo"); + NamespaceString _originalNss = NamespaceString::createNamespaceString_forTest("db.foo"); UUID _originalUUID = UUID::gen(); OID _originalEpoch = OID::gen(); Timestamp _originalTimestamp = Timestamp(1); - NamespaceString _tempNss = NamespaceString("db.system.resharding." + _originalUUID.toString()); + NamespaceString _tempNss = NamespaceString::createNamespaceString_forTest( + "db.system.resharding." + _originalUUID.toString()); UUID _reshardingUUID = UUID::gen(); OID _tempEpoch = OID::gen(); Timestamp _tempTimestamp = Timestamp(2); @@ -956,27 +957,29 @@ TEST_F(ReshardingCoordinatorServiceTest, MultipleReshardingOperationsFail) { // Asserts that a resharding op with different namespace and different shard key fails with // ConflictingOperationInProgress. - ASSERT_THROWS_CODE(initializeAndGetCoordinator( - UUID::gen(), - NamespaceString("db.moo"), - NamespaceString("db.system.resharding." + UUID::gen().toString()), - ShardKeyPattern(BSON("shardKeyV1" << 1)), - UUID::gen(), - ShardKeyPattern(BSON("shardKeyV2" << 1))), - DBException, - ErrorCodes::ConflictingOperationInProgress); + ASSERT_THROWS_CODE( + initializeAndGetCoordinator(UUID::gen(), + NamespaceString::createNamespaceString_forTest("db.moo"), + NamespaceString::createNamespaceString_forTest( + "db.system.resharding." + UUID::gen().toString()), + ShardKeyPattern(BSON("shardKeyV1" << 1)), + UUID::gen(), + ShardKeyPattern(BSON("shardKeyV2" << 1))), + DBException, + ErrorCodes::ConflictingOperationInProgress); // Asserts that a resharding op with same namespace and different shard key fails with // ConflictingOperationInProgress. - ASSERT_THROWS_CODE(initializeAndGetCoordinator( - UUID::gen(), - _originalNss, - NamespaceString("db.system.resharding." + UUID::gen().toString()), - ShardKeyPattern(BSON("shardKeyV1" << 1)), - UUID::gen(), - _oldShardKey), - DBException, - ErrorCodes::ConflictingOperationInProgress); + ASSERT_THROWS_CODE( + initializeAndGetCoordinator(UUID::gen(), + _originalNss, + NamespaceString::createNamespaceString_forTest( + "db.system.resharding." + UUID::gen().toString()), + ShardKeyPattern(BSON("shardKeyV1" << 1)), + UUID::gen(), + _oldShardKey), + DBException, + ErrorCodes::ConflictingOperationInProgress); runReshardingToCompletion(TransitionFunctionMap{}, std::move(stateTransitionsGuard)); } diff --git a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp index 878b8b1fdc5..c9fb99d7c47 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp @@ -712,12 +712,13 @@ protected: writeStateTransitionUpdateExpectSuccess(operationContext(), expectedCoordinatorDoc); } - NamespaceString _originalNss = NamespaceString("db.foo"); + NamespaceString _originalNss = NamespaceString::createNamespaceString_forTest("db.foo"); UUID _originalUUID = UUID::gen(); OID _originalEpoch = OID::gen(); Timestamp _originalTimestamp{3}; - NamespaceString _tempNss = NamespaceString("db.system.resharding." + _originalUUID.toString()); + NamespaceString _tempNss = NamespaceString::createNamespaceString_forTest( + "db.system.resharding." + _originalUUID.toString()); UUID _reshardingUUID = UUID::gen(); OID _tempEpoch = OID::gen(); diff --git a/src/mongo/db/s/resharding/resharding_data_replication_test.cpp b/src/mongo/db/s/resharding/resharding_data_replication_test.cpp index 3d5934199d3..fd6ed5a9188 100644 --- a/src/mongo/db/s/resharding/resharding_data_replication_test.cpp +++ b/src/mongo/db/s/resharding/resharding_data_replication_test.cpp @@ -112,7 +112,8 @@ private: const StringData _currentShardKey = "sk"; - const NamespaceString _sourceNss{"test_crud", "collection_being_resharded"}; + const NamespaceString _sourceNss = + NamespaceString::createNamespaceString_forTest("test_crud", "collection_being_resharded"); const UUID _sourceUUID = UUID::gen(); const ShardId _myDonorId{"myDonorId"}; diff --git a/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp index b060d4bfe5f..be15507846e 100644 --- a/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp +++ b/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp @@ -82,7 +82,7 @@ void runInTransaction(OperationContext* opCtx, Callable&& func) { class DestinedRecipientTest : public ShardServerTestFixture { public: - const NamespaceString kNss{"test.foo"}; + const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.foo"); const std::string kShardKey = "x"; const HostAndPort kConfigHostAndPort{"DummyConfig", 12345}; const std::vector kShardList = {ShardType("shard0", "Host0:12345"), @@ -200,11 +200,11 @@ protected: CollectionGeneration gen(OID::gen(), Timestamp(1, 1)); env.version = ShardVersion(ChunkVersion(gen, {1, 0}), boost::optional(boost::none)); - env.tempNss = - NamespaceString(kNss.db(), - fmt::format("{}{}", - NamespaceString::kTemporaryReshardingCollectionPrefix, - env.sourceUuid.toString())); + env.tempNss = NamespaceString::createNamespaceString_forTest( + kNss.db(), + fmt::format("{}{}", + NamespaceString::kTemporaryReshardingCollectionPrefix, + env.sourceUuid.toString())); uassertStatusOK(createCollection( operationContext(), env.tempNss.dbName(), BSON("create" << env.tempNss.coll()))); diff --git a/src/mongo/db/s/resharding/resharding_donor_oplog_iterator_test.cpp b/src/mongo/db/s/resharding/resharding_donor_oplog_iterator_test.cpp index a0491b06e7c..a986971b1c5 100644 --- a/src/mongo/db/s/resharding/resharding_donor_oplog_iterator_test.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_oplog_iterator_test.cpp @@ -181,9 +181,10 @@ public: } private: - const NamespaceString _oplogNss{"{}.{}xxx.yyy"_format( - NamespaceString::kConfigDb, NamespaceString::kReshardingLocalOplogBufferPrefix)}; - const NamespaceString _crudNss{"test.foo"}; + const NamespaceString _oplogNss = + NamespaceString::createNamespaceString_forTest("{}.{}xxx.yyy"_format( + NamespaceString::kConfigDb, NamespaceString::kReshardingLocalOplogBufferPrefix)); + const NamespaceString _crudNss = NamespaceString::createNamespaceString_forTest("test.foo"); const UUID _uuid{UUID::gen()}; RAIIServerParameterControllerForTest controller{"reshardingOplogBatchLimitOperations", 1}; diff --git a/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.cpp b/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.cpp index b8e6911e4f5..6752df4100d 100644 --- a/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.cpp @@ -55,7 +55,8 @@ class ReshardingDonorRecipientCommonInternalsTest : public ShardServerTestFixtur public: const UUID kExistingUUID = UUID::gen(); const Timestamp kExistingTimestamp = Timestamp(10, 5); - const NamespaceString kOriginalNss = NamespaceString("db", "foo"); + const NamespaceString kOriginalNss = + NamespaceString::createNamespaceString_forTest("db", "foo"); const NamespaceString kTemporaryReshardingNss = resharding::constructTemporaryReshardingNss("db", kExistingUUID); @@ -643,10 +644,10 @@ TEST_F(ReshardingDonorRecipientCommonInternalsTest, ClearReshardingFilteringMeta TEST_F(ReshardingDonorRecipientCommonInternalsTest, ClearReshardingFilteringMetaDataForActiveOp) { OperationContext* opCtx = operationContext(); - NamespaceString sourceNss1 = NamespaceString("db", "one"); + NamespaceString sourceNss1 = NamespaceString::createNamespaceString_forTest("db", "one"); NamespaceString tempReshardingNss1 = resharding::constructTemporaryReshardingNss(sourceNss1.db(), UUID::gen()); - NamespaceString sourceNss2 = NamespaceString("db", "two"); + NamespaceString sourceNss2 = NamespaceString::createNamespaceString_forTest("db", "two"); NamespaceString tempReshardingNss2 = resharding::constructTemporaryReshardingNss(sourceNss2.db(), UUID::gen()); ShardId shardId1 = ShardId{"recipient1"}; diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp index db9109e13d5..f3518a0349b 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp @@ -345,12 +345,16 @@ protected: } static constexpr int kWriterPoolSize = 4; - const NamespaceString kOplogNs{"config.localReshardingOplogBuffer.xxx.yyy"}; - const NamespaceString kCrudNs{"foo.bar"}; + const NamespaceString kOplogNs = + NamespaceString::createNamespaceString_forTest("config.localReshardingOplogBuffer.xxx.yyy"); + const NamespaceString kCrudNs = NamespaceString::createNamespaceString_forTest("foo.bar"); const UUID kCrudUUID = UUID::gen(); - const NamespaceString kAppliedToNs{"foo", "system.resharding.{}"_format(kCrudUUID.toString())}; - const NamespaceString kStashNs{"foo", "{}.{}"_format(kCrudNs.coll(), kOplogNs.coll())}; - const NamespaceString kOtherDonorStashNs{"foo", "{}.{}"_format("otherstash", "otheroplog")}; + const NamespaceString kAppliedToNs = NamespaceString::createNamespaceString_forTest( + "foo", "system.resharding.{}"_format(kCrudUUID.toString())); + const NamespaceString kStashNs = NamespaceString::createNamespaceString_forTest( + "foo", "{}.{}"_format(kCrudNs.coll(), kOplogNs.coll())); + const NamespaceString kOtherDonorStashNs = NamespaceString::createNamespaceString_forTest( + "foo", "{}.{}"_format("otherstash", "otheroplog")); const std::vector kStashCollections{kStashNs, kOtherDonorStashNs}; const ShardId kMyShardId{"shard1"}; const ShardId kOtherShardId{"shard2"}; diff --git a/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp index 62b408da0b7..455bad8a526 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp @@ -356,8 +356,10 @@ private: }; TEST_F(ReshardingOplogFetcherTest, TestBasic) { - const NamespaceString outputCollectionNss("dbtests.outputCollection"); - const NamespaceString dataCollectionNss("dbtests.runFetchIteration"); + const NamespaceString outputCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.outputCollection"); + const NamespaceString dataCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.runFetchIteration"); setupBasic(outputCollectionNss, dataCollectionNss, _destinationShard); @@ -386,8 +388,10 @@ TEST_F(ReshardingOplogFetcherTest, TestBasic) { } TEST_F(ReshardingOplogFetcherTest, TestTrackLastSeen) { - const NamespaceString outputCollectionNss("dbtests.outputCollection"); - const NamespaceString dataCollectionNss("dbtests.runFetchIteration"); + const NamespaceString outputCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.outputCollection"); + const NamespaceString dataCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.runFetchIteration"); setupBasic(outputCollectionNss, dataCollectionNss, _destinationShard); @@ -423,8 +427,10 @@ TEST_F(ReshardingOplogFetcherTest, TestTrackLastSeen) { } TEST_F(ReshardingOplogFetcherTest, TestFallingOffOplog) { - const NamespaceString outputCollectionNss("dbtests.outputCollection"); - const NamespaceString dataCollectionNss("dbtests.runFetchIteration"); + const NamespaceString outputCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.outputCollection"); + const NamespaceString dataCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.runFetchIteration"); setupBasic(outputCollectionNss, dataCollectionNss, _destinationShard); @@ -463,8 +469,10 @@ TEST_F(ReshardingOplogFetcherTest, TestFallingOffOplog) { } TEST_F(ReshardingOplogFetcherTest, TestAwaitInsert) { - const NamespaceString outputCollectionNss("dbtests.outputCollection"); - const NamespaceString dataCollectionNss("dbtests.runFetchIteration"); + const NamespaceString outputCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.outputCollection"); + const NamespaceString dataCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.runFetchIteration"); create(outputCollectionNss); create(dataCollectionNss); @@ -539,8 +547,10 @@ TEST_F(ReshardingOplogFetcherTest, TestAwaitInsert) { } TEST_F(ReshardingOplogFetcherTest, TestStartAtUpdatedWithProgressMarkOplogTs) { - const NamespaceString outputCollectionNss("dbtests.outputCollection"); - const NamespaceString dataCollectionNss("dbtests.runFetchIteration"); + const NamespaceString outputCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.outputCollection"); + const NamespaceString dataCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.runFetchIteration"); const NamespaceString otherCollection("dbtests.collectionNotBeingResharded"); create(outputCollectionNss); @@ -634,8 +644,10 @@ TEST_F(ReshardingOplogFetcherTest, TestStartAtUpdatedWithProgressMarkOplogTs) { } TEST_F(ReshardingOplogFetcherTest, RetriesOnRemoteInterruptionError) { - const NamespaceString outputCollectionNss("dbtests.outputCollection"); - const NamespaceString dataCollectionNss("dbtests.runFetchIteration"); + const NamespaceString outputCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.outputCollection"); + const NamespaceString dataCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.runFetchIteration"); create(outputCollectionNss); create(dataCollectionNss); @@ -674,8 +686,10 @@ TEST_F(ReshardingOplogFetcherTest, RetriesOnRemoteInterruptionError) { } TEST_F(ReshardingOplogFetcherTest, ImmediatelyDoneWhenFinalOpHasAlreadyBeenFetched) { - const NamespaceString outputCollectionNss("dbtests.outputCollection"); - const NamespaceString dataCollectionNss("dbtests.runFetchIteration"); + const NamespaceString outputCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.outputCollection"); + const NamespaceString dataCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.runFetchIteration"); create(outputCollectionNss); create(dataCollectionNss); @@ -704,8 +718,10 @@ TEST_F(ReshardingOplogFetcherTest, ImmediatelyDoneWhenFinalOpHasAlreadyBeenFetch DEATH_TEST_REGEX_F(ReshardingOplogFetcherTest, CannotFetchMoreWhenFinalOpHasAlreadyBeenFetched, "Invariant failure.*_startAt != kFinalOpAlreadyFetched") { - const NamespaceString outputCollectionNss("dbtests.outputCollection"); - const NamespaceString dataCollectionNss("dbtests.runFetchIteration"); + const NamespaceString outputCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.outputCollection"); + const NamespaceString dataCollectionNss = + NamespaceString::createNamespaceString_forTest("dbtests.runFetchIteration"); create(outputCollectionNss); create(dataCollectionNss); diff --git a/src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp index 3b9f854cefd..0cbc3a44c78 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp @@ -386,8 +386,8 @@ public: private: // Used for pre/post image oplog entry lookup. const ShardId _donorShardId{"donor-0"}; - const NamespaceString _oplogBufferNss{NamespaceString::kReshardingLocalOplogBufferPrefix + - _donorShardId.toString()}; + const NamespaceString _oplogBufferNss = NamespaceString::createNamespaceString_forTest( + NamespaceString::kReshardingLocalOplogBufferPrefix + _donorShardId.toString()); }; TEST_F(ReshardingOplogSessionApplicationTest, IncomingRetryableWriteForNewSession) { diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_external_state_test.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_external_state_test.cpp index 4a457b0da84..cf01d4db953 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_external_state_test.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_external_state_test.cpp @@ -57,12 +57,12 @@ class RecipientServiceExternalStateTest : public CatalogCacheTestFixture, public: const ShardKeyPattern kShardKey = ShardKeyPattern(BSON("_id" << 1)); - const NamespaceString kOrigNss = NamespaceString("db.foo"); + const NamespaceString kOrigNss = NamespaceString::createNamespaceString_forTest("db.foo"); const OID kOrigEpoch = OID::gen(); const Timestamp kOrigTimestamp = Timestamp(1); const UUID kOrigUUID = UUID::gen(); - const NamespaceString kReshardingNss = NamespaceString( + const NamespaceString kReshardingNss = NamespaceString::createNamespaceString_forTest( str::stream() << "db." << NamespaceString::kTemporaryReshardingCollectionPrefix << kOrigUUID); const ShardKeyPattern kReshardingKey = ShardKeyPattern(BSON("newKey" << 1)); diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp index 9db36980da8..8664473c978 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp @@ -164,7 +164,8 @@ private: const StringData _currentShardKey = "oldKey"; - const NamespaceString _sourceNss{"sourcedb", "sourcecollection"}; + const NamespaceString _sourceNss = + NamespaceString::createNamespaceString_forTest("sourcedb", "sourcecollection"); const UUID _sourceUUID = UUID::gen(); const ShardId _someDonorId{"myDonorId"}; @@ -263,7 +264,8 @@ public: ShardId{"donor3"}}, durationCount(Milliseconds{5})); - NamespaceString sourceNss("sourcedb", "sourcecollection"); + NamespaceString sourceNss = + NamespaceString::createNamespaceString_forTest("sourcedb", "sourcecollection"); auto sourceUUID = UUID::gen(); auto commonMetadata = CommonReshardingMetadata( UUID::gen(), diff --git a/src/mongo/db/s/resharding/resharding_util_test.cpp b/src/mongo/db/s/resharding/resharding_util_test.cpp index 69368692723..8de383855b7 100644 --- a/src/mongo/db/s/resharding/resharding_util_test.cpp +++ b/src/mongo/db/s/resharding/resharding_util_test.cpp @@ -92,7 +92,7 @@ protected: } private: - const NamespaceString _nss{"test.foo"}; + const NamespaceString _nss = NamespaceString::createNamespaceString_forTest("test.foo"); const std::string _shardKey = "x"; const ShardKeyPattern _shardKeyPattern = ShardKeyPattern(BSON("x" << "hashed")); diff --git a/src/mongo/db/s/session_catalog_migration_destination_test.cpp b/src/mongo/db/s/session_catalog_migration_destination_test.cpp index 303ca464e90..6e54739ffe8 100644 --- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp +++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp @@ -76,7 +76,7 @@ const ConnectionString kConfigConnStr = const ConnectionString kDonorConnStr = ConnectionString::forReplicaSet("donor", {HostAndPort("donor:1")}); const ShardId kFromShard("donor"); -const NamespaceString kNs("a.b"); +const NamespaceString kNs = NamespaceString::createNamespaceString_forTest("a.b"); /** * Creates an OplogEntry with given parameters and preset defaults for this test suite. diff --git a/src/mongo/db/s/session_catalog_migration_source_test.cpp b/src/mongo/db/s/session_catalog_migration_source_test.cpp index be08b3e4f7b..c94f9a009cf 100644 --- a/src/mongo/db/s/session_catalog_migration_source_test.cpp +++ b/src/mongo/db/s/session_catalog_migration_source_test.cpp @@ -59,8 +59,8 @@ namespace { using executor::RemoteCommandRequest; -const NamespaceString kNs("a.b"); -const NamespaceString kOtherNs("a.b.c"); +const NamespaceString kNs = NamespaceString::createNamespaceString_forTest("a.b"); +const NamespaceString kOtherNs = NamespaceString::createNamespaceString_forTest("a.b.c"); const KeyPattern kShardKey(BSON("x" << 1)); const ChunkRange kChunkRange(BSON("x" << 0), BSON("x" << 100)); const KeyPattern kNestedShardKey(BSON("x.y" << 1)); @@ -815,12 +815,12 @@ TEST_F(SessionCatalogMigrationSourceTest, OplogWithOtherNsShouldBeIgnored) { auto entry2 = makeOplogEntry( - repl::OpTime(Timestamp(53, 12), 2), // optime - repl::OpTypeEnum::kDelete, // op type - NamespaceString("x.y"), // namespace - BSON("x" << 30), // o - boost::none, // o2 - Date_t::now(), // wall clock time + repl::OpTime(Timestamp(53, 12), 2), // optime + repl::OpTypeEnum::kDelete, // op type + NamespaceString::createNamespaceString_forTest("x.y"), // namespace + BSON("x" << 30), // o + boost::none, // o2 + Date_t::now(), // wall clock time sessionId2, txnNumber2, {1}, // statement ids diff --git a/src/mongo/db/s/shard_key_index_util_test.cpp b/src/mongo/db/s/shard_key_index_util_test.cpp index 73e8f78779e..1b881f904dc 100644 --- a/src/mongo/db/s/shard_key_index_util_test.cpp +++ b/src/mongo/db/s/shard_key_index_util_test.cpp @@ -80,7 +80,7 @@ protected: } private: - const NamespaceString _nss{"test.user"}; + const NamespaceString _nss = NamespaceString::createNamespaceString_forTest("test.user"); boost::optional _coll; }; diff --git a/src/mongo/db/s/shard_local_test.cpp b/src/mongo/db/s/shard_local_test.cpp index 1021d3befdb..2bbd9b3d60a 100644 --- a/src/mongo/db/s/shard_local_test.cpp +++ b/src/mongo/db/s/shard_local_test.cpp @@ -173,7 +173,7 @@ StatusWith ShardLocalTest::runFindQuery(NamespaceString ns } TEST_F(ShardLocalTest, RunCommand) { - NamespaceString nss("admin.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("admin.bar"); StatusWith findAndModifyResponse = runFindAndModifyRunCommand( nss, BSON("fooItem" << 1), BSON("$set" << BSON("fooRandom" << 254))); @@ -185,7 +185,7 @@ TEST_F(ShardLocalTest, RunCommand) { } TEST_F(ShardLocalTest, FindOneWithoutLimit) { - NamespaceString nss("admin.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("admin.bar"); // Set up documents to be queried. StatusWith findAndModifyResponse = runFindAndModifyRunCommand( @@ -209,7 +209,7 @@ TEST_F(ShardLocalTest, FindOneWithoutLimit) { } TEST_F(ShardLocalTest, FindManyWithLimit) { - NamespaceString nss("admin.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("admin.bar"); // Set up documents to be queried. StatusWith findAndModifyResponse = runFindAndModifyRunCommand( @@ -239,7 +239,7 @@ TEST_F(ShardLocalTest, FindManyWithLimit) { } TEST_F(ShardLocalTest, FindNoMatchingDocumentsEmpty) { - NamespaceString nss("admin.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("admin.bar"); // Set up a document. StatusWith findAndModifyResponse = runFindAndModifyRunCommand( diff --git a/src/mongo/db/s/shard_metadata_util_test.cpp b/src/mongo/db/s/shard_metadata_util_test.cpp index af35cf373e8..f1bcf8fa4d1 100644 --- a/src/mongo/db/s/shard_metadata_util_test.cpp +++ b/src/mongo/db/s/shard_metadata_util_test.cpp @@ -46,8 +46,9 @@ using std::unique_ptr; using std::vector; using unittest::assertGet; -const NamespaceString kNss = NamespaceString("test.foo"); -const NamespaceString kChunkMetadataNss = NamespaceString("config.cache.chunks.test.foo"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.foo"); +const NamespaceString kChunkMetadataNss = + NamespaceString::createNamespaceString_forTest("config.cache.chunks.test.foo"); const ShardId kShardId = ShardId("shard0"); const bool kUnique = false; diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp index 0ae5ca1d584..354f7843a5c 100644 --- a/src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp +++ b/src/mongo/db/s/shard_server_catalog_cache_loader_test.cpp @@ -43,7 +43,7 @@ using std::vector; using unittest::assertGet; using CollectionAndChangedChunks = CatalogCacheLoader::CollectionAndChangedChunks; -const NamespaceString kNss = NamespaceString("foo.bar"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("foo.bar"); const std::string kPattern = "_id"; const ShardId kShardId = ShardId("shard0"); diff --git a/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp b/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp index c273fc9d486..a26efde5588 100644 --- a/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp +++ b/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp @@ -78,7 +78,7 @@ public: for (const auto& shardId : entry.shardsIds) { shardIds.push_back(ShardId(shardId)); } - auto nss = NamespaceString(entry.ns); + auto nss = NamespaceString::createNamespaceString_forTest(entry.ns); auto uuid = [&] { if (nss.coll().empty()) { // no uuid for database @@ -156,13 +156,13 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForCollAtClusterTime_S // 2 shards must own collection1 auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2"}); // 2 shards must own collection2 historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection2"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection2"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard3", "shard4"}); } @@ -183,7 +183,7 @@ TEST_F(CatalogClientAggregationsTest, // 3 shards must own collection1 at timestamp 4 auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); } @@ -202,17 +202,17 @@ TEST_F(CatalogClientAggregationsTest, setupConfigShard(opCtx, 3 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection"), Timestamp(3, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection"), Timestamp(3, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db2.collection"), Timestamp(3, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db2.collection"), Timestamp(3, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard2"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db3.collection"), Timestamp(3, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db3.collection"), Timestamp(3, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard3"}); } @@ -234,27 +234,27 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForCollAtClusterTime_D // no shards at timestamp 0 auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(0, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(0, 0)); assertSameHistoricalPlacement(historicalPlacement, {}); historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(1, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(1, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(2, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(2, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(5, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(5, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard4"}); } @@ -276,17 +276,17 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForCollAtClusterTime_S setupConfigShard(opCtx, 9 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection"), Timestamp(1, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection"), Timestamp(1, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection2"), Timestamp(1, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection2"), Timestamp(1, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard4", "shard5"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db2.collection"), Timestamp(1, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db2.collection"), Timestamp(1, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard6", "shard7", "shard8", "shard9"}); } @@ -308,7 +308,7 @@ TEST_F(CatalogClientAggregationsTest, setupConfigShard(opCtx, 8 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard4"}); } @@ -331,13 +331,13 @@ TEST_F(CatalogClientAggregationsTest, setupConfigShard(opCtx, 3 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection2"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection2"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1"}); // Note: at timestamp 3 the collection's shard list is not empty historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection2"), Timestamp(3, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection2"), Timestamp(3, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); } @@ -358,13 +358,13 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForCollAtClusterTime_A setupConfigShard(opCtx, 5 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(2, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(2, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard4"}); // Note: the primary shard is shard5 at timestamp 3 historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(3, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(3, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard5", "shard2", "shard3", "shard4"}); } @@ -387,7 +387,7 @@ TEST_F(CatalogClientAggregationsTest, setupConfigShard(opCtx, 8 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(1, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(1, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard4"}); } @@ -455,7 +455,7 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForDbAtClusterTime_Sin setupConfigShard(opCtx, 5 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(3, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(3, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard4", "shard5"}); @@ -478,17 +478,17 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForDbAtClusterTime_Mul setupConfigShard(opCtx, 7 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(5, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(5, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db2"), Timestamp(5, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db2"), Timestamp(5, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard4", "shard5", "shard6"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db3"), Timestamp(5, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db3"), Timestamp(5, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard7"}); } @@ -510,27 +510,27 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForDbAtClusterTime_Dif // no shards at timestamp 0 auto historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(0, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(0, 0)); assertSameHistoricalPlacement(historicalPlacement, {}); historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(1, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(1, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(2, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(2, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(5, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(5, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard4"}); } @@ -552,13 +552,13 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForDbAtClusterTime_Sam setupConfigShard(opCtx, 9 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(1, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(1, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard4", "shard5"}); historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db2"), Timestamp(1, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db2"), Timestamp(1, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard6", "shard7", "shard8", "shard9"}); } @@ -580,7 +580,7 @@ TEST_F(CatalogClientAggregationsTest, setupConfigShard(opCtx, 8 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard4"}); } @@ -602,13 +602,13 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForDbAtClusterTime_NoS setupConfigShard(opCtx, 3 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {}); // Note: at timestamp 3 the collection's shard list was not empty historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(3, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(3, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); } @@ -628,13 +628,13 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataForDbAtClusterTime_New setupConfigShard(opCtx, 4 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(2, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(2, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); // At timestamp 3 the db shard list was updated with a new primary historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(3, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(3, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard4", "shard1", "shard2", "shard3"}); } @@ -910,7 +910,9 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_RegexSta // testing config.system.collections auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("config.system.collections"), Timestamp(7, 0)); + opCtx, + NamespaceString::createNamespaceString_forTest("config.system.collections"), + Timestamp(7, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); } @@ -942,26 +944,26 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_RegexSta setupConfigShard(opCtx, 9 /*nShards*/); auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(12, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(12, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); // no data must be returned since the namespace is not found historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("d.collection1"), Timestamp(12, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("d.collection1"), Timestamp(12, 0)); assertSameHistoricalPlacement(historicalPlacement, {}); // database exists historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(12, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(12, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3", "shard7", "shard8", "shard9"}); // database does not exist historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("d"), Timestamp(12, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("d"), Timestamp(12, 0)); assertSameHistoricalPlacement(historicalPlacement, {}); } @@ -991,13 +993,13 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_RegexSta // db|db , db*db etc... must not be found when quering by database auto historicalPlacement = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(10, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(10, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); // db|db , db*db etc... must not be found when quering by collection historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection"), Timestamp(10, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection"), Timestamp(10, 0)); assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); } @@ -1018,13 +1020,16 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_Snapshot setupConfigShard(opCtx, 2 /*nShards*/); - ASSERT_THROWS_CODE(catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(4, 0)), - DBException, - ErrorCodes::SnapshotTooOld); + ASSERT_THROWS_CODE( + catalogClient()->getShardsThatOwnDataForDbAtClusterTime( + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(4, 0)), + DBException, + ErrorCodes::SnapshotTooOld); ASSERT_THROWS_CODE(catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(4, 0)), + opCtx, + NamespaceString::createNamespaceString_forTest("db.collection1"), + Timestamp(4, 0)), DBException, ErrorCodes::SnapshotTooOld); @@ -1042,13 +1047,13 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_EmptyHis // no shards must be returned auto historicalPlacement = catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db.collection1"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db.collection1"), Timestamp(4, 0)); assertSameHistoricalPlacement(historicalPlacement, {}); // no shards must be returned auto historicalPlacement2 = catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(4, 0)); + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(4, 0)); ASSERT_EQ(0U, historicalPlacement.getShards().size()); @@ -1066,31 +1071,36 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_InvalidO auto opCtx = operationContext(); // a namespace with collection must be provided - ASSERT_THROWS_CODE(catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString(""), Timestamp(0, 0)), - DBException, - ErrorCodes::InvalidOptions); - - ASSERT_THROWS_CODE(catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, NamespaceString("db"), Timestamp(0, 0)), - DBException, - ErrorCodes::InvalidOptions); + ASSERT_THROWS_CODE( + catalogClient()->getShardsThatOwnDataForCollAtClusterTime( + opCtx, NamespaceString::createNamespaceString_forTest(""), Timestamp(0, 0)), + DBException, + ErrorCodes::InvalidOptions); + + ASSERT_THROWS_CODE( + catalogClient()->getShardsThatOwnDataForCollAtClusterTime( + opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(0, 0)), + DBException, + ErrorCodes::InvalidOptions); // a namespace with only db must be provided ASSERT_THROWS_CODE(catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString("db.collection"), Timestamp(0, 0)), - DBException, - ErrorCodes::InvalidOptions); - ASSERT_THROWS_CODE(catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString(""), Timestamp(0, 0)), + opCtx, + NamespaceString::createNamespaceString_forTest("db.collection"), + Timestamp(0, 0)), DBException, ErrorCodes::InvalidOptions); + ASSERT_THROWS_CODE( + catalogClient()->getShardsThatOwnDataForDbAtClusterTime( + opCtx, NamespaceString::createNamespaceString_forTest(""), Timestamp(0, 0)), + DBException, + ErrorCodes::InvalidOptions); } // ############################# Indexes ############################# TEST_F(CatalogClientAggregationsTest, TestCollectionAndIndexesAggregationWithNoIndexes) { - const NamespaceString nss{"TestDB.TestColl"}; + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("TestDB.TestColl"); const ChunkVersion placementVersion{{OID::gen(), Timestamp(1, 0)}, {1, 0}}; const std::string shardName = "shard01"; const UUID uuid{UUID::gen()}; @@ -1113,7 +1123,7 @@ TEST_F(CatalogClientAggregationsTest, TestCollectionAndIndexesAggregationWithNoI } TEST_F(CatalogClientAggregationsTest, TestCollectionAndIndexesWithIndexes) { - const NamespaceString nss{"TestDB.TestColl"}; + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("TestDB.TestColl"); const ChunkVersion placementVersion{{OID::gen(), Timestamp(1, 0)}, {1, 0}}; const std::string shardName = "shard01"; const UUID uuid{UUID::gen()}; @@ -1143,8 +1153,10 @@ TEST_F(CatalogClientAggregationsTest, TestCollectionAndIndexesWithIndexes) { } TEST_F(CatalogClientAggregationsTest, TestCollectionAndIndexesWithMultipleCollections) { - const NamespaceString nssColl1{"TestDB.Collection1"}; - const NamespaceString nssColl2{"TestDB.Collection2"}; + const NamespaceString nssColl1 = + NamespaceString::createNamespaceString_forTest("TestDB.Collection1"); + const NamespaceString nssColl2 = + NamespaceString::createNamespaceString_forTest("TestDB.Collection2"); const ChunkVersion placementVersion{{OID::gen(), Timestamp(1, 0)}, {1, 0}}; const std::string shardName = "shard01"; const UUID uuidColl1{UUID::gen()}; diff --git a/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp b/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp index c6fc1755328..2c113a84448 100644 --- a/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp +++ b/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp @@ -122,7 +122,7 @@ public: : _impl{UUID::gen(), BSON("command" << "test"), - NamespaceString("test.source"), + NamespaceString::createNamespaceString_forTest("test.source"), ShardingDataTransformInstanceMetrics::Role::kDonor, startTime, clockSource, diff --git a/src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h b/src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h index e109215195c..1cf579d45a3 100644 --- a/src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h +++ b/src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h @@ -239,7 +239,8 @@ protected: constexpr static auto kOldestTime = Date_t::fromMillisSinceEpoch(std::numeric_limits::min()); constexpr static int64_t kOldestTimeLeft = 3000; - const NamespaceString kTestNamespace = NamespaceString("test.source"); + const NamespaceString kTestNamespace = + NamespaceString::createNamespaceString_forTest("test.source"); const BSONObj kTestCommand = BSON("command" << "test"); diff --git a/src/mongo/db/s/sharding_ddl_util_test.cpp b/src/mongo/db/s/sharding_ddl_util_test.cpp index 830b680622d..7b373dfb284 100644 --- a/src/mongo/db/s/sharding_ddl_util_test.cpp +++ b/src/mongo/db/s/sharding_ddl_util_test.cpp @@ -86,7 +86,7 @@ private: } }; -const NamespaceString kToNss("test.to"); +const NamespaceString kToNss = NamespaceString::createNamespaceString_forTest("test.to"); // Query 'limit' objects from the database into an array. void findN(DBClientBase& client, @@ -109,7 +109,7 @@ TEST_F(ShardingDDLUtilTest, ShardedRenameMetadata) { auto opCtx = operationContext(); DBDirectClient client(opCtx); - const NamespaceString fromNss("test.from"); + const NamespaceString fromNss = NamespaceString::createNamespaceString_forTest("test.from"); const auto fromCollQuery = BSON(CollectionType::kNssFieldName << fromNss.ns()); const auto toCollQuery = BSON(CollectionType::kNssFieldName << kToNss.ns()); @@ -250,14 +250,15 @@ TEST_F(ShardingDDLUtilTest, RenamePreconditionsTargetNamespaceIsTooLong) { const std::string dbName{"test"}; // Check that no exception is thrown if the namespace of the target collection is long enough - const NamespaceString longEnoughNss{ + const NamespaceString longEnoughNss = NamespaceString::createNamespaceString_forTest( dbName + "." + - std::string(NamespaceString::MaxNsShardedCollectionLen - dbName.length() - 1, 'x')}; + std::string(NamespaceString::MaxNsShardedCollectionLen - dbName.length() - 1, 'x')); sharding_ddl_util::checkRenamePreconditions( opCtx, true /* sourceIsSharded */, longEnoughNss, false /* dropTarget */); // Check that an exception is thrown if the namespace of the target collection is too long - const NamespaceString tooLongNss{longEnoughNss.ns() + 'x'}; + const NamespaceString tooLongNss = + NamespaceString::createNamespaceString_forTest(longEnoughNss.ns() + 'x'); ASSERT_THROWS_CODE(sharding_ddl_util::checkRenamePreconditions( opCtx, true /* sourceIsSharded */, tooLongNss, false /* dropTarget */), AssertionException, diff --git a/src/mongo/db/s/sharding_initialization_op_observer_test.cpp b/src/mongo/db/s/sharding_initialization_op_observer_test.cpp index eb8bc9a248b..14c82f29fb6 100644 --- a/src/mongo/db/s/sharding_initialization_op_observer_test.cpp +++ b/src/mongo/db/s/sharding_initialization_op_observer_test.cpp @@ -113,7 +113,9 @@ TEST_F(ShardingInitializationOpObserverTest, GlobalInitDoesntGetCalledIfWriteAbo { AutoGetCollection autoColl( - operationContext(), NamespaceString("admin.system.version"), MODE_IX); + operationContext(), + NamespaceString::createNamespaceString_forTest("admin.system.version"), + MODE_IX); WriteUnitOfWork wuow(operationContext()); InsertStatement stmt(shardIdentity.toShardIdentityDocument()); diff --git a/src/mongo/db/s/sharding_recovery_service_test.cpp b/src/mongo/db/s/sharding_recovery_service_test.cpp index 605beb5ec13..8996648cb0f 100644 --- a/src/mongo/db/s/sharding_recovery_service_test.cpp +++ b/src/mongo/db/s/sharding_recovery_service_test.cpp @@ -46,11 +46,13 @@ namespace mongo { class ShardingRecoveryServiceTest : public ShardServerTestFixture { public: - inline static const NamespaceString collNss{"TestDB", "TestCollection"}; + inline static const NamespaceString collNss = + NamespaceString::createNamespaceString_forTest("TestDB", "TestCollection"); inline static const BSONObj collOpReason = BSON("Dummy operation on collection" << collNss.ns()); - inline static const NamespaceString dbName{"TestDB"}; + inline static const NamespaceString dbName = + NamespaceString::createNamespaceString_forTest("TestDB"); inline static const BSONObj dbOpReason = BSON("Dummy operation on database" << dbName.ns()); inline static const BSONObj differentOpReason = BSON("Yet another dummy operation" << true); diff --git a/src/mongo/db/s/sharding_util_refresh_test.cpp b/src/mongo/db/s/sharding_util_refresh_test.cpp index d386ac55fa0..3a384b59312 100644 --- a/src/mongo/db/s/sharding_util_refresh_test.cpp +++ b/src/mongo/db/s/sharding_util_refresh_test.cpp @@ -74,7 +74,7 @@ protected: TEST_F(ShardingRefresherTest, refresherTwoShardsSucceed) { auto opCtx = operationContext(); - auto nss = NamespaceString("mydb", "mycoll"); + auto nss = NamespaceString::createNamespaceString_forTest("mydb", "mycoll"); auto future = launchAsync([&] { sharding_util::tellShardsToRefreshCollection(opCtx, kShardIdList, nss, executor()); }); @@ -87,7 +87,7 @@ TEST_F(ShardingRefresherTest, refresherTwoShardsSucceed) { TEST_F(ShardingRefresherTest, refresherTwoShardsFirstErrors) { auto opCtx = operationContext(); - auto nss = NamespaceString("mydb", "mycoll"); + auto nss = NamespaceString::createNamespaceString_forTest("mydb", "mycoll"); auto future = launchAsync([&] { sharding_util::tellShardsToRefreshCollection(opCtx, kShardIdList, nss, executor()); }); @@ -99,7 +99,7 @@ TEST_F(ShardingRefresherTest, refresherTwoShardsFirstErrors) { TEST_F(ShardingRefresherTest, refresherTwoShardsSecondErrors) { auto opCtx = operationContext(); - auto nss = NamespaceString("mydb", "mycoll"); + auto nss = NamespaceString::createNamespaceString_forTest("mydb", "mycoll"); auto future = launchAsync([&] { sharding_util::tellShardsToRefreshCollection(opCtx, kShardIdList, nss, executor()); }); @@ -112,7 +112,7 @@ TEST_F(ShardingRefresherTest, refresherTwoShardsSecondErrors) { TEST_F(ShardingRefresherTest, refresherTwoShardsWriteConcernFailed) { auto opCtx = operationContext(); - auto nss = NamespaceString("mydb", "mycoll"); + auto nss = NamespaceString::createNamespaceString_forTest("mydb", "mycoll"); auto future = launchAsync([&] { sharding_util::tellShardsToRefreshCollection(opCtx, kShardIdList, nss, executor()); }); diff --git a/src/mongo/db/s/split_chunk_request_test.cpp b/src/mongo/db/s/split_chunk_request_test.cpp index 00179486ca6..a2884a3d3a7 100644 --- a/src/mongo/db/s/split_chunk_request_test.cpp +++ b/src/mongo/db/s/split_chunk_request_test.cpp @@ -44,7 +44,8 @@ TEST(SplitChunkRequest, BasicValidConfigCommand) { << BSON("a" << 10) << "splitPoints" << BSON_ARRAY(BSON("a" << 5)) << "shard" << "shard0000" << "fromChunkSplitter" << true))); - ASSERT_EQ(NamespaceString("TestDB", "TestColl"), request.getNamespace()); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"), + request.getNamespace()); ASSERT_EQ(OID("7fffffff0000000000000001"), request.getEpoch()); ASSERT(ChunkRange(BSON("a" << 1), BSON("a" << 10)) == request.getChunkRange()); ASSERT_BSONOBJ_EQ(BSON("a" << 5), request.getSplitPoints().at(0)); @@ -60,7 +61,8 @@ TEST(SplitChunkRequest, ValidWithMultipleSplits) { << BSON("a" << 10) << "splitPoints" << BSON_ARRAY(BSON("a" << 5) << BSON("a" << 7)) << "shard" << "shard0000"))); - ASSERT_EQ(NamespaceString("TestDB", "TestColl"), request.getNamespace()); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"), + request.getNamespace()); ASSERT_EQ(OID("7fffffff0000000000000001"), request.getEpoch()); ASSERT(ChunkRange(BSON("a" << 1), BSON("a" << 10)) == request.getChunkRange()); ASSERT_BSONOBJ_EQ(BSON("a" << 5), request.getSplitPoints().at(0)); diff --git a/src/mongo/db/s/split_vector_test.cpp b/src/mongo/db/s/split_vector_test.cpp index 95904b99e8b..ff6cd6f9ab4 100644 --- a/src/mongo/db/s/split_vector_test.cpp +++ b/src/mongo/db/s/split_vector_test.cpp @@ -40,7 +40,7 @@ namespace mongo { namespace { -const NamespaceString kNss = NamespaceString("foo", "bar"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("foo", "bar"); const std::string kPattern = "_id"; void setUnshardedFilteringMetadata(OperationContext* opCtx, const NamespaceString& nss) { @@ -250,17 +250,18 @@ TEST_F(SplitVectorTest, NoSplit) { } TEST_F(SplitVectorTest, NoCollection) { - ASSERT_THROWS_CODE(splitVector(operationContext(), - NamespaceString("dummy", "collection"), - BSON(kPattern << 1), - BSON(kPattern << 0), - BSON(kPattern << 100), - false, - boost::none, - boost::none, - boost::none), - DBException, - ErrorCodes::NamespaceNotFound); + ASSERT_THROWS_CODE( + splitVector(operationContext(), + NamespaceString::createNamespaceString_forTest("dummy", "collection"), + BSON(kPattern << 1), + BSON(kPattern << 0), + BSON(kPattern << 100), + false, + boost::none, + boost::none, + boost::none), + DBException, + ErrorCodes::NamespaceNotFound); } TEST_F(SplitVectorTest, NoIndex) { @@ -291,7 +292,7 @@ TEST_F(SplitVectorTest, NoMaxChunkSize) { ErrorCodes::InvalidOptions); } -const NamespaceString kJumboNss = NamespaceString("foo", "bar2"); +const NamespaceString kJumboNss = NamespaceString::createNamespaceString_forTest("foo", "bar2"); const std::string kJumboPattern = "a"; class SplitVectorJumboTest : public ShardServerTestFixture { @@ -344,7 +345,8 @@ TEST_F(SplitVectorJumboTest, JumboChunk) { ASSERT_EQUALS(splitKeys.size(), 0UL); } -const NamespaceString kMaxResponseNss = NamespaceString("foo", "bar3"); +const NamespaceString kMaxResponseNss = + NamespaceString::createNamespaceString_forTest("foo", "bar3"); // This is not the actual max bytes size -- we are rounding down from 512000. int maxShardingUnitTestOplogDocSize = 510000; diff --git a/src/mongo/db/s/start_chunk_clone_request_test.cpp b/src/mongo/db/s/start_chunk_clone_request_test.cpp index 0bfe77c5174..ac13dcbf78c 100644 --- a/src/mongo/db/s/start_chunk_clone_request_test.cpp +++ b/src/mongo/db/s/start_chunk_clone_request_test.cpp @@ -59,7 +59,7 @@ TEST(StartChunkCloneRequest, CreateAsCommandComplete) { BSONObjBuilder builder; StartChunkCloneRequest::appendAsCommand( &builder, - NamespaceString("TestDB.TestColl"), + NamespaceString::createNamespaceString_forTest("TestDB.TestColl"), migrationId, lsid, txnNumber, @@ -75,7 +75,8 @@ TEST(StartChunkCloneRequest, CreateAsCommandComplete) { BSONObj cmdObj = builder.obj(); auto request = assertGet(StartChunkCloneRequest::createFromCommand( - NamespaceString(cmdObj["_recvChunkStart"].String()), cmdObj)); + NamespaceString::createNamespaceString_forTest(cmdObj["_recvChunkStart"].String()), + cmdObj)); ASSERT_EQ("TestDB.TestColl", request.getNss().ns()); ASSERT_EQ(sessionId.toString(), request.getSessionId().toString()); diff --git a/src/mongo/db/s/type_shard_collection_test.cpp b/src/mongo/db/s/type_shard_collection_test.cpp index f21418cc206..fbaf66c3eb6 100644 --- a/src/mongo/db/s/type_shard_collection_test.cpp +++ b/src/mongo/db/s/type_shard_collection_test.cpp @@ -39,7 +39,7 @@ namespace { using unittest::assertGet; -const NamespaceString kNss = NamespaceString("db.coll"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("db.coll"); const BSONObj kKeyPattern = BSON("a" << 1); const BSONObj kDefaultCollation = BSON("locale" << "fr_CA"); diff --git a/src/mongo/db/serverless/shard_split_donor_service_test.cpp b/src/mongo/db/serverless/shard_split_donor_service_test.cpp index e781cc48b7d..d680a73278b 100644 --- a/src/mongo/db/serverless/shard_split_donor_service_test.cpp +++ b/src/mongo/db/serverless/shard_split_donor_service_test.cpp @@ -457,7 +457,8 @@ protected: "donorSetForTest", 3, true /* hasPrimary */, false /* dollarPrefixHosts */}; MockReplicaSet _recipientSet{ "recipientSetForTest", 3, true /* hasPrimary */, false /* dollarPrefixHosts */}; - const NamespaceString _nss{"testDB2", "testColl2"}; + const NamespaceString _nss = + NamespaceString::createNamespaceString_forTest("testDB2", "testColl2"); std::vector _tenantIds = {TenantId(OID::gen()), TenantId(OID::gen())}; std::string _recipientTagName{"$recipientNode"}; std::string _recipientSetName{_recipientSet.getURI().getSetName()}; diff --git a/src/mongo/db/shard_role_test.cpp b/src/mongo/db/shard_role_test.cpp index 8ec8e43f476..eade9a4bff1 100644 --- a/src/mongo/db/shard_role_test.cpp +++ b/src/mongo/db/shard_role_test.cpp @@ -122,9 +122,11 @@ protected: const DatabaseName dbNameTestDb{"test"}; const DatabaseVersion dbVersionTestDb{UUID::gen(), Timestamp(1, 0)}; - const NamespaceString nssUnshardedCollection1{dbNameTestDb, "unsharded"}; + const NamespaceString nssUnshardedCollection1 = + NamespaceString::createNamespaceString_forTest(dbNameTestDb, "unsharded"); - const NamespaceString nssShardedCollection1{dbNameTestDb, "sharded"}; + const NamespaceString nssShardedCollection1 = + NamespaceString::createNamespaceString_forTest(dbNameTestDb, "sharded"); const ShardVersion shardVersionShardedCollection1{ ChunkVersion(CollectionGeneration{OID::gen(), Timestamp(5, 0)}, CollectionPlacement(10, 1)), boost::optional(boost::none)}; @@ -178,7 +180,8 @@ TEST_F(ShardRoleTest, NamespaceOrViewAcquisitionRequestWithOpCtxTakesPlacementFr } { - const NamespaceString anotherCollection("test2.foo"); + const NamespaceString anotherCollection = + NamespaceString::createNamespaceString_forTest("test2.foo"); ScopedSetShardRole setShardRole( opCtx(), anotherCollection, ShardVersion::UNSHARDED(), dbVersionTestDb); NamespaceOrViewAcquisitionRequest acquisitionRequest(opCtx(), nss, {}); @@ -486,7 +489,8 @@ TEST_F(ShardRoleTest, AcquireShardedCollWithoutSpecifyingPlacementVersion) { // Acquire inexistent collections TEST_F(ShardRoleTest, AcquireCollectionFailsIfItDoesNotExist) { - const NamespaceString inexistentNss(dbNameTestDb, "inexistent"); + const NamespaceString inexistentNss = + NamespaceString::createNamespaceString_forTest(dbNameTestDb, "inexistent"); NamespaceOrViewAcquisitionRequest::PlacementConcern placementConcern; ASSERT_THROWS_CODE( acquireCollectionsOrViews(opCtx(), @@ -501,7 +505,8 @@ TEST_F(ShardRoleTest, AcquireCollectionFailsIfItDoesNotExist) { TEST_F(ShardRoleTest, AcquireInexistentCollectionWithWrongPlacementThrowsBecauseWrongPlacement) { const auto incorrectDbVersion = dbVersionTestDb.makeUpdated(); - const NamespaceString inexistentNss(dbNameTestDb, "inexistent"); + const NamespaceString inexistentNss = + NamespaceString::createNamespaceString_forTest(dbNameTestDb, "inexistent"); NamespaceOrViewAcquisitionRequest::PlacementConcern placementConcern{incorrectDbVersion, {}}; ASSERT_THROWS_WITH_CHECK( diff --git a/src/mongo/db/stats/top_test.cpp b/src/mongo/db/stats/top_test.cpp index 4c2a459d44a..c6f7b784bde 100644 --- a/src/mongo/db/stats/top_test.cpp +++ b/src/mongo/db/stats/top_test.cpp @@ -37,7 +37,7 @@ namespace { using namespace mongo; TEST(TopTest, CollectionDropped) { - Top().collectionDropped(NamespaceString("test.coll")); + Top().collectionDropped(NamespaceString::createNamespaceString_forTest("test.coll")); } } // namespace diff --git a/src/mongo/db/storage/historical_ident_tracker_test.cpp b/src/mongo/db/storage/historical_ident_tracker_test.cpp index 974cb6d0c81..072c10b443e 100644 --- a/src/mongo/db/storage/historical_ident_tracker_test.cpp +++ b/src/mongo/db/storage/historical_ident_tracker_test.cpp @@ -36,25 +36,42 @@ TEST(HistoricalIdentTracker, RecordHistoricalIdents) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(10, 10)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.b"), UUID::gen(), Timestamp(20, 20)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.c"), UUID::gen(), Timestamp(21, 21)); - tracker.recordDrop(ident, /*nss=*/NamespaceString("test.d"), UUID::gen(), Timestamp(25, 25)); - - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); - - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(15, 15))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); - - ASSERT_EQ(tracker.lookup(ident, Timestamp(21, 21))->first, NamespaceString("test.d")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(24, 24))->first, NamespaceString("test.d")); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(10, 10)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.b"), + UUID::gen(), + Timestamp(20, 20)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.c"), + UUID::gen(), + Timestamp(21, 21)); + tracker.recordDrop(ident, + /*nss=*/NamespaceString::createNamespaceString_forTest("test.d"), + UUID::gen(), + Timestamp(25, 25)); + + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); + + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(15, 15))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); + + ASSERT_EQ(tracker.lookup(ident, Timestamp(21, 21))->first, + NamespaceString::createNamespaceString_forTest("test.d")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(24, 24))->first, + NamespaceString::createNamespaceString_forTest("test.d")); ASSERT(!tracker.lookup(ident, Timestamp(25, 25))); ASSERT(!tracker.lookup(ident, Timestamp::max())); @@ -64,9 +81,18 @@ TEST(HistoricalIdentTracker, SkipRecordingNullTimestamps) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename(ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(1)); - tracker.recordRename(ident, /*oldNss=*/NamespaceString("test.b"), UUID::gen(), Timestamp(2)); - tracker.recordDrop(ident, /*nss=*/NamespaceString("test.c"), UUID::gen(), Timestamp(3)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(1)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.b"), + UUID::gen(), + Timestamp(2)); + tracker.recordDrop(ident, + /*nss=*/NamespaceString::createNamespaceString_forTest("test.c"), + UUID::gen(), + Timestamp(3)); ASSERT(!tracker.lookup(ident, Timestamp::min())); ASSERT(!tracker.lookup(ident, Timestamp(1))); @@ -79,19 +105,25 @@ TEST(HistoricalIdentTracker, RemoveEntriesOlderThanSingle) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(50, 50)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(50, 50)); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(49, 49))->first, NamespaceString("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(49, 49))->first, + NamespaceString::createNamespaceString_forTest("test.a")); ASSERT(!tracker.lookup(ident, Timestamp(50, 50))); tracker.removeEntriesOlderThan(Timestamp::min()); tracker.removeEntriesOlderThan(Timestamp(49, 49)); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(49, 49))->first, NamespaceString("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(49, 49))->first, + NamespaceString::createNamespaceString_forTest("test.a")); tracker.removeEntriesOlderThan(Timestamp(50, 50)); @@ -104,30 +136,44 @@ TEST(HistoricalIdentTracker, RemoveEntriesOlderThanMultiple) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(10, 10)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.b"), UUID::gen(), Timestamp(20, 20)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.c"), UUID::gen(), Timestamp(21, 21)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(10, 10)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.b"), + UUID::gen(), + Timestamp(20, 20)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.c"), + UUID::gen(), + Timestamp(21, 21)); tracker.removeEntriesOlderThan(Timestamp::min()); tracker.removeEntriesOlderThan(Timestamp(5, 5)); tracker.removeEntriesOlderThan(Timestamp(9, 9)); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); tracker.removeEntriesOlderThan(Timestamp(15, 15)); ASSERT(!tracker.lookup(ident, Timestamp::min())); ASSERT(!tracker.lookup(ident, Timestamp(9, 9))); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); tracker.removeEntriesOlderThan(Timestamp(21, 21)); @@ -143,14 +189,18 @@ TEST(HistoricalIdentTracker, RollbackToSingle) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(10, 10)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(10, 10)); tracker.rollbackTo(Timestamp(10, 10)); tracker.rollbackTo(Timestamp::max()); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); tracker.rollbackTo(Timestamp(9, 9)); @@ -164,27 +214,40 @@ TEST(HistoricalIdentTracker, RollbackToMultiple) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(10, 10)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.b"), UUID::gen(), Timestamp(20, 20)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.c"), UUID::gen(), Timestamp(21, 21)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(10, 10)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.b"), + UUID::gen(), + Timestamp(20, 20)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.c"), + UUID::gen(), + Timestamp(21, 21)); tracker.rollbackTo(Timestamp::max()); tracker.rollbackTo(Timestamp(22, 22)); tracker.rollbackTo(Timestamp(21, 21)); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); tracker.rollbackTo(Timestamp(15, 15)); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); ASSERT(!tracker.lookup(ident, Timestamp(10, 10))); ASSERT(!tracker.lookup(ident, Timestamp(19, 19))); ASSERT(!tracker.lookup(ident, Timestamp(20, 20))); @@ -203,20 +266,26 @@ TEST(HistoricalIdentTracker, PinAndUnpinTimestamp) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(10, 10)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(10, 10)); tracker.pinAtTimestamp(Timestamp(5, 5)); tracker.removeEntriesOlderThan(Timestamp::max()); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); tracker.pinAtTimestamp(Timestamp(9, 9)); tracker.removeEntriesOlderThan(Timestamp::max()); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); tracker.unpin(); tracker.removeEntriesOlderThan(Timestamp::max()); @@ -231,41 +300,60 @@ TEST(HistoricalIdentTracker, PinnedTimestampRemoveEntriesOlderThan) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(10, 10)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.b"), UUID::gen(), Timestamp(20, 20)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.c"), UUID::gen(), Timestamp(21, 21)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(10, 10)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.b"), + UUID::gen(), + Timestamp(20, 20)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.c"), + UUID::gen(), + Timestamp(21, 21)); tracker.pinAtTimestamp(Timestamp(5, 5)); tracker.removeEntriesOlderThan(Timestamp::max()); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); tracker.pinAtTimestamp(Timestamp(9, 9)); tracker.removeEntriesOlderThan(Timestamp(9, 9)); tracker.removeEntriesOlderThan(Timestamp(10, 10)); tracker.removeEntriesOlderThan(Timestamp::max()); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); tracker.pinAtTimestamp(Timestamp(15, 15)); tracker.removeEntriesOlderThan(Timestamp::max()); ASSERT(!tracker.lookup(ident, Timestamp::min())); ASSERT(!tracker.lookup(ident, Timestamp(9, 9))); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); tracker.pinAtTimestamp(Timestamp(21, 21)); tracker.removeEntriesOlderThan(Timestamp::max()); @@ -281,38 +369,58 @@ TEST(HistoricalIdentTracker, PinnedTimestampRollbackTo) { HistoricalIdentTracker tracker; const std::string ident = "ident"; - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.a"), UUID::gen(), Timestamp(10, 10)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.b"), UUID::gen(), Timestamp(20, 20)); - tracker.recordRename( - ident, /*oldNss=*/NamespaceString("test.c"), UUID::gen(), Timestamp(21, 21)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.a"), + UUID::gen(), + Timestamp(10, 10)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.b"), + UUID::gen(), + Timestamp(20, 20)); + tracker.recordRename(ident, + /*oldNss=*/NamespaceString::createNamespaceString_forTest("test.c"), + UUID::gen(), + Timestamp(21, 21)); tracker.pinAtTimestamp(Timestamp(30, 30)); tracker.rollbackTo(Timestamp::min()); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); tracker.pinAtTimestamp(Timestamp(21, 21)); tracker.rollbackTo(Timestamp::min()); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, NamespaceString("test.c")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(20, 20))->first, + NamespaceString::createNamespaceString_forTest("test.c")); tracker.pinAtTimestamp(Timestamp(20, 20)); tracker.rollbackTo(Timestamp::min()); - ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, NamespaceString("test.a")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, NamespaceString("test.b")); - ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, NamespaceString("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp::min())->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(9, 9))->first, + NamespaceString::createNamespaceString_forTest("test.a")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(10, 10))->first, + NamespaceString::createNamespaceString_forTest("test.b")); + ASSERT_EQ(tracker.lookup(ident, Timestamp(19, 19))->first, + NamespaceString::createNamespaceString_forTest("test.b")); ASSERT(!tracker.lookup(ident, Timestamp(20, 20))); diff --git a/src/mongo/db/storage/index_entry_comparison_test.cpp b/src/mongo/db/storage/index_entry_comparison_test.cpp index 76661cdb381..0ff271789c7 100644 --- a/src/mongo/db/storage/index_entry_comparison_test.cpp +++ b/src/mongo/db/storage/index_entry_comparison_test.cpp @@ -39,7 +39,7 @@ namespace mongo { void buildDupKeyErrorStatusProducesExpectedErrorObject( DuplicateKeyErrorInfo::FoundValue&& foundValue) { - NamespaceString collNss("test.foo"); + NamespaceString collNss = NamespaceString::createNamespaceString_forTest("test.foo"); std::string indexName("a_1_b_1"); auto keyPattern = BSON("a" << 1 << "b" << 1); auto keyValue = BSON("" << 10 << "" @@ -95,7 +95,7 @@ void duplicateKeyErrorSerializationAndParseReturnTheSameObject( BSONObj collation, BSONObj keyValueWithFieldName, BSONObj expectedEncodedKeyValueField) { - NamespaceString collNss("test.foo"); + NamespaceString collNss = NamespaceString::createNamespaceString_forTest("test.foo"); std::string indexName("a_1_b_1"); auto dupKeyStatus = buildDupKeyErrorStatus(keyValue, collNss, indexName, keyPattern, collation); @@ -148,7 +148,7 @@ TEST(IndexEntryComparison, BuildDupKeyErrorSerializeAndParseReturnTheSameObjectF TEST(IndexEntryComparison, BuildDupKeyErrorMessageIncludesCollationAndHexEncodedCollationKey) { StringData mockCollationKey("bar"); - NamespaceString collNss("test.foo"); + NamespaceString collNss = NamespaceString::createNamespaceString_forTest("test.foo"); std::string indexName("a_1"); auto keyPattern = BSON("a" << 1); auto keyValue = BSON("" << mockCollationKey); @@ -173,7 +173,7 @@ TEST(IndexEntryComparison, BuildDupKeyErrorMessageIncludesCollationAndHexEncoded } TEST(IndexEntryComparison, BuildDupKeyErrorMessageHexEncodesInvalidUTF8ForIndexWithoutCollation) { - NamespaceString collNss("test.foo"); + NamespaceString collNss = NamespaceString::createNamespaceString_forTest("test.foo"); std::string indexName("a_1"); auto keyPattern = BSON("a" << 1); diff --git a/src/mongo/db/storage/kv/durable_catalog_test.cpp b/src/mongo/db/storage/kv/durable_catalog_test.cpp index 9bf2a31e610..b079b4b965c 100644 --- a/src/mongo/db/storage/kv/durable_catalog_test.cpp +++ b/src/mongo/db/storage/kv/durable_catalog_test.cpp @@ -66,7 +66,7 @@ public: void setUp() override { CatalogTestFixture::setUp(); - _nss = NamespaceString("unittests.durable_catalog"); + _nss = NamespaceString::createNamespaceString_forTest("unittests.durable_catalog"); _collectionUUID = createCollection(_nss, CollectionOptions()).uuid; } @@ -271,7 +271,7 @@ protected: return res; } - NamespaceString nss{"unittest", "import"}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("unittest", "import"); std::string ident; std::string idxIdent; std::shared_ptr md; @@ -806,7 +806,7 @@ TEST_F(DurableCatalogTest, IdentSuffixUsesRand) { const std::string rand = "0000000000000000000"; getCatalog()->setRand_forTest(rand); - const NamespaceString nss = NamespaceString("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); auto uuid = (createCollection(nss, CollectionOptions())).uuid; auto collection = CollectionCatalog::get(operationContext()) @@ -832,7 +832,7 @@ TEST_F(ImportCollectionTest, ImportCollectionRandConflict) { { // Check that a newly created collection doesn't use 'rand' as the suffix in the ident. - const NamespaceString nss = NamespaceString("a.b"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); auto catalogId = (createCollection(nss, CollectionOptions())).catalogId; ASSERT(!StringData(getCatalog()->getEntry(catalogId).ident).endsWith(rand)); @@ -846,7 +846,8 @@ TEST_F(DurableCatalogTest, CheckTimeseriesBucketsMayHaveMixedSchemaDataFlagFCVLa serverGlobalParams.mutableFeatureCompatibility.setVersion(multiversion::GenericFCV::kLatest); { - const NamespaceString regularNss = NamespaceString("test.regular"); + const NamespaceString regularNss = + NamespaceString::createNamespaceString_forTest("test.regular"); createCollection(regularNss, CollectionOptions()); Lock::GlobalLock globalLock{operationContext(), MODE_IS}; @@ -859,7 +860,8 @@ TEST_F(DurableCatalogTest, CheckTimeseriesBucketsMayHaveMixedSchemaDataFlagFCVLa } { - const NamespaceString bucketsNss = NamespaceString("system.buckets.ts"); + const NamespaceString bucketsNss = + NamespaceString::createNamespaceString_forTest("system.buckets.ts"); CollectionOptions options; options.timeseries = TimeseriesOptions(/*timeField=*/"t"); createCollection(bucketsNss, options); @@ -881,7 +883,8 @@ TEST_F(DurableCatalogTest, CreateCollectionCatalogEntryHasCorrectTenantNamespace gMultitenancySupport = true; auto tenantId = TenantId(OID::gen()); - const NamespaceString nss = NamespaceString(tenantId, "test.regular"); + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest(tenantId, "test.regular"); createCollection(nss, CollectionOptions()); auto collection = CollectionCatalog::get(operationContext()) @@ -910,15 +913,17 @@ TEST_F(DurableCatalogTest, ScanForCatalogEntryByNssBasic) { */ auto tenantId = TenantId(OID::gen()); - const NamespaceString nssFirst = NamespaceString(tenantId, "test.first"); + const NamespaceString nssFirst = + NamespaceString::createNamespaceString_forTest(tenantId, "test.first"); auto catalogIdAndUUIDFirst = createCollection(nssFirst, CollectionOptions()); - const NamespaceString nssSecond = NamespaceString("system.buckets.ts"); + const NamespaceString nssSecond = + NamespaceString::createNamespaceString_forTest("system.buckets.ts"); CollectionOptions options; options.timeseries = TimeseriesOptions(/*timeField=*/"t"); auto catalogIdAndUUIDSecond = createCollection(nssSecond, options); - const NamespaceString nssThird = NamespaceString("test.third"); + const NamespaceString nssThird = NamespaceString::createNamespaceString_forTest("test.third"); auto catalogIdAndUUIDThird = createCollection(nssThird, CollectionOptions()); /** @@ -954,8 +959,8 @@ TEST_F(DurableCatalogTest, ScanForCatalogEntryByNssBasic) { nssFirst); ASSERT_EQ(getCatalog()->getEntry(catalogIdAndUUIDFirst.catalogId).nss, nssFirst); - auto catalogEntryDoesNotExist = - getCatalog()->scanForCatalogEntryByNss(operationContext(), NamespaceString("foo", "bar")); + auto catalogEntryDoesNotExist = getCatalog()->scanForCatalogEntryByNss( + operationContext(), NamespaceString::createNamespaceString_forTest("foo", "bar")); ASSERT(catalogEntryDoesNotExist == boost::none); } diff --git a/src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp b/src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp index f2e5b0b3641..21614b2446a 100644 --- a/src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp +++ b/src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp @@ -203,8 +203,10 @@ public: auto op = makeOperation(); WriteUnitOfWork wuow(op); std::string ns = "a.b"; - ASSERT_OK(engine->createRecordStore(op, NamespaceString(ns), ns, CollectionOptions())); - rs = engine->getRecordStore(op, NamespaceString(ns), ns, CollectionOptions()); + ASSERT_OK(engine->createRecordStore( + op, NamespaceString::createNamespaceString_forTest(ns), ns, CollectionOptions())); + rs = engine->getRecordStore( + op, NamespaceString::createNamespaceString_forTest(ns), ns, CollectionOptions()); ASSERT(rs); } diff --git a/src/mongo/db/storage/kv/storage_engine_test.cpp b/src/mongo/db/storage/kv/storage_engine_test.cpp index 0e6d85e82dd..537e4ef899f 100644 --- a/src/mongo/db/storage/kv/storage_engine_test.cpp +++ b/src/mongo/db/storage/kv/storage_engine_test.cpp @@ -66,12 +66,14 @@ TEST_F(StorageEngineTest, ReconcileIdentsTest) { // Add a collection, `db.coll1` to both the DurableCatalog and KVEngine. The returned value is // the `ident` name given to the collection. - auto swCollInfo = createCollection(opCtx.get(), NamespaceString("db.coll1")); + auto swCollInfo = + createCollection(opCtx.get(), NamespaceString::createNamespaceString_forTest("db.coll1")); ASSERT_OK(swCollInfo.getStatus()); // Create a table in the KVEngine not reflected in the DurableCatalog. This should be dropped // when reconciling. - ASSERT_OK(createCollTable(opCtx.get(), NamespaceString("db.coll2"))); + ASSERT_OK( + createCollTable(opCtx.get(), NamespaceString::createNamespaceString_forTest("db.coll2"))); auto reconcileResult = unittest::assertGet(reconcile(opCtx.get())); ASSERT_EQUALS(0UL, reconcileResult.indexesToRebuild.size()); @@ -98,7 +100,7 @@ TEST_F(StorageEngineTest, ReconcileIdentsTest) { TEST_F(StorageEngineTest, LoadCatalogDropsOrphansAfterUncleanShutdown) { auto opCtx = cc().makeOperationContext(); - const NamespaceString collNs("db.coll1"); + const NamespaceString collNs = NamespaceString::createNamespaceString_forTest("db.coll1"); auto swCollInfo = createCollection(opCtx.get(), collNs); ASSERT_OK(swCollInfo.getStatus()); @@ -248,7 +250,7 @@ TEST_F(StorageEngineTest, ReconcileUnfinishedIndex) { Lock::GlobalLock lk(&*opCtx, MODE_X); - const NamespaceString ns("db.coll1"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("db.coll1"); const std::string indexName("a_1"); auto swCollInfo = createCollection(opCtx.get(), ns); @@ -285,7 +287,7 @@ TEST_F(StorageEngineTest, ReconcileUnfinishedIndex) { TEST_F(StorageEngineTest, ReconcileUnfinishedBackgroundSecondaryIndex) { auto opCtx = cc().makeOperationContext(); - const NamespaceString ns("db.coll1"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("db.coll1"); const std::string indexName("a_1"); auto swCollInfo = createCollection(opCtx.get(), ns); @@ -330,7 +332,7 @@ TEST_F(StorageEngineTest, ReconcileUnfinishedBackgroundSecondaryIndex) { TEST_F(StorageEngineTest, ReconcileTwoPhaseIndexBuilds) { auto opCtx = cc().makeOperationContext(); - const NamespaceString ns("db.coll1"); + const NamespaceString ns = NamespaceString::createNamespaceString_forTest("db.coll1"); const std::string indexA("a_1"); const std::string indexB("b_1"); @@ -398,7 +400,7 @@ TEST_F(StorageEngineTest, ReconcileTwoPhaseIndexBuilds) { TEST_F(StorageEngineRepairTest, LoadCatalogRecoversOrphans) { auto opCtx = cc().makeOperationContext(); - const NamespaceString collNs("db.coll1"); + const NamespaceString collNs = NamespaceString::createNamespaceString_forTest("db.coll1"); auto swCollInfo = createCollection(opCtx.get(), collNs); ASSERT_OK(swCollInfo.getStatus()); @@ -425,7 +427,7 @@ TEST_F(StorageEngineRepairTest, LoadCatalogRecoversOrphans) { TEST_F(StorageEngineRepairTest, ReconcileSucceeds) { auto opCtx = cc().makeOperationContext(); - const NamespaceString collNs("db.coll1"); + const NamespaceString collNs = NamespaceString::createNamespaceString_forTest("db.coll1"); auto swCollInfo = createCollection(opCtx.get(), collNs); ASSERT_OK(swCollInfo.getStatus()); @@ -448,7 +450,7 @@ TEST_F(StorageEngineRepairTest, ReconcileSucceeds) { TEST_F(StorageEngineRepairTest, LoadCatalogRecoversOrphansInCatalog) { auto opCtx = cc().makeOperationContext(); - const NamespaceString collNs("db.coll1"); + const NamespaceString collNs = NamespaceString::createNamespaceString_forTest("db.coll1"); auto swCollInfo = createCollection(opCtx.get(), collNs); ASSERT_OK(swCollInfo.getStatus()); ASSERT(collectionExists(opCtx.get(), collNs)); @@ -470,7 +472,8 @@ TEST_F(StorageEngineRepairTest, LoadCatalogRecoversOrphansInCatalog) { _storageEngine->loadCatalog(opCtx.get(), boost::none, StorageEngine::LastShutdownState::kClean); auto identNs = swCollInfo.getValue().ident; std::replace(identNs.begin(), identNs.end(), '-', '_'); - NamespaceString orphanNs = NamespaceString("local.orphan." + identNs); + NamespaceString orphanNs = + NamespaceString::createNamespaceString_forTest("local.orphan." + identNs); ASSERT(identExists(opCtx.get(), swCollInfo.getValue().ident)); ASSERT(collectionExists(opCtx.get(), orphanNs)); @@ -482,7 +485,7 @@ TEST_F(StorageEngineRepairTest, LoadCatalogRecoversOrphansInCatalog) { TEST_F(StorageEngineTest, LoadCatalogDropsOrphans) { auto opCtx = cc().makeOperationContext(); - const NamespaceString collNs("db.coll1"); + const NamespaceString collNs = NamespaceString::createNamespaceString_forTest("db.coll1"); auto swCollInfo = createCollection(opCtx.get(), collNs); ASSERT_OK(swCollInfo.getStatus()); ASSERT(collectionExists(opCtx.get(), collNs)); @@ -513,7 +516,8 @@ TEST_F(StorageEngineTest, LoadCatalogDropsOrphans) { ASSERT(!identExists(opCtx.get(), swCollInfo.getValue().ident)); auto identNs = swCollInfo.getValue().ident; std::replace(identNs.begin(), identNs.end(), '-', '_'); - NamespaceString orphanNs = NamespaceString("local.orphan." + identNs); + NamespaceString orphanNs = + NamespaceString::createNamespaceString_forTest("local.orphan." + identNs); ASSERT(!collectionExists(opCtx.get(), orphanNs)); } @@ -691,8 +695,8 @@ TEST_F(TimestampKVEngineTest, TimestampAdvancesOnNotification) { TEST_F(StorageEngineTestNotEphemeral, UseAlternateStorageLocation) { auto opCtx = cc().makeOperationContext(); - const NamespaceString coll1Ns("db.coll1"); - const NamespaceString coll2Ns("db.coll2"); + const NamespaceString coll1Ns = NamespaceString::createNamespaceString_forTest("db.coll1"); + const NamespaceString coll2Ns = NamespaceString::createNamespaceString_forTest("db.coll2"); auto swCollInfo = createCollection(opCtx.get(), coll1Ns); ASSERT_OK(swCollInfo.getStatus()); ASSERT(collectionExists(opCtx.get(), coll1Ns)); diff --git a/src/mongo/db/storage/storage_engine_test_fixture.h b/src/mongo/db/storage/storage_engine_test_fixture.h index 064969715ab..c573ba3fa99 100644 --- a/src/mongo/db/storage/storage_engine_test_fixture.h +++ b/src/mongo/db/storage/storage_engine_test_fixture.h @@ -195,7 +195,7 @@ public: Status removeEntry(OperationContext* opCtx, StringData collNs, DurableCatalog* catalog) { CollectionPtr collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace( - opCtx, NamespaceString(collNs)); + opCtx, NamespaceString::createNamespaceString_forTest(collNs)); return dynamic_cast(catalog)->_removeEntry(opCtx, collection->getCatalogId()); } diff --git a/src/mongo/db/storage/storage_repair_observer_test.cpp b/src/mongo/db/storage/storage_repair_observer_test.cpp index 4cd072cc7ba..614d7ee2e87 100644 --- a/src/mongo/db/storage/storage_repair_observer_test.cpp +++ b/src/mongo/db/storage/storage_repair_observer_test.cpp @@ -48,7 +48,8 @@ namespace mongo { namespace { -static const NamespaceString kConfigNss("local.system.replset"); +static const NamespaceString kConfigNss = + NamespaceString::createNamespaceString_forTest("local.system.replset"); static const std::string kRepairIncompleteFileName = "_repair_incomplete"; using boost::filesystem::path; @@ -69,13 +70,17 @@ public: BSONObj replConfig; Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "local"), MODE_X); Helpers::putSingleton( - opCtx, NamespaceString(boost::none, "local.system.replset"), replConfig); + opCtx, + NamespaceString::createNamespaceString_forTest(boost::none, "local.system.replset"), + replConfig); } void assertReplConfigValid(OperationContext* opCtx, bool valid) { BSONObj replConfig; ASSERT(Helpers::getSingleton( - opCtx, NamespaceString(boost::none, "local.system.replset"), replConfig)); + opCtx, + NamespaceString::createNamespaceString_forTest(boost::none, "local.system.replset"), + replConfig)); if (valid) { ASSERT(!replConfig.hasField("repaired")); } else { @@ -87,7 +92,9 @@ public: BSONObj replConfig; Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "local"), MODE_IS); return Helpers::getSingleton( - opCtx, NamespaceString(boost::none, "local.system.replset"), replConfig); + opCtx, + NamespaceString::createNamespaceString_forTest(boost::none, "local.system.replset"), + replConfig); } path repairFilePath() { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_no_fixture_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_no_fixture_test.cpp index 435ed0e3a32..997a7735f45 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_no_fixture_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_no_fixture_test.cpp @@ -164,7 +164,7 @@ TEST(WiredTigerKVEngineNoFixtureTest, Basic) { auto client = serviceContext->makeClient("myclient"); auto opCtx = serviceContext->makeOperationContext(client.get()); - NamespaceString nss("test.t"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.t"); StringData ident("rollback_to_stable40"); CollectionOptions collectionOptions; auto keyFormat = KeyFormat::Long; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp index c9cb597fede..44cd6572383 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp @@ -140,7 +140,7 @@ public: TEST_F(WiredTigerKVEngineRepairTest, OrphanedDataFilesCanBeRecovered) { auto opCtxPtr = _makeOperationContext(); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); std::string ident = "collection-1234"; std::string record = "abcd"; CollectionOptions defaultCollectionOptions; @@ -197,7 +197,7 @@ TEST_F(WiredTigerKVEngineRepairTest, OrphanedDataFilesCanBeRecovered) { TEST_F(WiredTigerKVEngineRepairTest, UnrecoverableOrphanedDataFilesAreRebuilt) { auto opCtxPtr = _makeOperationContext(); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); std::string ident = "collection-1234"; std::string record = "abcd"; CollectionOptions defaultCollectionOptions; @@ -369,7 +369,7 @@ TEST_F(WiredTigerKVEngineTest, IdentDrop) { auto opCtxPtr = _makeOperationContext(); - NamespaceString nss("a.b"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.b"); std::string ident = "collection-1234"; CollectionOptions defaultCollectionOptions; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp index 83cce0e4a06..4e42aab8656 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp @@ -1091,7 +1091,7 @@ TEST(WiredTigerRecordStoreTest, ClusteredRecordStore) { ASSERT(opCtx.get()); const std::string ns = "testRecordStore"; - const NamespaceString nss(ns); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest(ns); const std::string uri = WiredTigerKVEngine::kTableUriPrefix + ns; const StatusWith result = WiredTigerRecordStore::generateCreateString(kWiredTigerEngineName, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp index f730b21a33c..11513c44cb7 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp @@ -83,7 +83,7 @@ public: virtual std::unique_ptr createRecordStore(OperationContext* opCtx, const std::string& ns) final { std::string ident = ns; - NamespaceString nss(ns); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(ns); std::string uri = WiredTigerKVEngine::kTableUriPrefix + ns; StatusWith result = WiredTigerRecordStore::generateCreateString(kWiredTigerEngineName, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp index 16704935431..5cd34749f14 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp @@ -104,7 +104,7 @@ TEST(WiredTigerRecordStoreTest, SizeStorer1) { { ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); WiredTigerRecordStore::Params params; - params.nss = NamespaceString("a.b"); + params.nss = NamespaceString::createNamespaceString_forTest("a.b"); params.ident = ident; params.engineName = kWiredTigerEngineName; params.isCapped = false; diff --git a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_helpers_test.cpp b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_helpers_test.cpp index c685a9b36b2..8171fac5a4e 100644 --- a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_helpers_test.cpp +++ b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_helpers_test.cpp @@ -42,7 +42,7 @@ namespace mongo::timeseries::bucket_catalog { namespace { -const NamespaceString kNss = NamespaceString("test.ts"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.ts"); class BucketCatalogHelpersTest : public CatalogTestFixture { protected: diff --git a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp index 35c2cc7f5e4..d56a822e782 100644 --- a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp +++ b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp @@ -92,9 +92,12 @@ protected: StringData _timeField = "time"; StringData _metaField = "meta"; - NamespaceString _ns1{"bucket_catalog_test_1", "t_1"}; - NamespaceString _ns2{"bucket_catalog_test_1", "t_2"}; - NamespaceString _ns3{"bucket_catalog_test_2", "t_1"}; + NamespaceString _ns1 = + NamespaceString::createNamespaceString_forTest("bucket_catalog_test_1", "t_1"); + NamespaceString _ns2 = + NamespaceString::createNamespaceString_forTest("bucket_catalog_test_1", "t_2"); + NamespaceString _ns3 = + NamespaceString::createNamespaceString_forTest("bucket_catalog_test_2", "t_1"); }; class BucketCatalogWithoutMetadataTest : public BucketCatalogTest { @@ -1791,7 +1794,7 @@ TEST_F(BucketCatalogTest, CannotInsertIntoOutdatedBucket) { // If we advance the catalog era, then we shouldn't use a bucket that was fetched during a // previous era. - const NamespaceString fakeNs{"test.foo"}; + const NamespaceString fakeNs = NamespaceString::createNamespaceString_forTest("test.foo"); const auto fakeId = OID(); _bucketCatalog->directWriteStart(fakeNs, fakeId); _bucketCatalog->directWriteFinish(fakeNs, fakeId); diff --git a/src/mongo/db/timeseries/bucket_catalog/bucket_state_registry_test.cpp b/src/mongo/db/timeseries/bucket_catalog/bucket_state_registry_test.cpp index fb454990420..d63356e97d5 100644 --- a/src/mongo/db/timeseries/bucket_catalog/bucket_state_registry_test.cpp +++ b/src/mongo/db/timeseries/bucket_catalog/bucket_state_registry_test.cpp @@ -81,9 +81,9 @@ public: } WithLock withLock = WithLock::withoutLock(); - NamespaceString ns1{"db.test1"}; - NamespaceString ns2{"db.test2"}; - NamespaceString ns3{"db.test3"}; + NamespaceString ns1 = NamespaceString::createNamespaceString_forTest("db.test1"); + NamespaceString ns2 = NamespaceString::createNamespaceString_forTest("db.test2"); + NamespaceString ns3 = NamespaceString::createNamespaceString_forTest("db.test3"); BSONElement elem; BucketMetadata bucketMetadata{elem, nullptr}; BucketKey bucketKey1{ns1, bucketMetadata}; diff --git a/src/mongo/db/timeseries/bucket_compression_test.cpp b/src/mongo/db/timeseries/bucket_compression_test.cpp index 3b1d7ef7215..0f2387f1514 100644 --- a/src/mongo/db/timeseries/bucket_compression_test.cpp +++ b/src/mongo/db/timeseries/bucket_compression_test.cpp @@ -77,8 +77,8 @@ const BSONObj sampleBucket = mongo::fromjson(R"({ })"); TEST(TimeseriesBucketCompression, BasicRoundtrip) { - auto compressed = - timeseries::compressBucket(sampleBucket, "t"_sd, NamespaceString{"test.foo"}, false); + auto compressed = timeseries::compressBucket( + sampleBucket, "t"_sd, NamespaceString::createNamespaceString_forTest("test.foo"), false); ASSERT_TRUE(compressed.compressedBucket.has_value()); auto decompressed = timeseries::decompressBucket(compressed.compressedBucket.value()); ASSERT_TRUE(decompressed.has_value()); diff --git a/src/mongo/db/timeseries/timeseries_dotted_path_support_test.cpp b/src/mongo/db/timeseries/timeseries_dotted_path_support_test.cpp index 67bfe010451..3a895d4afd7 100644 --- a/src/mongo/db/timeseries/timeseries_dotted_path_support_test.cpp +++ b/src/mongo/db/timeseries/timeseries_dotted_path_support_test.cpp @@ -46,7 +46,7 @@ protected: void runTest(const BSONObj& obj, const std::function& test) { test(obj); - NamespaceString nss{"test"}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test"); auto compressionResult = timeseries::compressBucket(obj, "time", nss, true); ASSERT_TRUE(compressionResult.compressedBucket.has_value()); ASSERT_FALSE(compressionResult.decompressionFailed); diff --git a/src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp b/src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp index 397e6cb7c41..e82516fdff0 100644 --- a/src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp +++ b/src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp @@ -103,7 +103,8 @@ protected: ServiceContext::UniqueOperationContext _opCtx; StringData _metaField = "tag"; - NamespaceString _ns{"timeseries_update_delete_util_test", "system.buckets.t"}; + NamespaceString _ns = NamespaceString::createNamespaceString_forTest( + "timeseries_update_delete_util_test", "system.buckets.t"); }; TEST_F(TimeseriesUpdateDeleteUtilTest, TranslateQueryEmpty) { diff --git a/src/mongo/db/timeseries/timeseries_write_util_test.cpp b/src/mongo/db/timeseries/timeseries_write_util_test.cpp index 8ed35720316..3688ccd5c5b 100644 --- a/src/mongo/db/timeseries/timeseries_write_util_test.cpp +++ b/src/mongo/db/timeseries/timeseries_write_util_test.cpp @@ -182,7 +182,8 @@ TEST_F(TimeseriesWriteUtilTest, MakeNewBucketFromMeasurementsWithMeta) { } TEST_F(TimeseriesWriteUtilTest, PerformAtomicDelete) { - NamespaceString ns{"db_timeseries_write_util_test", "PerformAtomicDelete"}; + NamespaceString ns = NamespaceString::createNamespaceString_forTest( + "db_timeseries_write_util_test", "PerformAtomicDelete"); auto opCtx = operationContext(); ASSERT_OK(createCollection(opCtx, ns.dbName(), @@ -234,7 +235,8 @@ TEST_F(TimeseriesWriteUtilTest, PerformAtomicDelete) { } TEST_F(TimeseriesWriteUtilTest, PerformAtomicUpdate) { - NamespaceString ns{"db_timeseries_write_util_test", "PerformAtomicUpdate"}; + NamespaceString ns = NamespaceString::createNamespaceString_forTest( + "db_timeseries_write_util_test", "PerformAtomicUpdate"); auto opCtx = operationContext(); ASSERT_OK(createCollection(opCtx, ns.dbName(), diff --git a/src/mongo/db/transaction/transaction_api_test.cpp b/src/mongo/db/transaction/transaction_api_test.cpp index 453045dbafa..fbaedc67e5a 100644 --- a/src/mongo/db/transaction/transaction_api_test.cpp +++ b/src/mongo/db/transaction/transaction_api_test.cpp @@ -1792,7 +1792,7 @@ TEST_F(TxnAPITest, CommitAfterTransientErrorAfterRetryCommitUsesOriginalWriteCon } TEST_F(TxnAPITest, TestExhaustiveFindWithSingleBatch) { - FindCommandRequest findCommand(NamespaceString("foo.bar")); + FindCommandRequest findCommand(NamespaceString::createNamespaceString_forTest("foo.bar")); findCommand.setBatchSize(1); findCommand.setSingleBatch(true); @@ -1817,7 +1817,7 @@ TEST_F(TxnAPITest, TestExhaustiveFindWithSingleBatch) { } TEST_F(TxnAPITest, TestExhaustiveFindWithMultipleBatches) { - FindCommandRequest findCommand(NamespaceString("foo.bar")); + FindCommandRequest findCommand(NamespaceString::createNamespaceString_forTest("foo.bar")); findCommand.setBatchSize(1); findCommand.setSingleBatch(false); @@ -1850,7 +1850,7 @@ TEST_F(TxnAPITest, TestExhaustiveFindWithMultipleBatches) { } TEST_F(TxnAPITest, TestExhaustiveFindErrorOnFind) { - FindCommandRequest findCommand(NamespaceString("foo.bar")); + FindCommandRequest findCommand(NamespaceString::createNamespaceString_forTest("foo.bar")); findCommand.setBatchSize(1); findCommand.setSingleBatch(true); @@ -1875,7 +1875,7 @@ TEST_F(TxnAPITest, TestExhaustiveFindErrorOnFind) { } TEST_F(TxnAPITest, TestExhaustiveFindErrorOnGetMore) { - FindCommandRequest findCommand(NamespaceString("foo.bar")); + FindCommandRequest findCommand(NamespaceString::createNamespaceString_forTest("foo.bar")); findCommand.setBatchSize(2); findCommand.setSingleBatch(false); @@ -2031,16 +2031,20 @@ TEST_F(TxnAPITest, MaxTimeMSIsSetIfOperationContextHasDeadlineAndIgnoresDefaultR } TEST_F(TxnAPITest, CannotBeUsedWithinShardedOperationsIfClientDoesNotSupportIt) { - OperationShardingState::setShardRole( - opCtx(), NamespaceString("foo.bar"), ShardVersion(), boost::none); + OperationShardingState::setShardRole(opCtx(), + NamespaceString::createNamespaceString_forTest("foo.bar"), + ShardVersion(), + boost::none); ASSERT_THROWS_CODE( resetTxnWithRetries(), DBException, ErrorCodes::duplicateCodeForTest(6638800)); } TEST_F(TxnAPITest, CanBeUsedWithinShardedOperationsIfClientSupportsIt) { - OperationShardingState::setShardRole( - opCtx(), NamespaceString("foo.bar"), ShardVersion(), boost::none); + OperationShardingState::setShardRole(opCtx(), + NamespaceString::createNamespaceString_forTest("foo.bar"), + ShardVersion(), + boost::none); // Should not throw. resetTxnWithRetriesWithClient(std::make_unique()); diff --git a/src/mongo/db/transaction/transaction_history_iterator_test.cpp b/src/mongo/db/transaction/transaction_history_iterator_test.cpp index 2d3874b6ac0..57f67845f90 100644 --- a/src/mongo/db/transaction/transaction_history_iterator_test.cpp +++ b/src/mongo/db/transaction/transaction_history_iterator_test.cpp @@ -61,24 +61,24 @@ repl::OplogEntry makeOplogEntry(repl::OpTime opTime, BSONObj docToInsert, boost::optional prevWriteOpTimeInTransaction) { return {repl::DurableOplogEntry( - opTime, // optime - repl::OpTypeEnum::kInsert, // opType - NamespaceString("a.b"), // namespace - boost::none, // uuid - boost::none, // fromMigrate - repl::OplogEntry::kOplogVersion, // version - docToInsert, // o - boost::none, // o2 - {}, // sessionInfo - boost::none, // upsert - Date_t(), // wall clock time - {}, // statement ids - prevWriteOpTimeInTransaction, // optime of previous write within same transaction - boost::none, // pre-image optime - boost::none, // post-image optime - boost::none, // ShardId of resharding recipient - boost::none, // _id - boost::none)}; // needsRetryImage + opTime, // optime + repl::OpTypeEnum::kInsert, // opType + NamespaceString::createNamespaceString_forTest("a.b"), // namespace + boost::none, // uuid + boost::none, // fromMigrate + repl::OplogEntry::kOplogVersion, // version + docToInsert, // o + boost::none, // o2 + {}, // sessionInfo + boost::none, // upsert + Date_t(), // wall clock time + {}, // statement ids + prevWriteOpTimeInTransaction, // optime of previous write within same transaction + boost::none, // pre-image optime + boost::none, // post-image optime + boost::none, // ShardId of resharding recipient + boost::none, // _id + boost::none)}; // needsRetryImage } } // namespace diff --git a/src/mongo/db/transaction/transaction_operations_test.cpp b/src/mongo/db/transaction/transaction_operations_test.cpp index 880d8dc8502..0d5a6f29d75 100644 --- a/src/mongo/db/transaction/transaction_operations_test.cpp +++ b/src/mongo/db/transaction/transaction_operations_test.cpp @@ -246,14 +246,16 @@ TEST(TransactionOperationsTest, GetApplyOpsInfoReturnsOneEntryContainingTwoOpera TransactionOperations::TransactionOperation op1; op1.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op1.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op1.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() + op1.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op1.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op1)); TransactionOperations::TransactionOperation op2; op2.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op2.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op2.setObject(BSON("_id" << 2)); // required for DurableReplOperation::serialize() + op2.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op2.setObject(BSON("_id" << 2)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op2)); // We have to allocate as many oplog slots as operations even though only @@ -283,14 +285,16 @@ TEST(TransactionOperationsTest, GetApplyOpsInfoRespectsOperationCountLimit) { TransactionOperations::TransactionOperation op1; op1.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op1.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op1.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() + op1.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op1.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op1)); TransactionOperations::TransactionOperation op2; op2.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op2.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op2.setObject(BSON("_id" << 2)); // required for DurableReplOperation::serialize() + op2.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op2.setObject(BSON("_id" << 2)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op2)); // We have to allocate as many oplog slots as operations even though only @@ -327,14 +331,16 @@ TEST(TransactionOperationsTest, GetApplyOpsInfoRespectsOperationSizeLimit) { TransactionOperations::TransactionOperation op1; op1.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op1.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op1.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() + op1.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op1.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op1)); TransactionOperations::TransactionOperation op2; op2.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op2.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op2.setObject(BSON("_id" << 2)); // required for DurableReplOperation::serialize() + op2.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op2.setObject(BSON("_id" << 2)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op2)); // We have to allocate as many oplog slots as operations even though only @@ -378,8 +384,9 @@ DEATH_TEST(TransactionOperationsTest, TransactionOperations::TransactionOperation op; op.setNeedsRetryImage(repl::RetryImageEnum::kPreImage); op.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() + op.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op)); // We allocated a slot for the operation but not for the pre-image. @@ -401,8 +408,9 @@ TEST(TransactionOperationsTest, GetApplyOpsInfoAssignsPreImageSlotBeforeOperatio TransactionOperations::TransactionOperation op; op.setNeedsRetryImage(repl::RetryImageEnum::kPreImage); op.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() + op.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op)); // We allocated a slot for the operation but not for the pre-image. @@ -430,8 +438,9 @@ TEST(TransactionOperationsTest, GetApplyOpsInfoAssignsLastOplogSlotForPrepare) { TransactionOperations::TransactionOperation op; op.setOpType(repl::OpTypeEnum::kInsert); // required for DurableReplOperation::serialize() - op.setNss(NamespaceString{"test.t"}); // required for DurableReplOperation::serialize() - op.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() + op.setNss(NamespaceString::createNamespaceString_forTest( + "test.t")); // required for DurableReplOperation::serialize() + op.setObject(BSON("_id" << 1)); // required for DurableReplOperation::serialize() ASSERT_OK(ops.addOperation(op)); // We allocate two oplog slots and confirm that the second oplog slot is assigned @@ -488,7 +497,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesSingleOperation) { // Add a small operation. This should be packed into a single applyOps entry. TransactionOperations::TransactionOperation op; op.setOpType(repl::OpTypeEnum::kInsert); - op.setNss(NamespaceString{"test.t"}); + op.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op.setObject(BSON("_id" << 1 << "x" << 1)); op.setTid(tenant); std::vector stmtIds = {1}; @@ -514,7 +523,9 @@ TEST(TransactionOperationsTest, LogOplogEntriesSingleOperation) { std::vector stmtIdsWritten) { ASSERT(entry) << "tried to log null applyOps oplog entry"; ASSERT_EQ(entry->getOpType(), repl::OpTypeEnum::kCommand); - ASSERT_EQ(entry->getNss(), NamespaceString{NamespaceString::kAdminDb}.getCommandNS()); + ASSERT_EQ(entry->getNss(), + NamespaceString::createNamespaceString_forTest(NamespaceString::kAdminDb) + .getCommandNS()); ASSERT_EQ(entry->getOpTime(), oplogSlots[0]); const auto& prevWriteOpTime = entry->getPrevWriteOpTimeInTransaction(); ASSERT(prevWriteOpTime); @@ -550,7 +561,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultipleOperationsCommitUnprepare // in the applyOps chain. TransactionOperations::TransactionOperation op1; op1.setOpType(repl::OpTypeEnum::kInsert); - op1.setNss(NamespaceString{"test.t"}); + op1.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op1.setObject(BSON("_id" << 1 << "x" << 1)); op1.setTid(tenant); std::vector stmtIds1 = {1}; @@ -559,7 +570,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultipleOperationsCommitUnprepare TransactionOperations::TransactionOperation op2; op2.setOpType(repl::OpTypeEnum::kInsert); - op2.setNss(NamespaceString{"test.t"}); + op2.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op2.setObject(BSON("_id" << 2 << "x" << 2)); op2.setTid(tenant); std::vector stmtIds2 = {2}; @@ -568,7 +579,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultipleOperationsCommitUnprepare TransactionOperations::TransactionOperation op3; op3.setOpType(repl::OpTypeEnum::kInsert); - op3.setNss(NamespaceString{"test.t"}); + op3.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op3.setObject(BSON("_id" << 3 << "x" << 3)); op3.setTid(tenant); std::vector stmtIds3 = {3}; @@ -598,7 +609,9 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultipleOperationsCommitUnprepare ASSERT(entry) << "tried to log null applyOps oplog entry"; ASSERT_EQ(entry->getOpType(), repl::OpTypeEnum::kCommand); - ASSERT_EQ(entry->getNss(), NamespaceString{NamespaceString::kAdminDb}.getCommandNS()); + ASSERT_EQ(entry->getNss(), + NamespaceString::createNamespaceString_forTest(NamespaceString::kAdminDb) + .getCommandNS()); auto expectedOpTime = oplogSlots[numEntriesLogged]; ASSERT_EQ(entry->getOpTime(), expectedOpTime); @@ -670,7 +683,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultipleOperationsPreparedTransac // in the applyOps chain. TransactionOperations::TransactionOperation op1; op1.setOpType(repl::OpTypeEnum::kInsert); - op1.setNss(NamespaceString{"test.t"}); + op1.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op1.setObject(BSON("_id" << 1 << "x" << 1)); op1.setTid(tenant); std::vector stmtIds1 = {1}; @@ -679,7 +692,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultipleOperationsPreparedTransac TransactionOperations::TransactionOperation op2; op2.setOpType(repl::OpTypeEnum::kInsert); - op2.setNss(NamespaceString{"test.t"}); + op2.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op2.setObject(BSON("_id" << 2 << "x" << 2)); op2.setTid(tenant); std::vector stmtIds2 = {2}; @@ -688,7 +701,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultipleOperationsPreparedTransac TransactionOperations::TransactionOperation op3; op3.setOpType(repl::OpTypeEnum::kInsert); - op3.setNss(NamespaceString{"test.t"}); + op3.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op3.setObject(BSON("_id" << 3 << "x" << 3)); op3.setTid(tenant); std::vector stmtIds3 = {3}; @@ -717,7 +730,9 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultipleOperationsPreparedTransac std::vector stmtIdsWritten) { ASSERT(entry) << "tried to log null applyOps oplog entry"; ASSERT_EQ(entry->getOpType(), repl::OpTypeEnum::kCommand); - ASSERT_EQ(entry->getNss(), NamespaceString{NamespaceString::kAdminDb}.getCommandNS()); + ASSERT_EQ(entry->getNss(), + NamespaceString::createNamespaceString_forTest(NamespaceString::kAdminDb) + .getCommandNS()); auto expectedOpTime = oplogSlots[numEntriesLogged]; ASSERT_EQ(entry->getOpTime(), expectedOpTime); @@ -816,7 +831,7 @@ TEST(TransactionOperationsTest, for (int i = 0; i < 2; i++) { TransactionOperations::TransactionOperation op; op.setOpType(repl::OpTypeEnum::kInsert); - op.setNss(NamespaceString{"test.t"}); + op.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op.setObject(BSON("_id" << i << "x" << std::string(15 * 1024 * 1024, 'x'))); ASSERT_OK(ops.addOperation(op)); @@ -847,7 +862,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesExtractsPreImage) { // Add a small operation with a pre images. TransactionOperations::TransactionOperation op; op.setOpType(repl::OpTypeEnum::kInsert); - op.setNss(NamespaceString{"test.t"}); + op.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op.setObject(BSON("_id" << 1 << "x" << 1)); op.setNeedsRetryImage(repl::RetryImageEnum::kPreImage); op.setPreImage(BSON("_id" << 1)); @@ -890,7 +905,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesExtractsPostImage) { // Add a small operation with a pre images. TransactionOperations::TransactionOperation op; op.setOpType(repl::OpTypeEnum::kInsert); - op.setNss(NamespaceString{"test.t"}); + op.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op.setObject(BSON("_id" << 1 << "x" << 1)); op.setNeedsRetryImage(repl::RetryImageEnum::kPostImage); op.setPostImage(BSON("_id" << 1)); @@ -934,7 +949,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultiplePrePostImagesInSameEntry) // Add two small operations with pre/post images. TransactionOperations::TransactionOperation op1; op1.setOpType(repl::OpTypeEnum::kInsert); - op1.setNss(NamespaceString{"test.t"}); + op1.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op1.setObject(BSON("_id" << 1 << "x" << 1)); op1.setNeedsRetryImage(repl::RetryImageEnum::kPreImage); op1.setPreImage(BSON("_id" << 1)); @@ -942,7 +957,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultiplePrePostImagesInSameEntry) TransactionOperations::TransactionOperation op2; op2.setOpType(repl::OpTypeEnum::kInsert); - op2.setNss(NamespaceString{"test.t"}); + op2.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op2.setObject(BSON("_id" << 2 << "x" << 2)); op2.setNeedsRetryImage(repl::RetryImageEnum::kPostImage); op2.setPostImage(BSON("_id" << 2)); @@ -976,7 +991,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultiplePrePostImagesInDifferentE // Add two large 15MB operations with pre/post images. TransactionOperations::TransactionOperation op1; op1.setOpType(repl::OpTypeEnum::kInsert); - op1.setNss(NamespaceString{"test.t"}); + op1.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op1.setObject(BSON("_id" << 1 << "x" << std::string(15 * 1024 * 1024, 'x'))); op1.setNeedsRetryImage(repl::RetryImageEnum::kPreImage); op1.setPreImage(BSON("_id" << 1)); @@ -984,7 +999,7 @@ TEST(TransactionOperationsTest, LogOplogEntriesMultiplePrePostImagesInDifferentE TransactionOperations::TransactionOperation op2; op2.setOpType(repl::OpTypeEnum::kInsert); - op2.setNss(NamespaceString{"test.t"}); + op2.setNss(NamespaceString::createNamespaceString_forTest("test.t")); op2.setObject(BSON("_id" << 2 << "x" << std::string(15 * 1024 * 1024, 'x'))); op2.setNeedsRetryImage(repl::RetryImageEnum::kPostImage); op2.setPostImage(BSON("_id" << 2)); diff --git a/src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp b/src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp index 3a5a784b4a9..4247f055262 100644 --- a/src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp +++ b/src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp @@ -57,7 +57,7 @@ namespace mongo { namespace { -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); /** * Creates an OplogEntry with given parameters and preset defaults for this test suite. diff --git a/src/mongo/db/transaction/transaction_participant_test.cpp b/src/mongo/db/transaction/transaction_participant_test.cpp index f38ed96ab36..f5b53a25d60 100644 --- a/src/mongo/db/transaction/transaction_participant_test.cpp +++ b/src/mongo/db/transaction/transaction_participant_test.cpp @@ -74,7 +74,7 @@ namespace mongo { namespace { -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); /** * Creates an OplogEntry with given parameters and preset defaults for this test suite. @@ -691,7 +691,8 @@ TEST_F(TxnParticipantTest, PrepareSucceedsWithNestedLocks) { } TEST_F(TxnParticipantTest, PrepareFailsOnTemporaryCollection) { - NamespaceString tempCollNss(kNss.db(), "tempCollection"); + NamespaceString tempCollNss = + NamespaceString::createNamespaceString_forTest(kNss.db(), "tempCollection"); UUID tempCollUUID = UUID::gen(); // Create a temporary collection so that we can write to it. @@ -1010,7 +1011,8 @@ TEST_F(TxnParticipantTest, UnstashFailsShouldLeaveTxnResourceStashUnchanged) { // Simulate the locking of an insert. { Lock::DBLock dbLock(opCtx(), DatabaseName(boost::none, "test"), MODE_IX); - Lock::CollectionLock collLock(opCtx(), NamespaceString("test.foo"), MODE_IX); + Lock::CollectionLock collLock( + opCtx(), NamespaceString::createNamespaceString_forTest("test.foo"), MODE_IX); } auto prepareTimestamp = txnParticipant.prepareTransaction(opCtx(), {}); @@ -1166,7 +1168,8 @@ TEST_F(TxnParticipantTest, StepDownDuringPreparedAbortReleasesRSTL) { // Simulate the locking of an insert. { Lock::DBLock dbLock(opCtx(), DatabaseName(boost::none, "test"), MODE_IX); - Lock::CollectionLock collLock(opCtx(), NamespaceString("test.foo"), MODE_IX); + Lock::CollectionLock collLock( + opCtx(), NamespaceString::createNamespaceString_forTest("test.foo"), MODE_IX); } ASSERT_EQ(opCtx()->lockState()->getLockMode(resourceIdReplicationStateTransitionLock), MODE_IX); @@ -1219,7 +1222,8 @@ TEST_F(TxnParticipantTest, StepDownDuringPreparedCommitReleasesRSTL) { // Simulate the locking of an insert. { Lock::DBLock dbLock(opCtx(), DatabaseName(boost::none, "test"), MODE_IX); - Lock::CollectionLock collLock(opCtx(), NamespaceString("test.foo"), MODE_IX); + Lock::CollectionLock collLock( + opCtx(), NamespaceString::createNamespaceString_forTest("test.foo"), MODE_IX); } ASSERT_EQ(opCtx()->lockState()->getLockMode(resourceIdReplicationStateTransitionLock), MODE_IX); @@ -1888,7 +1892,8 @@ TEST_F(TxnParticipantTest, ReacquireLocksForPreparedTransactionsOnStepUp) { // Simulate the locking of an insert. { Lock::DBLock dbLock(opCtx(), DatabaseName(boost::none, "test"), MODE_IX); - Lock::CollectionLock collLock(opCtx(), NamespaceString("test.foo"), MODE_IX); + Lock::CollectionLock collLock( + opCtx(), NamespaceString::createNamespaceString_forTest("test.foo"), MODE_IX); } txnParticipant.prepareTransaction(opCtx(), repl::OpTime({1, 1}, 1)); txnParticipant.stashTransactionResources(opCtx()); diff --git a/src/mongo/db/ttl_test.cpp b/src/mongo/db/ttl_test.cpp index 8c3655142c1..aaa22316077 100644 --- a/src/mongo/db/ttl_test.cpp +++ b/src/mongo/db/ttl_test.cpp @@ -171,7 +171,7 @@ TEST_F(TTLTest, TTLPassSingleCollectionTwoIndexes) { SimpleClient client(opCtx()); - NamespaceString nss("testDB.coll0"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("testDB.coll0"); client.createCollection(nss); @@ -203,8 +203,8 @@ TEST_F(TTLTest, TTLPassMultipCollectionsPass) { SimpleClient client(opCtx()); - NamespaceString nss0("testDB.coll0"); - NamespaceString nss1("testDB.coll1"); + NamespaceString nss0 = NamespaceString::createNamespaceString_forTest("testDB.coll0"); + NamespaceString nss1 = NamespaceString::createNamespaceString_forTest("testDB.coll1"); client.createCollection(nss0); client.createCollection(nss1); @@ -265,7 +265,7 @@ TEST_F(TTLTest, TTLSingleSubPass) { // expected sub-passes differs from the expected sub-passes in the indidual test. int nInitialSubPasses = getTTLSubPasses(); - NamespaceString nss("testDB.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("testDB.coll"); client.createCollection(nss); @@ -323,7 +323,7 @@ TEST_F(TTLTest, TTLSubPassesRemoveExpiredDocuments) { // expected sub-passes differs from the expected sub-passes in the indidual test. int nInitialSubPasses = getTTLSubPasses(); - NamespaceString nss("testDB.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("testDB.coll"); client.createCollection(nss); @@ -400,7 +400,7 @@ TEST_F(TTLTest, TTLSubPassesRemoveExpiredDocumentsAddedBetweenSubPasses) { SimpleClient client(opCtx()); - NamespaceString nss("testDB.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("testDB.coll"); client.createCollection(nss); @@ -489,7 +489,7 @@ TEST_F(TTLTest, TTLSubPassesStartRemovingFromNewTTLIndex) { // expected sub-passes differs from the expected sub-passes in the indidual test. int nInitialSubPasses = getTTLSubPasses(); - NamespaceString nss("testDB.coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("testDB.coll"); client.createCollection(nss); diff --git a/src/mongo/db/update/update_driver_test.cpp b/src/mongo/db/update/update_driver_test.cpp index ecb93343b4c..7cf7888671c 100644 --- a/src/mongo/db/update/update_driver_test.cpp +++ b/src/mongo/db/update/update_driver_test.cpp @@ -204,10 +204,10 @@ class CreateFromQueryFixture : public mongo::unittest::Test { public: CreateFromQueryFixture() : _opCtx(_serviceContext.makeOperationContext()), - _driverOps(new UpdateDriver( - new ExpressionContext(_opCtx.get(), nullptr, NamespaceString("foo")))), - _driverRepl(new UpdateDriver( - new ExpressionContext(_opCtx.get(), nullptr, NamespaceString("foo")))) { + _driverOps(new UpdateDriver(new ExpressionContext( + _opCtx.get(), nullptr, NamespaceString::createNamespaceString_forTest("foo")))), + _driverRepl(new UpdateDriver(new ExpressionContext( + _opCtx.get(), nullptr, NamespaceString::createNamespaceString_forTest("foo")))) { _driverOps->parse(makeUpdateMod(fromjson("{$set:{'_':1}}")), _arrayFilters); _driverRepl->parse(makeUpdateMod(fromjson("{}")), _arrayFilters); } diff --git a/src/mongo/db/vector_clock_test.cpp b/src/mongo/db/vector_clock_test.cpp index af3aef564bd..96b223ad298 100644 --- a/src/mongo/db/vector_clock_test.cpp +++ b/src/mongo/db/vector_clock_test.cpp @@ -49,7 +49,8 @@ namespace mongo { namespace { -const NamespaceString kDummyNamespaceString("test", "foo"); +const NamespaceString kDummyNamespaceString = + NamespaceString::createNamespaceString_forTest("test", "foo"); using VectorClockTest = VectorClockTestFixture; diff --git a/src/mongo/db/views/resolved_view_test.cpp b/src/mongo/db/views/resolved_view_test.cpp index 82b0098b69d..4d8154b0f9e 100644 --- a/src/mongo/db/views/resolved_view_test.cpp +++ b/src/mongo/db/views/resolved_view_test.cpp @@ -45,8 +45,9 @@ namespace mongo { namespace { -const NamespaceString viewNss("testdb.testview"); -const NamespaceString backingNss("testdb.testcoll"); +const NamespaceString viewNss = NamespaceString::createNamespaceString_forTest("testdb.testview"); +const NamespaceString backingNss = + NamespaceString::createNamespaceString_forTest("testdb.testcoll"); const std::vector emptyPipeline; const BSONObj kDefaultCursorOptionDocument = BSON(aggregation_request_helper::kBatchSizeField << aggregation_request_helper::kDefaultBatchSize); diff --git a/src/mongo/db/views/view_catalog_test.cpp b/src/mongo/db/views/view_catalog_test.cpp index ec4a83d395b..7533b434c1d 100644 --- a/src/mongo/db/views/view_catalog_test.cpp +++ b/src/mongo/db/views/view_catalog_test.cpp @@ -203,30 +203,30 @@ public: }; TEST_F(ViewCatalogFixture, CreateExistingView) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT_NOT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } TEST_F(ViewCatalogFixture, CreateViewOnDifferentDatabase) { - const NamespaceString viewName("db1.view"); - const NamespaceString viewOn("db2.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db1.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db2.coll"); ASSERT_NOT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } TEST_F(ViewCatalogFixture, CanCreateViewWithExprPredicate) { - const NamespaceString viewOn("db.coll"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView(operationContext(), - NamespaceString("db.view1"), + NamespaceString::createNamespaceString_forTest("db.view1"), viewOn, BSON_ARRAY(BSON("$match" << BSON("$expr" << 1))), emptyCollation)); ASSERT_OK(createView(operationContext(), - NamespaceString("db.view2"), + NamespaceString::createNamespaceString_forTest("db.view2"), viewOn, BSON_ARRAY(BSON("$facet" << BSON("output" << BSON_ARRAY(BSON( "$match" << BSON("$expr" << 1)))))), @@ -234,17 +234,17 @@ TEST_F(ViewCatalogFixture, CanCreateViewWithExprPredicate) { } TEST_F(ViewCatalogFixture, CanCreateViewWithJSONSchemaPredicate) { - const NamespaceString viewOn("db.coll"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView( operationContext(), - NamespaceString("db.view1"), + NamespaceString::createNamespaceString_forTest("db.view1"), viewOn, BSON_ARRAY(BSON("$match" << BSON("$jsonSchema" << BSON("required" << BSON_ARRAY("x"))))), emptyCollation)); ASSERT_OK(createView( operationContext(), - NamespaceString("db.view2"), + NamespaceString::createNamespaceString_forTest("db.view2"), viewOn, BSON_ARRAY(BSON( "$facet" << BSON( @@ -254,9 +254,9 @@ TEST_F(ViewCatalogFixture, CanCreateViewWithJSONSchemaPredicate) { } TEST_F(ViewCatalogFixture, CanCreateViewWithLookupUsingPipelineSyntax) { - const NamespaceString viewOn("db.coll"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView(operationContext(), - NamespaceString("db.view"), + NamespaceString::createNamespaceString_forTest("db.view"), viewOn, BSON_ARRAY(BSON("$lookup" << BSON("from" << "fcoll" @@ -267,8 +267,8 @@ TEST_F(ViewCatalogFixture, CanCreateViewWithLookupUsingPipelineSyntax) { } TEST_F(ViewCatalogFixture, CreateViewWithPipelineFailsOnInvalidStageName) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); auto invalidPipeline = BSON_ARRAY(BSON("INVALID_STAGE_NAME" << 1)); ASSERT_THROWS(createView(operationContext(), viewName, viewOn, invalidPipeline, emptyCollation), @@ -276,8 +276,8 @@ TEST_F(ViewCatalogFixture, CreateViewWithPipelineFailsOnInvalidStageName) { } TEST_F(ReplViewCatalogFixture, CreateViewWithPipelineFailsOnChangeStreamsStage) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); // $changeStream cannot be used in a view definition pipeline. auto invalidPipeline = BSON_ARRAY(BSON("$changeStream" << BSONObj())); @@ -289,8 +289,8 @@ TEST_F(ReplViewCatalogFixture, CreateViewWithPipelineFailsOnChangeStreamsStage) } TEST_F(ReplViewCatalogFixture, CreateViewWithPipelineFailsOnCollectionlessStage) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); auto invalidPipeline = BSON_ARRAY(BSON("$currentOp" << BSONObj())); @@ -301,8 +301,8 @@ TEST_F(ReplViewCatalogFixture, CreateViewWithPipelineFailsOnCollectionlessStage) } TEST_F(ReplViewCatalogFixture, CreateViewWithPipelineFailsOnIneligibleStagePersistentWrite) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); // $out cannot be used in a view definition pipeline. auto invalidPipeline = BSON_ARRAY(BSON("$out" @@ -323,8 +323,8 @@ TEST_F(ReplViewCatalogFixture, CreateViewWithPipelineFailsOnIneligibleStagePersi } TEST_F(ViewCatalogFixture, CreateViewOnInvalidCollectionName) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.$coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.$coll"); ASSERT_NOT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } @@ -334,14 +334,18 @@ TEST_F(ViewCatalogFixture, ExceedMaxViewDepthInOrder) { int i = 0; for (; i < ViewGraph::kMaxViewDepth; i++) { - const NamespaceString viewName(str::stream() << ns << i); - const NamespaceString viewOn(str::stream() << ns << (i + 1)); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << i); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << (i + 1)); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } - const NamespaceString viewName(str::stream() << ns << i); - const NamespaceString viewOn(str::stream() << ns << (i + 1)); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << i); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << (i + 1)); ASSERT_NOT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } @@ -352,38 +356,44 @@ TEST_F(ViewCatalogFixture, ExceedMaxViewDepthByJoining) { int size = ViewGraph::kMaxViewDepth * 2 / 3; for (; i < size; i++) { - const NamespaceString viewName(str::stream() << ns << i); - const NamespaceString viewOn(str::stream() << ns << (i + 1)); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << i); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << (i + 1)); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } for (i = 1; i < size + 1; i++) { - const NamespaceString viewName(str::stream() << ns << (size + i)); - const NamespaceString viewOn(str::stream() << ns << (size + i + 1)); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << (size + i)); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << (size + i + 1)); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } - const NamespaceString viewName(str::stream() << ns << size); - const NamespaceString viewOn(str::stream() << ns << (size + 1)); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << size); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(str::stream() << ns << (size + 1)); ASSERT_NOT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } TEST_F(ViewCatalogFixture, CreateViewCycles) { { - const NamespaceString viewName("db.view1"); - const NamespaceString viewOn("db.view1"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view1"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.view1"); ASSERT_NOT_OK( createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); } { - const NamespaceString view1("db.view1"); - const NamespaceString view2("db.view2"); - const NamespaceString view3("db.view3"); + const NamespaceString view1 = NamespaceString::createNamespaceString_forTest("db.view1"); + const NamespaceString view2 = NamespaceString::createNamespaceString_forTest("db.view2"); + const NamespaceString view3 = NamespaceString::createNamespaceString_forTest("db.view3"); ASSERT_OK(createView(operationContext(), view1, view2, emptyPipeline, emptyCollation)); ASSERT_OK(createView(operationContext(), view2, view3, emptyPipeline, emptyCollation)); @@ -406,8 +416,8 @@ TEST_F(ViewCatalogFixture, CanSuccessfullyCreateViewWhosePipelineIsExactlyAtMaxS ASSERT_EQ(pipelineSize, ViewGraph::kMaxViewPipelineSizeBytes); - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); const BSONObj collation; ASSERT_OK(createView(operationContext(), viewName, viewOn, builder.arr(), collation)); @@ -426,8 +436,8 @@ TEST_F(ViewCatalogFixture, CannotCreateViewWhosePipelineExceedsMaxSizeInBytes) { } builder << kTinyMatchStage; - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); const BSONObj collation; ASSERT_NOT_OK(createView(operationContext(), viewName, viewOn, builder.arr(), collation)); @@ -447,9 +457,9 @@ TEST_F(ViewCatalogFixture, CannotCreateViewIfItsFullyResolvedPipelineWouldExceed } builder2 << kTinyMatchStage; - const NamespaceString view1("db.view1"); - const NamespaceString view2("db.view2"); - const NamespaceString viewOn("db.coll"); + const NamespaceString view1 = NamespaceString::createNamespaceString_forTest("db.view1"); + const NamespaceString view2 = NamespaceString::createNamespaceString_forTest("db.view2"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); const BSONObj collation1; const BSONObj collation2; @@ -458,34 +468,34 @@ TEST_F(ViewCatalogFixture, CannotCreateViewIfItsFullyResolvedPipelineWouldExceed } TEST_F(ViewCatalogFixture, DropMissingView) { - NamespaceString viewName("db.view"); + NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); ASSERT_NOT_OK(dropView(operationContext(), viewName)); } TEST_F(ViewCatalogFixture, ModifyMissingView) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_NOT_OK(modifyView(operationContext(), viewName, viewOn, emptyPipeline)); } TEST_F(ViewCatalogFixture, ModifyViewOnDifferentDatabase) { - const NamespaceString viewName("db1.view"); - const NamespaceString viewOn("db2.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db1.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db2.coll"); ASSERT_NOT_OK(modifyView(operationContext(), viewName, viewOn, emptyPipeline)); } TEST_F(ViewCatalogFixture, ModifyViewOnInvalidCollectionName) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.$coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.$coll"); ASSERT_NOT_OK(modifyView(operationContext(), viewName, viewOn, emptyPipeline)); } TEST_F(ReplViewCatalogFixture, ModifyViewWithPipelineFailsOnIneligibleStage) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); auto validPipeline = BSON_ARRAY(BSON("$match" << BSON("_id" << 1))); auto invalidPipeline = BSON_ARRAY(BSON("$changeStream" << BSONObj())); @@ -500,12 +510,12 @@ TEST_F(ReplViewCatalogFixture, ModifyViewWithPipelineFailsOnIneligibleStage) { } TEST_F(ViewCatalogFixture, LookupMissingView) { - ASSERT(!lookup(operationContext(), NamespaceString("db.view"))); + ASSERT(!lookup(operationContext(), NamespaceString::createNamespaceString_forTest("db.view"))); } TEST_F(ViewCatalogFixture, LookupExistingView) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); @@ -513,18 +523,20 @@ TEST_F(ViewCatalogFixture, LookupExistingView) { } TEST_F(ViewCatalogFixture, LookupRIDExistingView) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); - auto resourceID = ResourceId(RESOURCE_COLLECTION, NamespaceString(boost::none, "db.view")); + auto resourceID = + ResourceId(RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "db.view")); ASSERT_EQ(ResourceCatalog::get(getServiceContext()).name(resourceID), std::string{"db.view"}); } TEST_F(ViewCatalogFixture, LookupRIDExistingViewRollback) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); { Lock::DBLock dbLock(operationContext(), viewName.dbName(), MODE_X); Lock::CollectionLock collLock(operationContext(), viewName, MODE_IX); @@ -541,26 +553,32 @@ TEST_F(ViewCatalogFixture, LookupRIDExistingViewRollback) { view_catalog_helpers::validatePipeline, emptyCollation)); } - auto resourceID = ResourceId(RESOURCE_COLLECTION, NamespaceString(boost::none, "db.view")); + auto resourceID = + ResourceId(RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "db.view")); ASSERT(!ResourceCatalog::get(getServiceContext()).name(resourceID)); } TEST_F(ViewCatalogFixture, LookupRIDAfterDrop) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT_OK(dropView(operationContext(), viewName)); - auto resourceID = ResourceId(RESOURCE_COLLECTION, NamespaceString(boost::none, "db.view")); + auto resourceID = + ResourceId(RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "db.view")); ASSERT(!ResourceCatalog::get(getServiceContext()).name(resourceID)); } TEST_F(ViewCatalogFixture, LookupRIDAfterDropRollback) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); - auto resourceID = ResourceId(RESOURCE_COLLECTION, NamespaceString(boost::none, "db.view")); + auto resourceID = + ResourceId(RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "db.view")); { WriteUnitOfWork wunit(operationContext()); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); @@ -586,20 +604,24 @@ TEST_F(ViewCatalogFixture, LookupRIDAfterDropRollback) { } TEST_F(ViewCatalogFixture, LookupRIDAfterModify) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); - auto resourceID = ResourceId(RESOURCE_COLLECTION, NamespaceString(boost::none, "db.view")); + auto resourceID = + ResourceId(RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "db.view")); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT_OK(modifyView(operationContext(), viewName, viewOn, emptyPipeline)); ASSERT_EQ(ResourceCatalog::get(getServiceContext()).name(resourceID), viewName.ns()); } TEST_F(ViewCatalogFixture, LookupRIDAfterModifyRollback) { - const NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + const NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); - auto resourceID = ResourceId(RESOURCE_COLLECTION, NamespaceString(boost::none, "db.view")); + auto resourceID = + ResourceId(RESOURCE_COLLECTION, + NamespaceString::createNamespaceString_forTest(boost::none, "db.view")); { WriteUnitOfWork wunit(operationContext()); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); @@ -629,8 +651,8 @@ TEST_F(ViewCatalogFixture, LookupRIDAfterModifyRollback) { } TEST_F(ViewCatalogFixture, CreateViewThenDropAndLookup) { - NamespaceString viewName("db.view"); - const NamespaceString viewOn("db.coll"); + NamespaceString viewName = NamespaceString::createNamespaceString_forTest("db.view"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT_OK(dropView(operationContext(), viewName)); @@ -639,10 +661,10 @@ TEST_F(ViewCatalogFixture, CreateViewThenDropAndLookup) { } TEST_F(ViewCatalogFixture, Iterate) { - const NamespaceString view1("db.view1"); - const NamespaceString view2("db.view2"); - const NamespaceString view3("db.view3"); - const NamespaceString viewOn("db.coll"); + const NamespaceString view1 = NamespaceString::createNamespaceString_forTest("db.view1"); + const NamespaceString view2 = NamespaceString::createNamespaceString_forTest("db.view2"); + const NamespaceString view3 = NamespaceString::createNamespaceString_forTest("db.view3"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); ASSERT_OK(createView(operationContext(), view1, viewOn, emptyPipeline, emptyCollation)); ASSERT_OK(createView(operationContext(), view2, viewOn, emptyPipeline, emptyCollation)); @@ -663,10 +685,10 @@ TEST_F(ViewCatalogFixture, Iterate) { } TEST_F(ViewCatalogFixture, ResolveViewCorrectPipeline) { - const NamespaceString view1("db.view1"); - const NamespaceString view2("db.view2"); - const NamespaceString view3("db.view3"); - const NamespaceString viewOn("db.coll"); + const NamespaceString view1 = NamespaceString::createNamespaceString_forTest("db.view1"); + const NamespaceString view2 = NamespaceString::createNamespaceString_forTest("db.view2"); + const NamespaceString view3 = NamespaceString::createNamespaceString_forTest("db.view3"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); BSONArrayBuilder pipeline1; BSONArrayBuilder pipeline3; BSONArrayBuilder pipeline2; @@ -709,9 +731,9 @@ TEST_F(ViewCatalogFixture, ResolveViewOnCollectionNamespace) { } TEST_F(ViewCatalogFixture, ResolveViewCorrectlyExtractsDefaultCollation) { - const NamespaceString view1("db.view1"); - const NamespaceString view2("db.view2"); - const NamespaceString viewOn("db.coll"); + const NamespaceString view1 = NamespaceString::createNamespaceString_forTest("db.view1"); + const NamespaceString view2 = NamespaceString::createNamespaceString_forTest("db.view2"); + const NamespaceString viewOn = NamespaceString::createNamespaceString_forTest("db.coll"); BSONArrayBuilder pipeline1; BSONArrayBuilder pipeline2; @@ -753,8 +775,10 @@ public: TEST_F(ServerlessViewCatalogFixture, LookupExistingViewBeforeAndAfterDropFeatureFlagOff) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); - const NamespaceString viewName(db()->name(), "view"); - const NamespaceString viewOn(db()->name(), "coll"); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(db()->name(), "view"); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(db()->name(), "coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT(lookup(operationContext(), viewName)); @@ -766,8 +790,10 @@ TEST_F(ServerlessViewCatalogFixture, LookupExistingViewBeforeAndAfterDropFeature TEST_F(ServerlessViewCatalogFixture, LookupExistingViewBeforeAndAfterDropFeatureFlagOn) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); - const NamespaceString viewName(db()->name(), "view"); - const NamespaceString viewOn(db()->name(), "coll"); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(db()->name(), "view"); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(db()->name(), "coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT(lookup(operationContext(), viewName)); @@ -778,8 +804,10 @@ TEST_F(ServerlessViewCatalogFixture, LookupExistingViewBeforeAndAfterDropFeature TEST_F(ServerlessViewCatalogFixture, ModifyViewBelongingToTenantFeatureFlagOff) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); - const NamespaceString viewName(db()->name(), "db1.view"); - const NamespaceString viewOn(db()->name(), "db2.coll"); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(db()->name(), "db1.view"); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(db()->name(), "db2.coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT_EQ(lookup(operationContext(), viewName)->pipeline().size(), 0); @@ -794,8 +822,10 @@ TEST_F(ServerlessViewCatalogFixture, ModifyViewBelongingToTenantFeatureFlagOff) TEST_F(ServerlessViewCatalogFixture, ModifyViewBelongingToTenantFeatureFlagOn) { RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); - const NamespaceString viewName(db()->name(), "db1.view"); - const NamespaceString viewOn(db()->name(), "db2.coll"); + const NamespaceString viewName = + NamespaceString::createNamespaceString_forTest(db()->name(), "db1.view"); + const NamespaceString viewOn = + NamespaceString::createNamespaceString_forTest(db()->name(), "db2.coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT_EQ(lookup(operationContext(), viewName)->pipeline().size(), 0); diff --git a/src/mongo/db/views/view_definition_test.cpp b/src/mongo/db/views/view_definition_test.cpp index ad2459c81fc..68d467a9137 100644 --- a/src/mongo/db/views/view_definition_test.cpp +++ b/src/mongo/db/views/view_definition_test.cpp @@ -44,10 +44,13 @@ namespace mongo { namespace { -const NamespaceString viewNss("testdb.testview"); -const NamespaceString backingNss("testdb.testcoll"); -const NamespaceString bucketsColl("testdb.system.buckets.testcoll"); -const NamespaceString timeseriesColl("testdb.testcoll"); +const NamespaceString viewNss = NamespaceString::createNamespaceString_forTest("testdb.testview"); +const NamespaceString backingNss = + NamespaceString::createNamespaceString_forTest("testdb.testcoll"); +const NamespaceString bucketsColl = + NamespaceString::createNamespaceString_forTest("testdb.system.buckets.testcoll"); +const NamespaceString timeseriesColl = + NamespaceString::createNamespaceString_forTest("testdb.testcoll"); const BSONObj samplePipeline = BSON_ARRAY(BSON("limit" << 9)); TEST(ViewDefinitionTest, ViewDefinitionCreationCorrectlyBuildsNamespaceStrings) { @@ -97,7 +100,8 @@ DEATH_TEST_REGEX(ViewDefinitionTest, R"#(Invariant failure.*_viewNss.db\(\) == viewOnNss.db\(\))#") { ViewDefinition viewDef( viewNss.dbName(), viewNss.coll(), backingNss.coll(), samplePipeline, nullptr); - NamespaceString badViewOn("someOtherDb.someOtherCollection"); + NamespaceString badViewOn = + NamespaceString::createNamespaceString_forTest("someOtherDb.someOtherCollection"); viewDef.setViewOn(badViewOn); } @@ -106,7 +110,8 @@ TEST(ViewDefinitionTest, SetViewOnSucceedsIfNewViewOnIsInSameDatabaseAsView) { viewNss.dbName(), viewNss.coll(), backingNss.coll(), samplePipeline, nullptr); ASSERT_EQ(viewDef.viewOn(), backingNss); - NamespaceString newViewOn("testdb.othercollection"); + NamespaceString newViewOn = + NamespaceString::createNamespaceString_forTest("testdb.othercollection"); viewDef.setViewOn(newViewOn); ASSERT_EQ(newViewOn, viewDef.viewOn()); } @@ -143,8 +148,10 @@ TEST(ViewDefinitionTest, ViewDefinitionCreationCorrectlySetsTimeseries) { TEST(ViewDefinitionTest, ViewDefinitionCreationCorrectlyBuildsNamespaceStringsWithTenantIds) { TenantId tenantId(OID::gen()); - NamespaceString viewNss(tenantId, "testdb.testview"); - NamespaceString backingNss(tenantId, "testdb.testcoll"); + NamespaceString viewNss = + NamespaceString::createNamespaceString_forTest(tenantId, "testdb.testview"); + NamespaceString backingNss = + NamespaceString::createNamespaceString_forTest(tenantId, "testdb.testcoll"); ViewDefinition viewDef( viewNss.dbName(), viewNss.coll(), backingNss.coll(), samplePipeline, nullptr); diff --git a/src/mongo/db/views/view_graph_test.cpp b/src/mongo/db/views/view_graph_test.cpp index 1a8760e7135..2d91b7fe094 100644 --- a/src/mongo/db/views/view_graph_test.cpp +++ b/src/mongo/db/views/view_graph_test.cpp @@ -49,9 +49,9 @@ const auto kTestDb = DatabaseName(boost::none, "test"); constexpr auto kFooName = "foo"_sd; constexpr auto kBarName = "bar"_sd; constexpr auto kQuxName = "qux"_sd; -const auto kFooNamespace = NamespaceString(kTestDb, kFooName); -const auto kBarNamespace = NamespaceString(kTestDb, kBarName); -const auto kQuxNamespace = NamespaceString(kTestDb, kQuxName); +const auto kFooNamespace = NamespaceString::createNamespaceString_forTest(kTestDb, kFooName); +const auto kBarNamespace = NamespaceString::createNamespaceString_forTest(kTestDb, kBarName); +const auto kQuxNamespace = NamespaceString::createNamespaceString_forTest(kTestDb, kQuxName); const auto kEmptyPipeline = BSONArray(); const auto kBinaryCollation = BSONObj(); const auto kFilipinoCollation = BSON("locale" @@ -249,8 +249,8 @@ TEST_F(ViewGraphFixture, DifferentTenantsCanCreateViewWithConflictingNamespaces) DatabaseName db1(TenantId(OID::gen()), "test"); DatabaseName db2(TenantId(OID::gen()), "test"); - NamespaceString viewOn1(db1, kBarName); - NamespaceString viewOn2(db2, kBarName); + NamespaceString viewOn1 = NamespaceString::createNamespaceString_forTest(db1, kBarName); + NamespaceString viewOn2 = NamespaceString::createNamespaceString_forTest(db2, kBarName); // Create a view "foo" on tenant1's collection "test.bar". const auto fooView1 = @@ -265,7 +265,7 @@ TEST_F(ViewGraphFixture, DifferentTenantsCanCreateViewWithConflictingNamespaces) ASSERT_EQ(viewGraph()->size(), 4UL); // Remove tenant1's view "foo". - NamespaceString viewToRemove(db1, kFooName); + NamespaceString viewToRemove = NamespaceString::createNamespaceString_forTest(db1, kFooName); viewGraph()->remove(viewToRemove); ASSERT_EQ(viewGraph()->size(), 2UL); } diff --git a/src/mongo/dbtests/cursor_manager_test.cpp b/src/mongo/dbtests/cursor_manager_test.cpp index 4b634dc2db3..fa85089ff26 100644 --- a/src/mongo/dbtests/cursor_manager_test.cpp +++ b/src/mongo/dbtests/cursor_manager_test.cpp @@ -53,7 +53,7 @@ namespace mongo { namespace { -const NamespaceString kTestNss{"test.collection"}; +const NamespaceString kTestNss = NamespaceString::createNamespaceString_forTest("test.collection"); class CursorManagerTest : public unittest::Test { public: @@ -214,16 +214,17 @@ TEST_F(CursorManagerTest, InactiveCursorShouldTimeout) { CursorManager* cursorManager = useCursorManager(); auto clock = useClock(); - cursorManager->registerCursor(_opCtx.get(), - {makeFakePlanExecutor(), - NamespaceString{"test.collection"}, - {}, - APIParameters(), - {}, - repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern), - ReadPreferenceSetting(ReadPreference::PrimaryOnly), - BSONObj(), - PrivilegeVector()}); + cursorManager->registerCursor( + _opCtx.get(), + {makeFakePlanExecutor(), + NamespaceString::createNamespaceString_forTest("test.collection"), + {}, + APIParameters(), + {}, + repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern), + ReadPreferenceSetting(ReadPreference::PrimaryOnly), + BSONObj(), + PrivilegeVector()}); ASSERT_EQ(0UL, cursorManager->timeoutCursors(_opCtx.get(), Date_t())); @@ -231,16 +232,17 @@ TEST_F(CursorManagerTest, InactiveCursorShouldTimeout) { ASSERT_EQ(1UL, cursorManager->timeoutCursors(_opCtx.get(), clock->now())); ASSERT_EQ(0UL, cursorManager->numCursors()); - cursorManager->registerCursor(_opCtx.get(), - {makeFakePlanExecutor(), - NamespaceString{"test.collection"}, - {}, - APIParameters(), - {}, - repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern), - ReadPreferenceSetting(ReadPreference::PrimaryOnly), - BSONObj(), - PrivilegeVector()}); + cursorManager->registerCursor( + _opCtx.get(), + {makeFakePlanExecutor(), + NamespaceString::createNamespaceString_forTest("test.collection"), + {}, + APIParameters(), + {}, + repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern), + ReadPreferenceSetting(ReadPreference::PrimaryOnly), + BSONObj(), + PrivilegeVector()}); ASSERT_EQ(1UL, cursorManager->timeoutCursors(_opCtx.get(), Date_t::max())); ASSERT_EQ(0UL, cursorManager->numCursors()); } @@ -255,7 +257,7 @@ TEST_F(CursorManagerTest, InactivePinnedCursorShouldNotTimeout) { auto cursorPin = cursorManager->registerCursor( _opCtx.get(), {makeFakePlanExecutor(), - NamespaceString{"test.collection"}, + NamespaceString::createNamespaceString_forTest("test.collection"), {}, APIParameters(), {}, @@ -281,7 +283,7 @@ TEST_F(CursorManagerTest, MarkedAsKilledCursorsShouldBeDeletedOnCursorPin) { auto cursorPin = cursorManager->registerCursor( _opCtx.get(), {makeFakePlanExecutor(), - NamespaceString{"test.collection"}, + NamespaceString::createNamespaceString_forTest("test.collection"), {}, APIParameters(), {}, @@ -316,7 +318,7 @@ TEST_F(CursorManagerTest, InactiveKilledCursorsShouldTimeout) { auto cursorPin = cursorManager->registerCursor( _opCtx.get(), {makeFakePlanExecutor(), - NamespaceString{"test.collection"}, + NamespaceString::createNamespaceString_forTest("test.collection"), {}, APIParameters(), {}, diff --git a/src/mongo/dbtests/extensions_callback_real_test.cpp b/src/mongo/dbtests/extensions_callback_real_test.cpp index a74c5f7dcdd..6cf71af0f8c 100644 --- a/src/mongo/dbtests/extensions_callback_real_test.cpp +++ b/src/mongo/dbtests/extensions_callback_real_test.cpp @@ -244,7 +244,7 @@ TEST_F(ExtensionsCallbackRealTest, TextDiacriticSensitiveAndCaseSensitiveTrue) { // // $where parsing tests. // -const NamespaceString kTestNss = NamespaceString("db.dummy"); +const NamespaceString kTestNss = NamespaceString::createNamespaceString_forTest("db.dummy"); TEST_F(ExtensionsCallbackRealTest, WhereExpressionDesugarsToExprAndInternalJs) { if (_isDesugarWhereToFunctionOn) { diff --git a/src/mongo/dbtests/index_access_method_test.cpp b/src/mongo/dbtests/index_access_method_test.cpp index a1c20d7a5d8..710358daf58 100644 --- a/src/mongo/dbtests/index_access_method_test.cpp +++ b/src/mongo/dbtests/index_access_method_test.cpp @@ -228,7 +228,8 @@ TEST(IndexAccessMethodSetDifference, ShouldNotReportOverlapsFromNonDisjointSets) TEST(IndexAccessMethodInsertKeys, DuplicatesCheckingOnSecondaryUniqueIndexes) { ServiceContext::UniqueOperationContext opCtxRaii = cc().makeOperationContext(); OperationContext* opCtx = opCtxRaii.get(); - NamespaceString nss("unittests.DuplicatesCheckingOnSecondaryUniqueIndexes"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "unittests.DuplicatesCheckingOnSecondaryUniqueIndexes"); auto indexName = "a_1"; auto indexSpec = BSON("name" << indexName << "key" << BSON("a" << 1) << "unique" << true << "v" << static_cast(IndexDescriptor::IndexVersion::kV2)); @@ -263,7 +264,8 @@ TEST(IndexAccessMethodInsertKeys, InsertWhenPrepareUnique) { if (feature_flags::gCollModIndexUnique.isEnabled(serverGlobalParams.featureCompatibility)) { ServiceContext::UniqueOperationContext opCtxRaii = cc().makeOperationContext(); OperationContext* opCtx = opCtxRaii.get(); - NamespaceString nss("unittests.InsertWhenPrepareUnique"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.InsertWhenPrepareUnique"); auto indexName = "a_1"; auto indexSpec = BSON("name" << indexName << "key" << BSON("a" << 1) << "prepareUnique" << true << "v" @@ -299,7 +301,8 @@ TEST(IndexAccessMethodUpdateKeys, UpdateWhenPrepareUnique) { if (feature_flags::gCollModIndexUnique.isEnabled(serverGlobalParams.featureCompatibility)) { ServiceContext::UniqueOperationContext opCtxRaii = cc().makeOperationContext(); OperationContext* opCtx = opCtxRaii.get(); - NamespaceString nss("unittests.UpdateWhenPrepareUnique"); + NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.UpdateWhenPrepareUnique"); auto indexName = "a_1"; auto indexSpec = BSON("name" << indexName << "key" << BSON("a" << 1) << "prepareUnique" << true << "v" diff --git a/src/mongo/dbtests/insert_test.cpp b/src/mongo/dbtests/insert_test.cpp index 9f28bede251..450eb9a18e6 100644 --- a/src/mongo/dbtests/insert_test.cpp +++ b/src/mongo/dbtests/insert_test.cpp @@ -37,7 +37,7 @@ namespace mongo { namespace { -const auto kInsertTestNss = NamespaceString{"dbtests.InsertTest"}; +const auto kInsertTestNss = NamespaceString::createNamespaceString_forTest("dbtests.InsertTest"); class InsertTest : public unittest::Test { public: diff --git a/src/mongo/dbtests/mock_dbclient_conn_test.cpp b/src/mongo/dbtests/mock_dbclient_conn_test.cpp index c7be3c00343..dcbf16dd2b1 100644 --- a/src/mongo/dbtests/mock_dbclient_conn_test.cpp +++ b/src/mongo/dbtests/mock_dbclient_conn_test.cpp @@ -65,14 +65,14 @@ TEST(MockDBClientConnTest, QueryCount) { MockDBClientConnection conn(&server); ASSERT_EQUALS(0U, server.getQueryCount()); - conn.find(FindCommandRequest(NamespaceString("foo.bar"))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("foo.bar"))); } ASSERT_EQUALS(1U, server.getQueryCount()); { MockDBClientConnection conn(&server); - conn.find(FindCommandRequest(NamespaceString("foo.bar"))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("foo.bar"))); ASSERT_EQUALS(2U, server.getQueryCount()); } } @@ -90,7 +90,8 @@ TEST(MockDBClientConnTest, SkipBasedOnResumeAfter) { { MockDBClientConnection conn{&server}; - FindCommandRequest findRequest{FindCommandRequest{NamespaceString{ns}}}; + FindCommandRequest findRequest{ + FindCommandRequest{NamespaceString::createNamespaceString_forTest(ns)}}; findRequest.setResumeAfter(BSON("n" << 2)); auto cursor = conn.find(std::move(findRequest)); @@ -111,7 +112,8 @@ TEST(MockDBClientConnTest, RequestResumeToken) { { MockDBClientConnection conn{&server}; - FindCommandRequest findRequest{FindCommandRequest{NamespaceString{ns}}}; + FindCommandRequest findRequest{ + FindCommandRequest{NamespaceString::createNamespaceString_forTest(ns)}}; findRequest.setRequestResumeToken(true); findRequest.setBatchSize(2); @@ -130,7 +132,7 @@ TEST(MockDBClientConnTest, InsertAndQuery) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(!cursor->more()); server.insert(ns, BSON("x" << 1)); @@ -140,7 +142,7 @@ TEST(MockDBClientConnTest, InsertAndQuery) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -157,7 +159,7 @@ TEST(MockDBClientConnTest, InsertAndQuery) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -180,7 +182,7 @@ TEST(MockDBClientConnTest, InsertAndQueryTwice) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -192,7 +194,7 @@ TEST(MockDBClientConnTest, InsertAndQueryTwice) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -213,7 +215,7 @@ TEST(MockDBClientConnTest, QueryWithNoResults) { server.insert(ns, BSON("x" << 1)); MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString("other.ns"))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("other.ns"))); ASSERT(!cursor->more()); } @@ -245,7 +247,7 @@ TEST(MockDBClientConnTest, MultiNSInsertAndQuery) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns1))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns1))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -261,7 +263,7 @@ TEST(MockDBClientConnTest, MultiNSInsertAndQuery) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns2))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns2))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -281,7 +283,7 @@ TEST(MockDBClientConnTest, MultiNSInsertAndQuery) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns3))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns3))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -298,7 +300,7 @@ TEST(MockDBClientConnTest, SimpleRemove) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(!cursor->more()); conn.insert(ns, BSON("x" << 1)); @@ -313,7 +315,7 @@ TEST(MockDBClientConnTest, SimpleRemove) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(!cursor->more()); } @@ -322,7 +324,7 @@ TEST(MockDBClientConnTest, SimpleRemove) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(!cursor->more()); } @@ -357,14 +359,14 @@ TEST(MockDBClientConnTest, MultiNSRemove) { conn.remove(ns2, BSONObj{} /*filter*/); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns2))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns2))); ASSERT(!cursor->more()); } { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns1))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns1))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -380,7 +382,7 @@ TEST(MockDBClientConnTest, MultiNSRemove) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns3))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns3))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -416,7 +418,7 @@ TEST(MockDBClientConnTest, InsertAfterRemove) { { MockDBClientConnection conn(&server); std::unique_ptr cursor = - conn.find(FindCommandRequest(NamespaceString(ns))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest(ns))); ASSERT(cursor->more()); BSONObj firstDoc = cursor->next(); @@ -565,7 +567,8 @@ TEST(MockDBClientConnTest, Shutdown) { server.shutdown(); ASSERT(!server.isRunning()); - ASSERT_THROWS(conn.find(FindCommandRequest(NamespaceString("test.user"))), + ASSERT_THROWS(conn.find(FindCommandRequest( + NamespaceString::createNamespaceString_forTest("test.user"))), mongo::NetworkException); } @@ -588,18 +591,20 @@ TEST(MockDBClientConnTest, Restart) { // Do some queries and commands then check the counters later that // new instance still has it - conn1.find(FindCommandRequest(NamespaceString("test.user"))); + conn1.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("test.user"))); BSONObj response; conn1.runCommand({boost::none, "test"}, BSON("serverStatus" << 1), response); server.shutdown(); - ASSERT_THROWS(conn1.find(FindCommandRequest(NamespaceString("test.user"))), - mongo::NetworkException); + ASSERT_THROWS( + conn1.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("test.user"))), + mongo::NetworkException); // New connections shouldn't work either MockDBClientConnection conn2(&server); - ASSERT_THROWS(conn2.find(FindCommandRequest(NamespaceString("test.user"))), - mongo::NetworkException); + ASSERT_THROWS( + conn2.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("test.user"))), + mongo::NetworkException); ASSERT_EQUALS(1U, server.getQueryCount()); ASSERT_EQUALS(1U, server.getCmdCount()); @@ -609,14 +614,16 @@ TEST(MockDBClientConnTest, Restart) { { MockDBClientConnection conn(&server); - conn.find(FindCommandRequest(NamespaceString("test.user"))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("test.user"))); } // Old connections still shouldn't work - ASSERT_THROWS(conn1.find(FindCommandRequest(NamespaceString("test.user"))), - mongo::NetworkException); - ASSERT_THROWS(conn2.find(FindCommandRequest(NamespaceString("test.user"))), - mongo::NetworkException); + ASSERT_THROWS( + conn1.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("test.user"))), + mongo::NetworkException); + ASSERT_THROWS( + conn2.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("test.user"))), + mongo::NetworkException); ASSERT_EQUALS(2U, server.getQueryCount()); ASSERT_EQUALS(1U, server.getCmdCount()); @@ -627,7 +634,8 @@ TEST(MockDBClientConnTest, ClearCounter) { server.setCommandReply("serverStatus", BSON("ok" << 1)); MockDBClientConnection conn(&server); - conn.find(FindCommandRequest(FindCommandRequest(NamespaceString("test.user")))); + conn.find(FindCommandRequest( + FindCommandRequest(NamespaceString::createNamespaceString_forTest("test.user")))); BSONObj response; conn.runCommand({boost::none, "test"}, BSON("serverStatus" << 1), response); @@ -645,7 +653,7 @@ TEST(MockDBClientConnTest, Delay) { { mongo::Timer timer; - conn.find(FindCommandRequest(NamespaceString("x.x"))); + conn.find(FindCommandRequest(NamespaceString::createNamespaceString_forTest("x.x"))); const int nowInMilliSec = timer.millis(); // Use a more lenient lower bound since some platforms like Windows // don't guarantee that sleeps will not wake up earlier (unlike @@ -669,7 +677,7 @@ const auto docObj = [](int i) { return BSON("_id" << i); }; const auto metadata = [](int i) { return BSON("$fakeMetaData" << i); }; const long long cursorId = 123; const bool moreToCome = true; -const NamespaceString nss("test", "coll"); +const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); TEST(MockDBClientConnTest, SimulateCallAndRecvResponses) { MockRemoteDBServer server("test"); diff --git a/src/mongo/dbtests/plan_executor_invalidation_test.cpp b/src/mongo/dbtests/plan_executor_invalidation_test.cpp index 64d6d06222e..55087fb5e8f 100644 --- a/src/mongo/dbtests/plan_executor_invalidation_test.cpp +++ b/src/mongo/dbtests/plan_executor_invalidation_test.cpp @@ -52,7 +52,8 @@ namespace mongo { using std::unique_ptr; -static const NamespaceString nss("unittests.PlanExecutorInvalidationTest"); +static const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("unittests.PlanExecutorInvalidationTest"); /** * Test fixture for verifying that plan executors correctly raise errors when invalidating events diff --git a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp index 893252abec3..b3bc4faf4c3 100644 --- a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp +++ b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp @@ -52,7 +52,8 @@ static const RecordId kMetadataId = record_id_helpers::reservedIdFor( record_id_helpers::ReservationId::kWildcardMultikeyMetadataId, KeyFormat::Long); static const int kIndexVersion = static_cast(IndexDescriptor::kLatestIndexVersion); -static const NamespaceString kDefaultNSS{"wildcard_multikey_persistence.test"}; +static const NamespaceString kDefaultNSS = + NamespaceString::createNamespaceString_forTest("wildcard_multikey_persistence.test"); static const std::string kDefaultIndexName{"wildcard_multikey"}; static const BSONObj kDefaultIndexKey = fromjson("{'$**': 1}"); static const BSONObj kDefaultPathProjection; diff --git a/src/mongo/executor/async_rpc_test.cpp b/src/mongo/executor/async_rpc_test.cpp index 75199ec5e02..b38b749112e 100644 --- a/src/mongo/executor/async_rpc_test.cpp +++ b/src/mongo/executor/async_rpc_test.cpp @@ -454,7 +454,7 @@ TEST_F(AsyncRPCTestFixture, SuccessfulFind) { std::unique_ptr targeter = std::make_unique(); auto opCtxHolder = makeOperationContext(); DatabaseName testDbName = DatabaseName("testdb", boost::none); - NamespaceString nss(testDbName); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(testDbName); FindCommandRequest findCmd(nss); auto options = std::make_shared>( @@ -766,7 +766,7 @@ TEST_F(AsyncRPCTestFixture, SendTxnCommandWithoutTxnRouterAppendsNoTxnFields) { auto targeter = std::make_unique( shardId, opCtxHolder.get(), readPref, getExecutorPtr(), testHost); DatabaseName testDbName = DatabaseName("testdb", boost::none); - NamespaceString nss(testDbName); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(testDbName); FindCommandRequest findCmd(nss); auto options = std::make_shared>( @@ -799,7 +799,7 @@ TEST_F(AsyncRPCTxnTestFixture, MultipleSendTxnCommand) { auto targeter = std::make_unique( shardId, getOpCtx(), readPref, getExecutorPtr(), testHost); DatabaseName testDbName = DatabaseName("testdb", boost::none); - NamespaceString nss(testDbName); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(testDbName); // Set up the transaction metadata. TxnNumber txnNum{3}; @@ -862,7 +862,7 @@ TEST_F(AsyncRPCTxnTestFixture, SendTxnCommandWithGenericArgs) { auto targeter = std::make_unique( shardId, getOpCtx(), readPref, getExecutorPtr(), testHost); DatabaseName testDbName = DatabaseName("testdb", boost::none); - NamespaceString nss(testDbName); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(testDbName); // Set up the transaction metadata. TxnNumber txnNum{3}; @@ -927,7 +927,7 @@ TEST_F(AsyncRPCTxnTestFixture, SendTxnCommandReturnsRemoteError) { auto targeter = std::make_unique( shardId, getOpCtx(), readPref, getExecutorPtr(), testHost); DatabaseName testDbName = DatabaseName("testdb", boost::none); - NamespaceString nss(testDbName); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(testDbName); // Set up the transaction metadata. TxnNumber txnNum{3}; @@ -964,7 +964,7 @@ TEST_F(AsyncRPCTxnTestFixture, SendTxnCommandReturnsLocalError) { auto targeter = std::make_unique( shardId, getOpCtx(), readPref, getExecutorPtr(), testHost); DatabaseName testDbName = DatabaseName("testdb", boost::none); - NamespaceString nss(testDbName); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(testDbName); // Set up the transaction metadata. TxnNumber txnNum{3}; diff --git a/src/mongo/executor/hedged_async_rpc_test.cpp b/src/mongo/executor/hedged_async_rpc_test.cpp index 25326b42766..287dd153c6a 100644 --- a/src/mongo/executor/hedged_async_rpc_test.cpp +++ b/src/mongo/executor/hedged_async_rpc_test.cpp @@ -137,7 +137,8 @@ public: bh); } - const NamespaceString testNS = NamespaceString("testdb", "testcoll"); + const NamespaceString testNS = + NamespaceString::createNamespaceString_forTest("testdb", "testcoll"); const FindCommandRequest testFindCmd = FindCommandRequest(testNS); const BSONObj testFirstBatch = BSON("x" << 1); diff --git a/src/mongo/executor/mock_network_fixture.cpp b/src/mongo/executor/mock_network_fixture.cpp index cd3fa278430..a96e98562df 100644 --- a/src/mongo/executor/mock_network_fixture.cpp +++ b/src/mongo/executor/mock_network_fixture.cpp @@ -45,7 +45,9 @@ namespace mock { MockNetwork::Matcher::Matcher(const BSONObj& matcherQuery) { auto expCtx = make_intrusive( - nullptr /* opCtx */, nullptr /* collator */, NamespaceString{"db.coll"} /* dummy nss */); + nullptr /* opCtx */, + nullptr /* collator */, + NamespaceString::createNamespaceString_forTest("db.coll") /* dummy nss */); // Expression matcher doesn't have copy constructor, so wrap it in a shared_ptr for capture. auto m = std::make_shared(matcherQuery, std::move(expCtx)); _matcherFunc = [=](const BSONObj& request) { return m->matches(request); }; diff --git a/src/mongo/executor/task_executor_cursor_integration_test.cpp b/src/mongo/executor/task_executor_cursor_integration_test.cpp index ff1b7cd9e41..f4588761748 100644 --- a/src/mongo/executor/task_executor_cursor_integration_test.cpp +++ b/src/mongo/executor/task_executor_cursor_integration_test.cpp @@ -109,7 +109,7 @@ size_t createTestData(std::string ns, size_t numDocs) { } dbclient->dropCollection(NamespaceString(ns)); dbclient->insert(ns, docs); - return dbclient->count(NamespaceString(ns)); + return dbclient->count(NamespaceString::createNamespaceString_forTest(ns)); } // Test that we can actually use a TaskExecutorCursor to read multiple batches from a remote host diff --git a/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp b/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp index 9626f068541..63132f22050 100644 --- a/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp +++ b/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp @@ -41,9 +41,9 @@ namespace { using namespace cluster_server_parameter_test_util; const std::vector kIgnoredNamespaces = { - NamespaceString("config"_sd, "settings"_sd), - NamespaceString("local"_sd, "clusterParameters"_sd), - NamespaceString("test"_sd, "foo"_sd)}; + NamespaceString::createNamespaceString_forTest("config"_sd, "settings"_sd), + NamespaceString::createNamespaceString_forTest("local"_sd, "clusterParameters"_sd), + NamespaceString::createNamespaceString_forTest("test"_sd, "foo"_sd)}; typedef ClusterParameterWithStorage ClusterTestParameter; @@ -429,7 +429,7 @@ TEST_F(ClusterServerParameterOpObserverTest, onDropDatabase) { TEST_F(ClusterServerParameterOpObserverTest, onRenameCollection) { initializeState(); - const NamespaceString kTestFoo("test", "foo"); + const NamespaceString kTestFoo = NamespaceString::createNamespaceString_forTest("test", "foo"); // Rename ignorable collections. assertIgnoredOtherNamespaces([&](const auto& nss) { doRenameCollection(nss, kTestFoo); }, boost::none); @@ -482,7 +482,7 @@ TEST_F(ClusterServerParameterOpObserverTest, onRenameCollection) { TEST_F(ClusterServerParameterOpObserverTest, onImportCollection) { initializeState(); - const NamespaceString kTestFoo("test", "foo"); + const NamespaceString kTestFoo = NamespaceString::createNamespaceString_forTest("test", "foo"); // Import ignorable collections. assertIgnoredOtherNamespaces([&](const auto& nss) { doImportCollection(nss); }, boost::none); @@ -512,7 +512,7 @@ TEST_F(ClusterServerParameterOpObserverTest, onImportCollection) { TEST_F(ClusterServerParameterOpObserverTest, onReplicationRollback) { initializeState(); - const NamespaceString kTestFoo("test", "foo"); + const NamespaceString kTestFoo = NamespaceString::createNamespaceString_forTest("test", "foo"); // Import ignorable collections. assertIgnoredOtherNamespaces([&](const auto& nss) { doReplicationRollback({nss}); }, boost::none); diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp index 8abbbb11fb3..c9a29cfc323 100644 --- a/src/mongo/idl/idl_test.cpp +++ b/src/mongo/idl/idl_test.cpp @@ -359,7 +359,7 @@ TEST(IDLOneTypeTests, TestNamespaceString) { auto testStruct = One_namespacestring::parse(ctxt, testDoc); assert_same_types(); - ASSERT_EQUALS(testStruct.getValue(), NamespaceString("foo.bar")); + ASSERT_EQUALS(testStruct.getValue(), NamespaceString::createNamespaceString_forTest("foo.bar")); // Positive: Test we can roundtrip from the just parsed document { @@ -374,7 +374,7 @@ TEST(IDLOneTypeTests, TestNamespaceString) { { BSONObjBuilder builder; One_namespacestring one_new; - one_new.setValue(NamespaceString("foo.bar")); + one_new.setValue(NamespaceString::createNamespaceString_forTest("foo.bar")); one_new.serialize(&builder); auto serializedDoc = builder.obj(); @@ -2478,7 +2478,8 @@ TEST(IDLCommand, TestConcatentateWithDb) { auto testStruct = BasicConcatenateWithDbCommand::parse(ctxt, makeOMR(testDoc)); ASSERT_EQUALS(testStruct.getField1(), 3); ASSERT_EQUALS(testStruct.getField2(), "five"); - ASSERT_EQUALS(testStruct.getNamespace(), NamespaceString("db.coll1")); + ASSERT_EQUALS(testStruct.getNamespace(), + NamespaceString::createNamespaceString_forTest("db.coll1")); assert_same_types(); @@ -2493,7 +2494,8 @@ TEST(IDLCommand, TestConcatentateWithDb) { << "five"); BSONObjBuilder builder; - BasicConcatenateWithDbCommand one_new(NamespaceString("db.coll1")); + BasicConcatenateWithDbCommand one_new( + NamespaceString::createNamespaceString_forTest("db.coll1")); one_new.setField1(3); one_new.setField2("five"); one_new.serialize(BSONObj(), &builder); @@ -2504,7 +2506,8 @@ TEST(IDLCommand, TestConcatentateWithDb) { // Positive: Test we can serialize from nothing the same document { - BasicConcatenateWithDbCommand one_new(NamespaceString("db.coll1")); + BasicConcatenateWithDbCommand one_new( + NamespaceString::createNamespaceString_forTest("db.coll1")); one_new.setField1(3); one_new.setField2("five"); ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(testStruct)); @@ -2528,7 +2531,8 @@ TEST(IDLCommand, TestConcatentateWithDb_WithTenant) { auto testStruct = BasicConcatenateWithDbCommand::parse(ctxt, makeOMRWithTenant(testDoc, tenantId)); ASSERT_EQUALS(testStruct.getDbName(), DatabaseName(tenantId, "db")); - ASSERT_EQUALS(testStruct.getNamespace(), NamespaceString(tenantId, "db.coll1")); + ASSERT_EQUALS(testStruct.getNamespace(), + NamespaceString::createNamespaceString_forTest(tenantId, "db.coll1")); assert_same_types(); @@ -2540,7 +2544,7 @@ TEST(IDLCommand, TestConcatentateWithDb_TestConstructor) { const auto tenantId = TenantId(OID::gen()); const DatabaseName dbName(tenantId, "db"); - const NamespaceString nss(NamespaceString(dbName, "coll1")); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest(dbName, "coll1"); BasicConcatenateWithDbCommand testRequest(nss); ASSERT_EQUALS(testRequest.getDbName().tenantId(), dbName.tenantId()); ASSERT_EQUALS(testRequest.getDbName(), dbName); @@ -2557,7 +2561,8 @@ TEST(IDLCommand, TestConcatentateWithDbSymbol) { << "$db" << "db"); auto testStruct = BasicConcatenateWithDbCommand::parse(ctxt, makeOMR(testDoc)); - ASSERT_EQUALS(testStruct.getNamespace(), NamespaceString("db.coll1")); + ASSERT_EQUALS(testStruct.getNamespace(), + NamespaceString::createNamespaceString_forTest("db.coll1")); } } @@ -2623,7 +2628,8 @@ TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestNSS) { auto testStruct = BasicConcatenateWithDbOrUUIDCommand::parse(ctxt, makeOMR(testDoc)); ASSERT_EQUALS(testStruct.getField1(), 3); ASSERT_EQUALS(testStruct.getField2(), "five"); - ASSERT_EQUALS(testStruct.getNamespaceOrUUID().nss().value(), NamespaceString("db.coll1")); + ASSERT_EQUALS(testStruct.getNamespaceOrUUID().nss().value(), + NamespaceString::createNamespaceString_forTest("db.coll1")); assert_same_types(); @@ -2638,7 +2644,8 @@ TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestNSS) { << "five"); BSONObjBuilder builder; - BasicConcatenateWithDbOrUUIDCommand one_new(NamespaceString("db.coll1")); + BasicConcatenateWithDbOrUUIDCommand one_new( + NamespaceString::createNamespaceString_forTest("db.coll1")); one_new.setField1(3); one_new.setField2("five"); one_new.serialize(BSONObj(), &builder); @@ -2649,7 +2656,8 @@ TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestNSS) { // Positive: Test we can serialize from nothing the same document { - BasicConcatenateWithDbOrUUIDCommand one_new(NamespaceString("db.coll1")); + BasicConcatenateWithDbOrUUIDCommand one_new( + NamespaceString::createNamespaceString_forTest("db.coll1")); one_new.setField1(3); one_new.setField2("five"); ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(one_new)); @@ -2674,7 +2682,7 @@ TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestNSS_WithTenant) { BasicConcatenateWithDbOrUUIDCommand::parse(ctxt, makeOMRWithTenant(testDoc, tenantId)); ASSERT_EQUALS(testStruct.getDbName(), DatabaseName(tenantId, "db")); ASSERT_EQUALS(testStruct.getNamespaceOrUUID().nss().value(), - NamespaceString(tenantId, "db.coll1")); + NamespaceString::createNamespaceString_forTest(tenantId, "db.coll1")); assert_same_types(); @@ -2766,7 +2774,8 @@ TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestConstructor) { ASSERT_EQUALS(testRequest1.getDbName().tenantId(), dbName.tenantId()); ASSERT_EQUALS(testRequest1.getDbName(), dbName); - const NamespaceStringOrUUID withNss(NamespaceString(dbName, "coll1")); + const NamespaceStringOrUUID withNss( + NamespaceString::createNamespaceString_forTest(dbName, "coll1")); BasicConcatenateWithDbOrUUIDCommand testRequest2(withNss); ASSERT_EQUALS(testRequest2.getDbName().tenantId(), dbName.tenantId()); ASSERT_EQUALS(testRequest2.getDbName(), dbName); @@ -2957,7 +2966,8 @@ TEST(IDLDocSequence, TestBasic) { auto testStruct = DocSequenceCommand::parse(ctxt, request); ASSERT_EQUALS(testStruct.getField1(), 3); ASSERT_EQUALS(testStruct.getField2(), "five"); - ASSERT_EQUALS(testStruct.getNamespace(), NamespaceString("db.coll1")); + ASSERT_EQUALS(testStruct.getNamespace(), + NamespaceString::createNamespaceString_forTest("db.coll1")); ASSERT_EQUALS(2UL, testStruct.getStructs().size()); ASSERT_EQUALS("hello", testStruct.getStructs()[0].getValue()); @@ -2986,7 +2996,7 @@ TEST(IDLDocSequence, TestBasic) { // Positive: Test we can serialize from nothing the same document { BSONObjBuilder builder; - DocSequenceCommand one_new(NamespaceString("db.coll1")); + DocSequenceCommand one_new(NamespaceString::createNamespaceString_forTest("db.coll1")); one_new.setField1(3); one_new.setField2("five"); @@ -3048,7 +3058,8 @@ void TestDocSequence(StringData name) { auto testStruct = TestT::parse(ctxt, request); ASSERT_EQUALS(testStruct.getField1(), 3); ASSERT_EQUALS(testStruct.getField2(), "five"); - ASSERT_EQUALS(testStruct.getNamespace(), NamespaceString("db.coll1")); + ASSERT_EQUALS(testStruct.getNamespace(), + NamespaceString::createNamespaceString_forTest("db.coll1")); ASSERT_EQUALS(2UL, testStruct.getStructs().size()); ASSERT_EQUALS("hello", testStruct.getStructs()[0].getValue()); @@ -3994,7 +4005,7 @@ TEST(IDLCommand, BasicNamespaceConstGetterCommand_TestNonConstGetterGeneration) // Test mutable getter modifies the command object. { auto& nssOrUuid = testStruct.getNamespaceOrUUID(); - const auto nss = NamespaceString("test.coll"); + const auto nss = NamespaceString::createNamespaceString_forTest("test.coll"); nssOrUuid.setNss(nss); nssOrUuid.preferNssForSerialization(); @@ -4107,7 +4118,8 @@ TEST(IDLCommand, auto testStruct = CommandTypeNamespaceCommand::parse(ctxt, makeOMRWithTenant(testDoc, tenantId)); ASSERT_EQUALS(testStruct.getDbName(), DatabaseName(tenantId, "admin")); - ASSERT_EQUALS(testStruct.getCommandParameter(), NamespaceString(tenantId, "db.coll1")); + ASSERT_EQUALS(testStruct.getCommandParameter(), + NamespaceString::createNamespaceString_forTest(tenantId, "db.coll1")); assert_same_types(); // Positive: Test we can roundtrip from the just parsed document ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(testStruct)); @@ -4131,7 +4143,8 @@ TEST(IDLCommand, TestCommandTypeNamespaceCommand_WithMultitenancySupportOn) { ASSERT_EQUALS(testStruct.getDbName(), DatabaseName(tenantId, "admin")); // Deserialize called from parse correctly sets the tenantId field. - ASSERT_EQUALS(testStruct.getCommandParameter(), NamespaceString(tenantId, "db.coll1")); + ASSERT_EQUALS(testStruct.getCommandParameter(), + NamespaceString::createNamespaceString_forTest(tenantId, "db.coll1")); assert_same_types(); // Positive: Test we can roundtrip from the just parsed document ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(testStruct)); @@ -4159,9 +4172,11 @@ TEST(IDLTypeCommand, TestCommandWithNamespaceMember_WithTenant) { assert_same_types&>(); - ASSERT_EQUALS(testStruct.getField1(), NamespaceString(tenantId, ns1)); - std::vector field2{NamespaceString(tenantId, ns2), - NamespaceString(tenantId, ns3)}; + ASSERT_EQUALS(testStruct.getField1(), + NamespaceString::createNamespaceString_forTest(tenantId, ns1)); + std::vector field2{ + NamespaceString::createNamespaceString_forTest(tenantId, ns2), + NamespaceString::createNamespaceString_forTest(tenantId, ns3)}; ASSERT_TRUE(field2 == testStruct.getField2()); // Positive: Test we can roundtrip from the just parsed document @@ -4194,9 +4209,11 @@ TEST(IDLTypeCommand, TestCommandWithNamespaceStruct_WithTenant) { assert_same_types(); assert_same_types&>(); - ASSERT_EQUALS(testStruct.getField1().getNs(), NamespaceString(tenantId, ns1)); - std::vector field2Nss{NamespaceString(tenantId, ns2), - NamespaceString(tenantId, ns3)}; + ASSERT_EQUALS(testStruct.getField1().getNs(), + NamespaceString::createNamespaceString_forTest(tenantId, ns1)); + std::vector field2Nss{ + NamespaceString::createNamespaceString_forTest(tenantId, ns2), + NamespaceString::createNamespaceString_forTest(tenantId, ns3)}; std::vector& field2 = testStruct.getField2(); ASSERT_TRUE(field2Nss[0] == field2[0].getNs()); ASSERT_TRUE(field2Nss[1] == field2[1].getNs()); diff --git a/src/mongo/rpc/op_msg_integration_test.cpp b/src/mongo/rpc/op_msg_integration_test.cpp index e94b2efaebf..e75b81e1647 100644 --- a/src/mongo/rpc/op_msg_integration_test.cpp +++ b/src/mongo/rpc/op_msg_integration_test.cpp @@ -122,7 +122,7 @@ TEST(OpMsg, FireAndForgetInsertWorks) { ] })"))); - ASSERT_EQ(conn->count(NamespaceString("test.collection")), 1u); + ASSERT_EQ(conn->count(NamespaceString::createNamespaceString_forTest("test.collection")), 1u); } TEST(OpMsg, DocumentSequenceLargeDocumentMultiInsertWorks) { @@ -152,8 +152,8 @@ TEST(OpMsg, DocumentSequenceLargeDocumentMultiInsertWorks) { Message reply; conn->call(request, reply); - ASSERT_EQ(conn->count(NamespaceString("test.collection")), 3u); - conn->dropCollection(NamespaceString("test.collection")); + ASSERT_EQ(conn->count(NamespaceString::createNamespaceString_forTest("test.collection")), 3u); + conn->dropCollection(NamespaceString::createNamespaceString_forTest("test.collection")); } TEST(OpMsg, DocumentSequenceMaxWriteBatchWorks) { @@ -185,8 +185,9 @@ TEST(OpMsg, DocumentSequenceMaxWriteBatchWorks) { Message reply; conn->call(request, reply); - ASSERT_EQ(conn->count(NamespaceString("test.collection")), write_ops::kMaxWriteBatchSize); - conn->dropCollection(NamespaceString("test.collection")); + ASSERT_EQ(conn->count(NamespaceString::createNamespaceString_forTest("test.collection")), + write_ops::kMaxWriteBatchSize); + conn->dropCollection(NamespaceString::createNamespaceString_forTest("test.collection")); } TEST(OpMsg, CloseConnectionOnFireAndForgetNotWritablePrimaryError) { @@ -331,7 +332,7 @@ void exhaustGetMoreTest(bool enableChecksum) { ON_BLOCK_EXIT([&] { enableClientChecksum(); }); - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); conn->dropCollection(nss); @@ -418,7 +419,7 @@ TEST(OpMsg, FindIgnoresExhaust) { return; } - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); conn->dropCollection(nss); @@ -450,7 +451,7 @@ TEST(OpMsg, ServerDoesNotSetMoreToComeOnErrorInGetMore) { return; } - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); conn->dropCollection(nss); @@ -497,7 +498,7 @@ TEST(OpMsg, MongosIgnoresExhaustForGetMore) { return; } - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); conn->dropCollection(nss); @@ -548,7 +549,7 @@ TEST(OpMsg, ExhaustWorksForAggCursor) { return; } - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); conn->dropCollection(nss); @@ -1226,7 +1227,7 @@ TEST(OpMsg, ExhaustWithDBClientCursorBehavesCorrectly) { return; } - NamespaceString nss("test", "coll"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll"); conn->dropCollection(nss); const int nDocs = 5; diff --git a/src/mongo/s/append_raw_responses_test.cpp b/src/mongo/s/append_raw_responses_test.cpp index ebff915739d..00d9c94d1df 100644 --- a/src/mongo/s/append_raw_responses_test.cpp +++ b/src/mongo/s/append_raw_responses_test.cpp @@ -196,7 +196,7 @@ protected: [] { OID epoch{OID::gen()}; Timestamp timestamp{1, 0}; - return StaleConfigInfo(NamespaceString("Foo.Bar"), + return StaleConfigInfo(NamespaceString::createNamespaceString_forTest("Foo.Bar"), ShardVersion(ChunkVersion({epoch, timestamp}, {1, 0}), boost::optional(boost::none)), boost::none, diff --git a/src/mongo/s/async_requests_sender_test.cpp b/src/mongo/s/async_requests_sender_test.cpp index 39874e7e898..b27d9b5644e 100644 --- a/src/mongo/s/async_requests_sender_test.cpp +++ b/src/mongo/s/async_requests_sender_test.cpp @@ -41,7 +41,7 @@ namespace mongo { namespace { -const NamespaceString kTestNss("testdb.testcoll"); +const NamespaceString kTestNss = NamespaceString::createNamespaceString_forTest("testdb.testcoll"); const HostAndPort kTestConfigShardHost = HostAndPort("FakeConfigHost", 12345); const std::vector kTestShardIds = { ShardId("FakeShard1"), ShardId("FakeShard2"), ShardId("FakeShard3")}; diff --git a/src/mongo/s/catalog/sharding_catalog_client_test.cpp b/src/mongo/s/catalog/sharding_catalog_client_test.cpp index 551feda38b9..3e4a0210164 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_test.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_test.cpp @@ -67,7 +67,8 @@ using std::vector; using unittest::assertGet; const int kMaxCommandRetry = 3; -const NamespaceString kNamespace("TestDB", "TestColl"); +const NamespaceString kNamespace = + NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); BSONObj getReplSecondaryOkMetadata() { BSONObjBuilder o; @@ -81,7 +82,7 @@ using ShardingCatalogClientTest = ShardingTestFixture; TEST_F(ShardingCatalogClientTest, GetCollectionExisting) { configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1")); - CollectionType expectedColl(NamespaceString("TestDB.TestNS"), + CollectionType expectedColl(NamespaceString::createNamespaceString_forTest("TestDB.TestNS"), OID::gen(), Timestamp(1, 1), Date_t::now(), @@ -138,7 +139,8 @@ TEST_F(ShardingCatalogClientTest, GetCollectionNotExisting) { auto future = launchAsync([this] { ASSERT_THROWS_CODE( - catalogClient()->getCollection(operationContext(), NamespaceString("NonExistent")), + catalogClient()->getCollection( + operationContext(), NamespaceString::createNamespaceString_forTest("NonExistent")), DBException, ErrorCodes::NamespaceNotFound); }); @@ -773,14 +775,14 @@ TEST_F(ShardingCatalogClientTest, RunUserManagementWriteCommandNotWritablePrimar TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsNoDb) { configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1")); - CollectionType coll1(NamespaceString{"test.coll1"}, + CollectionType coll1(NamespaceString::createNamespaceString_forTest("test.coll1"), OID::gen(), Timestamp(1, 1), network()->now(), UUID::gen(), BSON("_id" << 1)); - CollectionType coll2(NamespaceString{"anotherdb.coll1"}, + CollectionType coll2(NamespaceString::createNamespaceString_forTest("anotherdb.coll1"), OID::gen(), Timestamp(1, 1), network()->now(), @@ -831,7 +833,7 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsNoDb) { TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsWithDb) { configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1")); - CollectionType coll1(NamespaceString{"test.coll1"}, + CollectionType coll1(NamespaceString::createNamespaceString_forTest("test.coll1"), OID::gen(), Timestamp(1, 1), network()->now(), @@ -839,7 +841,7 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsWithDb) { BSON("_id" << 1)); coll1.setUnique(true); - CollectionType coll2(NamespaceString{"test.coll2"}, + CollectionType coll2(NamespaceString::createNamespaceString_forTest("test.coll2"), OID::gen(), Timestamp(1, 1), network()->now(), @@ -885,7 +887,7 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsInvalidCollectionType) { ASSERT_THROWS(catalogClient()->getCollections(operationContext(), "test"), DBException); }); - CollectionType validColl(NamespaceString{"test.coll1"}, + CollectionType validColl(NamespaceString::createNamespaceString_forTest("test.coll1"), OID::gen(), Timestamp(1, 1), network()->now(), @@ -983,20 +985,20 @@ TEST_F(ShardingCatalogClientTest, GetTagsForCollection) { configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1")); TagsType tagA; - tagA.setNS(NamespaceString("TestDB.TestColl")); + tagA.setNS(NamespaceString::createNamespaceString_forTest("TestDB.TestColl")); tagA.setTag("TagA"); tagA.setMinKey(BSON("a" << 100)); tagA.setMaxKey(BSON("a" << 200)); TagsType tagB; - tagB.setNS(NamespaceString("TestDB.TestColl")); + tagB.setNS(NamespaceString::createNamespaceString_forTest("TestDB.TestColl")); tagB.setTag("TagB"); tagB.setMinKey(BSON("a" << 200)); tagB.setMaxKey(BSON("a" << 300)); auto future = launchAsync([this] { const auto& tags = assertGet(catalogClient()->getTagsForCollection( - operationContext(), NamespaceString("TestDB.TestColl"))); + operationContext(), NamespaceString::createNamespaceString_forTest("TestDB.TestColl"))); ASSERT_EQ(2U, tags.size()); @@ -1032,7 +1034,7 @@ TEST_F(ShardingCatalogClientTest, GetTagsForCollectionNoTags) { auto future = launchAsync([this] { const auto& tags = assertGet(catalogClient()->getTagsForCollection( - operationContext(), NamespaceString("TestDB.TestColl"))); + operationContext(), NamespaceString::createNamespaceString_forTest("TestDB.TestColl"))); ASSERT_EQ(0U, tags.size()); @@ -1049,20 +1051,20 @@ TEST_F(ShardingCatalogClientTest, GetTagsForCollectionInvalidTag) { auto future = launchAsync([this] { const auto swTags = catalogClient()->getTagsForCollection( - operationContext(), NamespaceString("TestDB.TestColl")); + operationContext(), NamespaceString::createNamespaceString_forTest("TestDB.TestColl")); ASSERT_EQUALS(ErrorCodes::NoSuchKey, swTags.getStatus()); }); onFindCommand([](const RemoteCommandRequest& request) { TagsType tagA; - tagA.setNS(NamespaceString("TestDB.TestColl")); + tagA.setNS(NamespaceString::createNamespaceString_forTest("TestDB.TestColl")); tagA.setTag("TagA"); tagA.setMinKey(BSON("a" << 100)); tagA.setMaxKey(BSON("a" << 200)); TagsType tagB; - tagB.setNS(NamespaceString("TestDB.TestColl")); + tagB.setNS(NamespaceString::createNamespaceString_forTest("TestDB.TestColl")); tagB.setTag("TagB"); tagB.setMinKey(BSON("a" << 200)); // Missing maxKey diff --git a/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp b/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp index ac6bff8cea3..1bee8df06e4 100644 --- a/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp +++ b/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp @@ -409,7 +409,7 @@ TEST_F(UpdateRetryTest, NotWritablePrimaryOnceSuccessAfterRetry) { HostAndPort host2("TestHost2"); configTargeter()->setFindHostReturnValue(host1); - CollectionType collection(NamespaceString("db.coll"), + CollectionType collection(NamespaceString::createNamespaceString_forTest("db.coll"), OID::gen(), Timestamp(1, 1), network()->now(), diff --git a/src/mongo/s/catalog/type_collection_test.cpp b/src/mongo/s/catalog/type_collection_test.cpp index 66838362db0..2688d7106b6 100644 --- a/src/mongo/s/catalog/type_collection_test.cpp +++ b/src/mongo/s/catalog/type_collection_test.cpp @@ -58,7 +58,7 @@ TEST(CollectionType, Basic) { << "fr_CA") << CollectionType::kUniqueFieldName << true)); - ASSERT(coll.getNss() == NamespaceString{"db.coll"}); + ASSERT(coll.getNss() == NamespaceString::createNamespaceString_forTest("db.coll")); ASSERT_EQUALS(coll.getEpoch(), oid); ASSERT_EQUALS(coll.getUuid(), uuid); ASSERT_EQUALS(coll.getTimestamp(), timestamp); @@ -91,7 +91,7 @@ TEST(CollectionType, AllFieldsPresent) { << CollectionType::kUniqueFieldName << true << CollectionType::kUuidFieldName << uuid << CollectionType::kReshardingFieldsFieldName << reshardingFields.toBSON())); - ASSERT(coll.getNss() == NamespaceString{"db.coll"}); + ASSERT(coll.getNss() == NamespaceString::createNamespaceString_forTest("db.coll")); ASSERT_EQUALS(coll.getEpoch(), oid); ASSERT_EQUALS(coll.getTimestamp(), timestamp); ASSERT_EQUALS(coll.getUpdatedAt(), Date_t::fromMillisSinceEpoch(1)); @@ -146,7 +146,7 @@ TEST(CollectionType, Pre22Format) { << Date_t::fromMillisSinceEpoch(1) << "dropped" << false << "key" << BSON("a" << 1) << "unique" << false)); - ASSERT(coll.getNss() == NamespaceString{"db.coll"}); + ASSERT(coll.getNss() == NamespaceString::createNamespaceString_forTest("db.coll")); ASSERT(!coll.getEpoch().isSet()); ASSERT_EQUALS(coll.getUpdatedAt(), Date_t::fromMillisSinceEpoch(1)); ASSERT_BSONOBJ_EQ(coll.getKeyPattern().toBSON(), BSON("a" << 1)); diff --git a/src/mongo/s/catalog_cache_refresh_test.cpp b/src/mongo/s/catalog_cache_refresh_test.cpp index 4d18c95827e..6f913d5bf6d 100644 --- a/src/mongo/s/catalog_cache_refresh_test.cpp +++ b/src/mongo/s/catalog_cache_refresh_test.cpp @@ -46,7 +46,7 @@ namespace { using executor::RemoteCommandRequest; using unittest::assertGet; -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); class CatalogCacheRefreshTest : public CatalogCacheTestFixture { protected: diff --git a/src/mongo/s/catalog_cache_test.cpp b/src/mongo/s/catalog_cache_test.cpp index 1df4e541f27..50111fd8784 100644 --- a/src/mongo/s/catalog_cache_test.cpp +++ b/src/mongo/s/catalog_cache_test.cpp @@ -191,7 +191,8 @@ protected: .toBSON(CursorResponse::ResponseType::InitialResponse); } - const NamespaceString kNss{"catalgoCacheTestDB.foo"}; + const NamespaceString kNss = + NamespaceString::createNamespaceString_forTest("catalgoCacheTestDB.foo"); const UUID kUUID = UUID::gen(); const std::string kPattern{"_id"}; const ShardKeyPattern kShardKeyPattern{BSON(kPattern << 1)}; diff --git a/src/mongo/s/chunk_manager_query_test.cpp b/src/mongo/s/chunk_manager_query_test.cpp index a474e37691d..adef2f2e8ee 100644 --- a/src/mongo/s/chunk_manager_query_test.cpp +++ b/src/mongo/s/chunk_manager_query_test.cpp @@ -43,7 +43,7 @@ namespace mongo { namespace { -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); class ChunkManagerQueryTest : public CatalogCacheTestFixture { protected: diff --git a/src/mongo/s/chunk_map_test.cpp b/src/mongo/s/chunk_map_test.cpp index 88378ff53e1..f0e71e7aaaa 100644 --- a/src/mongo/s/chunk_map_test.cpp +++ b/src/mongo/s/chunk_map_test.cpp @@ -33,7 +33,7 @@ namespace mongo { namespace { -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); const ShardId kThisShard("testShard"); class ChunkMapTest : public unittest::Test { diff --git a/src/mongo/s/chunk_test.cpp b/src/mongo/s/chunk_test.cpp index 8031f58e5b2..9ecdc310306 100644 --- a/src/mongo/s/chunk_test.cpp +++ b/src/mongo/s/chunk_test.cpp @@ -33,7 +33,7 @@ namespace mongo { namespace { -const NamespaceString kNss("test.foo"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.foo"); const ShardId kShardOne("shardOne"); const ShardId kShardTwo("shardTwo"); const KeyPattern kShardKeyPattern(BSON("a" << 1)); diff --git a/src/mongo/s/collection_routing_info_targeter_test.cpp b/src/mongo/s/collection_routing_info_targeter_test.cpp index e81df416820..8119ce8dc42 100644 --- a/src/mongo/s/collection_routing_info_targeter_test.cpp +++ b/src/mongo/s/collection_routing_info_targeter_test.cpp @@ -49,7 +49,7 @@ namespace { using unittest::assertGet; -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); auto buildUpdate(const NamespaceString& nss, BSONObj query, BSONObj update, bool upsert) { write_ops::UpdateCommandRequest updateOp(nss); diff --git a/src/mongo/s/commands/cluster_aggregate_test.cpp b/src/mongo/s/commands/cluster_aggregate_test.cpp index 67002da94d8..2f9c9a137b8 100644 --- a/src/mongo/s/commands/cluster_aggregate_test.cpp +++ b/src/mongo/s/commands/cluster_aggregate_test.cpp @@ -94,7 +94,7 @@ protected: */ Status testRunAggregateEarlyExit(const BSONObj& inputBson) { BSONObjBuilder result; - NamespaceString nss{"a.collection"}; + NamespaceString nss = NamespaceString::createNamespaceString_forTest("a.collection"); auto client = getServiceContext()->makeClient("ClusterCmdClient"); auto opCtx = client->makeOperationContext(); auto request = aggregation_request_helper::parseFromBSONForTests(nss, inputBson); diff --git a/src/mongo/s/commands/cluster_command_test_fixture.h b/src/mongo/s/commands/cluster_command_test_fixture.h index b1e3a84588c..6b0fedc80fb 100644 --- a/src/mongo/s/commands/cluster_command_test_fixture.h +++ b/src/mongo/s/commands/cluster_command_test_fixture.h @@ -42,7 +42,7 @@ class ClusterCommandTestFixture : public CatalogCacheTestFixture { protected: const size_t numShards = 2; - const NamespaceString kNss = NamespaceString("test", "coll"); + const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test", "coll"); const LogicalTime kInMemoryLogicalTime = LogicalTime(Timestamp(10, 1)); diff --git a/src/mongo/s/commands/document_shard_key_update_test.cpp b/src/mongo/s/commands/document_shard_key_update_test.cpp index b8fe91f3903..56884e58923 100644 --- a/src/mongo/s/commands/document_shard_key_update_test.cpp +++ b/src/mongo/s/commands/document_shard_key_update_test.cpp @@ -50,7 +50,7 @@ public: }; TEST_F(DocumentShardKeyUpdateTest, constructShardKeyDeleteCmdObj) { - NamespaceString nss("test.foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.foo"); BSONObj updatePreImage = BSON("x" << 4 << "y" << 3 << "_id" << 20); auto deleteCmdObj = constructShardKeyDeleteCmdObj(nss, updatePreImage); @@ -66,7 +66,7 @@ TEST_F(DocumentShardKeyUpdateTest, constructShardKeyDeleteCmdObj) { } TEST_F(DocumentShardKeyUpdateTest, constructShardKeyInsertCmdObj) { - NamespaceString nss("test.foo"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.foo"); BSONObj updatePostImage = BSON("x" << 4 << "y" << 3 << "_id" << 20); auto insertCmdObj = constructShardKeyInsertCmdObj(nss, updatePostImage, false); diff --git a/src/mongo/s/query/cluster_client_cursor_impl_test.cpp b/src/mongo/s/query/cluster_client_cursor_impl_test.cpp index 2581aa18116..be09e027337 100644 --- a/src/mongo/s/query/cluster_client_cursor_impl_test.cpp +++ b/src/mongo/s/query/cluster_client_cursor_impl_test.cpp @@ -64,7 +64,8 @@ TEST_F(ClusterClientCursorImplTest, NumReturnedSoFar) { ClusterClientCursorImpl cursor( _opCtx.get(), std::move(mockStage), - ClusterClientCursorParams(NamespaceString("unused"), APIParameters(), {}), + ClusterClientCursorParams( + NamespaceString::createNamespaceString_forTest("unused"), APIParameters(), {}), boost::none); ASSERT_EQ(cursor.getNumReturnedSoFar(), 0); @@ -87,10 +88,11 @@ TEST_F(ClusterClientCursorImplTest, QueueResult) { mockStage->queueResult(BSON("a" << 1)); mockStage->queueResult(BSON("a" << 4)); - ClusterClientCursorImpl cursor(_opCtx.get(), - std::move(mockStage), - ClusterClientCursorParams(NamespaceString("unused"), {}), - boost::none); + ClusterClientCursorImpl cursor( + _opCtx.get(), + std::move(mockStage), + ClusterClientCursorParams(NamespaceString::createNamespaceString_forTest("unused"), {}), + boost::none); auto firstResult = cursor.next(); ASSERT_OK(firstResult.getStatus()); @@ -128,10 +130,11 @@ TEST_F(ClusterClientCursorImplTest, RemotesExhausted) { mockStage->queueResult(BSON("a" << 2)); mockStage->markRemotesExhausted(); - ClusterClientCursorImpl cursor(_opCtx.get(), - std::move(mockStage), - ClusterClientCursorParams(NamespaceString("unused"), {}), - boost::none); + ClusterClientCursorImpl cursor( + _opCtx.get(), + std::move(mockStage), + ClusterClientCursorParams(NamespaceString::createNamespaceString_forTest("unused"), {}), + boost::none); ASSERT_TRUE(cursor.remotesExhausted()); auto firstResult = cursor.next(); @@ -160,10 +163,11 @@ TEST_F(ClusterClientCursorImplTest, RemoteTimeoutPartialResultsDisallowed) { mockStage->queueError(Status(ErrorCodes::MaxTimeMSExpired, "timeout")); mockStage->markRemotesExhausted(); - ClusterClientCursorImpl cursor(_opCtx.get(), - std::move(mockStage), - ClusterClientCursorParams(NamespaceString("unused"), {}), - boost::none); + ClusterClientCursorImpl cursor( + _opCtx.get(), + std::move(mockStage), + ClusterClientCursorParams(NamespaceString::createNamespaceString_forTest("unused"), {}), + boost::none); ASSERT_TRUE(cursor.remotesExhausted()); auto firstResult = cursor.next(); @@ -185,7 +189,8 @@ TEST_F(ClusterClientCursorImplTest, RemoteTimeoutPartialResultsAllowed) { mockStage->queueError(Status(ErrorCodes::MaxTimeMSExpired, "timeout")); mockStage->markRemotesExhausted(); - auto params = ClusterClientCursorParams(NamespaceString("unused"), {}); + auto params = + ClusterClientCursorParams(NamespaceString::createNamespaceString_forTest("unused"), {}); params.isAllowPartialResults = true; ClusterClientCursorImpl cursor( @@ -210,10 +215,11 @@ TEST_F(ClusterClientCursorImplTest, ForwardsAwaitDataTimeout) { auto mockStagePtr = mockStage.get(); ASSERT_NOT_OK(mockStage->getAwaitDataTimeout().getStatus()); - ClusterClientCursorImpl cursor(_opCtx.get(), - std::move(mockStage), - ClusterClientCursorParams(NamespaceString("unused"), {}), - boost::none); + ClusterClientCursorImpl cursor( + _opCtx.get(), + std::move(mockStage), + ClusterClientCursorParams(NamespaceString::createNamespaceString_forTest("unused"), {}), + boost::none); ASSERT_OK(cursor.setAwaitDataTimeout(Milliseconds(789))); auto awaitDataTimeout = mockStagePtr->getAwaitDataTimeout(); @@ -227,10 +233,11 @@ TEST_F(ClusterClientCursorImplTest, ChecksForInterrupt) { mockStage->queueResult(BSON("a" << i)); } - ClusterClientCursorImpl cursor(_opCtx.get(), - std::move(mockStage), - ClusterClientCursorParams(NamespaceString("unused"), {}), - boost::none); + ClusterClientCursorImpl cursor( + _opCtx.get(), + std::move(mockStage), + ClusterClientCursorParams(NamespaceString::createNamespaceString_forTest("unused"), {}), + boost::none); // Pull one result out of the cursor. auto result = cursor.next(); @@ -252,14 +259,14 @@ TEST_F(ClusterClientCursorImplTest, ChecksForInterrupt) { TEST_F(ClusterClientCursorImplTest, LogicalSessionIdsOnCursors) { // Make a cursor with no lsid auto mockStage = std::make_unique(_opCtx.get()); - ClusterClientCursorParams params(NamespaceString("test"), {}); + ClusterClientCursorParams params(NamespaceString::createNamespaceString_forTest("test"), {}); ClusterClientCursorImpl cursor{ _opCtx.get(), std::move(mockStage), std::move(params), boost::none}; ASSERT(!cursor.getLsid()); // Make a cursor with an lsid auto mockStage2 = std::make_unique(_opCtx.get()); - ClusterClientCursorParams params2(NamespaceString("test"), {}); + ClusterClientCursorParams params2(NamespaceString::createNamespaceString_forTest("test"), {}); auto lsid = makeLogicalSessionIdForTest(); ClusterClientCursorImpl cursor2{_opCtx.get(), std::move(mockStage2), std::move(params2), lsid}; ASSERT(*(cursor2.getLsid()) == lsid); @@ -270,7 +277,8 @@ TEST_F(ClusterClientCursorImplTest, ShouldStoreLSIDIfSetOnOpCtx) { { // Make a cursor with no lsid or txnNumber. - ClusterClientCursorParams params(NamespaceString("test"), {}); + ClusterClientCursorParams params(NamespaceString::createNamespaceString_forTest("test"), + {}); params.lsid = _opCtx->getLogicalSessionId(); params.txnNumber = _opCtx->getTxnNumber(); @@ -284,7 +292,8 @@ TEST_F(ClusterClientCursorImplTest, ShouldStoreLSIDIfSetOnOpCtx) { { // Make a cursor with an lsid and no txnNumber. - ClusterClientCursorParams params(NamespaceString("test"), {}); + ClusterClientCursorParams params(NamespaceString::createNamespaceString_forTest("test"), + {}); params.lsid = _opCtx->getLogicalSessionId(); params.txnNumber = _opCtx->getTxnNumber(); @@ -298,7 +307,8 @@ TEST_F(ClusterClientCursorImplTest, ShouldStoreLSIDIfSetOnOpCtx) { { // Make a cursor with an lsid and txnNumber. - ClusterClientCursorParams params(NamespaceString("test"), {}); + ClusterClientCursorParams params(NamespaceString::createNamespaceString_forTest("test"), + {}); params.lsid = _opCtx->getLogicalSessionId(); params.txnNumber = _opCtx->getTxnNumber(); @@ -316,7 +326,8 @@ TEST_F(ClusterClientCursorImplTest, ShouldStoreAPIParameters) { apiParams.setAPIStrict(true); apiParams.setAPIDeprecationErrors(true); - ClusterClientCursorParams params(NamespaceString("test"), apiParams, {}); + ClusterClientCursorParams params( + NamespaceString::createNamespaceString_forTest("test"), apiParams, {}); ClusterClientCursorImpl cursor( _opCtx.get(), std::move(mockStage), std::move(params), boost::none); diff --git a/src/mongo/s/query/cluster_cursor_manager_test.cpp b/src/mongo/s/query/cluster_cursor_manager_test.cpp index 36ba0d15f5c..b27ca5c2d19 100644 --- a/src/mongo/s/query/cluster_cursor_manager_test.cpp +++ b/src/mongo/s/query/cluster_cursor_manager_test.cpp @@ -45,7 +45,7 @@ namespace mongo { namespace { using unittest::assertGet; -const NamespaceString nss("test.collection"); +const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.collection"); class ClusterCursorManagerTest : public ServiceContextTest { protected: diff --git a/src/mongo/s/query/cluster_exchange_test.cpp b/src/mongo/s/query/cluster_exchange_test.cpp index 5711ea5da64..023acc46cbd 100644 --- a/src/mongo/s/query/cluster_exchange_test.cpp +++ b/src/mongo/s/query/cluster_exchange_test.cpp @@ -49,7 +49,8 @@ using MergeStrategyDescriptor = DocumentSourceMerge::MergeStrategyDescriptor; using WhenMatched = MergeStrategyDescriptor::WhenMatched; using WhenNotMatched = MergeStrategyDescriptor::WhenNotMatched; -const NamespaceString kTestTargetNss = NamespaceString{"unittests", "out_ns"}; +const NamespaceString kTestTargetNss = + NamespaceString::createNamespaceString_forTest("unittests", "out_ns"); class ClusterExchangeTest : public ShardedAggTestFixture { protected: diff --git a/src/mongo/s/query/results_merger_test_fixture.cpp b/src/mongo/s/query/results_merger_test_fixture.cpp index 33a1816d795..637c879e87b 100644 --- a/src/mongo/s/query/results_merger_test_fixture.cpp +++ b/src/mongo/s/query/results_merger_test_fixture.cpp @@ -46,7 +46,8 @@ const std::vector ResultsMergerTestFixture::kTestShardHosts = { HostAndPort("FakeShard2Host", 12345), HostAndPort("FakeShard3Host", 12345)}; -const NamespaceString ResultsMergerTestFixture::kTestNss = NamespaceString{"testdb.testcoll"}; +const NamespaceString ResultsMergerTestFixture::kTestNss = + NamespaceString::createNamespaceString_forTest("testdb.testcoll"); void ResultsMergerTestFixture::setUp() { ShardingTestFixture::setUp(); diff --git a/src/mongo/s/query/sharded_agg_test_fixture.h b/src/mongo/s/query/sharded_agg_test_fixture.h index c166abee481..87df3b43630 100644 --- a/src/mongo/s/query/sharded_agg_test_fixture.h +++ b/src/mongo/s/query/sharded_agg_test_fixture.h @@ -53,7 +53,8 @@ public: class ShardedAggTestFixture : public CatalogCacheTestFixture { public: - const NamespaceString kTestAggregateNss = NamespaceString{"unittests", "sharded_agg_test"}; + const NamespaceString kTestAggregateNss = + NamespaceString::createNamespaceString_forTest("unittests", "sharded_agg_test"); void setUp() { CatalogCacheTestFixture::setUp(); diff --git a/src/mongo/s/query/store_possible_cursor_test.cpp b/src/mongo/s/query/store_possible_cursor_test.cpp index 7bef51b82f1..ed92a642bc4 100644 --- a/src/mongo/s/query/store_possible_cursor_test.cpp +++ b/src/mongo/s/query/store_possible_cursor_test.cpp @@ -41,7 +41,7 @@ namespace mongo { namespace { -const NamespaceString nss("test.collection"); +const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.collection"); const HostAndPort hostAndPort("testhost", 27017); const ShardId shardId("testshard"); diff --git a/src/mongo/s/query_analysis_sampler_test.cpp b/src/mongo/s/query_analysis_sampler_test.cpp index b62ebb93c13..be85431e911 100644 --- a/src/mongo/s/query_analysis_sampler_test.cpp +++ b/src/mongo/s/query_analysis_sampler_test.cpp @@ -153,7 +153,8 @@ protected: return _mockClock->now(); } - const NamespaceString nss{"testDb", "testColl"}; + const NamespaceString nss = + NamespaceString::createNamespaceString_forTest("testDb", "testColl"); const UUID collUuid = UUID::gen(); private: @@ -531,9 +532,12 @@ protected: const HostAndPort kTestConfigShardHost = HostAndPort("FakeConfigHost", 12345); - const NamespaceString nss0{"testDb", "testColl0"}; - const NamespaceString nss1{"testDb", "testColl1"}; - const NamespaceString nss2{"testDb", "testColl2"}; + const NamespaceString nss0 = + NamespaceString::createNamespaceString_forTest("testDb", "testColl0"); + const NamespaceString nss1 = + NamespaceString::createNamespaceString_forTest("testDb", "testColl1"); + const NamespaceString nss2 = + NamespaceString::createNamespaceString_forTest("testDb", "testColl2"); const UUID collUuid0 = UUID::gen(); const UUID collUuid1 = UUID::gen(); diff --git a/src/mongo/s/request_types/balance_chunk_request_test.cpp b/src/mongo/s/request_types/balance_chunk_request_test.cpp index a1475991bd2..f02a77b9e48 100644 --- a/src/mongo/s/request_types/balance_chunk_request_test.cpp +++ b/src/mongo/s/request_types/balance_chunk_request_test.cpp @@ -43,14 +43,14 @@ TEST(BalanceChunkRequest, RoundTrip) { UUID uuid{UUID::gen()}; ChunkVersion version({OID::gen(), Timestamp(2, 0)}, {30, 1}); auto obj = BalanceChunkRequest::serializeToRebalanceCommandForConfig( - NamespaceString("DB.Test"), + NamespaceString::createNamespaceString_forTest("DB.Test"), ChunkRange(BSON("A" << 100), BSON("A" << 200)), uuid, ShardId("TestShard"), version); auto request = assertGet(BalanceChunkRequest::parseFromConfigCommand(obj)); - ASSERT_EQ(NamespaceString("DB.Test"), request.getNss()); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest("DB.Test"), request.getNss()); ASSERT_BSONOBJ_EQ(ChunkRange(BSON("A" << 100), BSON("A" << 200)).toBSON(), request.getChunk().getRange().toBSON()); ASSERT_EQ(uuid, request.getChunk().getCollectionUUID()); diff --git a/src/mongo/s/request_types/merge_chunks_request_test.cpp b/src/mongo/s/request_types/merge_chunks_request_test.cpp index ad4db8fcd76..368fd33d127 100644 --- a/src/mongo/s/request_types/merge_chunks_request_test.cpp +++ b/src/mongo/s/request_types/merge_chunks_request_test.cpp @@ -52,7 +52,8 @@ TEST(ConfigSvrMergeChunks, BasicValidConfigCommand) { << "shard0000" << "$db" << "admin")); - ASSERT_EQ(NamespaceString("TestDB", "TestColl"), request.getCommandParameter()); + ASSERT_EQ(NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"), + request.getCommandParameter()); ASSERT_TRUE(collUUID == request.getCollectionUUID()); ASSERT_TRUE(chunkRange == request.getChunkRange()); ASSERT_EQ("shard0000", request.getShard().toString()); diff --git a/src/mongo/s/routing_table_history_test.cpp b/src/mongo/s/routing_table_history_test.cpp index 7c8973a7237..c18f38cc8d3 100644 --- a/src/mongo/s/routing_table_history_test.cpp +++ b/src/mongo/s/routing_table_history_test.cpp @@ -42,7 +42,7 @@ namespace mongo { namespace { const ShardId kThisShard("thisShard"); -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); /** * Creates a new routing table from the input routing table by inserting the chunks specified by diff --git a/src/mongo/s/shard_key_pattern_query_util_index_bounds_test.cpp b/src/mongo/s/shard_key_pattern_query_util_index_bounds_test.cpp index 672067b9ad9..c498d7ea8e6 100644 --- a/src/mongo/s/shard_key_pattern_query_util_index_bounds_test.cpp +++ b/src/mongo/s/shard_key_pattern_query_util_index_bounds_test.cpp @@ -51,7 +51,7 @@ protected: // Utility function to create a CanonicalQuery std::unique_ptr canonicalize(const char* queryStr) { BSONObj queryObj = fromjson(queryStr); - const NamespaceString nss("test.foo"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.foo"); auto findCommand = std::make_unique(nss); findCommand->setFilter(queryObj); boost::intrusive_ptr expCtx( @@ -635,7 +635,7 @@ TEST_F(CMCollapseTreeTest, GeoNearLimitationsInPlace) { "{a: 2, b: {$near: {$geometry: {type: \"Point\", coordinates: [0, 0]}, $minDistance: " "0, $maxDistance: 2}}, c: {$near: {$geometry: {type: \"Point\", coordinates: [0, 0]}, " "$minDistance: 0, $maxDistance: 2}}}"); - const NamespaceString nss("test.foo"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.foo"); auto findCommand = std::make_unique(nss); findCommand->setFilter(queryObj); boost::intrusive_ptr expCtx( @@ -657,7 +657,7 @@ TEST_F(CMCollapseTreeTest, GeoNearLimitationsInPlace) { BSONObj queryObj = fromjson( "{$or: {a: 2, b: {$near: {$geometry: {type: \"Point\", coordinates: [0, 0]}, " "$minDistance: 0, $maxDistance: 2}}}}"); - const NamespaceString nss("test.foo"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test.foo"); auto findCommand = std::make_unique(nss); findCommand->setFilter(queryObj); boost::intrusive_ptr expCtx( diff --git a/src/mongo/s/shard_key_pattern_test.cpp b/src/mongo/s/shard_key_pattern_test.cpp index a59f0494f73..f1e51a51a7b 100644 --- a/src/mongo/s/shard_key_pattern_test.cpp +++ b/src/mongo/s/shard_key_pattern_test.cpp @@ -48,7 +48,7 @@ protected: } BSONObj queryKey(const ShardKeyPattern& pattern, const BSONObj& query) { - const NamespaceString nss("foo"); + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo"); StatusWith status = extractShardKeyFromBasicQuery(_opCtx, nss, pattern, query); if (!status.isOK()) diff --git a/src/mongo/s/stale_exception_test.cpp b/src/mongo/s/stale_exception_test.cpp index 1e92988516d..35564248140 100644 --- a/src/mongo/s/stale_exception_test.cpp +++ b/src/mongo/s/stale_exception_test.cpp @@ -33,7 +33,7 @@ namespace mongo { namespace { -const NamespaceString kNss("test.nss"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("test.nss"); TEST(StaleExceptionTest, StaleConfigInfoSerializationTest) { const ShardId kShardId("SHARD_ID"); diff --git a/src/mongo/s/stale_shard_version_helpers_test.cpp b/src/mongo/s/stale_shard_version_helpers_test.cpp index 20e44b5249a..8bd43224eda 100644 --- a/src/mongo/s/stale_shard_version_helpers_test.cpp +++ b/src/mongo/s/stale_shard_version_helpers_test.cpp @@ -41,7 +41,7 @@ namespace { class AsyncShardVersionRetry : public ShardingTestFixture { public: NamespaceString nss() const { - return NamespaceString("test", "foo"); + return NamespaceString::createNamespaceString_forTest("test", "foo"); } StringData desc() const { diff --git a/src/mongo/s/transaction_router_test.cpp b/src/mongo/s/transaction_router_test.cpp index 837099e53fd..353fc2f363c 100644 --- a/src/mongo/s/transaction_router_test.cpp +++ b/src/mongo/s/transaction_router_test.cpp @@ -111,7 +111,7 @@ protected: const BSONObj kDummyResWithWriteConcernError = BSON("ok" << 1 << "writeConcernError" << kDummyWriteConcernError); - const NamespaceString kViewNss = NamespaceString("test.foo"); + const NamespaceString kViewNss = NamespaceString::createNamespaceString_forTest("test.foo"); const Status kStaleConfigStatus = { StaleConfigInfo(kViewNss, ShardVersion::UNSHARDED(), boost::none, shard1), diff --git a/src/mongo/s/write_ops/batch_write_exec_test.cpp b/src/mongo/s/write_ops/batch_write_exec_test.cpp index 0977244b890..bc1ffdb1ff0 100644 --- a/src/mongo/s/write_ops/batch_write_exec_test.cpp +++ b/src/mongo/s/write_ops/batch_write_exec_test.cpp @@ -330,7 +330,7 @@ public: }); } - const NamespaceString nss{"foo.bar"}; + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); const CollectionGeneration gen{OID::gen(), Timestamp(1, 1)}; MockNSTargeter singleShardNSTargeter{ @@ -1950,7 +1950,7 @@ public: }()}); } - const NamespaceString nss{"foo.bar"}; + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); }; TEST_F(BatchWriteExecTargeterErrorTest, TargetedFailedAndErrorResponse) { @@ -2095,7 +2095,7 @@ public: BatchWriteExecTest::tearDown(); } - const NamespaceString nss{"foo.bar"}; + const NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); private: boost::optional _scopedSession; diff --git a/src/mongo/s/write_ops/batch_write_op_test.cpp b/src/mongo/s/write_ops/batch_write_op_test.cpp index abb7ccd4fa5..46bd5a26c79 100644 --- a/src/mongo/s/write_ops/batch_write_op_test.cpp +++ b/src/mongo/s/write_ops/batch_write_op_test.cpp @@ -120,7 +120,7 @@ protected: using BatchWriteOpTest = WriteOpTestFixture; TEST_F(BatchWriteOpTest, SingleOp) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -152,7 +152,7 @@ TEST_F(BatchWriteOpTest, SingleOp) { } TEST_F(BatchWriteOpTest, SingleError) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -190,7 +190,7 @@ TEST_F(BatchWriteOpTest, SingleError) { } TEST_F(BatchWriteOpTest, SingleTargetError) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterHalfRange(nss, endpoint); @@ -224,7 +224,7 @@ TEST_F(BatchWriteOpTest, SingleTargetError) { // Write concern error test - we should pass write concern to sub-batches, and pass up the write // concern error if one occurs. TEST_F(BatchWriteOpTest, SingleWriteConcernErrorOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -266,7 +266,7 @@ TEST_F(BatchWriteOpTest, SingleWriteConcernErrorOrdered) { // Single-op stale version test. We should retry the same batch until we're not stale. TEST_F(BatchWriteOpTest, SingleStaleError) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -329,7 +329,7 @@ TEST_F(BatchWriteOpTest, SingleStaleError) { // Multi-op targeting test (ordered) TEST_F(BatchWriteOpTest, MultiOpSameShardOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -365,7 +365,7 @@ TEST_F(BatchWriteOpTest, MultiOpSameShardOrdered) { // Multi-op targeting test (unordered) TEST_F(BatchWriteOpTest, MultiOpSameShardUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -407,7 +407,7 @@ TEST_F(BatchWriteOpTest, MultiOpSameShardUnordered) { // Multi-op, multi-endpoing targeting test (ordered). There should be two sets of single batches // (one to each shard, one-by-one) TEST_F(BatchWriteOpTest, MultiOpTwoShardsOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -473,7 +473,7 @@ void verifyTargetedBatches(std::map expected, // Multi-op, multi-endpoint targeting test (unordered). There should be one set of two batches (one // to each shard). TEST_F(BatchWriteOpTest, MultiOpTwoShardsUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -518,7 +518,7 @@ TEST_F(BatchWriteOpTest, MultiOpTwoShardsUnordered) { // Multi-op (ordered) targeting test where each op goes to both shards. There should be two sets of // two batches to each shard (two for each delete op). TEST_F(BatchWriteOpTest, MultiOpTwoShardsEachOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -573,7 +573,7 @@ TEST_F(BatchWriteOpTest, MultiOpTwoShardsEachOrdered) { // Multi-op (unaordered) targeting test where each op goes to both shards. There should be one set // of two batches to each shard (containing writes for both ops). TEST_F(BatchWriteOpTest, MultiOpTwoShardsEachUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -620,7 +620,7 @@ TEST_F(BatchWriteOpTest, MultiOpTwoShardsEachUnordered) { // shards. Should batch the first two ops, then second ops should be batched separately, then last // ops should be batched together. TEST_F(BatchWriteOpTest, MultiOpOneOrTwoShardsOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -714,7 +714,7 @@ TEST_F(BatchWriteOpTest, MultiOpOneOrTwoShardsOrdered) { // Multi-op (unordered) targeting test where first two ops go to one shard, second two ops go to two // shards. Should batch all the ops together into two batches of four ops for each shard. TEST_F(BatchWriteOpTest, MultiOpOneOrTwoShardsUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -767,7 +767,7 @@ TEST_F(BatchWriteOpTest, MultiOpOneOrTwoShardsUnordered) { // Multi-op targeting test where two ops go to two separate shards and there's an error on one op on // one shard. There should be one set of two batches to each shard and an error reported. TEST_F(BatchWriteOpTest, MultiOpSingleShardErrorUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -827,7 +827,7 @@ TEST_F(BatchWriteOpTest, MultiOpSingleShardErrorUnordered) { // Multi-op targeting test where two ops go to two separate shards and there's an error on each op // on each shard. There should be one set of two batches to each shard and and two errors reported. TEST_F(BatchWriteOpTest, MultiOpTwoShardErrorsUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -884,7 +884,7 @@ TEST_F(BatchWriteOpTest, MultiOpTwoShardErrorsUnordered) { // Multi-op targeting test where each op goes to both shards and there's an error on one op on one // shard. There should be one set of two batches to each shard and an error reported. TEST_F(BatchWriteOpTest, MultiOpPartialSingleShardErrorUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -946,7 +946,7 @@ TEST_F(BatchWriteOpTest, MultiOpPartialSingleShardErrorUnordered) { // shard. There should be one set of two batches to each shard and an error reported, the second op // should not get run. TEST_F(BatchWriteOpTest, MultiOpPartialSingleShardErrorOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -1007,7 +1007,7 @@ TEST_F(BatchWriteOpTest, MultiOpPartialSingleShardErrorOrdered) { // for single-doc batches, since the error means there's no write concern applied. Don't suppress // the error if ordered : false. TEST_F(BatchWriteOpTest, MultiOpErrorAndWriteConcernErrorUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -1050,7 +1050,7 @@ TEST_F(BatchWriteOpTest, MultiOpErrorAndWriteConcernErrorUnordered) { // Single-op (ordered) error and write concern error test. Suppress the write concern error if // ordered and we also have an error TEST_F(BatchWriteOpTest, SingleOpErrorAndWriteConcernErrorOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -1105,7 +1105,7 @@ TEST_F(BatchWriteOpTest, SingleOpErrorAndWriteConcernErrorOrdered) { // Targeting failure on second op in batch op (ordered) TEST_F(BatchWriteOpTest, MultiOpFailedTargetOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterHalfRange(nss, endpoint); @@ -1159,7 +1159,7 @@ TEST_F(BatchWriteOpTest, MultiOpFailedTargetOrdered) { // Targeting failure on second op in batch op (unordered) TEST_F(BatchWriteOpTest, MultiOpFailedTargetUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterHalfRange(nss, endpoint); @@ -1212,7 +1212,7 @@ TEST_F(BatchWriteOpTest, MultiOpFailedTargetUnordered) { // Batch failure (ok : 0) reported in a multi-op batch (ordered). Expect this gets translated down // into write errors for first affected write. TEST_F(BatchWriteOpTest, MultiOpFailedBatchOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -1259,7 +1259,7 @@ TEST_F(BatchWriteOpTest, MultiOpFailedBatchOrdered) { // Batch failure (ok : 0) reported in a multi-op batch (unordered). Expect this gets translated down // into write errors for all affected writes. TEST_F(BatchWriteOpTest, MultiOpFailedBatchUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -1315,7 +1315,7 @@ TEST_F(BatchWriteOpTest, MultiOpFailedBatchUnordered) { // Batch aborted (ordered). Expect this gets translated down into write error for first affected // write. TEST_F(BatchWriteOpTest, MultiOpAbortOrdered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -1358,7 +1358,7 @@ TEST_F(BatchWriteOpTest, MultiOpAbortOrdered) { // Batch aborted (unordered). Expect this gets translated down into write errors for all affected // writes. TEST_F(BatchWriteOpTest, MultiOpAbortUnordered) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -1398,7 +1398,7 @@ TEST_F(BatchWriteOpTest, MultiOpAbortUnordered) { // Multi-op targeting test where each op goes to both shards and both return a write concern error TEST_F(BatchWriteOpTest, MultiOpTwoWCErrors) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpointA(ShardId("shardA"), ShardVersion::IGNORED(), boost::none); ShardEndpoint endpointB(ShardId("shardB"), ShardVersion::IGNORED(), boost::none); @@ -1440,7 +1440,7 @@ TEST_F(BatchWriteOpTest, MultiOpTwoWCErrors) { } TEST_F(BatchWriteOpTest, AttachingStmtIds) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -1530,7 +1530,7 @@ using BatchWriteOpLimitTests = WriteOpTestFixture; // Big single operation test - should go through TEST_F(BatchWriteOpLimitTests, OneBigDoc) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -1565,7 +1565,7 @@ TEST_F(BatchWriteOpLimitTests, OneBigDoc) { // Big doc with smaller additional doc - should go through as two batches TEST_F(BatchWriteOpLimitTests, OneBigOneSmall) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterFullRange(nss, endpoint); @@ -1633,7 +1633,7 @@ private: }; TEST_F(BatchWriteOpTransactionTest, ThrowTargetingErrorsInTransaction_Delete) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterHalfRange(nss, endpoint); @@ -1662,7 +1662,7 @@ TEST_F(BatchWriteOpTransactionTest, ThrowTargetingErrorsInTransaction_Delete) { } TEST_F(BatchWriteOpTransactionTest, ThrowTargetingErrorsInTransaction_Update) { - NamespaceString nss("foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest("foo.bar"); ShardEndpoint endpoint(ShardId("shard"), ShardVersion::IGNORED(), boost::none); auto targeter = initTargeterHalfRange(nss, endpoint); @@ -1690,7 +1690,7 @@ TEST_F(BatchWriteOpTransactionTest, ThrowTargetingErrorsInTransaction_Update) { ASSERT_EQ(ErrorCodes::UnknownError, response.getErrDetailsAt(0).getStatus().code()); } -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); const int splitPoint = 50; class WriteWithoutShardKeyFixture : public CatalogCacheTestFixture { diff --git a/src/mongo/s/write_ops/batched_command_request_test.cpp b/src/mongo/s/write_ops/batched_command_request_test.cpp index 368d31aa4e9..6408a9c6084 100644 --- a/src/mongo/s/write_ops/batched_command_request_test.cpp +++ b/src/mongo/s/write_ops/batched_command_request_test.cpp @@ -81,7 +81,8 @@ TEST(BatchedCommandRequest, InsertWithShardVersion) { TEST(BatchedCommandRequest, InsertCloneWithIds) { BatchedCommandRequest batchedRequest([&] { - write_ops::InsertCommandRequest insertOp(NamespaceString("xyz.abc")); + write_ops::InsertCommandRequest insertOp( + NamespaceString::createNamespaceString_forTest("xyz.abc")); insertOp.setWriteCommandRequestBase([] { write_ops::WriteCommandRequestBase wcb; wcb.setOrdered(true); diff --git a/src/mongo/s/write_ops/batched_command_response_test.cpp b/src/mongo/s/write_ops/batched_command_response_test.cpp index d3daad2afde..e4eb5f3b447 100644 --- a/src/mongo/s/write_ops/batched_command_response_test.cpp +++ b/src/mongo/s/write_ops/batched_command_response_test.cpp @@ -70,7 +70,7 @@ TEST(BatchedCommandResponseTest, Basic) { TEST(BatchedCommandResponseTest, StaleConfigInfo) { OID epoch = OID::gen(); - StaleConfigInfo staleInfo(NamespaceString("TestDB.TestColl"), + StaleConfigInfo staleInfo(NamespaceString::createNamespaceString_forTest("TestDB.TestColl"), ShardVersion(ChunkVersion({epoch, Timestamp(100, 0)}, {1, 0}), boost::optional(boost::none)), ShardVersion(ChunkVersion({epoch, Timestamp(100, 0)}, {2, 0}), @@ -166,7 +166,8 @@ TEST(BatchedCommandResponseTest, CompatibilityFromWriteErrorToBatchCommandRespon reply.getWriteCommandReplyBase().setN(1); reply.getWriteCommandReplyBase().setWriteErrors(std::vector{ write_ops::WriteError(1, - Status(StaleConfigInfo(NamespaceString("TestDB", "TestColl"), + Status(StaleConfigInfo(NamespaceString::createNamespaceString_forTest( + "TestDB", "TestColl"), versionReceived, boost::none, ShardId("TestShard")), diff --git a/src/mongo/s/write_ops/write_op_test.cpp b/src/mongo/s/write_ops/write_op_test.cpp index a318c56cf2d..ef067bdb55e 100644 --- a/src/mongo/s/write_ops/write_op_test.cpp +++ b/src/mongo/s/write_ops/write_op_test.cpp @@ -40,7 +40,7 @@ namespace mongo { namespace { -const NamespaceString kNss("foo.bar"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("foo.bar"); write_ops::DeleteOpEntry buildDelete(const BSONObj& query, bool multi) { write_ops::DeleteOpEntry entry; diff --git a/src/mongo/s/write_ops/write_without_shard_key_util_test.cpp b/src/mongo/s/write_ops/write_without_shard_key_util_test.cpp index 6a4ffdb5092..1d5f4561d18 100644 --- a/src/mongo/s/write_ops/write_without_shard_key_util_test.cpp +++ b/src/mongo/s/write_ops/write_without_shard_key_util_test.cpp @@ -40,7 +40,7 @@ namespace mongo { namespace write_without_shard_key { namespace { -const NamespaceString kNss("TestDB", "TestColl"); +const NamespaceString kNss = NamespaceString::createNamespaceString_forTest("TestDB", "TestColl"); const int splitPoint = 50; class WriteWithoutShardKeyUtilTest : public CatalogCacheTestFixture { diff --git a/src/mongo/util/namespace_string_util_test.cpp b/src/mongo/util/namespace_string_util_test.cpp index 66af53401eb..b59d13ebcf6 100644 --- a/src/mongo/util/namespace_string_util_test.cpp +++ b/src/mongo/util/namespace_string_util_test.cpp @@ -44,7 +44,7 @@ TEST(NamespaceStringUtilTest, SerializeMultitenancySupportOnFeatureFlagRequireTe RAIIServerParameterControllerForTest multitenanyController("multitenancySupport", true); RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); TenantId tenantId(OID::gen()); - NamespaceString nss(tenantId, "foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tenantId, "foo.bar"); ASSERT_EQ(NamespaceStringUtil::serialize(nss), "foo.bar"); } @@ -55,14 +55,14 @@ TEST(NamespaceStringUtilTest, SerializeMultitenancySupportOnFeatureFlagRequireTe RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); TenantId tenantId(OID::gen()); std::string tenantNsStr = str::stream() << tenantId.toString() << "_foo.bar"; - NamespaceString nss(tenantId, "foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(tenantId, "foo.bar"); ASSERT_EQ(NamespaceStringUtil::serialize(nss), tenantNsStr); } // Serialize correctly when multitenancySupport is disabled. TEST(NamespaceStringUtilTest, SerializeMultitenancySupportOff) { RAIIServerParameterControllerForTest multitenanyController("multitenancySupport", false); - NamespaceString nss(boost::none, "foo.bar"); + NamespaceString nss = NamespaceString::createNamespaceString_forTest(boost::none, "foo.bar"); ASSERT_EQ(NamespaceStringUtil::serialize(nss), "foo.bar"); } @@ -86,7 +86,7 @@ TEST(NamespaceStringUtilTest, NamespaceString nss = NamespaceStringUtil::deserialize(tenantId, "foo.bar"); ASSERT_EQ(nss.ns(), "foo.bar"); ASSERT(nss.tenantId()); - ASSERT_EQ(nss, NamespaceString(tenantId, "foo.bar")); + ASSERT_EQ(nss, NamespaceString::createNamespaceString_forTest(tenantId, "foo.bar")); } // Assert that if multitenancySupport is enabled and featureFlagRequireTenantID is disabled, @@ -113,7 +113,7 @@ TEST(NamespaceStringUtilTest, DeserializeMultitenancySupportOnFeatureFlagRequire NamespaceString nss1 = NamespaceStringUtil::deserialize(tenantId, tenantNsStr); ASSERT_EQ(nss.ns(), "foo.bar"); ASSERT(nss.tenantId()); - ASSERT_EQ(nss, NamespaceString(tenantId, "foo.bar")); + ASSERT_EQ(nss, NamespaceString::createNamespaceString_forTest(tenantId, "foo.bar")); ASSERT_EQ(nss, nss1); } @@ -145,7 +145,7 @@ TEST(NamespaceStringUtilTest, DeserializeMultitenancySupportOffFeatureFlagRequir NamespaceString nss = NamespaceStringUtil::deserialize(boost::none, "foo.bar"); ASSERT_EQ(nss.ns(), "foo.bar"); ASSERT(!nss.tenantId()); - ASSERT_EQ(nss, NamespaceString(boost::none, "foo.bar")); + ASSERT_EQ(nss, NamespaceString::createNamespaceString_forTest(boost::none, "foo.bar")); } } // namespace mongo -- cgit v1.2.1