Skip to content

Commit 4444309

Browse files
committed
Updated retryable-reads tests to latest spec version
1 parent a12213f commit 4444309

25 files changed

+819
-26
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ public static List<CommandEvent> getExpectedEvents(final BsonArray expectedEvent
8181
// If the spec test supplies a $db field in the command, then use that database.
8282
if (commandDocument.containsKey("$db")) {
8383
actualDatabaseName = commandDocument.getString("$db").getValue();
84-
}
85-
else if (commandName.equals("commitTransaction") || commandName.equals("abortTransaction")) {
86-
actualDatabaseName = "admin";
8784
} else if (commandName.equals("")) {
8885
commandName = commandDocument.keySet().iterator().next();
8986
}
87+
88+
if (isAdminCommand(commandName)) {
89+
actualDatabaseName = "admin";
90+
}
91+
9092
// Not clear whether these global fields should be included, but also not clear how to efficiently exclude them
9193
if (ClusterFixture.serverVersionAtLeast(3, 6)) {
9294
commandDocument.put("$db", new BsonString(actualDatabaseName));
@@ -110,6 +112,11 @@ else if (commandName.equals("commitTransaction") || commandName.equals("abortTra
110112
return expectedEvents;
111113
}
112114

115+
private static final List<String> ADMIN_COMMANDS = asList("commitTransaction", "abortTransaction", "listDatabases");
116+
static boolean isAdminCommand(final String commandName) {
117+
return ADMIN_COMMANDS.contains(commandName);
118+
}
119+
113120
static boolean isWriteCommand(final String commandName) {
114121
return asList("insert", "update", "delete").contains(commandName);
115122
}

driver-core/src/test/resources/retryable-reads/README.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ Each YAML file has the following keys:
8484
- ``bucket_name``: Optional. The GridFS bucket name to use for testing.
8585

8686
- ``data``: The data that should exist in the collection(s) under test before
87-
each test run.
87+
each test run. This will typically be an array of documents to be inserted
88+
into the collection under test (i.e. ``collection_name``); however, this field
89+
may also be an object mapping collection names to arrays of documents to be
90+
inserted into the specified collection.
8891

8992
- ``tests``: An array of tests that are to be run independently of each other.
9093
Each test will have some or all of the following fields:
@@ -126,6 +129,9 @@ GridFS Tests
126129
------------
127130

128131
GridFS tests are denoted by when the YAML file contains ``bucket_name``.
132+
The ``data`` field will also be an object, which maps collection names
133+
(e.g. ``fs.files``) to an array of documents that should be inserted into
134+
the specified collection.
129135

130136
``fs.files`` and ``fs.chunks`` should be created in the database
131137
specified by ``database_name``. This could be done via inserts or by
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.1.11"
5+
}
6+
],
7+
"database_name": "retryable-reads-tests",
8+
"collection_name": "coll",
9+
"data": [
10+
{
11+
"_id": 1,
12+
"x": 11
13+
},
14+
{
15+
"_id": 2,
16+
"x": 22
17+
},
18+
{
19+
"_id": 3,
20+
"x": 33
21+
}
22+
],
23+
"tests": [
24+
{
25+
"description": "Aggregate with $merge does not retry",
26+
"failPoint": {
27+
"configureFailPoint": "failCommand",
28+
"mode": {
29+
"times": 1
30+
},
31+
"data": {
32+
"failCommands": [
33+
"aggregate"
34+
],
35+
"closeConnection": true
36+
}
37+
},
38+
"operations": [
39+
{
40+
"object": "collection",
41+
"name": "aggregate",
42+
"arguments": {
43+
"pipeline": [
44+
{
45+
"$match": {
46+
"_id": {
47+
"$gt": 1
48+
}
49+
}
50+
},
51+
{
52+
"$sort": {
53+
"x": 1
54+
}
55+
},
56+
{
57+
"$merge": {
58+
"into": "output-collection"
59+
}
60+
}
61+
]
62+
},
63+
"error": true
64+
}
65+
],
66+
"expectations": [
67+
{
68+
"command_started_event": {
69+
"command": {
70+
"aggregate": "coll",
71+
"pipeline": [
72+
{
73+
"$match": {
74+
"_id": {
75+
"$gt": 1
76+
}
77+
}
78+
},
79+
{
80+
"$sort": {
81+
"x": 1
82+
}
83+
},
84+
{
85+
"$merge": {
86+
"into": "output-collection"
87+
}
88+
}
89+
]
90+
},
91+
"command_name": "aggregate",
92+
"database_name": "retryable-reads-tests"
93+
}
94+
}
95+
]
96+
}
97+
]
98+
}

driver-core/src/test/resources/retryable-reads/aggregate-serverErrors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
]
126126
},
127127
{
128-
"description": "Aggregate succeeds after InterruptedDueToStepDown",
128+
"description": "Aggregate succeeds after InterruptedDueToReplStateChange",
129129
"failPoint": {
130130
"configureFailPoint": "failCommand",
131131
"mode": {

driver-core/src/test/resources/retryable-reads/count-serverErrors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
]
7272
},
7373
{
74-
"description": "Count succeeds after InterruptedDueToStepDown",
74+
"description": "Count succeeds after InterruptedDueToReplStateChange",
7575
"failPoint": {
7676
"configureFailPoint": "failCommand",
7777
"mode": {

driver-core/src/test/resources/retryable-reads/countDocuments-serverErrors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
]
9898
},
9999
{
100-
"description": "CountDocuments succeeds after InterruptedDueToStepDown",
100+
"description": "CountDocuments succeeds after InterruptedDueToReplStateChange",
101101
"failPoint": {
102102
"configureFailPoint": "failCommand",
103103
"mode": {

driver-core/src/test/resources/retryable-reads/distinct-serverErrors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
]
9696
},
9797
{
98-
"description": "Distinct succeeds after InterruptedDueToStepDown",
98+
"description": "Distinct succeeds after InterruptedDueToReplStateChange",
9999
"failPoint": {
100100
"configureFailPoint": "failCommand",
101101
"mode": {

driver-core/src/test/resources/retryable-reads/estimatedDocumentCount-serverErrors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
]
6969
},
7070
{
71-
"description": "EstimatedDocumentCount succeeds after InterruptedDueToStepDown",
71+
"description": "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange",
7272
"failPoint": {
7373
"configureFailPoint": "failCommand",
7474
"mode": {

driver-core/src/test/resources/retryable-reads/find-serverErrors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
]
115115
},
116116
{
117-
"description": "Find succeeds after InterruptedDueToStepDown",
117+
"description": "Find succeeds after InterruptedDueToReplStateChange",
118118
"failPoint": {
119119
"configureFailPoint": "failCommand",
120120
"mode": {

driver-core/src/test/resources/retryable-reads/findOne-serverErrors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
]
9595
},
9696
{
97-
"description": "FindOne succeeds after InterruptedDueToStepDown",
97+
"description": "FindOne succeeds after InterruptedDueToReplStateChange",
9898
"failPoint": {
9999
"configureFailPoint": "failCommand",
100100
"mode": {

0 commit comments

Comments
 (0)