Skip to content

Commit f9606ec

Browse files
Ensure findOne does not set batchSize=1 (#1659)
JAVA-5666
1 parent cbd99ae commit f9606ec

File tree

10 files changed

+199
-10
lines changed

10 files changed

+199
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"description": "findOne",
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": "find-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": "find-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+
"_id": 4,
47+
"x": 44
48+
},
49+
{
50+
"_id": 5,
51+
"x": 55
52+
},
53+
{
54+
"_id": 6,
55+
"x": 66
56+
}
57+
]
58+
}
59+
],
60+
"tests": [
61+
{
62+
"description": "FindOne with filter",
63+
"operations": [
64+
{
65+
"object": "collection0",
66+
"name": "findOne",
67+
"arguments": {
68+
"filter": {
69+
"_id": 1
70+
}
71+
},
72+
"expectResult": {
73+
"_id": 1,
74+
"x": 11
75+
}
76+
}
77+
],
78+
"expectEvents": [
79+
{
80+
"client": "client0",
81+
"events": [
82+
{
83+
"commandStartedEvent": {
84+
"command": {
85+
"find": "coll0",
86+
"filter": {
87+
"_id": 1
88+
},
89+
"batchSize": {
90+
"$$exists": false
91+
},
92+
"limit": 1,
93+
"singleBatch": true
94+
},
95+
"commandName": "find",
96+
"databaseName": "find-tests"
97+
}
98+
}
99+
]
100+
}
101+
]
102+
},
103+
{
104+
"description": "FindOne with filter, sort, and skip",
105+
"operations": [
106+
{
107+
"object": "collection0",
108+
"name": "findOne",
109+
"arguments": {
110+
"filter": {
111+
"_id": {
112+
"$gt": 2
113+
}
114+
},
115+
"sort": {
116+
"_id": 1
117+
},
118+
"skip": 2
119+
},
120+
"expectResult": {
121+
"_id": 5,
122+
"x": 55
123+
}
124+
}
125+
],
126+
"expectEvents": [
127+
{
128+
"client": "client0",
129+
"events": [
130+
{
131+
"commandStartedEvent": {
132+
"command": {
133+
"find": "coll0",
134+
"filter": {
135+
"_id": {
136+
"$gt": 2
137+
}
138+
},
139+
"sort": {
140+
"_id": 1
141+
},
142+
"skip": 2,
143+
"batchSize": {
144+
"$$exists": false
145+
},
146+
"limit": 1,
147+
"singleBatch": true
148+
},
149+
"commandName": "find",
150+
"databaseName": "find-tests"
151+
}
152+
}
153+
]
154+
}
155+
]
156+
}
157+
]
158+
}

driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedCrudTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class UnifiedCrudTest() : UnifiedTest() {
2424
@JvmStatic
2525
@Throws(URISyntaxException::class, IOException::class)
2626
fun data(): Collection<Arguments>? {
27-
return getTestData("unified-test-format/crud", true)
27+
return getTestData("unified-test-format/crud", true, Language.KOTLIN)
2828
}
2929
}
3030
}

driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedTest.kt

+4
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ internal abstract class UnifiedTest() : JUnifiedTest() {
3939
): ClientEncryption {
4040
TODO("Not yet implemented - JAVA-4896")
4141
}
42+
43+
override fun isReactive(): Boolean = true
44+
45+
override fun getLanguage(): Language = Language.KOTLIN
4246
}

driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedCrudTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class UnifiedCrudTest() : UnifiedTest() {
2424
@JvmStatic
2525
@Throws(URISyntaxException::class, IOException::class)
2626
fun data(): Collection<Arguments>? {
27-
return getTestData("unified-test-format/crud", false)
27+
return getTestData("unified-test-format/crud", false, Language.KOTLIN)
2828
}
2929
}
3030
}

driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ internal abstract class UnifiedTest() : JUnifiedTest() {
3939
): ClientEncryption {
4040
TODO("Not yet implemented - JAVA-4896")
4141
}
42+
43+
override fun getLanguage(): Language = Language.KOTLIN
4244
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ protected void postCleanUp(final TestDef testDef) {
101101

102102
@NonNull
103103
protected static Collection<Arguments> getTestData(final String directory) {
104-
return getTestData(directory, true);
104+
return getTestData(directory, true, Language.JAVA);
105105
}
106106
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ OperationResult executeFind(final BsonDocument operation) {
408408
});
409409
}
410410

