Skip to content

Commit 3952536

Browse files
authored
Add command monitoring unified tests for serverConnectionId (#833)
The driver already supports the feature, so this is just test changes. It includes support for version 1.6 of the unified test format. JAVA-4238
1 parent 1648ad6 commit 3952536

File tree

6 files changed

+222
-1
lines changed

6 files changed

+222
-1
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"description": "pre-42-server-connection-id",
3+
"schemaVersion": "1.6",
4+
"runOnRequirements": [
5+
{
6+
"maxServerVersion": "4.0.99"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client",
13+
"observeEvents": [
14+
"commandStartedEvent",
15+
"commandSucceededEvent",
16+
"commandFailedEvent"
17+
]
18+
}
19+
},
20+
{
21+
"database": {
22+
"id": "database",
23+
"client": "client",
24+
"databaseName": "server-connection-id-tests"
25+
}
26+
},
27+
{
28+
"collection": {
29+
"id": "collection",
30+
"database": "database",
31+
"collectionName": "coll"
32+
}
33+
}
34+
],
35+
"initialData": [
36+
{
37+
"databaseName": "server-connection-id-tests",
38+
"collectionName": "coll",
39+
"documents": []
40+
}
41+
],
42+
"tests": [
43+
{
44+
"description": "command events do not include server connection id",
45+
"operations": [
46+
{
47+
"name": "insertOne",
48+
"object": "collection",
49+
"arguments": {
50+
"document": {
51+
"x": 1
52+
}
53+
}
54+
},
55+
{
56+
"name": "find",
57+
"object": "collection",
58+
"arguments": {
59+
"filter": {
60+
"$or": true
61+
}
62+
},
63+
"expectError": {
64+
"isError": true
65+
}
66+
}
67+
],
68+
"expectEvents": [
69+
{
70+
"client": "client",
71+
"events": [
72+
{
73+
"commandStartedEvent": {
74+
"commandName": "insert",
75+
"hasServerConnectionId": false
76+
}
77+
},
78+
{
79+
"commandSucceededEvent": {
80+
"commandName": "insert",
81+
"hasServerConnectionId": false
82+
}
83+
},
84+
{
85+
"commandStartedEvent": {
86+
"commandName": "find",
87+
"hasServerConnectionId": false
88+
}
89+
},
90+
{
91+
"commandFailedEvent": {
92+
"commandName": "find",
93+
"hasServerConnectionId": false
94+
}
95+
}
96+
]
97+
}
98+
]
99+
}
100+
]
101+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"description": "server-connection-id",
3+
"schemaVersion": "1.6",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "4.2"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client",
13+
"observeEvents": [
14+
"commandStartedEvent",
15+
"commandSucceededEvent",
16+
"commandFailedEvent"
17+
]
18+
}
19+
},
20+
{
21+
"database": {
22+
"id": "database",
23+
"client": "client",
24+
"databaseName": "server-connection-id-tests"
25+
}
26+
},
27+
{
28+
"collection": {
29+
"id": "collection",
30+
"database": "database",
31+
"collectionName": "coll"
32+
}
33+
}
34+
],
35+
"initialData": [
36+
{
37+
"databaseName": "server-connection-id-tests",
38+
"collectionName": "coll",
39+
"documents": []
40+
}
41+
],
42+
"tests": [
43+
{
44+
"description": "command events include server connection id",
45+
"operations": [
46+
{
47+
"name": "insertOne",
48+
"object": "collection",
49+
"arguments": {
50+
"document": {
51+
"x": 1
52+
}
53+
}
54+
},
55+
{
56+
"name": "find",
57+
"object": "collection",
58+
"arguments": {
59+
"filter": {
60+
"$or": true
61+
}
62+
},
63+
"expectError": {
64+
"isError": true
65+
}
66+
}
67+
],
68+
"expectEvents": [
69+
{
70+
"client": "client",
71+
"events": [
72+
{
73+
"commandStartedEvent": {
74+
"commandName": "insert",
75+
"hasServerConnectionId": true
76+
}
77+
},
78+
{
79+
"commandSucceededEvent": {
80+
"commandName": "insert",
81+
"hasServerConnectionId": true
82+
}
83+
},
84+
{
85+
"commandStartedEvent": {
86+
"commandName": "find",
87+
"hasServerConnectionId": true
88+
}
89+
},
90+
{
91+
"commandFailedEvent": {
92+
"commandName": "find",
93+
"hasServerConnectionId": true
94+
}
95+
}
96+
]
97+
}
98+
]
99+
}
100+
]
101+
}

driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/CommandMonitoringTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@
2525
import java.net.URISyntaxException;
2626
import java.util.Collection;
2727

28+
import static org.junit.Assume.assumeFalse;
29+
2830
public class CommandMonitoringTest extends UnifiedReactiveStreamsTest {
2931
public CommandMonitoringTest(@SuppressWarnings("unused") final String fileDescription,
3032
@SuppressWarnings("unused") final String testDescription,
3133
final String schemaVersion, @Nullable final BsonArray runOnRequirements, final BsonArray entities,
3234
final BsonArray initialData, final BsonDocument definition) {
3335
super(schemaVersion, runOnRequirements, entities, initialData, definition);
36+
// The driver has a hack where getLastError command is executed as part of the handshake in order to get a connectionId
37+
// even when the hello command response doesn't contain it.
38+
assumeFalse(fileDescription.equals("pre-42-server-connection-id"));
3439
}
3540

3641
@Parameterized.Parameters(name = "{0}: {1}")

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public CommandMonitoringTest(@SuppressWarnings("unused") final String fileDescri
3838
final BsonDocument definition) {
3939
super(schemaVersion, runOnRequirements, entities, initialData, definition);
4040
assumeFalse(isServerlessTest());
41+
// The driver has a hack where getLastError command is executed as part of the handshake in order to get a connectionId
42+
// even when the hello command response doesn't contain it.
43+
assumeFalse(fileDescription.equals("pre-42-server-connection-id"));
4144
}
4245

4346
@Parameterized.Parameters(name = "{0}: {1}")

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public void assertCommandEventsEquality(final String client, final BsonArray exp
6868
}
6969
}
7070

71+
if (expected.containsKey("hasServerConnectionId")) {
72+
boolean hasServerConnectionId = expected.getBoolean("hasServerConnectionId").getValue();
73+
Integer serverConnectionId = actual.getConnectionDescription().getConnectionId().getServerValue();
74+
if (hasServerConnectionId) {
75+
assertNotNull(context.getMessage("Expected serverConnectionId"), serverConnectionId);
76+
} else {
77+
assertNull(context.getMessage("Expected no serverConnectionId"), serverConnectionId);
78+
}
79+
}
80+
7181
if (actual.getClass().equals(CommandStartedEvent.class)) {
7282
assertEquals(context.getMessage("Expected CommandStartedEvent"), eventType, "commandStartedEvent");
7383
CommandStartedEvent actualCommandStartedEvent = (CommandStartedEvent) actual;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ public void setUp() {
143143
|| schemaVersion.startsWith("1.2")
144144
|| schemaVersion.startsWith("1.3")
145145
|| schemaVersion.startsWith("1.4")
146-
|| schemaVersion.startsWith("1.5"));
146+
|| schemaVersion.startsWith("1.5")
147+
|| schemaVersion.startsWith("1.6"));
147148
if (runOnRequirements != null) {
148149
assumeTrue("Run-on requirements not met",
149150
runOnRequirementsMet(runOnRequirements, getMongoClientSettings(), getServerVersion()));

0 commit comments

Comments
 (0)