-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-3991 Add versioned API connection examples #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3464,11 +3464,11 @@ with_transaction_example (bson_error_t *error) | |
* members in the URI string; e.g. | ||
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \ | ||
* "27017/?replicaSet=myRepl"; | ||
* client = test_framework_client_new (uri_repl); | ||
* client = mongoc_client_new (uri_repl); | ||
* For a sharded cluster, connect to the mongos instances; e.g. | ||
* uri_sharded = | ||
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/"; | ||
* client = test_framework_client_new (uri_sharded); | ||
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
|
@@ -3572,6 +3572,146 @@ callback (mongoc_client_session_t *session, | |
} | ||
/* End Transactions withTxn API Example 1 */ | ||
|
||
static void | ||
_test_sample_versioned_api_example_1 (void) | ||
{ | ||
/* Start Versioned API Example 1 */ | ||
mongoc_client_t *client = NULL; | ||
mongoc_server_api_t *server_api = NULL; | ||
mongoc_server_api_version_t server_api_version; | ||
bson_error_t error; | ||
|
||
/* For a replica set, include the replica set name and a seedlist of the | ||
* members in the URI string; e.g. | ||
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \ | ||
* "27017/?replicaSet=myRepl"; | ||
* client = mongoc_client_new (uri_repl); | ||
* For a sharded cluster, connect to the mongos instances; e.g. | ||
* uri_sharded = | ||
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/"; | ||
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
|
||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
|
||
mongoc_client_set_server_api (client, server_api, &error); | ||
/* End Versioned API Example 1 */ | ||
|
||
mongoc_client_destroy (client); | ||
mongoc_server_api_destroy (server_api); | ||
} | ||
|
||
static void | ||
_test_sample_versioned_api_example_2 (void) | ||
{ | ||
/* Start Versioned API Example 2 */ | ||
mongoc_client_t *client = NULL; | ||
mongoc_server_api_t *server_api = NULL; | ||
mongoc_server_api_version_t server_api_version; | ||
bson_error_t error; | ||
|
||
/* For a replica set, include the replica set name and a seedlist of the | ||
* members in the URI string; e.g. | ||
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \ | ||
* "27017/?replicaSet=myRepl"; | ||
* client = mongoc_client_new (uri_repl); | ||
* For a sharded cluster, connect to the mongos instances; e.g. | ||
* uri_sharded = | ||
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/"; | ||
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
|
||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
mongoc_server_api_strict (server_api, true); | ||
|
||
mongoc_client_set_server_api (client, server_api, &error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a |
||
/* End Versioned API Example 2 */ | ||
|
||
mongoc_client_destroy (client); | ||
mongoc_server_api_destroy (server_api); | ||
} | ||
|
||
static void | ||
_test_sample_versioned_api_example_3 (void) | ||
{ | ||
/* Start Versioned API Example 3 */ | ||
mongoc_client_t *client = NULL; | ||
mongoc_server_api_t *server_api = NULL; | ||
mongoc_server_api_version_t server_api_version; | ||
bson_error_t error; | ||
|
||
/* For a replica set, include the replica set name and a seedlist of the | ||
* members in the URI string; e.g. | ||
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \ | ||
* "27017/?replicaSet=myRepl"; | ||
* client = mongoc_client_new (uri_repl); | ||
* For a sharded cluster, connect to the mongos instances; e.g. | ||
* uri_sharded = | ||
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/"; | ||
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
|
||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
mongoc_server_api_strict (server_api, false); | ||
|
||
mongoc_client_set_server_api (client, server_api, &error); | ||
/* End Versioned API Example 3 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a |
||
|
||
mongoc_client_destroy (client); | ||
mongoc_server_api_destroy (server_api); | ||
} | ||
|
||
static void | ||
_test_sample_versioned_api_example_4 (void) | ||
{ | ||
/* Start Versioned API Example 4 */ | ||
mongoc_client_t *client = NULL; | ||
mongoc_server_api_t *server_api = NULL; | ||
mongoc_server_api_version_t server_api_version; | ||
bson_error_t error; | ||
|
||
/* For a replica set, include the replica set name and a seedlist of the | ||
* members in the URI string; e.g. | ||
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \ | ||
* "27017/?replicaSet=myRepl"; | ||
* client = mongoc_client_new (uri_repl); | ||
* For a sharded cluster, connect to the mongos instances; e.g. | ||
* uri_sharded = | ||
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/"; | ||
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
|
||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
mongoc_server_api_deprecation_errors (server_api, true); | ||
|
||
mongoc_client_set_server_api (client, server_api, &error); | ||
/* End Versioned API Example 4 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a |
||
|
||
mongoc_client_destroy (client); | ||
mongoc_server_api_destroy (server_api); | ||
} | ||
|
||
static void | ||
test_sample_versioned_api (void) | ||
{ | ||
_test_sample_versioned_api_example_1 (); | ||
_test_sample_versioned_api_example_2 (); | ||
_test_sample_versioned_api_example_3 (); | ||
_test_sample_versioned_api_example_4 (); | ||
} | ||
|
||
static void | ||
test_sample_commands (void) | ||
{ | ||
|
@@ -3649,6 +3789,10 @@ test_sample_commands (void) | |
test_sample_txn_commands (client); | ||
} | ||
|
||
if (test_framework_max_wire_version_at_least (WIRE_VERSION_4_9)) { | ||
test_sample_versioned_api (); | ||
} | ||
|
||
mongoc_collection_drop (collection, NULL); | ||
|
||
mongoc_collection_destroy (collection); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a
mongoc_client_destroy (client)
andmongoc_server_api_destroy (server_api)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in all 4 tests (outside of the sample code)