Skip to content

Commit 0b606c1

Browse files
authored
CSHARP-4184: Sync'd distinct-commnet tests from CRUD spec and updated unified runner. (#843)
1 parent cc23814 commit 0b606c1

File tree

3 files changed

+288
-5
lines changed

3 files changed

+288
-5
lines changed
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
{
2+
"description": "distinct-comment",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"observeEvents": [
9+
"commandStartedEvent"
10+
]
11+
}
12+
},
13+
{
14+
"database": {
15+
"id": "database0",
16+
"client": "client0",
17+
"databaseName": "distinct-comment-tests"
18+
}
19+
},
20+
{
21+
"collection": {
22+
"id": "collection0",
23+
"database": "database0",
24+
"collectionName": "coll0"
25+
}
26+
}
27+
],
28+
"initialData": [
29+
{
30+
"collectionName": "coll0",
31+
"databaseName": "distinct-comment-tests",
32+
"documents": [
33+
{
34+
"_id": 1,
35+
"x": 11
36+
},
37+
{
38+
"_id": 2,
39+
"x": 22
40+
},
41+
{
42+
"_id": 3,
43+
"x": 33
44+
}
45+
]
46+
}
47+
],
48+
"tests": [
49+
{
50+
"description": "distinct with document comment",
51+
"runOnRequirements": [
52+
{
53+
"minServerVersion": "4.4.14"
54+
}
55+
],
56+
"operations": [
57+
{
58+
"name": "distinct",
59+
"object": "collection0",
60+
"arguments": {
61+
"fieldName": "x",
62+
"filter": {},
63+
"comment": {
64+
"key": "value"
65+
}
66+
},
67+
"expectResult": [ 11, 22, 33 ]
68+
}
69+
],
70+
"expectEvents": [
71+
{
72+
"client": "client0",
73+
"events": [
74+
{
75+
"commandStartedEvent": {
76+
"command": {
77+
"distinct": "coll0",
78+
"key": "x",
79+
"query": {},
80+
"comment": {
81+
"key": "value"
82+
}
83+
},
84+
"commandName": "distinct",
85+
"databaseName": "distinct-comment-tests"
86+
}
87+
}
88+
]
89+
}
90+
]
91+
},
92+
{
93+
"description": "distinct with string comment",
94+
"runOnRequirements": [
95+
{
96+
"minServerVersion": "4.4.0"
97+
}
98+
],
99+
"operations": [
100+
{
101+
"name": "distinct",
102+
"object": "collection0",
103+
"arguments": {
104+
"fieldName": "x",
105+
"filter": {},
106+
"comment": "comment"
107+
},
108+
"expectResult": [ 11, 22, 33 ]
109+
}
110+
],
111+
"expectEvents": [
112+
{
113+
"client": "client0",
114+
"events": [
115+
{
116+
"commandStartedEvent": {
117+
"command": {
118+
"distinct": "coll0",
119+
"key": "x",
120+
"query": {},
121+
"comment": "comment"
122+
},
123+
"commandName": "distinct",
124+
"databaseName": "distinct-comment-tests"
125+
}
126+
}
127+
]
128+
}
129+
]
130+
},
131+
{
132+
"description": "distinct with document comment - pre 4.4, server error",
133+
"runOnRequirements": [
134+
{
135+
"minServerVersion": "3.6.0",
136+
"maxServerVersion": "4.4.13"
137+
}
138+
],
139+
"operations": [
140+
{
141+
"name": "distinct",
142+
"object": "collection0",
143+
"arguments": {
144+
"fieldName": "x",
145+
"filter": {},
146+
"comment": {
147+
"key": "value"
148+
}
149+
},
150+
"expectError": {
151+
"isClientError": false
152+
}
153+
}
154+
],
155+
"expectEvents": [
156+
{
157+
"client": "client0",
158+
"events": [
159+
{
160+
"commandStartedEvent": {
161+
"command": {
162+
"distinct": "coll0",
163+
"key": "x",
164+
"query": {},
165+
"comment": {
166+
"key": "value"
167+
}
168+
},
169+
"commandName": "distinct",
170+
"databaseName": "distinct-comment-tests"
171+
}
172+
}
173+
]
174+
}
175+
]
176+
}
177+
]
178+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
description: "distinct-comment"
2+
3+
schemaVersion: "1.0"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
observeEvents: [ commandStartedEvent ]
9+
- database:
10+
id: &database0 database0
11+
client: *client0
12+
databaseName: &database0Name distinct-comment-tests
13+
- collection:
14+
id: &collection0 collection0
15+
database: *database0
16+
collectionName: &collection0Name coll0
17+
18+
initialData:
19+
- collectionName: *collection0Name
20+
databaseName: *database0Name
21+
documents:
22+
- { _id: 1, x: 11 }
23+
- { _id: 2, x: 22 }
24+
- { _id: 3, x: 33 }
25+
26+
tests:
27+
- description: "distinct with document comment"
28+
runOnRequirements:
29+
# https://jira.mongodb.org/browse/SERVER-44847
30+
# Server supports distinct with comment of any type for comment starting from 4.4.14.
31+
- minServerVersion: "4.4.14"
32+
operations:
33+
- name: distinct
34+
object: *collection0
35+
arguments:
36+
fieldName: &fieldName x
37+
filter: &filter {}
38+
comment: &documentComment { key: "value"}
39+
expectResult: [ 11, 22, 33 ]
40+
expectEvents:
41+
- client: *client0
42+
events:
43+
- commandStartedEvent:
44+
command:
45+
distinct: *collection0Name
46+
key: *fieldName
47+
query: *filter
48+
comment: *documentComment
49+
commandName: distinct
50+
databaseName: *database0Name
51+
52+
- description: "distinct with string comment"
53+
runOnRequirements:
54+
- minServerVersion: "4.4.0"
55+
operations:
56+
- name: distinct
57+
object: *collection0
58+
arguments:
59+
fieldName: *fieldName
60+
filter: *filter
61+
comment: &stringComment "comment"
62+
expectResult: [ 11, 22, 33 ]
63+
expectEvents:
64+
- client: *client0
65+
events:
66+
- commandStartedEvent:
67+
command:
68+
distinct: *collection0Name
69+
key: *fieldName
70+
query: *filter
71+
comment: *stringComment
72+
commandName: distinct
73+
databaseName: *database0Name
74+
75+
- description: "distinct with document comment - pre 4.4, server error"
76+
runOnRequirements:
77+
- minServerVersion: "3.6.0"
78+
maxServerVersion: "4.4.13"
79+
operations:
80+
- name: distinct
81+
object: *collection0
82+
arguments:
83+
fieldName: *fieldName
84+
filter: *filter
85+
comment: *documentComment
86+
expectError:
87+
isClientError: false
88+
expectEvents:
89+
- client: *client0
90+
events:
91+
- commandStartedEvent:
92+
command:
93+
distinct: *collection0Name
94+
key: *fieldName
95+
query: *filter
96+
comment: *documentComment
97+
commandName: distinct
98+
databaseName: *database0Name

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedDistinctOperation.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ public class UnifiedDistinctOperation : IUnifiedEntityTestOperation
2525
private readonly IMongoCollection<BsonDocument> _collection;
2626
private readonly string _fieldName;
2727
private readonly FilterDefinition<BsonDocument> _filter;
28+
private readonly DistinctOptions _options;
2829
private readonly IClientSessionHandle _session;
2930