411+
/**
412+
* There is no explicit {@code findOne()} method in {@link MongoCollection} class.
413+
* Its feature was emulated by {@link FindIterable#first()}, which would close cursor on server
414+
* by setting {@code batchSize} and {@code limit} appropriately.
415+
*/
411416
OperationResult executeFindOne(final BsonDocument operation) {
412417
return resultOf(() -> createFindIterable(operation).first());
413418
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ protected ClientEncryption createClientEncryption(final MongoClient keyVaultClie
5151

5252
@NonNull
5353
protected static Collection<Arguments> getTestData(final String directory) {
54-
return getTestData(directory, false);
54+
return getTestData(directory, false, Language.JAVA);
5555
}
5656
}

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ public Entities getEntities() {
161161
}
162162

163163
@NonNull
164-
protected static Collection<Arguments> getTestData(final String directory, final boolean isReactive) {
164+
protected static Collection<Arguments> getTestData(final String directory, final boolean isReactive, final Language language) {
165165
List<Arguments> data = new ArrayList<>();
166166
for (BsonDocument fileDocument : getTestDocuments("/" + directory + "/")) {
167167
for (BsonValue cur : fileDocument.getArray("tests")) {
168168

169169
final BsonDocument testDocument = cur.asDocument();
170170
String testDescription = testDocument.getString("description").getValue();
171171
String fileDescription = fileDocument.getString("description").getValue();
172-
TestDef testDef = testDef(directory, fileDescription, testDescription, isReactive);
172+
TestDef testDef = testDef(directory, fileDescription, testDescription, isReactive, language);
173173
applyCustomizations(testDef);
174174

175175
boolean forceFlaky = testDef.wasAssignedModifier(Modifier.FORCE_FLAKY);
@@ -240,7 +240,7 @@ public void setUp(
240240
rootContext.getAssertionContext().push(ContextElement.ofTest(definition));
241241
ignoreExtraEvents = false;
242242
if (directoryName != null && fileDescription != null && testDescription != null) {
243-
testDef = testDef(directoryName, fileDescription, testDescription, isReactive());
243+
testDef = testDef(directoryName, fileDescription, testDescription, isReactive(), getLanguage());
244244
applyCustomizations(testDef);
245245

246246
boolean skip = testDef.wasAssignedModifier(Modifier.SKIP);
@@ -329,6 +329,10 @@ protected boolean isReactive() {
329329
return false;
330330
}
331331

332+
protected Language getLanguage() {
333+
return Language.JAVA;
334+
}
335+
332336
@ParameterizedTest(name = "{0}")
333337
@MethodSource("data")
334338
public void shouldPassAllOutcomes(
@@ -1112,4 +1116,8 @@ protected void ignoreExtraCommandEvents(final boolean ignoreExtraEvents) {
11121116
protected void ignoreExtraEvents() {
11131117
this.ignoreExtraEvents = true;
11141118
}
1119+
1120+
public enum Language {
1121+
JAVA, KOTLIN
1122+
}
11151123
}

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public static void applyCustomizations(final TestDef def) {
143143
.test("crud", "findOneAndDelete-hint-unacknowledged", "Unacknowledged findOneAndDelete with hint string on 4.4+ server")
144144
.test("crud", "findOneAndDelete-hint-unacknowledged", "Unacknowledged findOneAndDelete with hint document on 4.4+ server");
145145

146+
def.skipNoncompliant("https://jira.mongodb.org/browse/JAVA-5838")
147+
.when(() -> def.isReactive() && UnifiedTest.Language.KOTLIN.equals(def.getLanguage()))
148+
.file("crud", "findOne");
149+
146150
// gridfs
147151

148152
def.skipDeprecated("contentType is deprecated in GridFS spec, and 4.x Java driver no longer supports it")
@@ -256,24 +260,28 @@ public static void applyCustomizations(final TestDef def) {
256260

257261
private UnifiedTestModifications() {}
258262

259-
public static TestDef testDef(final String dir, final String file, final String test, final boolean reactive) {
260-
return new TestDef(dir, file, test, reactive);
263+
public static TestDef testDef(final String dir, final String file, final String test, final boolean reactive,
264+
final UnifiedTest.Language language) {
265+
return new TestDef(dir, file, test, reactive, language);
261266
}
262267

263268
public static final class TestDef {
269+
264270
private final String dir;
265271
private final String file;
266272
private final String test;
267273
private final boolean reactive;
274+
private final UnifiedTest.Language language;
268275

269276
private final List<Modifier> modifiers = new ArrayList<>();
270277
private Function<Throwable, Boolean> matchesThrowable;
271278

272-
private TestDef(final String dir, final String file, final String test, final boolean reactive) {
279+
private TestDef(final String dir, final String file, final String test, final boolean reactive, final UnifiedTest.Language language) {
273280
this.dir = assertNotNull(dir);
274281
this.file = assertNotNull(file);
275282
this.test = assertNotNull(test);
276283
this.reactive = reactive;
284+
this.language = assertNotNull(language);
277285
}
278286

279287
/**
@@ -354,6 +362,10 @@ public boolean isReactive() {
354362
return reactive;
355363
}
356364

365+
public UnifiedTest.Language getLanguage() {
366+
return language;
367+
}
368+
357369
public boolean wasAssignedModifier(final Modifier modifier) {
358370
return this.modifiers.contains(modifier);
359371
}

0 commit comments

Comments
 (0)