Skip to content

Commit ac5dde8

Browse files
authored
Sync server discovery integration spec tests (#980)
Add support for readPreference argument to runAdminCommand JAVA-4677
1 parent 0523b3d commit ac5dde8

File tree

6 files changed

+31
-39
lines changed

6 files changed

+31
-39
lines changed

driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.mongodb.MongoClientSettings;
2020
import com.mongodb.MongoCommandException;
2121
import com.mongodb.MongoNamespace;
22+
import com.mongodb.ReadPreference;
2223
import com.mongodb.ServerCursor;
2324
import com.mongodb.WriteConcern;
2425
import com.mongodb.client.model.CreateCollectionOptions;
@@ -411,4 +412,8 @@ public void runAdminCommand(final String command) {
411412
public void runAdminCommand(final BsonDocument command) {
412413
new CommandReadOperation<>("admin", command, new BsonDocumentCodec()).execute(getBinding());
413414
}
415+
416+
public void runAdminCommand(final BsonDocument command, final ReadPreference readPreference) {
417+
new CommandReadOperation<>("admin", command, new BsonDocumentCodec()).execute(getBinding(readPreference));
418+
}
414419
}

driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-command-error.json

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"failPoint": {
118118
"configureFailPoint": "failCommand",
119119
"mode": {
120-
"times": 2
120+
"times": 4
121121
},
122122
"data": {
123123
"failCommands": [
@@ -162,22 +162,6 @@
162162
}
163163
]
164164
}
165-
},
166-
{
167-
"name": "assertEventCount",
168-
"object": "testRunner",
169-
"arguments": {
170-
"event": "ServerMarkedUnknownEvent",
171-
"count": 1
172-
}
173-
},
174-
{
175-
"name": "assertEventCount",
176-
"object": "testRunner",
177-
"arguments": {
178-
"event": "PoolClearedEvent",
179-
"count": 1
180-
}
181165
}
182166
],
183167
"expectations": [

driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-network-error.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"failPoint": {
117117
"configureFailPoint": "failCommand",
118118
"mode": {
119-
"times": 2
119+
"times": 4
120120
},
121121
"data": {
122122
"failCommands": [

driver-core/src/test/resources/server-discovery-and-monitoring-integration/hello-timeout.json

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"failPoint": {
118118
"configureFailPoint": "failCommand",
119119
"mode": {
120-
"times": 2
120+
"times": 4
121121
},
122122
"data": {
123123
"failCommands": [
@@ -160,22 +160,6 @@
160160
}
161161
]
162162
}
163-
},
164-
{
165-
"name": "assertEventCount",
166-
"object": "testRunner",
167-
"arguments": {
168-
"event": "ServerMarkedUnknownEvent",
169-
"count": 1
170-
}
171-
},
172-
{
173-
"name": "assertEventCount",
174-
"object": "testRunner",
175-
"arguments": {
176-
"event": "PoolClearedEvent",
177-
"count": 1
178-
}
179163
}
180164
],
181165
"expectations": [

driver-core/src/test/resources/server-discovery-and-monitoring-integration/rediscover-quickly-after-step-down.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,27 @@
4545
"name": "recordPrimary",
4646
"object": "testRunner"
4747
},
48+
{
49+
"name": "runAdminCommand",
50+
"object": "testRunner",
51+
"command_name": "replSetFreeze",
52+
"arguments": {
53+
"command": {
54+
"replSetFreeze": 0
55+
},
56+
"readPreference": {
57+
"mode": "Secondary"
58+
}
59+
}
60+
},
4861
{
4962
"name": "runAdminCommand",
5063
"object": "testRunner",
5164
"command_name": "replSetStepDown",
5265
"arguments": {
5366
"command": {
54-
"replSetStepDown": 1,
55-
"secondaryCatchUpPeriodSecs": 1,
67+
"replSetStepDown": 30,
68+
"secondaryCatchUpPeriodSecs": 30,
5669
"force": false
5770
}
5871
}
@@ -61,7 +74,7 @@
6174
"name": "waitForPrimaryChange",
6275
"object": "testRunner",
6376
"arguments": {
64-
"timeoutMS": 5000
77+
"timeoutMS": 15000
6578
}
6679
},
6780
{

driver-sync/src/test/functional/com/mongodb/client/AbstractUnifiedTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,13 @@ public Void execute() {
548548
newPrimary = getCurrentPrimary();
549549
}
550550
} else if (operationName.equals("runAdminCommand")) {
551-
collectionHelper.runAdminCommand(operation.getDocument("arguments").getDocument("command"));
551+
BsonDocument arguments = operation.getDocument("arguments");
552+
BsonDocument command = arguments.getDocument("command");
553+
if (arguments.containsKey("readPreference")) {
554+
collectionHelper.runAdminCommand(command, helper.getReadPreference(arguments));
555+
} else {
556+
collectionHelper.runAdminCommand(command);
557+
}
552558
} else if (operationName.equals("assertSessionPinned")) {
553559
final BsonDocument arguments = operation.getDocument("arguments", new BsonDocument());
554560
assertNotNull(sessionsMap.get(arguments.getString("session").getValue()).getPinnedServerAddress());

0 commit comments

Comments
 (0)