Skip to content

Commit e11931d

Browse files
committed
Merge branch 'main' into JAVA-5821
2 parents b9c8b43 + f9606ec commit e11931d

File tree

11 files changed

+220
-18
lines changed

11 files changed

+220
-18
lines changed

driver-core/src/test/functional/com/mongodb/internal/connection/ClientMetadataHelperProseTest.java

+21-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import static org.junit.jupiter.api.Assertions.assertThrows;
4848

4949
/**
50-
* See <a href="https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#test-plan">spec</a>
50+
* See <a href="https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.md#test-plan">spec</a>
5151
*
5252
* <p>
5353
* NOTE: This class also contains tests that aren't categorized as Prose tests.
@@ -175,16 +175,32 @@ public void test08NotLambda() {
175175
});
176176
}
177177

178+
@Test
179+
public void test09ValidContainerAndFaasProvider() {
180+
withWrapper()
181+
.withEnvironmentVariable("AWS_EXECUTION_ENV", "AWS_Lambda_java8")
182+
.withEnvironmentVariable("AWS_REGION", "us-east-2")
183+
.withEnvironmentVariable("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", "1024")
184+
.withEnvironmentVariable("KUBERNETES_SERVICE_HOST", "1")
185+
.run(() -> {
186+
BsonDocument expected = createExpectedClientMetadataDocument(APP_NAME);
187+
expected.put("env", BsonDocument.parse("{'name': 'aws.lambda', 'memory_mb': 1024, 'region': 'us-east-2', 'container': {'orchestrator': 'kubernetes'}}"));
188+
BsonDocument actual = createActualClientMetadataDocument();
189+
assertEquals(expected, actual);
190+
191+
performHello();
192+
});
193+
}
194+
178195
// Additional tests, not specified as prose tests:
179196

180197
@Test
181198
void testKubernetesMetadataIncluded() {
182199
withWrapper()
183-
.withEnvironmentVariable("AWS_EXECUTION_ENV", "AWS_Lambda_java8")
184200
.withEnvironmentVariable("KUBERNETES_SERVICE_HOST", "kubernetes.default.svc.cluster.local")
185201
.run(() -> {
186202
BsonDocument expected = createExpectedClientMetadataDocument(APP_NAME);
187-
expected.put("env", BsonDocument.parse("{'name': 'aws.lambda', 'container': {'orchestrator': 'kubernetes'}}"));
203+
expected.put("env", BsonDocument.parse("{'container': {'orchestrator': 'kubernetes'}}"));
188204
BsonDocument actual = createActualClientMetadataDocument();
189205
assertEquals(expected, actual);
190206

@@ -199,10 +215,9 @@ void testDockerMetadataIncluded() {
199215
pathsMockedStatic.when(() -> Files.exists(path)).thenReturn(true);
200216

201217
withWrapper()
202-
.withEnvironmentVariable("AWS_EXECUTION_ENV", "AWS_Lambda_java8")
203218
.run(() -> {
204219
BsonDocument expected = createExpectedClientMetadataDocument(APP_NAME);
205-
expected.put("env", BsonDocument.parse("{'name': 'aws.lambda', 'container': {'runtime': 'docker'}}"));
220+
expected.put("env", BsonDocument.parse("{'container': {'runtime': 'docker'}}"));
206221
BsonDocument actual = createActualClientMetadataDocument();
207222
assertEquals(expected, actual);
208223

@@ -218,12 +233,10 @@ void testDockerAndKubernetesMetadataIncluded() {
218233
pathsMockedStatic.when(() -> Files.exists(path)).thenReturn(true);
219234

220235
withWrapper()
221-
.withEnvironmentVariable("AWS_EXECUTION_ENV", "AWS_Lambda_java8")
222236
.withEnvironmentVariable("KUBERNETES_SERVICE_HOST", "kubernetes.default.svc.cluster.local")
223237
.run(() -> {
224238
BsonDocument expected = createExpectedClientMetadataDocument(APP_NAME);
225-
expected.put("env", BsonDocument.parse("{'name': 'aws.lambda', 'container': {'runtime': 'docker', "
226-
+ "'orchestrator': 'kubernetes'}}"));
239+
expected.put("env", BsonDocument.parse("{'container': {'runtime': 'docker', 'orchestrator': 'kubernetes'}}"));
227240
BsonDocument actual = createActualClientMetadataDocument();
228241
assertEquals(expected, actual);
229242

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("crud", true)
27+
return getTestData("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("crud", false)
27+
return getTestData("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
@@ -165,7 +165,7 @@ public Entities getEntities() {
165165
}
166166

167167
@NonNull
168-
protected static Collection<Arguments> getTestData(final String directory, final boolean isReactive) {
168+
protected static Collection<Arguments> getTestData(final String directory, final boolean isReactive, final Language language) {
169169
List<Arguments> data = new ArrayList<>();
170170

171171
for (BsonDocument fileDocument : getSpecTestDocuments(directory)) {
@@ -177,7 +177,7 @@ protected static Collection<Arguments> getTestData(final String directory, final
177177
for (BsonValue cur : fileDocument.getArray("tests")) {
178178
final BsonDocument testDocument = cur.asDocument();
179179
String testDescription = testDocument.getString("description").getValue();
180-
TestDef testDef = testDef(directory, fileDescription, testDescription, isReactive);
180+
TestDef testDef = testDef(directory, fileDescription, testDescription, isReactive, language);
181181
applyCustomizations(testDef);
182182

183183
boolean forceFlaky = testDef.wasAssignedModifier(Modifier.FORCE_FLAKY);
@@ -248,7 +248,7 @@ public void setUp(
248248
rootContext.getAssertionContext().push(ContextElement.ofTest(definition));
249249
ignoreExtraEvents = false;
250250
if (directoryName != null && fileDescription != null && testDescription != null) {
251-
testDef = testDef(directoryName, fileDescription, testDescription, isReactive());
251+
testDef = testDef(directoryName, fileDescription, testDescription, isReactive(), getLanguage());
252252
applyCustomizations(testDef);
253253

254254
boolean skip = testDef.wasAssignedModifier(Modifier.SKIP);
@@ -338,6 +338,10 @@ protected boolean isReactive() {
338338
return false;
339339
}
340340

341+
protected Language getLanguage() {
342+
return Language.JAVA;
343+
}
344+
341345
@ParameterizedTest(name = "{0}")
342346
@MethodSource("data")
343347
public void shouldPassAllOutcomes(
@@ -1121,4 +1125,8 @@ protected void ignoreExtraCommandEvents(final boolean ignoreExtraEvents) {
11211125
protected void ignoreExtraEvents() {
11221126
this.ignoreExtraEvents = true;
11231127
}
1128+
1129+
public enum Language {
1130+
JAVA, KOTLIN
1131+
}
11241132
}

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,17 @@ public static void applyCustomizations(final TestDef def) {
153153
.test("crud", "findOneAndDelete-hint-unacknowledged", "Unacknowledged findOneAndDelete with hint string on 4.4+ server")
154154
.test("crud", "findOneAndDelete-hint-unacknowledged", "Unacknowledged findOneAndDelete with hint document on 4.4+ server");
155155

156+
156157
def.skipJira("https://jira.mongodb.org/browse/JAVA-5827")
157158
.file("crud", "bypassDocumentValidation");
158159
def.skipNoncompliant("Find with batchSize equal to limit - batchSize is set to limit if limit is smaller")
159160
.test("crud", "find", "Find with batchSize equal to limit");
160161
def.skipNoncompliant("Updates and Replace bulk operations are split in the java driver")
161162
.file("crud", "bulkWrite-comment");
162163

164+
def.skipNoncompliant("https://jira.mongodb.org/browse/JAVA-5838")
165+
.when(() -> def.isReactive() && UnifiedTest.Language.KOTLIN.equals(def.getLanguage()))
166+
.file("crud", "findOne");
163167
// gridfs
164168

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

301305
private UnifiedTestModifications() {}
302306

303-
public static TestDef testDef(final String dir, final String file, final String test, final boolean reactive) {
304-
return new TestDef(dir, file, test, reactive);
307+
public static TestDef testDef(final String dir, final String file, final String test, final boolean reactive,
308+
final UnifiedTest.Language language) {
309+
return new TestDef(dir, file, test, reactive, language);
305310
}
306311

307312
public static final class TestDef {
313+
308314
private final String dir;
309315
private final String file;
310316
private final String test;
311317
private final boolean reactive;
318+
private final UnifiedTest.Language language;
312319

313320
private final List<Modifier> modifiers = new ArrayList<>();
314321
private Function<Throwable, Boolean> matchesThrowable;
315322

316-
private TestDef(final String dir, final String file, final String test, final boolean reactive) {
323+
private TestDef(final String dir, final String file, final String test, final boolean reactive, final UnifiedTest.Language language) {
317324
this.dir = assertNotNull(dir);
318325
this.file = assertNotNull(file);
319326
this.test = assertNotNull(test);
320327
this.reactive = reactive;
328+
this.language = assertNotNull(language);
321329
}
322330

323331
@Override
@@ -409,6 +417,10 @@ public boolean isReactive() {
409417
return reactive;
410418
}
411419

420+
public UnifiedTest.Language getLanguage() {
421+
return language;
422+
}
423+
412424
public boolean wasAssignedModifier(final Modifier modifier) {
413425
return this.modifiers.contains(modifier);
414426
}

0 commit comments

Comments
 (0)