From b4e009590ed9659a3861f5cd1c6d5839e1e1ee30 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Wed, 17 Aug 2022 18:01:25 -0400 Subject: [PATCH] Replace existing SDAM integration spec tests with unified tests JAVA-4658 --- config/checkstyle/suppressions.xml | 2 + .../auth-error.json | 140 ----- .../auth-misc-command-error.json | 140 ----- .../auth-network-error.json | 140 ----- .../auth-network-timeout-error.json | 143 ----- .../auth-shutdown-error.json | 140 ----- .../cancel-server-check.json | 130 ----- .../connectTimeoutMS.json | 149 ----- .../find-network-error.json | 144 ----- .../find-network-timeout-error.json | 119 ---- .../find-shutdown-error.json | 168 ------ .../hello-command-error.json | 223 -------- .../hello-network-error.json | 219 -------- .../hello-timeout.json | 337 ------------ .../insert-network-error.json | 156 ------ .../insert-shutdown-error.json | 167 ------ .../minPoolSize-error.json | 102 ---- .../rediscover-quickly-after-step-down.json | 165 ------ .../auth-error.json | 230 ++++++++ .../auth-misc-command-error.json | 230 ++++++++ .../auth-network-error.json | 230 ++++++++ .../auth-network-timeout-error.json | 233 ++++++++ .../auth-shutdown-error.json | 230 ++++++++ .../cancel-server-check.json | 201 +++++++ .../connectTimeoutMS.json | 221 ++++++++ .../find-network-error.json | 234 ++++++++ .../find-network-timeout-error.json | 199 +++++++ .../find-shutdown-error.json | 251 +++++++++ .../hello-command-error.json | 376 +++++++++++++ .../hello-network-error.json | 346 ++++++++++++ .../hello-timeout.json | 514 ++++++++++++++++++ .../insert-network-error.json | 246 +++++++++ .../insert-shutdown-error.json | 250 +++++++++ .../minPoolSize-error.json | 177 ++++++ .../pool-cleared-error.json | 204 ++++--- .../rediscover-quickly-after-step-down.json | 242 +++++++++ .../connection/TestServerListener.java | 60 +- .../ServerDiscoveryAndMonitoringTest.java | 45 -- ...ifiedServerDiscoveryAndMonitoringTest.java | 41 ++ ...tractServerDiscoveryAndMonitoringTest.java | 61 --- .../ServerDiscoveryAndMonitoringTest.java | 38 -- .../client/unified/ContextElement.java | 68 +++ .../com/mongodb/client/unified/Entities.java | 78 ++- .../mongodb/client/unified/EventMatcher.java | 108 ++++ .../client/unified/UnifiedCrudHelper.java | 15 +- ...ifiedServerDiscoveryAndMonitoringTest.java | 41 ++ .../mongodb/client/unified/UnifiedTest.java | 316 +++++++++-- 47 files changed, 5224 insertions(+), 3045 deletions(-) delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-misc-command-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-network-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-network-timeout-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-shutdown-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/cancel-server-check.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/connectTimeoutMS.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-network-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-network-timeout-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-shutdown-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-command-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-network-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-timeout.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/insert-network-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/insert-shutdown-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/minPoolSize-error.json delete mode 100644 driver-core/src/test/resources/server-discovery-and-monitoring-integration/rediscover-quickly-after-step-down.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-misc-command-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-network-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-network-timeout-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-shutdown-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/cancel-server-check.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/connectTimeoutMS.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-network-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-network-timeout-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-shutdown-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-command-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-network-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-timeout.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/insert-network-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/insert-shutdown-error.json create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/minPoolSize-error.json rename driver-core/src/test/resources/{server-discovery-and-monitoring-integration => unified-test-format/server-discovery-and-monitoring}/pool-cleared-error.json (60%) create mode 100644 driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/rediscover-quickly-after-step-down.json delete mode 100644 driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ServerDiscoveryAndMonitoringTest.java create mode 100644 driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java delete mode 100644 driver-sync/src/test/functional/com/mongodb/client/AbstractServerDiscoveryAndMonitoringTest.java delete mode 100644 driver-sync/src/test/functional/com/mongodb/client/ServerDiscoveryAndMonitoringTest.java create mode 100644 driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml index 0ac0bf127af..9e0b973971a 100644 --- a/config/checkstyle/suppressions.xml +++ b/config/checkstyle/suppressions.xml @@ -34,6 +34,8 @@ + + diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-error.json deleted file mode 100644 index 064d660e321..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-error.json +++ /dev/null @@ -1,140 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4", - "authEnabled": true - } - ], - "database_name": "sdam-tests", - "collection_name": "auth-error", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Reset server and pool after AuthenticationFailure error", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "saslContinue" - ], - "appName": "authErrorTest", - "errorCode": 18 - } - }, - "clientOptions": { - "retryWrites": false, - "appname": "authErrorTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "error": true - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "auth-error", - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-misc-command-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-misc-command-error.json deleted file mode 100644 index 70dd59251df..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-misc-command-error.json +++ /dev/null @@ -1,140 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4", - "authEnabled": true - } - ], - "database_name": "sdam-tests", - "collection_name": "auth-misc-error", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Reset server and pool after misc command error", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "saslContinue" - ], - "appName": "authMiscErrorTest", - "errorCode": 1 - } - }, - "clientOptions": { - "retryWrites": false, - "appname": "authMiscErrorTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "error": true - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "auth-misc-error", - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-network-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-network-error.json deleted file mode 100644 index a75a398c5e1..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-network-error.json +++ /dev/null @@ -1,140 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4", - "authEnabled": true - } - ], - "database_name": "sdam-tests", - "collection_name": "auth-network-error", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Reset server and pool after network error during authentication", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "saslContinue" - ], - "closeConnection": true, - "appName": "authNetworkErrorTest" - } - }, - "clientOptions": { - "retryWrites": false, - "appname": "authNetworkErrorTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "error": true - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "auth-network-error", - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-network-timeout-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-network-timeout-error.json deleted file mode 100644 index a4ee7d9effd..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-network-timeout-error.json +++ /dev/null @@ -1,143 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4", - "authEnabled": true - } - ], - "database_name": "sdam-tests", - "collection_name": "auth-network-timeout-error", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Reset server and pool after network timeout error during authentication", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "saslContinue" - ], - "blockConnection": true, - "blockTimeMS": 500, - "appName": "authNetworkTimeoutErrorTest" - } - }, - "clientOptions": { - "retryWrites": false, - "appname": "authNetworkTimeoutErrorTest", - "connectTimeoutMS": 250, - "socketTimeoutMS": 250 - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "error": true - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "auth-network-timeout-error", - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-shutdown-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-shutdown-error.json deleted file mode 100644 index 2dab90e1c56..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/auth-shutdown-error.json +++ /dev/null @@ -1,140 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4", - "authEnabled": true - } - ], - "database_name": "sdam-tests", - "collection_name": "auth-shutdown-error", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Reset server and pool after shutdown error during authentication", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "saslContinue" - ], - "appName": "authShutdownErrorTest", - "errorCode": 91 - } - }, - "clientOptions": { - "retryWrites": false, - "appname": "authShutdownErrorTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "error": true - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "auth-shutdown-error", - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/cancel-server-check.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/cancel-server-check.json deleted file mode 100644 index 95863509595..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/cancel-server-check.json +++ /dev/null @@ -1,130 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.0", - "topology": [ - "replicaset" - ] - }, - { - "minServerVersion": "4.2", - "topology": [ - "sharded" - ] - } - ], - "database_name": "sdam-tests", - "collection_name": "cancel-server-check", - "data": [], - "tests": [ - { - "description": "Cancel server check", - "clientOptions": { - "retryWrites": true, - "heartbeatFrequencyMS": 10000, - "serverSelectionTimeoutMS": 5000, - "appname": "cancelServerCheckTest" - }, - "operations": [ - { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 1 - } - } - }, - { - "name": "configureFailPoint", - "object": "testRunner", - "arguments": { - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "insert" - ], - "closeConnection": true - } - } - } - }, - { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 2 - } - }, - "result": { - "insertedId": 2 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 3 - } - }, - "result": { - "insertedId": 3 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 3 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/connectTimeoutMS.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/connectTimeoutMS.json deleted file mode 100644 index 36a6dc4507e..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/connectTimeoutMS.json +++ /dev/null @@ -1,149 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4" - } - ], - "database_name": "sdam-tests", - "collection_name": "connectTimeoutMS", - "data": [], - "tests": [ - { - "description": "connectTimeoutMS=0", - "clientOptions": { - "retryWrites": false, - "connectTimeoutMS": 0, - "heartbeatFrequencyMS": 500, - "appname": "connectTimeoutMS=0" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - }, - { - "name": "configureFailPoint", - "object": "testRunner", - "arguments": { - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "hello", - "isMaster" - ], - "appName": "connectTimeoutMS=0", - "blockConnection": true, - "blockTimeMS": 550 - } - } - } - }, - { - "name": "wait", - "object": "testRunner", - "arguments": { - "ms": 750 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 0 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 0 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "connectTimeoutMS", - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "connectTimeoutMS", - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-network-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-network-error.json deleted file mode 100644 index 4db2634cd62..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-network-error.json +++ /dev/null @@ -1,144 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4" - } - ], - "database_name": "sdam-tests", - "collection_name": "find-network-error", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Reset server and pool after network error on find", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "find" - ], - "closeConnection": true, - "appName": "findNetworkErrorTest" - } - }, - "clientOptions": { - "retryWrites": false, - "retryReads": false, - "appname": "findNetworkErrorTest" - }, - "operations": [ - { - "name": "find", - "object": "collection", - "arguments": { - "filter": { - "_id": 1 - } - }, - "error": true - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "find": "find-network-error" - }, - "command_name": "find", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "find-network-error", - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-network-timeout-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-network-timeout-error.json deleted file mode 100644 index c4e10b3a764..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-network-timeout-error.json +++ /dev/null @@ -1,119 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4" - } - ], - "database_name": "sdam-tests", - "collection_name": "find-network-timeout-error", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Ignore network timeout error on find", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "find" - ], - "blockConnection": true, - "blockTimeMS": 500, - "appName": "findNetworkTimeoutErrorTest" - } - }, - "clientOptions": { - "retryWrites": false, - "retryReads": false, - "appname": "findNetworkTimeoutErrorTest", - "socketTimeoutMS": 250 - }, - "operations": [ - { - "name": "find", - "object": "collection", - "arguments": { - "filter": { - "_id": 1 - } - }, - "error": true - }, - { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 3 - } - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 0 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 0 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "find": "find-network-timeout-error" - }, - "command_name": "find", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "find-network-timeout-error", - "documents": [ - { - "_id": 3 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 3 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-shutdown-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-shutdown-error.json deleted file mode 100644 index 65de8398b13..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/find-shutdown-error.json +++ /dev/null @@ -1,168 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4" - } - ], - "database_name": "sdam-tests", - "collection_name": "find-shutdown-error", - "data": [], - "tests": [ - { - "description": "Concurrent shutdown error on find", - "clientOptions": { - "retryWrites": false, - "retryReads": false, - "heartbeatFrequencyMS": 500, - "appname": "shutdownErrorFindTest" - }, - "operations": [ - { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 1 - } - } - }, - { - "name": "configureFailPoint", - "object": "testRunner", - "arguments": { - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "find" - ], - "appName": "shutdownErrorFindTest", - "errorCode": 91, - "blockConnection": true, - "blockTimeMS": 500 - } - } - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread1" - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread2" - } - }, - { - "name": "runOnThread", - "object": "testRunner", - "arguments": { - "name": "thread1", - "operation": { - "name": "find", - "object": "collection", - "arguments": { - "filter": { - "_id": 1 - } - }, - "error": true - } - } - }, - { - "name": "runOnThread", - "object": "testRunner", - "arguments": { - "name": "thread2", - "operation": { - "name": "find", - "object": "collection", - "arguments": { - "filter": { - "_id": 1 - } - }, - "error": true - } - } - }, - { - "name": "waitForThread", - "object": "testRunner", - "arguments": { - "name": "thread1" - } - }, - { - "name": "waitForThread", - "object": "testRunner", - "arguments": { - "name": "thread2" - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 4 - } - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 4 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-command-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-command-error.json deleted file mode 100644 index d3bccd39008..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-command-error.json +++ /dev/null @@ -1,223 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.9" - } - ], - "database_name": "sdam-tests", - "collection_name": "hello-command-error", - "data": [], - "tests": [ - { - "description": "Command error on Monitor handshake", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "hello", - "isMaster" - ], - "appName": "commandErrorHandshakeTest", - "closeConnection": false, - "errorCode": 91 - } - }, - "clientOptions": { - "retryWrites": false, - "connectTimeoutMS": 250, - "heartbeatFrequencyMS": 500, - "appname": "commandErrorHandshakeTest" - }, - "operations": [ - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "hello-command-error", - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - } - }, - { - "description": "Command error on Monitor check", - "clientOptions": { - "retryWrites": false, - "connectTimeoutMS": 1000, - "heartbeatFrequencyMS": 500, - "appname": "commandErrorCheckTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - }, - { - "name": "configureFailPoint", - "object": "testRunner", - "arguments": { - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 4 - }, - "data": { - "failCommands": [ - "hello", - "isMaster" - ], - "appName": "commandErrorCheckTest", - "closeConnection": false, - "blockConnection": true, - "blockTimeMS": 750, - "errorCode": 91 - } - } - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "hello-command-error", - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "hello-command-error", - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-network-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-network-error.json deleted file mode 100644 index f9761d75563..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-network-error.json +++ /dev/null @@ -1,219 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.9" - } - ], - "database_name": "sdam-tests", - "collection_name": "hello-network-error", - "data": [], - "tests": [ - { - "description": "Network error on Monitor handshake", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "hello", - "isMaster" - ], - "appName": "networkErrorHandshakeTest", - "closeConnection": true - } - }, - "clientOptions": { - "retryWrites": false, - "connectTimeoutMS": 250, - "heartbeatFrequencyMS": 500, - "appname": "networkErrorHandshakeTest" - }, - "operations": [ - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "hello-network-error", - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - } - }, - { - "description": "Network error on Monitor check", - "clientOptions": { - "retryWrites": false, - "connectTimeoutMS": 250, - "heartbeatFrequencyMS": 500, - "appname": "networkErrorCheckTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - }, - { - "name": "configureFailPoint", - "object": "testRunner", - "arguments": { - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 4 - }, - "data": { - "failCommands": [ - "hello", - "isMaster" - ], - "appName": "networkErrorCheckTest", - "closeConnection": true - } - } - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "hello-network-error", - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "hello-network-error", - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-timeout.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-timeout.json deleted file mode 100644 index 004f8f449d5..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-timeout.json +++ /dev/null @@ -1,337 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4" - } - ], - "database_name": "sdam-tests", - "collection_name": "hello-timeout", - "data": [], - "tests": [ - { - "description": "Network timeout on Monitor handshake", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "hello", - "isMaster" - ], - "appName": "timeoutMonitorHandshakeTest", - "blockConnection": true, - "blockTimeMS": 1000 - } - }, - "clientOptions": { - "retryWrites": false, - "connectTimeoutMS": 250, - "heartbeatFrequencyMS": 500, - "appname": "timeoutMonitorHandshakeTest" - }, - "operations": [ - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "hello-timeout", - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - } - }, - { - "description": "Network timeout on Monitor check", - "clientOptions": { - "retryWrites": false, - "connectTimeoutMS": 750, - "heartbeatFrequencyMS": 500, - "appname": "timeoutMonitorCheckTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - }, - { - "name": "configureFailPoint", - "object": "testRunner", - "arguments": { - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 4 - }, - "data": { - "failCommands": [ - "hello", - "isMaster" - ], - "appName": "timeoutMonitorCheckTest", - "blockConnection": true, - "blockTimeMS": 1000 - } - } - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "hello-timeout", - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "hello-timeout", - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - } - }, - { - "description": "Driver extends timeout while streaming", - "clientOptions": { - "retryWrites": false, - "connectTimeoutMS": 250, - "heartbeatFrequencyMS": 500, - "appname": "extendsTimeoutTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - } - }, - { - "name": "wait", - "object": "testRunner", - "arguments": { - "ms": 2000 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 0 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 0 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "hello-timeout", - "documents": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "hello-timeout", - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/insert-network-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/insert-network-error.json deleted file mode 100644 index fa8bb253e12..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/insert-network-error.json +++ /dev/null @@ -1,156 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4" - } - ], - "database_name": "sdam-tests", - "collection_name": "insert-network-error", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Reset server and pool after network error on insert", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "insert" - ], - "closeConnection": true, - "appName": "insertNetworkErrorTest" - } - }, - "clientOptions": { - "retryWrites": false, - "appname": "insertNetworkErrorTest" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "error": true - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "insert-network-error", - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "insert-network-error", - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/insert-shutdown-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/insert-shutdown-error.json deleted file mode 100644 index edde149a91b..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/insert-shutdown-error.json +++ /dev/null @@ -1,167 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4" - } - ], - "database_name": "sdam-tests", - "collection_name": "insert-shutdown-error", - "data": [], - "tests": [ - { - "description": "Concurrent shutdown error on insert", - "clientOptions": { - "retryWrites": false, - "heartbeatFrequencyMS": 500, - "appname": "shutdownErrorInsertTest" - }, - "operations": [ - { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 1 - } - } - }, - { - "name": "configureFailPoint", - "object": "testRunner", - "arguments": { - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "insert" - ], - "appName": "shutdownErrorInsertTest", - "errorCode": 91, - "blockConnection": true, - "blockTimeMS": 500 - } - } - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread1" - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread2" - } - }, - { - "name": "runOnThread", - "object": "testRunner", - "arguments": { - "name": "thread1", - "operation": { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 2 - } - }, - "error": true - } - } - }, - { - "name": "runOnThread", - "object": "testRunner", - "arguments": { - "name": "thread2", - "operation": { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 3 - } - }, - "error": true - } - } - }, - { - "name": "waitForThread", - "object": "testRunner", - "arguments": { - "name": "thread1" - } - }, - { - "name": "waitForThread", - "object": "testRunner", - "arguments": { - "name": "thread2" - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "insertOne", - "object": "collection", - "arguments": { - "document": { - "_id": 4 - } - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 4 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/minPoolSize-error.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/minPoolSize-error.json deleted file mode 100644 index 9f8e4f6f8be..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/minPoolSize-error.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.9" - } - ], - "database_name": "sdam-tests", - "collection_name": "sdam-minPoolSize-error", - "data": [], - "tests": [ - { - "description": "Network error on minPoolSize background creation", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "skip": 3 - }, - "data": { - "failCommands": [ - "hello", - "isMaster" - ], - "appName": "SDAMminPoolSizeError", - "closeConnection": true - } - }, - "clientOptions": { - "heartbeatFrequencyMS": 10000, - "appname": "SDAMminPoolSizeError", - "minPoolSize": 10, - "serverSelectionTimeoutMS": 1000, - "directConnection": true - }, - "operations": [ - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolReadyEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "runCommand", - "object": "database", - "command_name": "ping", - "arguments": { - "command": { - "ping": {} - } - }, - "error": true - }, - { - "name": "configureFailPoint", - "object": "testRunner", - "arguments": { - "failPoint": { - "configureFailPoint": "failCommand", - "mode": "off" - } - } - }, - { - "name": "runCommand", - "object": "database", - "command_name": "ping", - "arguments": { - "command": { - "ping": 1 - } - }, - "error": false - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolReadyEvent", - "count": 2 - } - } - ] - } - ] -} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/rediscover-quickly-after-step-down.json b/driver-core/src/test/resources/server-discovery-and-monitoring-integration/rediscover-quickly-after-step-down.json deleted file mode 100644 index 41fbdc695cf..00000000000 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/rediscover-quickly-after-step-down.json +++ /dev/null @@ -1,165 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.4", - "topology": [ - "replicaset" - ] - } - ], - "database_name": "sdam-tests", - "collection_name": "test-replSetStepDown", - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - } - ], - "tests": [ - { - "description": "Rediscover quickly after replSetStepDown", - "clientOptions": { - "appname": "replSetStepDownTest", - "heartbeatFrequencyMS": 60000, - "serverSelectionTimeoutMS": 5000, - "w": "majority" - }, - "operations": [ - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - } - }, - { - "name": "recordPrimary", - "object": "testRunner" - }, - { - "name": "runAdminCommand", - "object": "testRunner", - "command_name": "replSetFreeze", - "arguments": { - "command": { - "replSetFreeze": 0 - }, - "readPreference": { - "mode": "Secondary" - } - } - }, - { - "name": "runAdminCommand", - "object": "testRunner", - "command_name": "replSetStepDown", - "arguments": { - "command": { - "replSetStepDown": 30, - "secondaryCatchUpPeriodSecs": 30, - "force": false - } - } - }, - { - "name": "waitForPrimaryChange", - "object": "testRunner", - "arguments": { - "timeoutMS": 15000 - } - }, - { - "name": "insertMany", - "object": "collection", - "arguments": { - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 0 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "test-replSetStepDown", - "documents": [ - { - "_id": 3 - }, - { - "_id": 4 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - }, - { - "command_started_event": { - "command": { - "insert": "test-replSetStepDown", - "documents": [ - { - "_id": 5 - }, - { - "_id": 6 - } - ] - }, - "command_name": "insert", - "database_name": "sdam-tests" - } - } - ], - "outcome": { - "collection": { - "data": [ - { - "_id": 1 - }, - { - "_id": 2 - }, - { - "_id": 3 - }, - { - "_id": 4 - }, - { - "_id": 5 - }, - { - "_id": 6 - } - ] - } - } - } - ] -} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-error.json new file mode 100644 index 00000000000..5c78ecfe503 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-error.json @@ -0,0 +1,230 @@ +{ + "description": "auth-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "auth": true, + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "auth-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Reset server and pool after AuthenticationFailure error", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "saslContinue" + ], + "appName": "authErrorTest", + "errorCode": 18 + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "appname": "authErrorTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "auth-error" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "expectError": { + "isError": true + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "auth-error", + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "auth-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-misc-command-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-misc-command-error.json new file mode 100644 index 00000000000..6e1b645461e --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-misc-command-error.json @@ -0,0 +1,230 @@ +{ + "description": "auth-misc-command-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "auth": true, + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "auth-misc-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Reset server and pool after misc command error", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "saslContinue" + ], + "appName": "authMiscErrorTest", + "errorCode": 1 + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "appname": "authMiscErrorTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "auth-misc-error" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "expectError": { + "isError": true + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "auth-misc-error", + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "auth-misc-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-network-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-network-error.json new file mode 100644 index 00000000000..7606d2db7ab --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-network-error.json @@ -0,0 +1,230 @@ +{ + "description": "auth-network-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "auth": true, + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "auth-network-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Reset server and pool after network error during authentication", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "saslContinue" + ], + "closeConnection": true, + "appName": "authNetworkErrorTest" + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "appname": "authNetworkErrorTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "auth-network-error" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "expectError": { + "isError": true + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "auth-network-error", + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "auth-network-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-network-timeout-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-network-timeout-error.json new file mode 100644 index 00000000000..22066e8baeb --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-network-timeout-error.json @@ -0,0 +1,233 @@ +{ + "description": "auth-network-timeout-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "auth": true, + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "auth-network-timeout-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Reset server and pool after network timeout error during authentication", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "saslContinue" + ], + "blockConnection": true, + "blockTimeMS": 500, + "appName": "authNetworkTimeoutErrorTest" + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "appname": "authNetworkTimeoutErrorTest", + "connectTimeoutMS": 250, + "socketTimeoutMS": 250 + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "auth-network-timeout-error" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "expectError": { + "isError": true + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "auth-network-timeout-error", + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "auth-network-timeout-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-shutdown-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-shutdown-error.json new file mode 100644 index 00000000000..5dd7b5bb6fe --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/auth-shutdown-error.json @@ -0,0 +1,230 @@ +{ + "description": "auth-shutdown-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "auth": true, + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "auth-shutdown-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Reset server and pool after shutdown error during authentication", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "saslContinue" + ], + "appName": "authShutdownErrorTest", + "errorCode": 91 + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "appname": "authShutdownErrorTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "auth-shutdown-error" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "expectError": { + "isError": true + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "auth-shutdown-error", + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "auth-shutdown-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/cancel-server-check.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/cancel-server-check.json new file mode 100644 index 00000000000..896cc8d0871 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/cancel-server-check.json @@ -0,0 +1,201 @@ +{ + "description": "cancel-server-check", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.0", + "topologies": [ + "replicaset" + ], + "serverless": "forbid" + }, + { + "minServerVersion": "4.2", + "topologies": [ + "sharded" + ], + "serverless": "forbid" + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "cancel-server-check", + "databaseName": "sdam-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Cancel server check", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": true, + "heartbeatFrequencyMS": 10000, + "serverSelectionTimeoutMS": 5000, + "appname": "cancelServerCheckTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "cancel-server-check" + } + } + ] + } + }, + { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 1 + } + } + }, + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "insert" + ], + "closeConnection": true + } + }, + "client": "setupClient" + } + }, + { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 2 + } + }, + "expectResult": { + "insertedId": 2 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 3 + } + }, + "expectResult": { + "insertedId": 3 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "outcome": [ + { + "collectionName": "cancel-server-check", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/connectTimeoutMS.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/connectTimeoutMS.json new file mode 100644 index 00000000000..67a4d9da1d3 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/connectTimeoutMS.json @@ -0,0 +1,221 @@ +{ + "description": "connectTimeoutMS", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "connectTimeoutMS", + "databaseName": "sdam-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "connectTimeoutMS=0", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "connectTimeoutMS": 0, + "heartbeatFrequencyMS": 500, + "appname": "connectTimeoutMS=0" + }, + "useMultipleMongoses": false + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "connectTimeoutMS" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + }, + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "hello", + "isMaster" + ], + "appName": "connectTimeoutMS=0", + "blockConnection": true, + "blockTimeMS": 550 + } + }, + "client": "setupClient" + } + }, + { + "name": "wait", + "object": "testRunner", + "arguments": { + "ms": 750 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 0 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 0 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "connectTimeoutMS", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "connectTimeoutMS", + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "connectTimeoutMS", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-network-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-network-error.json new file mode 100644 index 00000000000..651466bfa6d --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-network-error.json @@ -0,0 +1,234 @@ +{ + "description": "find-network-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "find-network-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Reset server and pool after network error on find", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "find" + ], + "closeConnection": true, + "appName": "findNetworkErrorTest" + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "retryReads": false, + "appname": "findNetworkErrorTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "find-network-error" + } + } + ] + } + }, + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": 1 + } + }, + "expectError": { + "isError": true + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "find-network-error" + }, + "commandName": "find", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "find-network-error", + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "find-network-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-network-timeout-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-network-timeout-error.json new file mode 100644 index 00000000000..2bde6daa5df --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-network-timeout-error.json @@ -0,0 +1,199 @@ +{ + "description": "find-network-timeout-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "find-network-timeout-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Ignore network timeout error on find", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "find" + ], + "blockConnection": true, + "blockTimeMS": 500, + "appName": "findNetworkTimeoutErrorTest" + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "retryReads": false, + "appname": "findNetworkTimeoutErrorTest", + "socketTimeoutMS": 250 + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "find-network-timeout-error" + } + } + ] + } + }, + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": 1 + } + }, + "expectError": { + "isError": true + } + }, + { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 3 + } + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 0 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 0 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "find-network-timeout-error" + }, + "commandName": "find", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "find-network-timeout-error", + "documents": [ + { + "_id": 3 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "find-network-timeout-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-shutdown-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-shutdown-error.json new file mode 100644 index 00000000000..624ad352fc9 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/find-shutdown-error.json @@ -0,0 +1,251 @@ +{ + "description": "find-shutdown-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "find-shutdown-error", + "databaseName": "sdam-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Concurrent shutdown error on find", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "uriOptions": { + "retryWrites": false, + "retryReads": false, + "heartbeatFrequencyMS": 500, + "appname": "shutdownErrorFindTest" + }, + "observeEvents": [ + "serverDescriptionChangedEvent", + "poolClearedEvent" + ] + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "find-shutdown-error" + } + } + ] + } + }, + { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 1 + } + } + }, + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "find" + ], + "appName": "shutdownErrorFindTest", + "errorCode": 91, + "blockConnection": true, + "blockTimeMS": 500 + } + }, + "client": "setupClient" + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "thread": { + "id": "thread0" + } + }, + { + "thread": { + "id": "thread1" + } + } + ] + } + }, + { + "name": "runOnThread", + "object": "testRunner", + "arguments": { + "thread": "thread0", + "operation": { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": 1 + } + }, + "expectError": { + "isError": true + } + } + } + }, + { + "name": "runOnThread", + "object": "testRunner", + "arguments": { + "thread": "thread1", + "operation": { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": 1 + } + }, + "expectError": { + "isError": true + } + } + } + }, + { + "name": "waitForThread", + "object": "testRunner", + "arguments": { + "thread": "thread0" + } + }, + { + "name": "waitForThread", + "object": "testRunner", + "arguments": { + "thread": "thread1" + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 4 + } + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "outcome": [ + { + "collectionName": "find-shutdown-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 4 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-command-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-command-error.json new file mode 100644 index 00000000000..7d6046b76f5 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-command-error.json @@ -0,0 +1,376 @@ +{ + "description": "hello-command-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.9", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "hello-command-error", + "databaseName": "sdam-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Command error on Monitor handshake", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 4 + }, + "data": { + "failCommands": [ + "hello", + "isMaster" + ], + "appName": "commandErrorHandshakeTest", + "closeConnection": false, + "errorCode": 91 + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "serverDescriptionChangedEvent", + "poolClearedEvent", + "commandStartedEvent" + ], + "uriOptions": { + "retryWrites": false, + "connectTimeoutMS": 250, + "heartbeatFrequencyMS": 500, + "appname": "commandErrorHandshakeTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "hello-command-error" + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "hello-command-error", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "hello-command-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ] + }, + { + "description": "Command error on Monitor check", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "connectTimeoutMS": 1000, + "heartbeatFrequencyMS": 500, + "appname": "commandErrorCheckTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "hello-command-error" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + }, + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "hello", + "isMaster" + ], + "appName": "commandErrorCheckTest", + "closeConnection": false, + "blockConnection": true, + "blockTimeMS": 750, + "errorCode": 91 + } + }, + "client": "setupClient" + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "hello-command-error", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "hello-command-error", + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "hello-command-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-network-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-network-error.json new file mode 100644 index 00000000000..f44b26a9f91 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-network-error.json @@ -0,0 +1,346 @@ +{ + "description": "hello-network-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.9", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "hello-network-error", + "databaseName": "sdam-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Network error on Monitor handshake", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "hello", + "isMaster" + ], + "appName": "networkErrorHandshakeTest", + "closeConnection": true + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "connectTimeoutMS": 250, + "heartbeatFrequencyMS": 500, + "appname": "networkErrorHandshakeTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "hello-network-error" + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "hello-network-error", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "hello-network-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ] + }, + { + "description": "Network error on Monitor check", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "connectTimeoutMS": 250, + "heartbeatFrequencyMS": 500, + "appname": "networkErrorCheckTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "hello-network-error" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + }, + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 4 + }, + "data": { + "failCommands": [ + "hello", + "isMaster" + ], + "appName": "networkErrorCheckTest", + "closeConnection": true + } + }, + "client": "setupClient" + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "hello-network-error", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "hello-network-error", + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "hello-network-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-timeout.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-timeout.json new file mode 100644 index 00000000000..dfa6b48d66b --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/hello-timeout.json @@ -0,0 +1,514 @@ +{ + "description": "hello-timeout", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "hello-timeout", + "databaseName": "sdam-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Network timeout on Monitor handshake", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "hello", + "isMaster" + ], + "appName": "timeoutMonitorHandshakeTest", + "blockConnection": true, + "blockTimeMS": 1000 + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "connectTimeoutMS": 250, + "heartbeatFrequencyMS": 500, + "appname": "timeoutMonitorHandshakeTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "hello-timeout" + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "hello-timeout", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "hello-timeout", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ] + }, + { + "description": "Network timeout on Monitor check", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "connectTimeoutMS": 750, + "heartbeatFrequencyMS": 500, + "appname": "timeoutMonitorCheckTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "hello-timeout" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + }, + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 4 + }, + "data": { + "failCommands": [ + "hello", + "isMaster" + ], + "appName": "timeoutMonitorCheckTest", + "blockConnection": true, + "blockTimeMS": 1000 + } + }, + "client": "setupClient" + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "hello-timeout", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "hello-timeout", + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "hello-timeout", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + ] + }, + { + "description": "Driver extends timeout while streaming", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "connectTimeoutMS": 250, + "heartbeatFrequencyMS": 500, + "appname": "extendsTimeoutTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "hello-timeout" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + }, + { + "name": "wait", + "object": "testRunner", + "arguments": { + "ms": 2000 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 0 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 0 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "hello-timeout", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "hello-timeout", + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "hello-timeout", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/insert-network-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/insert-network-error.json new file mode 100644 index 00000000000..e4ba6684ae2 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/insert-network-error.json @@ -0,0 +1,246 @@ +{ + "description": "insert-network-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "insert-network-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Reset server and pool after network error on insert", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "insert" + ], + "closeConnection": true, + "appName": "insertNetworkErrorTest" + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "commandStartedEvent", + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": false, + "appname": "insertNetworkErrorTest" + }, + "useMultipleMongoses": false + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "insert-network-error" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "expectError": { + "isError": true + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "insert-network-error", + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "insert-network-error", + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "insert-network-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/insert-shutdown-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/insert-shutdown-error.json new file mode 100644 index 00000000000..3c724fa5e4c --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/insert-shutdown-error.json @@ -0,0 +1,250 @@ +{ + "description": "insert-shutdown-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "serverless": "forbid", + "topologies": [ + "single", + "replicaset", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "insert-shutdown-error", + "databaseName": "sdam-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Concurrent shutdown error on insert", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "uriOptions": { + "retryWrites": false, + "heartbeatFrequencyMS": 500, + "appname": "shutdownErrorInsertTest" + }, + "observeEvents": [ + "serverDescriptionChangedEvent", + "poolClearedEvent" + ] + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "insert-shutdown-error" + } + } + ] + } + }, + { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 1 + } + } + }, + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "insert" + ], + "appName": "shutdownErrorInsertTest", + "errorCode": 91, + "blockConnection": true, + "blockTimeMS": 500 + } + }, + "client": "setupClient" + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "thread": { + "id": "thread0" + } + }, + { + "thread": { + "id": "thread1" + } + } + ] + } + }, + { + "name": "runOnThread", + "object": "testRunner", + "arguments": { + "thread": "thread0", + "operation": { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 2 + } + }, + "expectError": { + "isError": true + } + } + } + }, + { + "name": "runOnThread", + "object": "testRunner", + "arguments": { + "thread": "thread1", + "operation": { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 3 + } + }, + "expectError": { + "isError": true + } + } + } + }, + { + "name": "waitForThread", + "object": "testRunner", + "arguments": { + "thread": "thread0" + } + }, + { + "name": "waitForThread", + "object": "testRunner", + "arguments": { + "thread": "thread1" + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "insertOne", + "object": "collection", + "arguments": { + "document": { + "_id": 4 + } + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + } + ], + "outcome": [ + { + "collectionName": "insert-shutdown-error", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 4 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/minPoolSize-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/minPoolSize-error.json new file mode 100644 index 00000000000..0234ac99292 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/minPoolSize-error.json @@ -0,0 +1,177 @@ +{ + "description": "minPoolSize-error", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.9", + "serverless": "forbid", + "topologies": [ + "single" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "sdam-minPoolSize-error", + "databaseName": "sdam-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Network error on minPoolSize background creation", + "operations": [ + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "client": "setupClient", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "skip": 3 + }, + "data": { + "failCommands": [ + "hello", + "isMaster" + ], + "appName": "SDAMminPoolSizeError", + "closeConnection": true + } + } + } + }, + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "serverDescriptionChangedEvent", + "poolClearedEvent", + "poolReadyEvent" + ], + "uriOptions": { + "heartbeatFrequencyMS": 10000, + "appname": "SDAMminPoolSizeError", + "minPoolSize": 10, + "serverSelectionTimeoutMS": 1000 + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "sdam-minPoolSize-error" + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolReadyEvent": {} + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 1 + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + "count": 1 + } + }, + { + "name": "runCommand", + "object": "database", + "arguments": { + "command": { + "ping": {} + }, + "commandName": "ping" + }, + "expectError": { + "isError": true + } + }, + { + "name": "failPoint", + "object": "testRunner", + "arguments": { + "failPoint": { + "configureFailPoint": "failCommand", + "mode": "off" + }, + "client": "setupClient" + } + }, + { + "name": "runCommand", + "object": "database", + "arguments": { + "command": { + "ping": 1 + }, + "commandName": "ping" + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolReadyEvent": {} + }, + "count": 2 + } + } + ] + } + ] +} diff --git a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/pool-cleared-error.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/pool-cleared-error.json similarity index 60% rename from driver-core/src/test/resources/server-discovery-and-monitoring-integration/pool-cleared-error.json rename to driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/pool-cleared-error.json index 52456f9e133..9a7dfd901c5 100644 --- a/driver-core/src/test/resources/server-discovery-and-monitoring-integration/pool-cleared-error.json +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/pool-cleared-error.json @@ -1,25 +1,72 @@ { - "runOn": [ + "description": "pool-cleared-error", + "schemaVersion": "1.10", + "runOnRequirements": [ { "minServerVersion": "4.9", - "topology": [ + "serverless": "forbid", + "topologies": [ "replicaset", "sharded" ] } ], - "database_name": "sdam-tests", - "collection_name": "pool-cleared-error", - "data": [], + "createEntities": [ + { + "client": { + "id": "setupClient", + "useMultipleMongoses": false + } + } + ], + "initialData": [ + { + "collectionName": "pool-cleared-error", + "databaseName": "sdam-tests", + "documents": [] + } + ], "tests": [ { "description": "PoolClearedError does not mark server unknown", - "clientOptions": { - "retryWrites": true, - "maxPoolSize": 1, - "appname": "poolClearedErrorTest" - }, "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "useMultipleMongoses": false, + "observeEvents": [ + "serverDescriptionChangedEvent", + "poolClearedEvent" + ], + "uriOptions": { + "retryWrites": true, + "maxPoolSize": 1, + "appname": "poolClearedErrorTest" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "pool-cleared-error" + } + } + ] + } + }, { "name": "insertOne", "object": "collection", @@ -30,7 +77,7 @@ } }, { - "name": "configureFailPoint", + "name": "failPoint", "object": "testRunner", "arguments": { "failPoint": { @@ -47,56 +94,53 @@ "closeConnection": true, "appName": "poolClearedErrorTest" } - } - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread1" - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread2" - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread3" - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread4" - } - }, - { - "name": "startThread", - "object": "testRunner", - "arguments": { - "name": "thread5" + }, + "client": "setupClient" } }, { - "name": "startThread", + "name": "createEntities", "object": "testRunner", "arguments": { - "name": "thread6" + "entities": [ + { + "thread": { + "id": "thread0" + } + }, + { + "thread": { + "id": "thread1" + } + }, + { + "thread": { + "id": "thread2" + } + }, + { + "thread": { + "id": "thread3" + } + }, + { + "thread": { + "id": "thread4" + } + }, + { + "thread": { + "id": "thread5" + } + } + ] } }, { "name": "runOnThread", "object": "testRunner", "arguments": { - "name": "thread1", + "thread": "thread0", "operation": { "name": "insertOne", "object": "collection", @@ -112,7 +156,7 @@ "name": "runOnThread", "object": "testRunner", "arguments": { - "name": "thread2", + "thread": "thread1", "operation": { "name": "insertOne", "object": "collection", @@ -128,7 +172,7 @@ "name": "runOnThread", "object": "testRunner", "arguments": { - "name": "thread3", + "thread": "thread2", "operation": { "name": "insertOne", "object": "collection", @@ -144,7 +188,7 @@ "name": "runOnThread", "object": "testRunner", "arguments": { - "name": "thread4", + "thread": "thread3", "operation": { "name": "insertOne", "object": "collection", @@ -160,7 +204,7 @@ "name": "runOnThread", "object": "testRunner", "arguments": { - "name": "thread5", + "thread": "thread4", "operation": { "name": "insertOne", "object": "collection", @@ -176,7 +220,7 @@ "name": "runOnThread", "object": "testRunner", "arguments": { - "name": "thread6", + "thread": "thread5", "operation": { "name": "insertOne", "object": "collection", @@ -192,49 +236,56 @@ "name": "waitForThread", "object": "testRunner", "arguments": { - "name": "thread1" + "thread": "thread0" } }, { "name": "waitForThread", "object": "testRunner", "arguments": { - "name": "thread2" + "thread": "thread1" } }, { "name": "waitForThread", "object": "testRunner", "arguments": { - "name": "thread3" + "thread": "thread2" } }, { "name": "waitForThread", "object": "testRunner", "arguments": { - "name": "thread4" + "thread": "thread3" } }, { "name": "waitForThread", "object": "testRunner", "arguments": { - "name": "thread5" + "thread": "thread4" } }, { "name": "waitForThread", "object": "testRunner", "arguments": { - "name": "thread6" + "thread": "thread5" } }, { "name": "waitForEvent", "object": "testRunner", "arguments": { - "event": "ServerMarkedUnknownEvent", + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, "count": 1 } }, @@ -242,7 +293,10 @@ "name": "waitForEvent", "object": "testRunner", "arguments": { - "event": "PoolClearedEvent", + "client": "client", + "event": { + "poolClearedEvent": {} + }, "count": 1 } }, @@ -259,7 +313,14 @@ "name": "assertEventCount", "object": "testRunner", "arguments": { - "event": "ServerMarkedUnknownEvent", + "client": "client", + "event": { + "serverDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, "count": 1 } }, @@ -267,14 +328,19 @@ "name": "assertEventCount", "object": "testRunner", "arguments": { - "event": "PoolClearedEvent", + "client": "client", + "event": { + "poolClearedEvent": {} + }, "count": 1 } } ], - "outcome": { - "collection": { - "data": [ + "outcome": [ + { + "collectionName": "pool-cleared-error", + "databaseName": "sdam-tests", + "documents": [ { "_id": 1 }, @@ -301,7 +367,7 @@ } ] } - } + ] } ] } diff --git a/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/rediscover-quickly-after-step-down.json b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/rediscover-quickly-after-step-down.json new file mode 100644 index 00000000000..0ad575cc9d0 --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/server-discovery-and-monitoring/rediscover-quickly-after-step-down.json @@ -0,0 +1,242 @@ +{ + "description": "rediscover-quickly-after-step-down", + "schemaVersion": "1.10", + "runOnRequirements": [ + { + "minServerVersion": "4.4", + "serverless": "forbid", + "topologies": [ + "replicaset" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "setupClient" + } + }, + { + "database": { + "id": "adminDatabase", + "client": "setupClient", + "databaseName": "admin" + } + } + ], + "initialData": [ + { + "collectionName": "test-replSetStepDown", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + } + ] + } + ], + "tests": [ + { + "description": "Rediscover quickly after replSetStepDown", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "poolClearedEvent", + "commandStartedEvent" + ], + "uriOptions": { + "appname": "replSetStepDownTest", + "heartbeatFrequencyMS": 60000, + "serverSelectionTimeoutMS": 5000, + "w": "majority" + } + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "sdam-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "test-replSetStepDown" + } + } + ] + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + } + }, + { + "name": "recordTopologyDescription", + "object": "testRunner", + "arguments": { + "client": "client", + "id": "topologyDescription" + } + }, + { + "name": "assertTopologyType", + "object": "testRunner", + "arguments": { + "topologyDescription": "topologyDescription", + "topologyType": "ReplicaSetWithPrimary" + } + }, + { + "name": "runCommand", + "object": "adminDatabase", + "arguments": { + "command": { + "replSetFreeze": 0 + }, + "readPreference": { + "mode": "Secondary" + }, + "commandName": "replSetFreeze" + } + }, + { + "name": "runCommand", + "object": "adminDatabase", + "arguments": { + "command": { + "replSetStepDown": 30, + "secondaryCatchUpPeriodSecs": 30, + "force": false + }, + "commandName": "replSetStepDown" + } + }, + { + "name": "waitForPrimaryChange", + "object": "testRunner", + "arguments": { + "client": "client", + "priorTopologyDescription": "topologyDescription", + "timeoutMS": 15000 + } + }, + { + "name": "insertMany", + "object": "collection", + "arguments": { + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "poolClearedEvent": {} + }, + "count": 0 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "command", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "test-replSetStepDown", + "documents": [ + { + "_id": 3 + }, + { + "_id": 4 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "test-replSetStepDown", + "documents": [ + { + "_id": 5 + }, + { + "_id": 6 + } + ] + }, + "commandName": "insert", + "databaseName": "sdam-tests" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "test-replSetStepDown", + "databaseName": "sdam-tests", + "documents": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + }, + { + "_id": 4 + }, + { + "_id": 5 + }, + { + "_id": 6 + } + ] + } + ] + } + ] +} diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/TestServerListener.java b/driver-core/src/test/unit/com/mongodb/internal/connection/TestServerListener.java index 9d3acb7774b..791b0b936d2 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/TestServerListener.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/TestServerListener.java @@ -23,31 +23,47 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Predicate; -import static com.mongodb.assertions.Assertions.isTrue; import static com.mongodb.assertions.Assertions.notNull; -class TestServerListener implements ServerListener { +public class TestServerListener implements ServerListener { private ServerOpeningEvent serverOpeningEvent; private ServerClosedEvent serverClosedEvent; private final List serverDescriptionChangedEvents = new ArrayList(); + private final Lock lock = new ReentrantLock(); + private final Condition condition = lock.newCondition(); + private volatile int waitingForEventCount; + private Predicate waitingForEventMatcher; @Override public void serverOpening(final ServerOpeningEvent event) { - isTrue("serverOpeningEvent is null", serverOpeningEvent == null); serverOpeningEvent = event; } @Override public void serverClosed(final ServerClosedEvent event) { - isTrue("serverClostedEvent is null", serverClosedEvent == null); serverClosedEvent = event; } @Override public void serverDescriptionChanged(final ServerDescriptionChangedEvent event) { notNull("event", event); - serverDescriptionChangedEvents.add(event); + lock.lock(); + try { + serverDescriptionChangedEvents.add(event); + if (waitingForEventCount != 0 && containsEvents()) { + condition.signalAll(); + } + + } finally { + lock.unlock(); + } } public ServerOpeningEvent getServerOpeningEvent() { @@ -61,4 +77,38 @@ public ServerClosedEvent getServerClosedEvent() { public List getServerDescriptionChangedEvents() { return serverDescriptionChangedEvents; } + + public void waitForServerDescriptionChangedEvent(final Predicate matcher, final int count, + final int time, final TimeUnit unit) throws InterruptedException, TimeoutException { + if (count <= 0) { + throw new IllegalArgumentException(); + } + lock.lock(); + try { + if (waitingForEventCount != 0) { + throw new IllegalStateException("Already waiting for events"); + } + waitingForEventCount = count; + waitingForEventMatcher = matcher; + if (containsEvents()) { + return; + } + if (!condition.await(time, unit)) { + throw new TimeoutException("Timed out waiting for " + count + " ServerDescriptionChangedEvent events. " + + "The count after timing out is " + countEvents()); + } + } finally { + waitingForEventCount = 0; + waitingForEventMatcher = null; + lock.unlock(); + } + } + + private long countEvents() { + return serverDescriptionChangedEvents.stream().filter(waitingForEventMatcher).count(); + } + + private boolean containsEvents() { + return countEvents() >= waitingForEventCount; + } } diff --git a/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ServerDiscoveryAndMonitoringTest.java b/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ServerDiscoveryAndMonitoringTest.java deleted file mode 100644 index 7df92c9d0e8..00000000000 --- a/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ServerDiscoveryAndMonitoringTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2008-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mongodb.reactivestreams.client; - -import com.mongodb.MongoClientSettings; -import com.mongodb.client.AbstractServerDiscoveryAndMonitoringTest; -import com.mongodb.client.MongoClient; -import com.mongodb.connection.StreamFactoryFactory; -import com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient; -import org.bson.BsonArray; -import org.bson.BsonDocument; - -import static com.mongodb.ClusterFixture.getOverriddenStreamFactoryFactory; - -public class ServerDiscoveryAndMonitoringTest extends AbstractServerDiscoveryAndMonitoringTest { - public ServerDiscoveryAndMonitoringTest(final String filename, final String description, final String databaseName, - final String collectionName, final BsonArray data, final BsonDocument definition, - final boolean skipTest) { - super(filename, description, databaseName, collectionName, data, definition, skipTest); - } - - @Override - protected MongoClient createMongoClient(final MongoClientSettings settings) { - return new SyncMongoClient(MongoClients.create(settings)); - } - - @Override - protected StreamFactoryFactory getStreamFactoryFactory() { - return getOverriddenStreamFactoryFactory(); - } -} diff --git a/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java b/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java new file mode 100644 index 00000000000..4ea7b43bb02 --- /dev/null +++ b/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mongodb.reactivestreams.client.unified; + +import com.mongodb.lang.Nullable; +import org.bson.BsonArray; +import org.bson.BsonDocument; +import org.junit.runners.Parameterized; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Collection; + +public class UnifiedServerDiscoveryAndMonitoringTest extends UnifiedReactiveStreamsTest { + public UnifiedServerDiscoveryAndMonitoringTest(@SuppressWarnings("unused") final String fileDescription, + @SuppressWarnings("unused") final String testDescription, + final String schemaVersion, + @Nullable final BsonArray runOnRequirements, final BsonArray entities, final BsonArray initialData, + final BsonDocument definition) { + super(schemaVersion, runOnRequirements, entities, initialData, definition); + } + + @Parameterized.Parameters(name = "{0}: {1}") + public static Collection data() throws URISyntaxException, IOException { + return getTestData("unified-test-format/server-discovery-and-monitoring"); + } +} diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractServerDiscoveryAndMonitoringTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractServerDiscoveryAndMonitoringTest.java deleted file mode 100644 index 64f25503b30..00000000000 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractServerDiscoveryAndMonitoringTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2008-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.mongodb.client; - -import org.bson.BsonArray; -import org.bson.BsonDocument; -import org.bson.BsonString; -import org.bson.BsonValue; -import org.junit.runners.Parameterized; -import util.JsonPoweredTestHelper; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import static com.mongodb.JsonTestServerVersionChecker.skipTest; -import static com.mongodb.client.Fixture.getDefaultDatabaseName; - -public abstract class AbstractServerDiscoveryAndMonitoringTest extends AbstractUnifiedTest { - public AbstractServerDiscoveryAndMonitoringTest(final String filename, final String description, final String databaseName, - final String collectionName, final BsonArray data, final BsonDocument definition, - final boolean skipTest) { - super(filename, description, databaseName, collectionName, data, definition, skipTest, false); - } - - @Parameterized.Parameters(name = "{0}: {1}") - public static Collection data() throws URISyntaxException, IOException { - List data = new ArrayList(); - for (File file : JsonPoweredTestHelper.getTestFiles("/server-discovery-and-monitoring-integration")) { - BsonDocument testDocument = JsonPoweredTestHelper.getTestDocument(file); - - for (BsonValue test : testDocument.getArray("tests")) { - data.add(new Object[]{file.getName(), test.asDocument().getString("description").getValue(), - testDocument.getString("database_name", new BsonString(getDefaultDatabaseName())).getValue(), - testDocument.getString("collection_name", - new BsonString(file.getName().substring(0, file.getName().lastIndexOf(".")))).getValue(), - testDocument.getArray("data"), test.asDocument(), skipTest(testDocument, test.asDocument())}); - } - } - return data; - } - -} diff --git a/driver-sync/src/test/functional/com/mongodb/client/ServerDiscoveryAndMonitoringTest.java b/driver-sync/src/test/functional/com/mongodb/client/ServerDiscoveryAndMonitoringTest.java deleted file mode 100644 index 62807efb102..00000000000 --- a/driver-sync/src/test/functional/com/mongodb/client/ServerDiscoveryAndMonitoringTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2008-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mongodb.client; - -import com.mongodb.MongoClientSettings; -import org.bson.BsonArray; -import org.bson.BsonDocument; - -import static com.mongodb.ClusterFixture.isServerlessTest; -import static org.junit.Assume.assumeFalse; - -public class ServerDiscoveryAndMonitoringTest extends AbstractServerDiscoveryAndMonitoringTest { - public ServerDiscoveryAndMonitoringTest(final String filename, final String description, final String databaseName, - final String collectionName, final BsonArray data, final BsonDocument definition, - final boolean skipTest) { - super(filename, description, databaseName, collectionName, data, definition, skipTest); - assumeFalse(isServerlessTest()); - } - - @Override - protected MongoClient createMongoClient(final MongoClientSettings settings) { - return MongoClients.create(settings); - } -} diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/ContextElement.java b/driver-sync/src/test/functional/com/mongodb/client/unified/ContextElement.java index 6a4c648c563..59eda7e9c97 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/ContextElement.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/ContextElement.java @@ -73,6 +73,74 @@ public static ContextElement ofConnectionPoolEvent(final BsonDocument expected, return new ConnectionPoolEventMatchingContextElement(expected, actual, eventPosition); } + public static ContextElement ofWaitForPrimaryChange() { + return new ContextElement() { + @Override + public String toString() { + return "Wait For Primary Change Context\n"; + } + }; + } + + public static ContextElement ofWaitForThread(final String threadId) { + return new ContextElement() { + @Override + public String toString() { + return "Wait For Thread Context:\n" + + " Thread id: " + threadId + "\n"; + } + }; + } + + public static ContextElement ofTopologyType(final String topologyType) { + return new ContextElement() { + @Override + public String toString() { + return "Topology Type Context:\n" + + " Topology Type: " + topologyType + "\n"; + } + }; + } + + public static ContextElement ofWaitForConnectionPoolEvents(final String client, final BsonDocument event, final int count) { + return new EventCountContext("Wait For Connection Pool Events", client, event, count); + } + + public static ContextElement ofConnectionPoolEventCount(final String client, final BsonDocument event, final int count) { + return new EventCountContext("Connection Pool Event Count", client, event, count); + } + + public static ContextElement ofWaitForServerDescriptionChangedEvents(final String client, final BsonDocument event, final int count) { + return new EventCountContext("Wait For Server Description Changed Events", client, event, count); + } + + public static ContextElement ofServerDescriptionChangeEventCount(final String client, final BsonDocument event, final int count) { + return new EventCountContext("Server Description Changed Event Count", client, event, count); + } + + private static class EventCountContext extends ContextElement { + + private final String name; + private final String client; + private final BsonDocument event; + private final int count; + + EventCountContext(final String name, final String client, final BsonDocument event, final int count) { + this.name = name; + this.client = client; + this.event = event; + this.count = count; + } + + @Override + public String toString() { + return name + " Context: " + "\n" + + " Client: " + client + "\n" + + " Event:\n" + + event.toJson(JsonWriterSettings.builder().indent(true).build()) + "\n" + + " Count: " + count + "\n"; + } + } private static class TestContextContextElement extends ContextElement { private final BsonDocument definition; diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java b/driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java index 982e67b1bb7..cbb33c1f8fa 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/Entities.java @@ -34,6 +34,7 @@ import com.mongodb.client.gridfs.GridFSBucket; import com.mongodb.client.vault.ClientEncryption; import com.mongodb.connection.ClusterConnectionMode; +import com.mongodb.connection.ClusterDescription; import com.mongodb.connection.ConnectionId; import com.mongodb.connection.ServerId; import com.mongodb.event.CommandEvent; @@ -55,6 +56,7 @@ import com.mongodb.event.ConnectionReadyEvent; import com.mongodb.internal.connection.TestCommandListener; import com.mongodb.internal.connection.TestConnectionPoolListener; +import com.mongodb.internal.connection.TestServerListener; import org.bson.BsonArray; import org.bson.BsonBoolean; import org.bson.BsonDocument; @@ -71,6 +73,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; import java.util.function.Function; @@ -97,6 +102,8 @@ public final class Entities { "id", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities", "observeEvents", "observeSensitiveCommands", "ignoreCommandMonitoringEvents")); private final Set entityNames = new HashSet<>(); + private final Map threads = new HashMap<>(); + private final Map>> tasks = new HashMap<>(); private final Map results = new HashMap<>(); private final Map clients = new HashMap<>(); private final Map databases = new HashMap<>(); @@ -107,7 +114,9 @@ public final class Entities { private final Map clientEncryptions = new HashMap<>(); private final Map clientCommandListeners = new HashMap<>(); private final Map clientConnectionPoolListeners = new HashMap<>(); + private final Map clientServerListeners = new HashMap<>(); private final Map> cursors = new HashMap<>(); + private final Map topologyDescriptions = new HashMap<>(); private final Map successCounts = new HashMap<>(); private final Map iterationCounts = new HashMap<>(); private final Map errorDocumentsMap = new HashMap<>(); @@ -186,6 +195,30 @@ public MongoCursor getCursor(final String id) { return getEntity(id, cursors, "cursors"); } + public void addTopologyDescription(final String id, final ClusterDescription clusterDescription) { + putEntity(id, clusterDescription, topologyDescriptions); + } + + public ClusterDescription getTopologyDescription(final String id) { + return getEntity(id, topologyDescriptions, "topologyDescription"); + } + + public ExecutorService getThread(final String id) { + return getEntity(id, threads, "thread"); + } + + public void addThreadTask(final String id, final Future task) { + getEntity(id, tasks, "tasks").add(task); + } + + public List> getThreadTasks(final String id) { + return getEntity(id, tasks, "tasks"); + } + + public void clearThreadTasks(final String id) { + getEntity(id, tasks, "tasks").clear(); + } + public boolean hasClient(final String id) { return clients.containsKey(id); } @@ -234,6 +267,10 @@ public TestConnectionPoolListener getConnectionPoolListener(final String id) { return getEntity(id + "-connection-pool-listener", clientConnectionPoolListeners, "connection pool listener"); } + public TestServerListener getServerListener(final String id) { + return getEntity(id + "-server-listener", clientServerListeners, "server listener"); + } + private T getEntity(final String id, final Map entities, final String type) { T entity = entities.get(id); if (entity == null) { @@ -259,6 +296,9 @@ public void init(final BsonArray entitiesArray, BsonDocument entity = cur.asDocument().getDocument(entityType); String id = entity.getString("id").getValue(); switch (entityType) { + case "thread": + initThread(entity, id); + break; case "client": initClient(entity, id, mongoClientSupplier, waitForPoolAsyncWorkManagerStart); break; @@ -288,6 +328,11 @@ public void init(final BsonArray entitiesArray, } } + private void initThread(final BsonDocument entity, final String id) { + putEntity(id, Executors.newSingleThreadExecutor(), threads); + tasks.put(id, new ArrayList<>()); + } + private void initClient(final BsonDocument entity, final String id, final Function mongoClientSupplier, final boolean waitForPoolAsyncWorkManagerStart) { @@ -306,6 +351,10 @@ private void initClient(final BsonDocument entity, final String id, clientSettingsBuilder = getMongoClientSettingsBuilder(); } + TestServerListener testClusterListener = new TestServerListener(); + clientSettingsBuilder.applyToServerSettings(builder -> builder.addServerListener(testClusterListener)); + putEntity(id + "-server-listener", testClusterListener, clientServerListeners); + if (entity.containsKey("observeEvents")) { List ignoreCommandMonitoringEvents = entity .getArray("ignoreCommandMonitoringEvents", new BsonArray()).stream() @@ -332,6 +381,7 @@ private void initClient(final BsonDocument entity, final String id, builder.addConnectionPoolListener(testConnectionPoolListener)); putEntity(id + "-connection-pool-listener", testConnectionPoolListener, clientConnectionPoolListeners); } + if (entity.containsKey("storeEventsAsEntities")) { BsonArray storeEventsAsEntitiesArray = entity.getArray("storeEventsAsEntities"); for (BsonValue eventValue : storeEventsAsEntitiesArray) { @@ -379,15 +429,38 @@ private void initClient(final BsonDocument entity, final String id, new ReadConcern(ReadConcernLevel.fromString(value.asString().getValue()))); break; case "w": - clientSettingsBuilder.writeConcern(new WriteConcern(value.asInt32().intValue())); + if (value.isString()) { + clientSettingsBuilder.writeConcern(new WriteConcern(value.asString().getValue())); + } else { + clientSettingsBuilder.writeConcern(new WriteConcern(value.asInt32().intValue())); + } break; case "maxPoolSize": clientSettingsBuilder.applyToConnectionPoolSettings(builder -> builder.maxSize(value.asNumber().intValue())); break; + case "minPoolSize": + clientSettingsBuilder.applyToConnectionPoolSettings(builder -> builder.minSize(value.asNumber().intValue())); + break; case "waitQueueTimeoutMS": clientSettingsBuilder.applyToConnectionPoolSettings(builder -> builder.maxWaitTime(value.asNumber().longValue(), TimeUnit.MILLISECONDS)); break; + case "heartbeatFrequencyMS": + clientSettingsBuilder.applyToServerSettings(builder -> + builder.heartbeatFrequency(value.asNumber().longValue(), TimeUnit.MILLISECONDS)); + break; + case "connectTimeoutMS": + clientSettingsBuilder.applyToSocketSettings(builder -> + builder.connectTimeout(value.asNumber().intValue(), TimeUnit.MILLISECONDS)); + break; + case "socketTimeoutMS": + clientSettingsBuilder.applyToSocketSettings(builder -> + builder.readTimeout(value.asNumber().intValue(), TimeUnit.MILLISECONDS)); + break; + case "serverSelectionTimeoutMS": + clientSettingsBuilder.applyToClusterSettings(builder -> + builder.serverSelectionTimeout(value.asNumber().longValue(), TimeUnit.MILLISECONDS)); + break; case "loadBalanced": if (value.asBoolean().getValue()) { clientSettingsBuilder.applyToClusterSettings(builder -> builder.mode(ClusterConnectionMode.LOAD_BALANCED)); @@ -555,6 +628,9 @@ public void close() { for (MongoClient client : clients.values()) { client.close(); } + for (ExecutorService executorService : threads.values()) { + executorService.shutdownNow(); + } } private static class EntityCommandListener implements CommandListener { diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/EventMatcher.java b/driver-sync/src/test/functional/com/mongodb/client/unified/EventMatcher.java index 3f8ef9d70a4..89da0ce58b6 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/EventMatcher.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/EventMatcher.java @@ -16,6 +16,7 @@ package com.mongodb.client.unified; +import com.mongodb.connection.ServerType; import com.mongodb.event.CommandEvent; import com.mongodb.event.CommandFailedEvent; import com.mongodb.event.CommandStartedEvent; @@ -23,16 +24,24 @@ import com.mongodb.event.ConnectionCheckOutFailedEvent; import com.mongodb.event.ConnectionClosedEvent; import com.mongodb.event.ConnectionPoolClearedEvent; +import com.mongodb.event.ConnectionPoolReadyEvent; +import com.mongodb.event.ServerDescriptionChangedEvent; +import com.mongodb.internal.connection.TestConnectionPoolListener; +import com.mongodb.internal.connection.TestServerListener; import org.bson.BsonArray; import org.bson.BsonDocument; import org.bson.types.ObjectId; +import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; final class EventMatcher { private final ValueMatcher valueMatcher; @@ -163,6 +172,105 @@ public void assertConnectionPoolEventsEquality(final String client, final boolea context.pop(); } + public void waitForConnectionPoolEvents(final String client, final BsonDocument event, final int count, + final TestConnectionPoolListener connectionPoolListener) { + context.push(ContextElement.ofWaitForConnectionPoolEvents(client, event, count)); + Class eventClass; + switch (event.getFirstKey()) { + case "poolClearedEvent": + eventClass = ConnectionPoolClearedEvent.class; + break; + case "poolReadyEvent": + eventClass = ConnectionPoolReadyEvent.class; + break; + default: + throw new UnsupportedOperationException("Unsupported event: " + event.getFirstKey()); + } + if (!event.getDocument(event.getFirstKey()).isEmpty()) { + throw new UnsupportedOperationException("Wait for connection pool events does not support event properties"); + } + try { + connectionPoolListener.waitForEvent(eventClass, count, 10, TimeUnit.SECONDS); + context.pop(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + fail(context.getMessage("Timed out waiting for connection pool events")); + } + } + + public void assertConnectionPoolEventCount(final String client, final BsonDocument event, final int count, final List events) { + context.push(ContextElement.ofConnectionPoolEventCount(client, event, count)); + Class eventClass; + switch (event.getFirstKey()) { + case "poolClearedEvent": + eventClass = ConnectionPoolClearedEvent.class; + break; + case "poolReadyEvent": + eventClass = ConnectionPoolReadyEvent.class; + break; + default: + throw new UnsupportedOperationException("Unsupported event: " + event.getFirstKey()); + } + if (!event.getDocument(event.getFirstKey()).isEmpty()) { + throw new UnsupportedOperationException("Wait for connection pool events does not support event properties"); + } + long matchCount = events.stream().filter(cur -> cur.getClass().equals(eventClass)).count(); + assertEquals(context.getMessage("Expected connection pool event counts to match"), count, matchCount); + context.pop(); + } + + + public void waitForServerDescriptionChangedEvents(final String client, final BsonDocument expectedEvent, final int count, + final TestServerListener serverListener) { + context.push(ContextElement.ofWaitForServerDescriptionChangedEvents(client, expectedEvent, count)); + BsonDocument expectedEventContents = getEventContents(expectedEvent); + try { + serverListener.waitForServerDescriptionChangedEvent( + event -> serverDescriptionChangedEventMatches(expectedEventContents, event), count, 10, TimeUnit.SECONDS); + context.pop(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (TimeoutException e) { + fail(context.getMessage("Timed out waiting for server description changed events")); + } + } + + public void assertServerDescriptionChangeEventCount(final String client, final BsonDocument expectedEvent, final int count, + final List events) { + BsonDocument expectedEventContents = getEventContents(expectedEvent); + context.push(ContextElement.ofServerDescriptionChangeEventCount(client, expectedEvent, count)); + long matchCount = events.stream().filter(event -> serverDescriptionChangedEventMatches(expectedEventContents, event)).count(); + assertEquals(context.getMessage("Expected server description changed event counts to match"), count, matchCount); + context.pop(); + } + + @NotNull + private BsonDocument getEventContents(final BsonDocument expectedEvent) { + if (!expectedEvent.getFirstKey().equals("serverDescriptionChangedEvent")) { + throw new UnsupportedOperationException("Unsupported event type " + expectedEvent.getFirstKey()); + } + @SuppressWarnings("OptionalGetWithoutIsPresent") + BsonDocument expectedEventContents = expectedEvent.values().stream().findFirst().get().asDocument(); + if (expectedEventContents.size() != 1 || !expectedEventContents.getFirstKey().equals("newDescription") + || expectedEventContents.getDocument("newDescription").size() != 1) { + throw new UnsupportedOperationException("Unsupported event contents " + expectedEvent); + } + return expectedEventContents; + } + + private static boolean serverDescriptionChangedEventMatches(final BsonDocument expectedEventContents, + final ServerDescriptionChangedEvent event) { + String newType = expectedEventContents.getDocument("newDescription").getString("type").getValue(); + //noinspection SwitchStatementWithTooFewBranches + switch (newType) { + case "Unknown": + return event.getNewDescription().getType() == ServerType.UNKNOWN; + default: + throw new UnsupportedOperationException(); + } + } + private static String getEventType(final Class eventClass) { String eventClassName = eventClass.getSimpleName(); if (eventClassName.startsWith("ConnectionPool")) { diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java index 567ed4636ad..00dedee658c 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java @@ -1267,11 +1267,14 @@ public OperationResult executeRunCommand(final BsonDocument operation) { BsonDocument arguments = operation.getDocument("arguments", new BsonDocument()); ClientSession session = getSession(arguments); BsonDocument command = arguments.getDocument("command"); + ReadPreference readPreference = arguments.containsKey("readPreference") + ? asReadPreference(arguments.getDocument("readPreference")) : null; for (Map.Entry cur : arguments.entrySet()) { switch (cur.getKey()) { case "command": case "commandName": case "session": + case "readPreference": break; default: throw new UnsupportedOperationException("Unsupported argument: " + cur.getKey()); @@ -1280,9 +1283,17 @@ public OperationResult executeRunCommand(final BsonDocument operation) { return resultOf(() -> { if (session == null) { - return database.runCommand(command, BsonDocument.class); + if (readPreference == null) { + return database.runCommand(command, BsonDocument.class); + } else { + return database.runCommand(command, readPreference, BsonDocument.class); + } } else { - return database.runCommand(session, command, BsonDocument.class); + if (readPreference == null) { + return database.runCommand(session, command, BsonDocument.class); + } else { + return database.runCommand(session, command, readPreference, BsonDocument.class); + } } }); } diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java new file mode 100644 index 00000000000..c01bdca845e --- /dev/null +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mongodb.client.unified; + +import com.mongodb.lang.Nullable; +import org.bson.BsonArray; +import org.bson.BsonDocument; +import org.junit.runners.Parameterized; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Collection; + +public class UnifiedServerDiscoveryAndMonitoringTest extends UnifiedSyncTest { + + public UnifiedServerDiscoveryAndMonitoringTest(@SuppressWarnings("unused") final String fileDescription, + @SuppressWarnings("unused") final String testDescription, + final String schemaVersion, @Nullable final BsonArray runOnRequirements, final BsonArray entities, + final BsonArray initialData, final BsonDocument definition) { + super(schemaVersion, runOnRequirements, entities, initialData, definition); + } + + @Parameterized.Parameters(name = "{0}: {1}") + public static Collection data() throws URISyntaxException, IOException { + return getTestData("unified-test-format/server-discovery-and-monitoring"); + } +} diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java index 5ffd06b121c..62f2f254b68 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java @@ -19,6 +19,7 @@ import com.mongodb.ClientEncryptionSettings; import com.mongodb.MongoClientSettings; import com.mongodb.MongoNamespace; +import com.mongodb.ReadPreference; import com.mongodb.WriteConcern; import com.mongodb.client.ClientSession; import com.mongodb.client.MongoClient; @@ -27,6 +28,9 @@ import com.mongodb.client.model.Filters; import com.mongodb.client.test.CollectionHelper; import com.mongodb.client.vault.ClientEncryption; +import com.mongodb.connection.ClusterDescription; +import com.mongodb.connection.ClusterType; +import com.mongodb.connection.ServerDescription; import com.mongodb.event.CommandEvent; import com.mongodb.event.CommandStartedEvent; import com.mongodb.internal.connection.TestCommandListener; @@ -36,6 +40,7 @@ import org.bson.BsonBoolean; import org.bson.BsonDocument; import org.bson.BsonDouble; +import org.bson.BsonInt32; import org.bson.BsonString; import org.bson.BsonValue; import org.bson.codecs.BsonDocumentCodec; @@ -55,6 +60,11 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import static com.mongodb.ClusterFixture.getServerVersion; @@ -68,6 +78,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import static util.JsonPoweredTestHelper.getTestDocument; import static util.JsonPoweredTestHelper.getTestFiles; @@ -84,15 +95,35 @@ public abstract class UnifiedTest { private final BsonArray entitiesArray; private final BsonArray initialData; private final BsonDocument definition; - private final AssertionContext context = new AssertionContext(); private final Entities entities = new Entities(); private final UnifiedCrudHelper crudHelper; private final UnifiedGridFSHelper gridFSHelper = new UnifiedGridFSHelper(entities); private final UnifiedClientEncryptionHelper clientEncryptionHelper = new UnifiedClientEncryptionHelper(entities); - private final ValueMatcher valueMatcher = new ValueMatcher(entities, context); - private final ErrorMatcher errorMatcher = new ErrorMatcher(context); - private final EventMatcher eventMatcher = new EventMatcher(valueMatcher, context); private final List failPoints = new ArrayList<>(); + private final UnifiedTestContext rootContext = new UnifiedTestContext(); + + private class UnifiedTestContext { + private final AssertionContext context = new AssertionContext(); + private final ValueMatcher valueMatcher = new ValueMatcher(entities, context); + private final ErrorMatcher errorMatcher = new ErrorMatcher(context); + private final EventMatcher eventMatcher = new EventMatcher(valueMatcher, context); + + AssertionContext getAssertionContext() { + return context; + } + + ValueMatcher getValueMatcher() { + return valueMatcher; + } + + ErrorMatcher getErrorMatcher() { + return errorMatcher; + } + + EventMatcher getEventMatcher() { + return eventMatcher; + } + } public UnifiedTest(@Nullable final String fileDescription, final String schemaVersion, @Nullable final BsonArray runOnRequirements, final BsonArray entitiesArray, final BsonArray initialData, final BsonDocument definition) { @@ -102,7 +133,7 @@ public UnifiedTest(@Nullable final String fileDescription, final String schemaVe this.entitiesArray = entitiesArray; this.initialData = initialData; this.definition = definition; - this.context.push(ContextElement.ofTest(definition)); + this.rootContext.getAssertionContext().push(ContextElement.ofTest(definition)); crudHelper = new UnifiedCrudHelper(entities, definition.getString("description").getValue()); } @@ -145,14 +176,16 @@ private static Object[] createTestData(final BsonDocument fileDocument, final Bs public void setUp() { assertTrue(String.format("Unsupported schema version %s", schemaVersion), schemaVersion.startsWith("1.0") - || schemaVersion.startsWith("1.1") - || schemaVersion.startsWith("1.2") - || schemaVersion.startsWith("1.3") - || schemaVersion.startsWith("1.4") - || schemaVersion.startsWith("1.5") - || schemaVersion.startsWith("1.6") - || schemaVersion.startsWith("1.7") - || schemaVersion.startsWith("1.8")); + || schemaVersion.startsWith("1.1") + || schemaVersion.startsWith("1.2") + || schemaVersion.startsWith("1.3") + || schemaVersion.startsWith("1.4") + || schemaVersion.startsWith("1.5") + || schemaVersion.startsWith("1.6") + || schemaVersion.startsWith("1.7") + || schemaVersion.startsWith("1.8") + || schemaVersion.startsWith("1.9") + || schemaVersion.startsWith("1.10")); if (runOnRequirements != null) { assumeTrue("Run-on requirements not met", runOnRequirementsMet(runOnRequirements, getMongoClientSettings(), getServerVersion())); @@ -186,19 +219,19 @@ public void shouldPassAllOutcomes() { BsonArray operations = definition.getArray("operations"); for (int i = 0; i < operations.size(); i++) { BsonValue cur = operations.get(i); - assertOperation(cur.asDocument(), i); + assertOperation(rootContext, cur.asDocument(), i); } if (definition.containsKey("outcome")) { - assertOutcome(); + assertOutcome(rootContext); } if (definition.containsKey("expectEvents")) { - compareEvents(definition); + compareEvents(rootContext, definition); } } - private void compareEvents(final BsonDocument definition) { + private void compareEvents(final UnifiedTestContext context, final BsonDocument definition) { for (BsonValue cur : definition.getArray("expectEvents")) { BsonDocument curClientEvents = cur.asDocument(); String client = curClientEvents.getString("client").getValue(); @@ -206,11 +239,11 @@ private void compareEvents(final BsonDocument definition) { String eventType = curClientEvents.getString("eventType", new BsonString("command")).getValue(); if (eventType.equals("command")) { TestCommandListener listener = entities.getClientCommandListener(client); - eventMatcher.assertCommandEventsEquality(client, ignoreExtraEvents, curClientEvents.getArray("events"), + context.getEventMatcher().assertCommandEventsEquality(client, ignoreExtraEvents, curClientEvents.getArray("events"), listener.getEvents()); } else if (eventType.equals("cmap")) { TestConnectionPoolListener listener = entities.getConnectionPoolListener(client); - eventMatcher.assertConnectionPoolEventsEquality(client, ignoreExtraEvents, curClientEvents.getArray("events"), + context.getEventMatcher().assertConnectionPoolEventsEquality(client, ignoreExtraEvents, curClientEvents.getArray("events"), listener.getEvents()); } else { throw new UnsupportedOperationException("Unexpected event type: " + eventType); @@ -218,42 +251,62 @@ private void compareEvents(final BsonDocument definition) { } } - private void assertOutcome() { + private void assertOutcome(final UnifiedTestContext context) { for (BsonValue cur : definition.getArray("outcome")) { BsonDocument curDocument = cur.asDocument(); MongoNamespace namespace = new MongoNamespace(curDocument.getString("databaseName").getValue(), curDocument.getString("collectionName").getValue()); List expectedOutcome = curDocument.getArray("documents").stream().map(BsonValue::asDocument).collect(toList()); List actualOutcome = new CollectionHelper<>(new BsonDocumentCodec(), namespace).find(); - context.push(ContextElement.ofOutcome(namespace, expectedOutcome, actualOutcome)); - assertEquals(context.getMessage("Outcomes are not equal"), expectedOutcome, actualOutcome); - context.pop(); + context.getAssertionContext().push(ContextElement.ofOutcome(namespace, expectedOutcome, actualOutcome)); + assertEquals(context.getAssertionContext().getMessage("Outcomes are not equal"), expectedOutcome, actualOutcome); + context.getAssertionContext().pop(); } } - private void assertOperation(final BsonDocument operation, final int operationIndex) { - OperationResult result = executeOperation(operation, operationIndex); - context.push(ContextElement.ofCompletedOperation(operation, result, operationIndex)); + private void assertOperation(final UnifiedTestContext context, final BsonDocument operation, final int operationIndex) { + OperationResult result = executeOperation(context, operation, operationIndex); + context.getAssertionContext().push(ContextElement.ofCompletedOperation(operation, result, operationIndex)); if (!operation.getBoolean("ignoreResultAndError", BsonBoolean.FALSE).getValue()) { if (operation.containsKey("expectResult")) { - assertNull(context.getMessage("The operation expects a result but an exception occurred"), + assertNull(context.getAssertionContext().getMessage("The operation expects a result but an exception occurred"), result.getException()); - valueMatcher.assertValuesMatch(operation.get("expectResult"), result.getResult()); + context.getValueMatcher().assertValuesMatch(operation.get("expectResult"), result.getResult()); } else if (operation.containsKey("expectError")) { - assertNotNull(context.getMessage("The operation expects an error but no exception was thrown"), result.getException()); - errorMatcher.assertErrorsMatch(operation.getDocument("expectError"), result.getException()); + assertNotNull(context.getAssertionContext().getMessage("The operation expects an error but no exception was thrown"), + result.getException()); + context.getErrorMatcher().assertErrorsMatch(operation.getDocument("expectError"), result.getException()); } else { - assertNull(context.getMessage("The operation expects no error but an exception occurred"), result.getException()); + assertNull(context.getAssertionContext().getMessage("The operation expects no error but an exception occurred"), + result.getException()); } } - context.pop(); + context.getAssertionContext().pop(); } - private OperationResult executeOperation(final BsonDocument operation, final int operationNum) { - context.push(ContextElement.ofStartedOperation(operation, operationNum)); + private OperationResult executeOperation(final UnifiedTestContext context, final BsonDocument operation, final int operationNum) { + context.getAssertionContext().push(ContextElement.ofStartedOperation(operation, operationNum)); String name = operation.getString("name").getValue(); try { switch (name) { + case "createEntities": + return executeCreateEntities(operation); + case "wait": + return executeWait(operation); + case "waitForEvent": + return executeWaitForEvent(context, operation); + case "waitForPrimaryChange": + return executeWaitPrimaryChange(context, operation); + case "waitForThread": + return executeWaitForThread(context, operation); + case "recordTopologyDescription": + return executeRecordTopologyDescription(operation); + case "assertTopologyType": + return executeAssertTopologyType(context, operation); + case "runOnThread": + return executeRunOnThread(context, operation); + case "assertEventCount": + return executeAssertEventCount(context, operation); case "failPoint": return executeFailPoint(operation); case "targetedFailPoint": @@ -273,7 +326,7 @@ private OperationResult executeOperation(final BsonDocument operation, final int case "assertDifferentLsidOnLastTwoCommands": return executeAssertDifferentLsidOnLastTwoCommands(operation); case "assertNumberConnectionsCheckedOut": - return executeAssertNumberConnectionsCheckedOut(operation); + return executeAssertNumberConnectionsCheckedOut(context, operation); case "assertSessionTransactionState": return executeAssertSessionTransactionState(operation); case "assertCollectionExists": @@ -339,7 +392,7 @@ private OperationResult executeOperation(final BsonDocument operation, final int case "abortTransaction": return crudHelper.executeAbortTransaction(operation); case "withTransaction": - return crudHelper.executeWithTransaction(operation, this::assertOperation); + return crudHelper.executeWithTransaction(operation, (op, idx) -> assertOperation(context, op, idx)); case "createFindCursor": return crudHelper.createFindCursor(operation); case "createChangeStream": @@ -359,7 +412,7 @@ private OperationResult executeOperation(final BsonDocument operation, final int case "runCommand": return crudHelper.executeRunCommand(operation); case "loop": - return loop(operation); + return loop(context, operation); case "createDataKey": return clientEncryptionHelper.executeCreateDataKey(operation); case "addKeyAltName": @@ -380,11 +433,11 @@ private OperationResult executeOperation(final BsonDocument operation, final int throw new UnsupportedOperationException("Unsupported test operation: " + name); } } finally { - context.pop(); + context.getAssertionContext().pop(); } } - private OperationResult loop(final BsonDocument operation) { + private OperationResult loop(final UnifiedTestContext context, final BsonDocument operation) { BsonDocument arguments = operation.getDocument("arguments"); int numIterations = 0; @@ -399,7 +452,7 @@ private OperationResult loop(final BsonDocument operation) { for (int i = 0; i < array.size(); i++) { BsonValue cur = array.get(i); try { - assertOperation(cur.asDocument().clone(), i); + assertOperation(context, cur.asDocument().clone(), i); numSuccessfulOperations++; } catch (AssertionError e) { if (storeFailures) { @@ -449,6 +502,185 @@ protected boolean terminateLoop() { return true; } + private OperationResult executeCreateEntities(final BsonDocument operation) { + entities.init(operation.getDocument("arguments").getArray("entities"), + false, + this::createMongoClient, + this::createGridFSBucket, + this::createClientEncryption); + return OperationResult.NONE; + } + + private OperationResult executeWait(final BsonDocument operation) { + try { + Thread.sleep(operation.getDocument("arguments").getNumber("ms").longValue()); + return OperationResult.NONE; + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + private OperationResult executeWaitForEvent(final UnifiedTestContext context, final BsonDocument operation) { + BsonDocument arguments = operation.getDocument("arguments"); + String clientId = arguments.getString("client").getValue(); + BsonDocument event = arguments.getDocument("event"); + String eventName = event.getFirstKey(); + int count = arguments.getNumber("count").intValue(); + + switch (eventName) { + case "serverDescriptionChangedEvent": + context.getEventMatcher().waitForServerDescriptionChangedEvents(clientId, event, count, + entities.getServerListener(clientId)); + break; + case "poolClearedEvent": + case "poolReadyEvent": + context.getEventMatcher().waitForConnectionPoolEvents(clientId, event, count, entities.getConnectionPoolListener(clientId)); + break; + default: + throw new UnsupportedOperationException("Unsupported event: " + eventName); + } + + return OperationResult.NONE; + } + + private OperationResult executeAssertEventCount(final UnifiedTestContext context, final BsonDocument operation) { + BsonDocument arguments = operation.getDocument("arguments"); + String clientId = arguments.getString("client").getValue(); + BsonDocument event = arguments.getDocument("event"); + String eventName = event.getFirstKey(); + int count = arguments.getNumber("count").intValue(); + + switch (eventName) { + case "serverDescriptionChangedEvent": + context.getEventMatcher().assertServerDescriptionChangeEventCount(clientId, event, count, + entities.getServerListener(clientId).getServerDescriptionChangedEvents()); + break; + case "poolClearedEvent": + case "poolReadyEvent": + context.getEventMatcher().assertConnectionPoolEventCount(clientId, event, count, + entities.getConnectionPoolListener(clientId).getEvents()); + break; + default: + throw new UnsupportedOperationException("Unsupported event: " + eventName); + } + + return OperationResult.NONE; + } + + private OperationResult executeWaitPrimaryChange(final UnifiedTestContext context, final BsonDocument operation) { + context.getAssertionContext().push(ContextElement.ofWaitForPrimaryChange()); + BsonDocument arguments = operation.getDocument("arguments"); + MongoClient client = entities.getClient(arguments.getString("client").getValue()); + ClusterDescription priorClusterDescription = + entities.getTopologyDescription(arguments.getString("priorTopologyDescription").getValue()); + ClusterDescription currentClusterDescription = client.getClusterDescription(); + long timeoutNanos = + TimeUnit.NANOSECONDS.convert(arguments.getNumber("timeoutMS", new BsonInt32(10000)).longValue(), TimeUnit.MILLISECONDS); + long startTime = System.nanoTime(); + while (primaryIsSame(priorClusterDescription, currentClusterDescription) || noPrimary(currentClusterDescription)) { + if (System.nanoTime() - startTime > timeoutNanos) { + fail(context.getAssertionContext().getMessage("Timed out waiting for primary change")); + } + try { + //noinspection BusyWait + Thread.sleep(10); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + currentClusterDescription = client.getClusterDescription(); + } + context.getAssertionContext().pop(); + return OperationResult.NONE; + } + + private boolean noPrimary(final ClusterDescription clusterDescription) { + return ReadPreference.primary().choose(clusterDescription).isEmpty(); + } + + private boolean primaryIsSame(final ClusterDescription priorClusterDescription, final ClusterDescription currentClusterDescription) { + List priorPrimaries = ReadPreference.primary().choose(priorClusterDescription); + List currentPrimaries = ReadPreference.primary().choose(currentClusterDescription); + if (priorPrimaries.isEmpty() && currentPrimaries.isEmpty()) { + return true; + } + if (priorPrimaries.size() == 1 && currentPrimaries.size() == 1) { + return priorPrimaries.get(0).getAddress().equals(currentPrimaries.get(0).getAddress()); + } else { + return false; + } + } + + private OperationResult executeWaitForThread(final UnifiedTestContext context, final BsonDocument operation) { + BsonDocument arguments = operation.getDocument("arguments"); + String threadId = arguments.getString("thread").getValue(); + context.getAssertionContext().push(ContextElement.ofWaitForThread(threadId)); + List> tasks = entities.getThreadTasks(threadId); + for (Future task : tasks) { + try { + task.get(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException executionException) { + try { + throw executionException.getCause(); + } catch (Throwable e) { + fail(context.getAssertionContext().getMessage(e.getMessage())); + } + } catch (TimeoutException e) { + fail(context.getAssertionContext().getMessage(e.getMessage())); + } + } + entities.clearThreadTasks(threadId); + context.getAssertionContext().pop(); + return OperationResult.NONE; + } + + private OperationResult executeRecordTopologyDescription(final BsonDocument operation) { + BsonDocument arguments = operation.getDocument("arguments"); + ClusterDescription clusterDescription = entities.getClient(arguments.getString("client").getValue()).getClusterDescription(); + String topologyDescriptionId = arguments.getString("id").getValue(); + entities.addTopologyDescription(topologyDescriptionId, clusterDescription); + return OperationResult.NONE; + } + + private OperationResult executeAssertTopologyType(final UnifiedTestContext context, final BsonDocument operation) { + BsonDocument arguments = operation.getDocument("arguments"); + ClusterDescription clusterDescription = entities.getTopologyDescription(arguments.getString("topologyDescription").getValue()); + String expectedTopologyType = arguments.getString("topologyType").getValue(); + + context.getAssertionContext().push(ContextElement.ofTopologyType(expectedTopologyType)); + + assertEquals(context.getAssertionContext().getMessage("Unexpected topology type"), getClusterType(expectedTopologyType), + clusterDescription.getType()); + + context.getAssertionContext().pop(); + return OperationResult.NONE; + } + + private ClusterType getClusterType(final String topologyType) { + if (topologyType.equalsIgnoreCase("Sharded")) { + return ClusterType.SHARDED; + } else if (topologyType.equalsIgnoreCase("LoadBalanced")) { + return ClusterType.LOAD_BALANCED; + } else if (topologyType.startsWith("ReplicaSet")) { + return ClusterType.REPLICA_SET; + } else if (topologyType.equalsIgnoreCase("Unknown")) { + return ClusterType.UNKNOWN; + } else { + throw new IllegalArgumentException("Unsupported topology type: " + topologyType); + } + } + + private OperationResult executeRunOnThread(final UnifiedTestContext context, final BsonDocument operation) { + UnifiedTestContext newContext = new UnifiedTestContext(); + BsonDocument arguments = operation.getDocument("arguments"); + String threadId = arguments.getString("thread").getValue(); + ExecutorService thread = entities.getThread(threadId); + Future future = thread.submit(() -> assertOperation(newContext, arguments.getDocument("operation"), 0)); + entities.addThreadTask(threadId, future); + return OperationResult.NONE; + } + private OperationResult executeFailPoint(final BsonDocument operation) { FailPoint failPoint = FailPoint.untargeted(operation, entities); failPoint.executeFailPoint(); @@ -499,10 +731,10 @@ private OperationResult executeAssertSessionPinniness(final BsonDocument operati return OperationResult.NONE; } - private OperationResult executeAssertNumberConnectionsCheckedOut(final BsonDocument operation) { + private OperationResult executeAssertNumberConnectionsCheckedOut(final UnifiedTestContext context, final BsonDocument operation) { TestConnectionPoolListener listener = entities.getConnectionPoolListener( operation.getDocument("arguments").getString("client").getValue()); - assertEquals(context.getMessage("Number of checked out connections must match expected"), + assertEquals(context.getAssertionContext().getMessage("Number of checked out connections must match expected"), operation.getDocument("arguments").getNumber("connections").intValue(), listener.getNumConnectionsCheckedOut()); return OperationResult.NONE; }