From ac5dde853c13c105e284e71f2f1d635e5828f3d2 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Fri, 15 Jul 2022 10:02:03 -0400 Subject: [PATCH] Sync server discovery integration spec tests (#980) Add support for readPreference argument to runAdminCommand JAVA-4677 --- .../mongodb/client/test/CollectionHelper.java | 5 +++++ .../hello-command-error.json | 18 +----------------- .../hello-network-error.json | 2 +- .../hello-timeout.json | 18 +----------------- .../rediscover-quickly-after-step-down.json | 19 ++++++++++++++++--- .../mongodb/client/AbstractUnifiedTest.java | 8 +++++++- 6 files changed, 31 insertions(+), 39 deletions(-) diff --git a/driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java b/driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java index 40d183850b0..dac473c4d28 100644 --- a/driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java +++ b/driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java @@ -19,6 +19,7 @@ import com.mongodb.MongoClientSettings; import com.mongodb.MongoCommandException; import com.mongodb.MongoNamespace; +import com.mongodb.ReadPreference; import com.mongodb.ServerCursor; import com.mongodb.WriteConcern; import com.mongodb.client.model.CreateCollectionOptions; @@ -411,4 +412,8 @@ public void runAdminCommand(final String command) { public void runAdminCommand(final BsonDocument command) { new CommandReadOperation<>("admin", command, new BsonDocumentCodec()).execute(getBinding()); } + + public void runAdminCommand(final BsonDocument command, final ReadPreference readPreference) { + new CommandReadOperation<>("admin", command, new BsonDocumentCodec()).execute(getBinding(readPreference)); + } } 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 index 05a93e751c5..d3bccd39008 100644 --- 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 @@ -117,7 +117,7 @@ "failPoint": { "configureFailPoint": "failCommand", "mode": { - "times": 2 + "times": 4 }, "data": { "failCommands": [ @@ -162,22 +162,6 @@ } ] } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } } ], "expectations": [ 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 index b699363923b..f9761d75563 100644 --- 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 @@ -116,7 +116,7 @@ "failPoint": { "configureFailPoint": "failCommand", "mode": { - "times": 2 + "times": 4 }, "data": { "failCommands": [ 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 index 7bdc61a9126..004f8f449d5 100644 --- 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 @@ -117,7 +117,7 @@ "failPoint": { "configureFailPoint": "failCommand", "mode": { - "times": 2 + "times": 4 }, "data": { "failCommands": [ @@ -160,22 +160,6 @@ } ] } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "ServerMarkedUnknownEvent", - "count": 1 - } - }, - { - "name": "assertEventCount", - "object": "testRunner", - "arguments": { - "event": "PoolClearedEvent", - "count": 1 - } } ], "expectations": [ 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 index d17146cc1d4..41fbdc695cf 100644 --- 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 @@ -45,14 +45,27 @@ "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": 1, - "secondaryCatchUpPeriodSecs": 1, + "replSetStepDown": 30, + "secondaryCatchUpPeriodSecs": 30, "force": false } } @@ -61,7 +74,7 @@ "name": "waitForPrimaryChange", "object": "testRunner", "arguments": { - "timeoutMS": 5000 + "timeoutMS": 15000 } }, { diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractUnifiedTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractUnifiedTest.java index 71b169fb9eb..fa01ba3903a 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractUnifiedTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractUnifiedTest.java @@ -548,7 +548,13 @@ public Void execute() { newPrimary = getCurrentPrimary(); } } else if (operationName.equals("runAdminCommand")) { - collectionHelper.runAdminCommand(operation.getDocument("arguments").getDocument("command")); + BsonDocument arguments = operation.getDocument("arguments"); + BsonDocument command = arguments.getDocument("command"); + if (arguments.containsKey("readPreference")) { + collectionHelper.runAdminCommand(command, helper.getReadPreference(arguments)); + } else { + collectionHelper.runAdminCommand(command); + } } else if (operationName.equals("assertSessionPinned")) { final BsonDocument arguments = operation.getDocument("arguments", new BsonDocument()); assertNotNull(sessionsMap.get(arguments.getString("session").getValue()).getPinnedServerAddress());