3031
public UnifiedDistinctOperation(
3132
IMongoCollection<BsonDocument> collection,
3233
string fieldName,
3334
FilterDefinition<BsonDocument> filter,
35+
DistinctOptions options,
3436
IClientSessionHandle session)
3537
{
3638
_collection = collection;
3739
_fieldName = fieldName;
3840
_filter = filter;
41+
_options = options;
3942
_session = session;
4043
}
4144

@@ -44,8 +47,8 @@ public OperationResult Execute(CancellationToken cancellationToken)
4447
try
4548
{
4649
using var cursor = _session == null
47-
? _collection.Distinct<BsonValue>(_fieldName, _filter, cancellationToken: cancellationToken)
48-
: _collection.Distinct<BsonValue>(_session, _fieldName, _filter, cancellationToken: cancellationToken);
50+
? _collection.Distinct<BsonValue>(_fieldName, _filter, _options, cancellationToken)
51+
: _collection.Distinct<BsonValue>(_session, _fieldName, _filter, _options, cancellationToken);
4952

5053
var result = cursor.ToList(cancellationToken);
5154

@@ -62,8 +65,8 @@ public async Task<OperationResult> ExecuteAsync(CancellationToken cancellationTo
6265
try
6366
{
6467
using var cursor = _session == null
65-
? await _collection.DistinctAsync<BsonValue>(_fieldName, _filter, cancellationToken: cancellationToken)
66-
: await _collection.DistinctAsync<BsonValue>(_session, _fieldName, _filter, cancellationToken: cancellationToken);
68+
? await _collection.DistinctAsync<BsonValue>(_fieldName, _filter, _options, cancellationToken)
69+
: await _collection.DistinctAsync<BsonValue>(_session, _fieldName, _filter, _options, cancellationToken);
6770

6871
var result = await cursor.ToListAsync(cancellationToken);
6972

@@ -91,12 +94,16 @@ public UnifiedDistinctOperation Build(string targetCollectionId, BsonDocument ar
9194

9295
string fieldName = null;
9396
FilterDefinition<BsonDocument> filter = null;
97+
DistinctOptions options = null;
9498
IClientSessionHandle session = null;
9599

96100
foreach (var argument in arguments)
97101
{
98102
switch (argument.Name)
99103
{
104+
case "comment":
105+
options = new DistinctOptions { Comment = argument.Value };
106+
break;
100107
case "fieldName":
101108
fieldName = argument.Value.AsString;
102109
break;
@@ -111,7 +118,7 @@ public UnifiedDistinctOperation Build(string targetCollectionId, BsonDocument ar
111118
}
112119
}
113120

114-
return new UnifiedDistinctOperation(collection, fieldName, filter, session);
121+
return new UnifiedDistinctOperation(collection, fieldName, filter, options, session);
115122
}
116123
}
117124
}

0 commit comments

Comments
 (0)