diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/README.rst b/driver-core/src/test/resources/initial-dns-seedlist-discovery/README.rst index 0e6404aa5b5..e8b33936845 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/README.rst +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/README.rst @@ -14,8 +14,9 @@ replica set name ``repl0``. The tests in the ``load-balanced`` directory MUST be executed against a load-balanced sharded cluster with the mongos servers running on localhost ports -27017 and 27018 (corresponding to the script in `drivers-evergreen-tools`_). The -load balancers, shard servers, and config servers may run on any open ports. +27017 and 27018 and ``--loadBalancerPort`` 27050 and 27051, respectively +(corresponding to the script in `drivers-evergreen-tools`_). The load balancers, +shard servers, and config servers may run on any open ports. .. _`drivers-evergreen-tools`: https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/run-load-balancer.sh @@ -56,7 +57,9 @@ these tests:: _mongodb._tcp.test19.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc. _mongodb._tcp.test20.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc. _mongodb._tcp.test21.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc. - _customname._tcp.test22.test.build.10gen.cc 86400 IN SRV 27017 localhost.test.build.10gen.cc + _customname._tcp.test22.test.build.10gen.cc 86400 IN SRV 27017 localhost.test.build.10gen.cc. + _mongodb._tcp.test23.test.build.10gen.cc. 86400 IN SRV 8000 localhost.test.build.10gen.cc. + _mongodb._tcp.test24.test.build.10gen.cc. 86400 IN SRV 8000 localhost.test.build.10gen.cc. Record TTL Class Text test5.test.build.10gen.cc. 86400 IN TXT "replicaSet=repl0&authSource=thisDB" @@ -68,12 +71,18 @@ these tests:: test11.test.build.10gen.cc. 86400 IN TXT "replicaS" "et=rep" "l0" test20.test.build.10gen.cc. 86400 IN TXT "loadBalanced=true" test21.test.build.10gen.cc. 86400 IN TXT "loadBalanced=false" + test24.test.build.10gen.cc. 86400 IN TXT "loadBalanced=true" -Note that ``test4`` is omitted deliberately to test what happens with no SRV -record. ``test9`` is missing because it was deleted during the development of -the tests. The missing ``test.`` sub-domain in the SRV record target for -``test12`` is deliberate. ``test22`` is used to test a custom service name -(``customname``). +Notes: + +- ``test4`` is omitted deliberately to test what happens with no SRV record. +- ``test9`` is missing because it was deleted during the development of the + tests. +- The missing ``test.`` sub-domain in the SRV record target for ``test12`` is + deliberate. +- ``test22`` is used to test a custom service name (``customname``). +- ``test23`` and ``test24`` point to port 8000 (HAProxy) and are used for + load-balanced tests. In our tests we have used ``localhost.test.build.10gen.cc`` as the domain, and then configured ``localhost.test.build.10gen.cc`` to resolve to 127.0.0.1. @@ -105,31 +114,51 @@ These YAML and JSON files contain the following fields: - ``error``: indicates that the parsing of the URI, or the resolving or contents of the SRV or TXT records included errors. - ``comment``: a comment to indicate why a test would fail. +- ``ping``: if false, the test runner should not run a "ping" operation. .. _`Connection String`: ../../connection-string/connection-string-spec.rst .. _`URI options`: ../../uri-options/uri-options.rst -For each file, create a MongoClient initialized with the ``mongodb+srv`` -connection string. - -If ``seeds`` is specified, drivers SHOULD verify that the set of hosts in the -client's initial seedlist matches the list in ``seeds``. If ``numSeeds`` is -specified, drivers SHOULD verify that the size of that set matches ``numSeeds``. - -If ``hosts`` is specified, drivers MUST verify that the set of -ServerDescriptions in the client's TopologyDescription eventually matches the -list in ``hosts``. If ``numHosts`` is specified, drivers MUST verify that the -size of that set matches ``numHosts``. - -If ``options`` is specified, drivers MUST verify each of the values under -``options`` match the MongoClient's parsed value for that option. There may be -other options parsed by the MongoClient as well, which a test does not verify. - -If ``parsed_options`` is specified, drivers MUST verify that each of the values -under ``parsed_options`` match the MongoClient's parsed value for that option. -Supported values include, but are not limited to, ``user`` and ``password`` -(parsed from ``UserInfo``) and ``auth_database`` (parsed from -``Auth database``). - -If ``error`` is specified and ``true``, drivers MUST verify that an error has -been thrown. +For each YAML file: + +- Create a MongoClient initialized with the ``mongodb+srv`` + connection string. +- Run a "ping" operation unless ``ping`` is false or ``error`` is true. + +Assertions: + +- If ``seeds`` is specified, drivers SHOULD verify that the set of hosts in the + client's initial seedlist matches the list in ``seeds``. If ``numSeeds`` is + specified, drivers SHOULD verify that the size of that set matches + ``numSeeds``. + +- If ``hosts`` is specified, drivers MUST verify that the set of + ServerDescriptions in the client's TopologyDescription eventually matches the + list in ``hosts``. If ``numHosts`` is specified, drivers MUST verify that the + size of that set matches ``numHosts``. + +- If ``options`` is specified, drivers MUST verify each of the values under + ``options`` match the MongoClient's parsed value for that option. There may be + other options parsed by the MongoClient as well, which a test does not verify. + +- If ``parsed_options`` is specified, drivers MUST verify that each of the + values under ``parsed_options`` match the MongoClient's parsed value for that + option. Supported values include, but are not limited to, ``user`` and + ``password`` (parsed from ``UserInfo``) and ``auth_database`` (parsed from + ``Auth database``). + +- If ``error`` is specified and ``true``, drivers MUST verify that initializing + the MongoClient throws an error. If ``error`` is not specified or is + ``false``, both initializing the MongoClient and running a ping operation must + succeed without throwing any errors. + +- If ``ping`` is not specified or ``true``, drivers MUST verify that running a + "ping" operation using the initialized MongoClient succeeds. If ``ping`` is + ``false``, drivers MUST NOT run a "ping" operation. + + **Note:** These tests are expected to be run against MongoDB databases with + and without authentication enabled. The "ping" operation does not require + authentication so should succeed with URIs that contain no userinfo (i.e. + no username and password). Tests with URIs that contain userinfo always set + ``ping`` to ``false`` because some drivers will fail handshake on a + connection if userinfo is provided but incorrect. diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json index 7f41932bb2f..6135defcdfe 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json @@ -1,14 +1,15 @@ { - "uri": "mongodb+srv://test20.test.build.10gen.cc/?directConnection=false", - "seeds": [ - "localhost.test.build.10gen.cc:27017" + "uri" : "mongodb+srv://test24.test.build.10gen.cc/?directConnection=false", + "seeds" : [ + "localhost.test.build.10gen.cc:8000" ], - "hosts": [ - "localhost.test.build.10gen.cc:27017" + "hosts" : [ + "localhost.test.build.10gen.cc:8000" ], - "options": { - "loadBalanced": true, - "ssl": true, - "directConnection": false - } + "options" : { + "loadBalanced" : true, + "ssl" : true, + "directConnection" : false + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-replicaSet-errors.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-replicaSet-errors.json index 9ed5ff22c22..b68fb6741db 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-replicaSet-errors.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-replicaSet-errors.json @@ -1,7 +1,7 @@ { - "uri": "mongodb+srv://test20.test.build.10gen.cc/?replicaSet=replset", - "seeds": [], - "hosts": [], - "error": true, - "comment": "Should fail because loadBalanced=true is incompatible with replicaSet" + "uri" : "mongodb+srv://test24.test.build.10gen.cc/?replicaSet=replset", + "seeds" : [], + "hosts" : [], + "error" : true, + "comment" : "Should fail because loadBalanced=true is incompatible with replicaSet" } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json index 0117b3e9cba..bdeef6508f7 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json @@ -1,13 +1,14 @@ { - "uri": "mongodb+srv://test20.test.build.10gen.cc/", - "seeds": [ - "localhost.test.build.10gen.cc:27017" + "uri" : "mongodb+srv://test24.test.build.10gen.cc/", + "seeds" : [ + "localhost.test.build.10gen.cc:8000" ], - "hosts": [ - "localhost.test.build.10gen.cc:27017" + "hosts" : [ + "localhost.test.build.10gen.cc:8000" ], - "options": { - "loadBalanced": true, - "ssl": true - } + "options" : { + "loadBalanced" : true, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-conflicts_with_loadBalanced-true-txt.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-conflicts_with_loadBalanced-true-txt.json index a7600a8a7b1..bec6458f432 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-conflicts_with_loadBalanced-true-txt.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-conflicts_with_loadBalanced-true-txt.json @@ -1,7 +1,7 @@ { - "uri": "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=1", - "seeds": [], - "hosts": [], - "error": true, - "comment": "Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true (TXT)" + "uri" : "mongodb+srv://test24.test.build.10gen.cc/?srvMaxHosts=1", + "seeds" : [], + "hosts" : [], + "error" : true, + "comment" : "Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true (TXT)" } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json index 8d48b5bbb93..36399de6a06 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json @@ -1,14 +1,15 @@ { - "uri": "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=0", - "seeds": [ - "localhost.test.build.10gen.cc:27017" + "uri" : "mongodb+srv://test24.test.build.10gen.cc/?srvMaxHosts=0", + "seeds" : [ + "localhost.test.build.10gen.cc:8000" ], - "hosts": [ - "localhost.test.build.10gen.cc:27017" + "hosts" : [ + "localhost.test.build.10gen.cc:8000" ], - "options": { - "loadBalanced": true, - "srvMaxHosts": 0, - "ssl": true - } + "options" : { + "loadBalanced" : true, + "srvMaxHosts" : 0, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json index 2382fccf852..f286437c049 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json @@ -1,14 +1,15 @@ { - "uri": "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=0", - "seeds": [ - "localhost.test.build.10gen.cc:27017" + "uri" : "mongodb+srv://test23.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=0", + "seeds" : [ + "localhost.test.build.10gen.cc:8000" ], - "hosts": [ - "localhost.test.build.10gen.cc:27017" + "hosts" : [ + "localhost.test.build.10gen.cc:8000" ], - "options": { - "loadBalanced": true, - "srvMaxHosts": 0, - "ssl": true - } + "options" : { + "loadBalanced" : true, + "srvMaxHosts" : 0, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json index 1d57bdcb3c8..1db505aa0de 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json @@ -3,13 +3,14 @@ "seeds": [ "localhost.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "ssl": true, - "directConnection": false - } + "options" : { + "ssl" : true, + "directConnection" : false + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json index 70c6c23a39c..f916d450b7c 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json @@ -8,14 +8,15 @@ "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "ssl": true + "options" : { + "replicaSet" : "repl0", + "ssl" : true }, - "parsed_options": { - "user": "b*b@f3tt=", - "password": "$4to@L8=MC", - "db": "mydb?" + "parsed_options" : { + "user" : "b*b@f3tt=", + "password" : "$4to@L8=MC", + "db" : "mydb?" }, - "comment": "Encoded user, pass, and DB parse correctly" + "ping" : false, + "comment" : "Encoded user, pass, and DB parse correctly" } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json index fd2e565c7b6..f9e1b1d4a3d 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json @@ -3,13 +3,14 @@ "seeds": [ "localhost.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "loadBalanced": false, - "ssl": true - } + "options" : { + "loadBalanced" : false, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json index 9a8267eaeb1..c77bd7c5e46 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json @@ -3,14 +3,15 @@ "seeds": [ "localhost.sub.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "ssl": true + "options" : { + "replicaSet" : "repl0", + "ssl" : true }, - "comment": "Is correct, as returned host name shared the URI root \"test.build.10gen.cc\"." + "ping" : true, + "comment" : "Is correct, as returned host name shared the URI root \"test.build.10gen.cc\"." } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json index cebb3b1ec32..845a0259eca 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json @@ -3,13 +3,14 @@ "seeds": [ "localhost.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "ssl": true - } + "options" : { + "replicaSet" : "repl0", + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json index 622668c351f..621330229f5 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json @@ -3,13 +3,14 @@ "seeds": [ "localhost.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "ssl": true - } + "options" : { + "replicaSet" : "repl0", + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-txt-record.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-txt-record.json index 2385021ad4b..d842f6d53cd 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-txt-record.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/one-txt-record.json @@ -3,14 +3,15 @@ "seeds": [ "localhost.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "authSource": "thisDB", - "ssl": true - } + "options" : { + "replicaSet" : "repl0", + "authSource" : "thisDB", + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srv-service-name.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srv-service-name.json index ec36cdbb00c..51cfe2b033f 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srv-service-name.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srv-service-name.json @@ -4,13 +4,14 @@ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "ssl": true, - "srvServiceName": "customname" - } + "options" : { + "ssl" : true, + "srvServiceName" : "customname" + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json index d9765ac6631..3fb18a29d5c 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json @@ -5,13 +5,14 @@ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "srvMaxHosts": 2, - "ssl": true - } + "options" : { + "srvMaxHosts" : 2, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json index 494bb87687a..eac9d0461fa 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json @@ -4,13 +4,14 @@ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "srvMaxHosts": 3, - "ssl": true - } + "options" : { + "srvMaxHosts" : 3, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json index de56350be4c..e473053bb8c 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json @@ -1,13 +1,14 @@ - { - "uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1", - "numSeeds": 1, - "hosts": [ - "localhost:27017", - "localhost:27018", - "localhost:27019" - ], - "options": { - "srvMaxHosts": 1, - "ssl": true - } - } +{ + "uri" : "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1", + "numSeeds" : 1, + "hosts" : [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options" : { + "srvMaxHosts" : 1, + "ssl" : true + }, + "ping" : true +} diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json index 241a901c649..bf94de00e0e 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json @@ -3,15 +3,16 @@ "seeds": [ "localhost.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "authSource": "thisDB", - "replicaSet": "repl0", - "srvMaxHosts": 0, - "ssl": true - } + "options" : { + "authSource" : "thisDB", + "replicaSet" : "repl0", + "srvMaxHosts" : 0, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.json index c68610a2012..04e39d64452 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.json @@ -4,14 +4,15 @@ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "srvMaxHosts": 0, - "ssl": true - } + "options" : { + "replicaSet" : "repl0", + "srvMaxHosts" : 0, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/two-results-default-port.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/two-results-default-port.json index 66028310a6d..053e6b9050a 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/two-results-default-port.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/two-results-default-port.json @@ -4,13 +4,14 @@ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "ssl": true - } + "options" : { + "replicaSet" : "repl0", + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.json index 4900f7cff1c..0d4de148638 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.json @@ -4,13 +4,14 @@ "localhost.test.build.10gen.cc:27018", "localhost.test.build.10gen.cc:27019" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "ssl": true - } + "options" : { + "replicaSet" : "repl0", + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.json index 0ebc737bd5f..27a7c475bad 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.json @@ -3,14 +3,15 @@ "seeds": [ "localhost.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "authSource": "thisDB", - "ssl": false - } + "options" : { + "replicaSet" : "repl0", + "authSource" : "thisDB", + "ssl" : false + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.json index 2626ba60839..434c6e90c41 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.json @@ -3,14 +3,15 @@ "seeds": [ "localhost.test.build.10gen.cc:27017" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "authSource": "otherDB", - "ssl": true - } + "options" : { + "replicaSet" : "repl0", + "authSource" : "otherDB", + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.json index 32710d75f77..c898bce909f 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.json @@ -9,11 +9,12 @@ "localhost:27018", "localhost:27019" ], - "options": { - "replicaSet": "repl0", - "ssl": true + "options" : { + "replicaSet" : "repl0", + "ssl" : true }, - "parsed_options": { - "auth_database": "adminDB" - } + "parsed_options" : { + "auth_database" : "adminDB" + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/uri-with-auth.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/uri-with-auth.json index cc7257d85ba..acd24ba2e6a 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/uri-with-auth.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/uri-with-auth.json @@ -1,17 +1,22 @@ { - "uri": "mongodb+srv://auser:apass@test1.test.build.10gen.cc/?replicaSet=repl0", - "seeds": [ + "uri" : "mongodb+srv://auser:apass@test1.test.build.10gen.cc/?replicaSet=repl0", + "seeds" : [ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost:27017", "localhost:27018", "localhost:27019" ], - "parsed_options": { - "user": "auser", - "password": "apass" + "options" : { + "replicaSet" : "repl0", + "ssl" : true }, - "comment": "Should preserve auth credentials" + "parsed_options" : { + "user" : "auser", + "password" : "apass" + }, + "ping" : false, + "comment" : "Should preserve auth credentials" } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.json index 46390726f0d..4d3c6d8a2b4 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.json @@ -5,12 +5,13 @@ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "options": { - "srvMaxHosts": 2, - "ssl": true - } + "options" : { + "srvMaxHosts" : 2, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.json index e02d72bf280..acf35fda5a2 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.json @@ -4,12 +4,13 @@ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "options": { - "srvMaxHosts": 3, - "ssl": true - } + "options" : { + "srvMaxHosts" : 3, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.json index fdcc1692c0f..62995464182 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.json @@ -1,9 +1,10 @@ { - "uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1", - "numSeeds": 1, - "numHosts": 1, - "options": { - "srvMaxHosts": 1, - "ssl": true - } + "uri" : "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1", + "numSeeds" : 1, + "numHosts" : 1, + "options" : { + "srvMaxHosts" : 1, + "ssl" : true + }, + "ping" : true } diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.json index 10ab9e656dc..06743c819c8 100644 --- a/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.json +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.json @@ -4,12 +4,13 @@ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "hosts": [ + "hosts" : [ "localhost.test.build.10gen.cc:27017", "localhost.test.build.10gen.cc:27018" ], - "options": { - "srvMaxHosts": 0, - "ssl": true - } + "options" : { + "srvMaxHosts" : 0, + "ssl" : true + }, + "ping" : true } diff --git a/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ReactiveInitialDnsSeedlistDiscoveryTest.java b/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ReactiveInitialDnsSeedlistDiscoveryTest.java index 59027010302..fbaf932fdda 100644 --- a/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ReactiveInitialDnsSeedlistDiscoveryTest.java +++ b/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ReactiveInitialDnsSeedlistDiscoveryTest.java @@ -34,8 +34,9 @@ public class ReactiveInitialDnsSeedlistDiscoveryTest extends InitialDnsSeedlistD public ReactiveInitialDnsSeedlistDiscoveryTest(final String filename, final Path parentDirectory, final String uri, final List seeds, final Integer numSeeds, final List hosts, final Integer numHosts, - final boolean isError, final BsonDocument options) { - super(filename, parentDirectory, uri, seeds, numSeeds, hosts, numHosts, isError, options); + final BsonDocument options, final BsonDocument parsedOptions, + final boolean isError, final boolean executePingCommand) { + super(filename, parentDirectory, uri, seeds, numSeeds, hosts, numHosts, options, parsedOptions, isError, executePingCommand); } @Override diff --git a/driver-sync/src/test/functional/com/mongodb/client/InitialDnsSeedlistDiscoveryTest.java b/driver-sync/src/test/functional/com/mongodb/client/InitialDnsSeedlistDiscoveryTest.java index 0e58127cd4e..7766b94f348 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/InitialDnsSeedlistDiscoveryTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/InitialDnsSeedlistDiscoveryTest.java @@ -17,7 +17,6 @@ package com.mongodb.client; import com.mongodb.Block; -import com.mongodb.ClusterFixture; import com.mongodb.ConnectionString; import com.mongodb.MongoClientException; import com.mongodb.MongoClientSettings; @@ -27,10 +26,8 @@ import com.mongodb.connection.ClusterSettings; import com.mongodb.connection.ServerDescription; import com.mongodb.connection.SslSettings; -import com.mongodb.event.ClusterClosedEvent; import com.mongodb.event.ClusterDescriptionChangedEvent; import com.mongodb.event.ClusterListener; -import com.mongodb.event.ClusterOpeningEvent; import com.mongodb.lang.Nullable; import org.bson.BsonArray; import org.bson.BsonBoolean; @@ -62,6 +59,7 @@ import static com.mongodb.ClusterFixture.isLoadBalanced; import static com.mongodb.ClusterFixture.isServerlessTest; import static com.mongodb.ClusterFixture.isSharded; +import static java.util.Objects.requireNonNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -81,27 +79,34 @@ public abstract class InitialDnsSeedlistDiscoveryTest { private final List hosts; @Nullable private final Integer numHosts; - private final boolean isError; private final BsonDocument options; + private final BsonDocument parsedOptions; + private final boolean isError; + private final boolean executePingCommand; public InitialDnsSeedlistDiscoveryTest(@SuppressWarnings("unused") final String filename, final Path parentDirectory, final String uri, @Nullable final List seeds, @Nullable final Integer numSeeds, @Nullable final List hosts, @Nullable final Integer numHosts, - final boolean isError, final BsonDocument options) { + final BsonDocument options, final BsonDocument parsedOptions, + final boolean isError, final boolean executePingCommand) { this.parentDirectory = parentDirectory; this.uri = uri; this.seeds = seeds; this.numSeeds = numSeeds; this.hosts = hosts; this.numHosts = numHosts; + this.parsedOptions = parsedOptions; this.isError = isError; this.options = options; + this.executePingCommand = executePingCommand; } public abstract MongoClient createMongoClient(MongoClientSettings settings); @Before public void setUp() { + assumeFalse(isServerlessTest()); + if (parentDirectory.endsWith("replica-set")) { assumeTrue(isDiscoverableReplicaSet()); } else if (parentDirectory.endsWith("load-balanced")) { @@ -114,111 +119,77 @@ public void setUp() { } @Test - public void shouldResolveTxtRecord() throws InterruptedException { - + public void shouldPassAllOutcomes() throws InterruptedException { if (isError) { - MongoClient client = null; - try { - final AtomicReference exceptionReference = new AtomicReference<>(); - final CountDownLatch latch = new CountDownLatch(1); + assertErrorCondition(); + } else { + assertNonErrorCondition(); + } + } + + public void assertErrorCondition() throws InterruptedException { + final AtomicReference exceptionReference = new AtomicReference<>(); + final CountDownLatch latch = new CountDownLatch(1); - ConnectionString connectionString; - MongoClientSettings settings; + ConnectionString connectionString; + MongoClientSettings settings; + try { + connectionString = new ConnectionString(uri); + final SslSettings sslSettings = getSslSettings(connectionString); + assumeTrue("SSL settings don't match", getSslSettings().isEnabled() == sslSettings.isEnabled()); + settings = MongoClientSettings.builder().applyConnectionString(connectionString) + .applyToSslSettings(builder -> { + builder.applySettings(sslSettings); + builder.invalidHostNameAllowed(true); + }) + .applyToClusterSettings(builder -> { + builder.serverSelectionTimeout(5, TimeUnit.SECONDS); + builder.addClusterListener(new ClusterListener() { + @Override + public void clusterDescriptionChanged(final ClusterDescriptionChangedEvent event) { + if (event.getNewDescription().getSrvResolutionException() != null) { + exceptionReference.set(event.getNewDescription().getSrvResolutionException()); + latch.countDown(); + } + } + }); + }) + .build(); + } catch (MongoClientException | IllegalArgumentException e) { + // all good + return; + } + try (MongoClient client = createMongoClient(settings)) { + // Load balancing mode has special rules regarding cluster event publishing, so we can't rely on those here. + // Instead, we just try to execute an operation and assert that it throws + if (settings.getClusterSettings().getMode() == ClusterConnectionMode.LOAD_BALANCED) { try { - connectionString = new ConnectionString(uri); - final SslSettings sslSettings = getSslSettings(connectionString); - assumeTrue("SSL settings don't match", getSslSettings().isEnabled() == sslSettings.isEnabled()); - settings = MongoClientSettings.builder().applyConnectionString(connectionString) - .applyToSslSettings(builder -> { - builder.applySettings(sslSettings); - builder.invalidHostNameAllowed(true); - }) - .applyToClusterSettings(builder -> { - builder.serverSelectionTimeout(5, TimeUnit.SECONDS); - builder.addClusterListener(new ClusterListener() { - @Override - public void clusterDescriptionChanged(final ClusterDescriptionChangedEvent event) { - if (event.getNewDescription().getSrvResolutionException() != null) { - exceptionReference.set(event.getNewDescription().getSrvResolutionException()); - latch.countDown(); - } - } - }); - }) - .build(); - } catch (MongoClientException | IllegalArgumentException e) { + client.getDatabase("admin").runCommand(new Document("ping", 1)); + } catch (MongoClientException e) { // all good - return; } - client = createMongoClient(settings); - // Load balancing mode has special rules regarding cluster event publishing, so we can't rely on those here. - // Instead, we just try to execute an operation and assert that it throws - if (settings.getClusterSettings().getMode() == ClusterConnectionMode.LOAD_BALANCED) { - try { - client.getDatabase("admin").runCommand(new Document("ping", 1)); - } catch (MongoClientException e) { - // all good - } - } else { - if (!latch.await(5, TimeUnit.SECONDS)) { - fail("Failed to capture SRV resolution exception"); - } - try { - throw exceptionReference.get(); - } catch (MongoClientException e) { - // all good - } - } - } finally { - if (client != null) { - client.close(); + } else { + if (!latch.await(5, TimeUnit.SECONDS)) { + fail("Failed to capture SRV resolution exception"); } - } - } else { - ConnectionString connectionString = new ConnectionString(this.uri); - - for (Map.Entry entry : options.entrySet()) { - switch (entry.getKey()) { - case "replicaSet": - assertEquals(entry.getValue().asString().getValue(), connectionString.getRequiredReplicaSetName()); - break; - case "ssl": - assertEquals(entry.getValue().asBoolean().getValue(), connectionString.getSslEnabled()); - break; - case "authSource": - // ignoring authSource for now, because without at least a userName also in the connection string, - // the authSource is ignored. If the test gets this far, at least we know that a TXT record - // containing in authSource doesn't blow up. We just don't test that it's actually used. - assertTrue(true); - break; - case "directConnection": - assertEquals(entry.getValue().asBoolean().getValue(), connectionString.isDirectConnection()); - break; - case "loadBalanced": - assertEquals(entry.getValue().asBoolean().getValue(), connectionString.isLoadBalanced()); - break; - case "srvMaxHosts": - assertEquals(Integer.valueOf(entry.getValue().asInt32().getValue()), connectionString.getSrvMaxHosts()); - break; - case "srvServiceName": - assertEquals(entry.getValue().asString().getValue(), connectionString.getSrvServiceName()); - break; - default: - throw new UnsupportedOperationException("No support configured yet for " + entry.getKey()); + try { + throw exceptionReference.get(); + } catch (MongoClientException e) { + // all good } } } } - @Test - public void shouldDiscoverSrvRecord() throws InterruptedException { - assumeFalse(isServerlessTest()); - assumeFalse(isError); + private void assertNonErrorCondition() throws InterruptedException { + CountDownLatch seedsLatch = new CountDownLatch(1); + CountDownLatch hostsLatch = new CountDownLatch(1); + ConnectionString connectionString = new ConnectionString(uri); + + assertOptions(connectionString); + assertParsedOptions(connectionString); - final CountDownLatch seedsLatch = new CountDownLatch(1); - final CountDownLatch hostsLatch = new CountDownLatch(1); - final ConnectionString connectionString = new ConnectionString(uri); - final SslSettings sslSettings = getSslSettings(connectionString); + SslSettings sslSettings = getSslSettings(connectionString); assumeTrue("SSL settings don't match", getSslSettings().isEnabled() == sslSettings.isEnabled()); @@ -228,14 +199,6 @@ public void shouldDiscoverSrvRecord() throws InterruptedException { public void apply(final ClusterSettings.Builder builder) { builder.applyConnectionString(connectionString) .addClusterListener(new ClusterListener() { - @Override - public void clusterOpening(final ClusterOpeningEvent event) { - } - - @Override - public void clusterClosed(final ClusterClosedEvent event) { - } - @Override public void clusterDescriptionChanged(final ClusterDescriptionChangedEvent event) { List seedsList = event.getNewDescription().getServerDescriptions() @@ -273,12 +236,74 @@ private void hostsCheck(final List actual, @Nullable final List .build(); try (MongoClient client = createMongoClient(settings)) { - assertTrue(seedsLatch.await(ClusterFixture.TIMEOUT, TimeUnit.SECONDS)); - assertTrue(hostsLatch.await(ClusterFixture.TIMEOUT, TimeUnit.SECONDS)); - assertTrue(client.getDatabase("admin").runCommand(new Document("ping", 1)).containsKey("ok")); + assertTrue(seedsLatch.await(10, TimeUnit.SECONDS)); + assertTrue(hostsLatch.await(10, TimeUnit.SECONDS)); + if (executePingCommand) { + assertTrue(client.getDatabase("admin").runCommand(new Document("ping", 1)).containsKey("ok")); + } + } + } + + private void assertOptions(final ConnectionString connectionString) { + for (Map.Entry entry : options.entrySet()) { + switch (entry.getKey()) { + case "replicaSet": + assertEquals(entry.getValue().asString().getValue(), connectionString.getRequiredReplicaSetName()); + break; + case "ssl": + assertEquals(entry.getValue().asBoolean().getValue(), connectionString.getSslEnabled()); + break; + case "authSource": + // ignoring authSource for now, because without at least a userName also in the connection string, + // the authSource is ignored. If the test gets this far, at least we know that a TXT record + // containing in authSource doesn't blow up. We just don't test that it's actually used. + assertTrue(true); + break; + case "directConnection": + assertEquals(entry.getValue().asBoolean().getValue(), connectionString.isDirectConnection()); + break; + case "loadBalanced": + assertEquals(entry.getValue().asBoolean().getValue(), connectionString.isLoadBalanced()); + break; + case "srvMaxHosts": + assertEquals(Integer.valueOf(entry.getValue().asInt32().getValue()), connectionString.getSrvMaxHosts()); + break; + case "srvServiceName": + assertEquals(entry.getValue().asString().getValue(), connectionString.getSrvServiceName()); + break; + default: + throw new UnsupportedOperationException("No support configured yet for " + entry.getKey()); + } } } + private void assertParsedOptions(final ConnectionString connectionString) { + for (Map.Entry entry : parsedOptions.entrySet()) { + switch (entry.getKey()) { + case "db": + assertEquals(entry.getValue().asString().getValue(), connectionString.getDatabase()); + break; + case "user": + String userName = requireNonNull(connectionString.getCredential()).getUserName(); + assertEquals(entry.getValue().asString().getValue(), userName); + break; + case "password": + String password = new String(requireNonNull(requireNonNull(connectionString.getCredential()).getPassword())); + assertEquals(entry.getValue().asString().getValue(), password); + break; + case "auth_database": + String source = connectionString.getCredential() == null + ? connectionString.getDatabase() + : connectionString.getCredential().getSource(); + assertEquals(entry.getValue().asString().getValue(), source); + break; + default: + throw new UnsupportedOperationException("No support configured yet for " + entry.getKey()); + } + } + } + + @Parameterized.Parameters(name = "{0}") public static Collection data() throws URISyntaxException, IOException { List data = new ArrayList<>(); @@ -292,8 +317,10 @@ public static Collection data() throws URISyntaxException, IOException toInteger(testDocument.getNumber("numSeeds", null)), toStringList(testDocument.getArray("hosts", null)), toInteger(testDocument.getNumber("numHosts", null)), + testDocument.getDocument("options", new BsonDocument()), + testDocument.getDocument("parsed_options", new BsonDocument()), testDocument.getBoolean("error", BsonBoolean.FALSE).getValue(), - testDocument.getDocument("options", new BsonDocument()) + testDocument.getBoolean("ping", BsonBoolean.TRUE).getValue() }); } diff --git a/driver-sync/src/test/functional/com/mongodb/client/SyncInitialDnsSeedlistDiscoveryTest.java b/driver-sync/src/test/functional/com/mongodb/client/SyncInitialDnsSeedlistDiscoveryTest.java index 8e34b18fd16..d3750434ea6 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/SyncInitialDnsSeedlistDiscoveryTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/SyncInitialDnsSeedlistDiscoveryTest.java @@ -25,8 +25,9 @@ public class SyncInitialDnsSeedlistDiscoveryTest extends InitialDnsSeedlistDiscoveryTest { public SyncInitialDnsSeedlistDiscoveryTest(final String filename, final Path parentDirectory, final String uri, final List seeds, final Integer numSeeds, final List hosts, final Integer numHosts, - final boolean isError, final BsonDocument options) { - super(filename, parentDirectory, uri, seeds, numSeeds, hosts, numHosts, isError, options); + final BsonDocument options, final BsonDocument parsedOptions, + final boolean isError, final boolean executePingCommand) { + super(filename, parentDirectory, uri, seeds, numSeeds, hosts, numHosts, options, parsedOptions, isError, executePingCommand); } @Override