Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"description": "pre-42-server-connection-id",
"schemaVersion": "1.6",
"runOnRequirements": [
{
"maxServerVersion": "4.0.99"
}
],
"createEntities": [
{
"client": {
"id": "client",
"observeEvents": [
"commandStartedEvent",
"commandSucceededEvent",
"commandFailedEvent"
]
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "server-connection-id-tests"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "coll"
}
}
],
"initialData": [
{
"databaseName": "server-connection-id-tests",
"collectionName": "coll",
"documents": []
}
],
"tests": [
{
"description": "command events do not include server connection id",
"operations": [
{
"name": "insertOne",
"object": "collection",
"arguments": {
"document": {
"x": 1
}
}
},
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {
"$or": true
}
},
"expectError": {
"isError": true
}
}
],
"expectEvents": [
{
"client": "client",
"events": [
{
"commandStartedEvent": {
"commandName": "insert",
"hasServerConnectionId": false
}
},
{
"commandSucceededEvent": {
"commandName": "insert",
"hasServerConnectionId": false
}
},
{
"commandStartedEvent": {
"commandName": "find",
"hasServerConnectionId": false
}
},
{
"commandFailedEvent": {
"commandName": "find",
"hasServerConnectionId": false
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"description": "server-connection-id",
"schemaVersion": "1.6",
"runOnRequirements": [
{
"minServerVersion": "4.2"
}
],
"createEntities": [
{
"client": {
"id": "client",
"observeEvents": [
"commandStartedEvent",
"commandSucceededEvent",
"commandFailedEvent"
]
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "server-connection-id-tests"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "coll"
}
}
],
"initialData": [
{
"databaseName": "server-connection-id-tests",
"collectionName": "coll",
"documents": []
}
],
"tests": [
{
"description": "command events include server connection id",
"operations": [
{
"name": "insertOne",
"object": "collection",
"arguments": {
"document": {
"x": 1
}
}
},
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {
"$or": true
}
},
"expectError": {
"isError": true
}
}
],
"expectEvents": [
{
"client": "client",
"events": [
{
"commandStartedEvent": {
"commandName": "insert",
"hasServerConnectionId": true
}
},
{
"commandSucceededEvent": {
"commandName": "insert",
"hasServerConnectionId": true
}
},
{
"commandStartedEvent": {
"commandName": "find",
"hasServerConnectionId": true
}
},
{
"commandFailedEvent": {
"commandName": "find",
"hasServerConnectionId": true
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
import java.net.URISyntaxException;
import java.util.Collection;

import static org.junit.Assume.assumeFalse;

public class CommandMonitoringTest extends UnifiedReactiveStreamsTest {
public CommandMonitoringTest(@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);
// The driver has a hack where getLastError command is executed as part of the handshake in order to get a connectionId
// even when the hello command response doesn't contain it.
assumeFalse(fileDescription.equals("pre-42-server-connection-id"));
}

@Parameterized.Parameters(name = "{0}: {1}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public CommandMonitoringTest(@SuppressWarnings("unused") final String fileDescri
final BsonDocument definition) {
super(schemaVersion, runOnRequirements, entities, initialData, definition);
assumeFalse(isServerlessTest());
// The driver has a hack where getLastError command is executed as part of the handshake in order to get a connectionId
// even when the hello command response doesn't contain it.
assumeFalse(fileDescription.equals("pre-42-server-connection-id"));
}

@Parameterized.Parameters(name = "{0}: {1}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public void assertCommandEventsEquality(final String client, final BsonArray exp
}
}

if (expected.containsKey("hasServerConnectionId")) {
boolean hasServerConnectionId = expected.getBoolean("hasServerConnectionId").getValue();
Integer serverConnectionId = actual.getConnectionDescription().getConnectionId().getServerValue();
if (hasServerConnectionId) {
assertNotNull(context.getMessage("Expected serverConnectionId"), serverConnectionId);
} else {
assertNull(context.getMessage("Expected no serverConnectionId"), serverConnectionId);
}
}

if (actual.getClass().equals(CommandStartedEvent.class)) {
assertEquals(context.getMessage("Expected CommandStartedEvent"), eventType, "commandStartedEvent");
CommandStartedEvent actualCommandStartedEvent = (CommandStartedEvent) actual;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public void setUp() {
|| schemaVersion.startsWith("1.2")
|| schemaVersion.startsWith("1.3")
|| schemaVersion.startsWith("1.4")
|| schemaVersion.startsWith("1.5"));
|| schemaVersion.startsWith("1.5")
|| schemaVersion.startsWith("1.6"));
if (runOnRequirements != null) {
assumeTrue("Run-on requirements not met",
runOnRequirementsMet(runOnRequirements, getMongoClientSettings(), getServerVersion()));
Expand Down