Skip to content

Commit 10a5cd3

Browse files
committed
CDRIVER-3991 Add versioned API connection examples
1 parent dad3355 commit 10a5cd3

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

src/libmongoc/tests/test-mongoc-sample-commands.c

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,6 +3572,134 @@ callback (mongoc_client_session_t *session,
35723572
}
35733573
/* End Transactions withTxn API Example 1 */
35743574

3575+
static void
3576+
_test_sample_versioned_api_example_1 (void)
3577+
{
3578+
/* Start Versioned API Example 1 */
3579+
mongoc_client_t *client = NULL;
3580+
mongoc_server_api_t *server_api = NULL;
3581+
mongoc_server_api_version_t server_api_version;
3582+
bson_error_t error;
3583+
3584+
/* For a replica set, include the replica set name and a seedlist of the
3585+
* members in the URI string; e.g.
3586+
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \
3587+
* "27017/?replicaSet=myRepl";
3588+
* client = test_framework_client_new (uri_repl);
3589+
* For a sharded cluster, connect to the mongos instances; e.g.
3590+
* uri_sharded =
3591+
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/";
3592+
* client = test_framework_client_new (uri_sharded);
3593+
*/
3594+
3595+
client = get_client ();
3596+
3597+
mongoc_server_api_version_from_string ("1", &server_api_version);
3598+
server_api = mongoc_server_api_new (server_api_version);
3599+
3600+
mongoc_client_set_server_api (client, server_api, &error);
3601+
/* End Versioned API Example 1 */
3602+
}
3603+
3604+
static void
3605+
_test_sample_versioned_api_example_2 (void)
3606+
{
3607+
/* Start Versioned API Example 2 */
3608+
mongoc_client_t *client = NULL;
3609+
mongoc_server_api_t *server_api = NULL;
3610+
mongoc_server_api_version_t server_api_version;
3611+
bson_error_t error;
3612+
3613+
/* For a replica set, include the replica set name and a seedlist of the
3614+
* members in the URI string; e.g.
3615+
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \
3616+
* "27017/?replicaSet=myRepl";
3617+
* client = test_framework_client_new (uri_repl);
3618+
* For a sharded cluster, connect to the mongos instances; e.g.
3619+
* uri_sharded =
3620+
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/";
3621+
* client = test_framework_client_new (uri_sharded);
3622+
*/
3623+
3624+
client = get_client ();
3625+
3626+
mongoc_server_api_version_from_string ("1", &server_api_version);
3627+
server_api = mongoc_server_api_new (server_api_version);
3628+
mongoc_server_api_strict (server_api, true);
3629+
3630+
mongoc_client_set_server_api (client, server_api, &error);
3631+
/* End Versioned API Example 2 */
3632+
}
3633+
3634+
static void
3635+
_test_sample_versioned_api_example_3 (void)
3636+
{
3637+
/* Start Versioned API Example 3 */
3638+
mongoc_client_t *client = NULL;
3639+
mongoc_server_api_t *server_api = NULL;
3640+
mongoc_server_api_version_t server_api_version;
3641+
bson_error_t error;
3642+
3643+
/* For a replica set, include the replica set name and a seedlist of the
3644+
* members in the URI string; e.g.
3645+
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \
3646+
* "27017/?replicaSet=myRepl";
3647+
* client = test_framework_client_new (uri_repl);
3648+
* For a sharded cluster, connect to the mongos instances; e.g.
3649+
* uri_sharded =
3650+
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/";
3651+
* client = test_framework_client_new (uri_sharded);
3652+
*/
3653+
3654+
client = get_client ();
3655+
3656+
mongoc_server_api_version_from_string ("1", &server_api_version);
3657+
server_api = mongoc_server_api_new (server_api_version);
3658+
mongoc_server_api_strict (server_api, false);
3659+
3660+
mongoc_client_set_server_api (client, server_api, &error);
3661+
/* End Versioned API Example 3 */
3662+
}
3663+
3664+
static void
3665+
_test_sample_versioned_api_example_4 (void)
3666+
{
3667+
/* Start Versioned API Example 4 */
3668+
mongoc_client_t *client = NULL;
3669+
mongoc_server_api_t *server_api = NULL;
3670+
mongoc_server_api_version_t server_api_version;
3671+
bson_error_t error;
3672+
3673+
/* For a replica set, include the replica set name and a seedlist of the
3674+
* members in the URI string; e.g.
3675+
* uri_repl = "mongodb://mongodb0.example.com:27017,mongodb1.example.com:" \
3676+
* "27017/?replicaSet=myRepl";
3677+
* client = test_framework_client_new (uri_repl);
3678+
* For a sharded cluster, connect to the mongos instances; e.g.
3679+
* uri_sharded =
3680+
* "mongodb://mongos0.example.com:27017,mongos1.example.com:27017/";
3681+
* client = test_framework_client_new (uri_sharded);
3682+
*/
3683+
3684+
client = get_client ();
3685+
3686+
mongoc_server_api_version_from_string ("1", &server_api_version);
3687+
server_api = mongoc_server_api_new (server_api_version);
3688+
mongoc_server_api_deprecation_errors (server_api, true);
3689+
3690+
mongoc_client_set_server_api (client, server_api, &error);
3691+
/* End Versioned API Example 4 */
3692+
}
3693+
3694+
static void
3695+
test_sample_versioned_api (void)
3696+
{
3697+
_test_sample_versioned_api_example_1 ();
3698+
_test_sample_versioned_api_example_2 ();
3699+
_test_sample_versioned_api_example_3 ();
3700+
_test_sample_versioned_api_example_4 ();
3701+
}
3702+
35753703
static void
35763704
test_sample_commands (void)
35773705
{
@@ -3648,6 +3776,7 @@ test_sample_commands (void)
36483776
if (!test_framework_max_wire_version_at_least (WIRE_VERSION_4_4)) {
36493777
test_sample_txn_commands (client);
36503778
}
3779+
test_sample_versioned_api ();
36513780

36523781
mongoc_collection_drop (collection, NULL);
36533782

0 commit comments

Comments
 (0)