Skip to content

Commit c6a2585

Browse files
committed
Update unified change stream tests
* Represent all cursors the same in Entities * Handle any MongoServerException in ErrorMatcher * Support "rename" operation * Special case some change stream tests that can't pass using ChangeStreamDocument JAVA-4470 JAVA-4555
1 parent 6243c36 commit c6a2585

File tree

5 files changed

+427
-58
lines changed

5 files changed

+427
-58
lines changed

driver-core/src/test/resources/unified-test-format/change-streams/change-streams.json

Lines changed: 306 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"schemaVersion": "1.0",
44
"runOnRequirements": [
55
{
6+
"minServerVersion": "3.6",
67
"topologies": [
78
"replicaset",
89
"sharded-replicaset"
@@ -168,7 +169,6 @@
168169
"description": "Test with document comment - pre 4.4",
169170
"runOnRequirements": [
170171
{
171-
"minServerVersion": "3.6.0",
172172
"maxServerVersion": "4.2.99"
173173
}
174174
],
@@ -213,11 +213,6 @@
213213
},
214214
{
215215
"description": "Test with string comment",
216-
"runOnRequirements": [
217-
{
218-
"minServerVersion": "3.6.0"
219-
}
220-
],
221216
"operations": [
222217
{
223218
"name": "createChangeStream",
@@ -347,7 +342,6 @@
347342
"description": "Test that comment is not set on getMore - pre 4.4",
348343
"runOnRequirements": [
349344
{
350-
"minServerVersion": "3.6.0",
351345
"maxServerVersion": "4.3.99",
352346
"topologies": [
353347
"replicaset"
@@ -431,6 +425,311 @@
431425
]
432426
}
433427
]
428+
},
429+
{
430+
"description": "to field is set in a rename change event",
431+
"runOnRequirements": [
432+
{
433+
"minServerVersion": "4.0.1"
434+
}
435+
],
436+
"operations": [
437+
{
438+
"name": "createChangeStream",
439+
"object": "collection0",
440+
"arguments": {
441+
"pipeline": []
442+
},
443+
"saveResultAsEntity": "changeStream0"
444+
},
445+
{
446+
"name": "dropCollection",
447+
"object": "database0",
448+
"arguments": {
449+
"collection": "collection1"
450+
}
451+
},
452+
{
453+
"name": "rename",
454+
"object": "collection0",
455+
"arguments": {
456+
"to": "collection1"
457+
}
458+
},
459+
{
460+
"name": "iterateUntilDocumentOrError",
461+
"object": "changeStream0",
462+
"expectResult": {
463+
"operationType": "rename",
464+
"ns": {
465+
"db": "database0",
466+
"coll": "collection0"
467+
},
468+
"to": {
469+
"db": "database0",
470+
"coll": "collection1"
471+
}
472+
}
473+
}
474+
]
475+
},
476+
{
477+
"description": "Test unknown operationType MUST NOT err",
478+
"operations": [
479+
{
480+
"name": "createChangeStream",
481+
"object": "collection0",
482+
"arguments": {
483+
"pipeline": [
484+
{
485+
"$project": {
486+
"operationType": "addedInFutureMongoDBVersion",
487+
"ns": 1
488+
}
489+
}
490+
]
491+
},
492+
"saveResultAsEntity": "changeStream0"
493+
},
494+
{
495+
"name": "insertOne",
496+
"object": "collection0",
497+
"arguments": {
498+
"document": {
499+
"_id": 1,
500+
"a": 1
501+
}
502+
}
503+
},
504+
{
505+
"name": "iterateUntilDocumentOrError",
506+
"object": "changeStream0",
507+
"expectResult": {
508+
"operationType": "addedInFutureMongoDBVersion",
509+
"ns": {
510+
"db": "database0",
511+
"coll": "collection0"
512+
}
513+
}
514+
}
515+
]
516+
},
517+
{
518+
"description": "Test newField added in response MUST NOT err",
519+
"operations": [
520+
{
521+
"name": "createChangeStream",
522+
"object": "collection0",
523+
"arguments": {
524+
"pipeline": [
525+
{
526+
"$project": {
527+
"operationType": 1,
528+
"ns": 1,
529+
"newField": "newFieldValue"
530+
}
531+
}
532+
]
533+
},
534+
"saveResultAsEntity": "changeStream0"
535+
},
536+
{
537+
"name": "insertOne",
538+
"object": "collection0",
539+
"arguments": {
540+
"document": {
541+
"_id": 1,
542+
"a": 1
543+
}
544+
}
545+
},
546+
{
547+
"name": "iterateUntilDocumentOrError",
548+
"object": "changeStream0",
549+
"expectResult": {
550+
"operationType": "insert",
551+
"ns": {
552+
"db": "database0",
553+
"coll": "collection0"
554+
},
555+
"newField": "newFieldValue"
556+
}
557+
}
558+
]
559+
},
560+
{
561+
"description": "Test new structure in ns document MUST NOT err",
562+
"operations": [
563+
{
564+
"name": "createChangeStream",
565+
"object": "collection0",
566+
"arguments": {
567+
"pipeline": [
568+
{
569+
"$project": {
570+
"operationType": "insert",
571+
"ns.viewOn": "db.coll"
572+
}
573+
}
574+
]
575+
},
576+
"saveResultAsEntity": "changeStream0"
577+
},
578+
{
579+
"name": "insertOne",
580+
"object": "collection0",
581+
"arguments": {
582+
"document": {
583+
"_id": 1,
584+
"a": 1
585+
}
586+
}
587+
},
588+
{
589+
"name": "iterateUntilDocumentOrError",
590+
"object": "changeStream0",
591+
"expectResult": {
592+
"operationType": "insert",
593+
"ns": {
594+
"viewOn": "db.coll"
595+
}
596+
}
597+
}
598+
]
599+
},
600+
{
601+
"description": "Test modified structure in ns document MUST NOT err",
602+
"operations": [
603+
{
604+
"name": "createChangeStream",
605+
"object": "collection0",
606+
"arguments": {
607+
"pipeline": [
608+
{
609+
"$project": {
610+
"operationType": "insert",
611+
"ns": {
612+
"db": "$ns.db",
613+
"coll": "$ns.coll",
614+
"viewOn": "db.coll"
615+
}
616+
}
617+
}
618+
]
619+
},
620+
"saveResultAsEntity": "changeStream0"
621+
},
622+
{
623+
"name": "insertOne",
624+
"object": "collection0",
625+
"arguments": {
626+
"document": {
627+
"_id": 1,
628+
"a": 1
629+
}
630+
}
631+
},
632+
{
633+
"name": "iterateUntilDocumentOrError",
634+
"object": "changeStream0",
635+
"expectResult": {
636+
"operationType": "insert",
637+
"ns": {
638+
"db": "database0",
639+
"coll": "collection0",
640+
"viewOn": "db.coll"
641+
}
642+
}
643+
}
644+
]
645+
},
646+
{
647+
"description": "Test server error on projecting out _id",
648+
"runOnRequirements": [
649+
{
650+
"minServerVersion": "4.2"
651+
}
652+
],
653+
"operations": [
654+
{
655+
"name": "createChangeStream",
656+
"object": "collection0",
657+
"arguments": {
658+
"pipeline": [
659+
{
660+
"$project": {
661+
"_id": 0
662+
}
663+
}
664+
]
665+
},
666+
"saveResultAsEntity": "changeStream0"
667+
},
668+
{
669+
"name": "insertOne",
670+
"object": "collection0",
671+
"arguments": {
672+
"document": {
673+
"_id": 1,
674+
"a": 1
675+
}
676+
}
677+
},
678+
{
679+
"name": "iterateUntilDocumentOrError",
680+
"object": "changeStream0",
681+
"expectError": {
682+
"errorCode": 280,
683+
"errorCodeName": "ChangeStreamFatalError",
684+
"errorLabelsContain": [
685+
"NonResumableChangeStreamError"
686+
]
687+
}
688+
}
689+
]
690+
},
691+
{
692+
"description": "Test projection in change stream returns expected fields",
693+
"operations": [
694+
{
695+
"name": "createChangeStream",
696+
"object": "collection0",
697+
"arguments": {
698+
"pipeline": [
699+
{
700+
"$project": {
701+
"optype": "$operationType",
702+
"ns": 1,
703+
"newField": "value"
704+
}
705+
}
706+
]
707+
},
708+
"saveResultAsEntity": "changeStream0"
709+
},
710+
{
711+
"name": "insertOne",
712+
"object": "collection0",
713+
"arguments": {
714+
"document": {
715+
"_id": 1,
716+
"a": 1
717+
}
718+
}
719+
},
720+
{
721+
"name": "iterateUntilDocumentOrError",
722+
"object": "changeStream0",
723+
"expectResult": {
724+
"optype": "insert",
725+
"ns": {
726+
"db": "database0",
727+
"coll": "collection0"
728+
},
729+
"newField": "value"
730+
}
731+
}
732+
]
434733
}
435734
]
436735
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.mongodb.client.MongoCursor;
3131
import com.mongodb.client.MongoDatabase;
3232
import com.mongodb.client.gridfs.GridFSBucket;
33-
import com.mongodb.client.model.changestream.ChangeStreamDocument;
3433
import com.mongodb.connection.ClusterConnectionMode;
3534
import com.mongodb.connection.ConnectionId;
3635
import com.mongodb.connection.ServerId;
@@ -102,7 +101,6 @@ public final class Entities {
102101
private final Map<String, GridFSBucket> buckets = new HashMap<>();
103102
private final Map<String, TestCommandListener> clientCommandListeners = new HashMap<>();
104103
private final Map<String, TestConnectionPoolListener> clientConnectionPoolListeners = new HashMap<>();
105-
private final Map<String, MongoCursor<ChangeStreamDocument<BsonDocument>>> changeStreamCursors = new HashMap<>();
106104
private final Map<String, MongoCursor<BsonDocument>> cursors = new HashMap<>();
107105
private final Map<String, Long> successCounts = new HashMap<>();
108106
private final Map<String, Long> iterationCounts = new HashMap<>();
@@ -174,18 +172,6 @@ public BsonValue getResult(final String id) {
174172
return getEntity(id, results, "result");
175173
}
176174

177-
public void addChangeStreamCursor(final String id, final MongoCursor<ChangeStreamDocument<BsonDocument>> cursor) {
178-
putEntity(id, cursor, changeStreamCursors);
179-
}
180-
181-
public MongoCursor<ChangeStreamDocument<BsonDocument>> getChangeStreamCursor(final String id) {
182-
return getEntity(id, changeStreamCursors, "change stream cursors");
183-
}
184-
185-
public boolean hasCursor(final String id) {
186-
return cursors.containsKey(id);
187-
}
188-
189175
public void addCursor(final String id, final MongoCursor<BsonDocument> cursor) {
190176
putEntity(id, cursor, cursors);
191177
}
@@ -512,9 +498,6 @@ private TransactionOptions getTransactionOptions(final BsonDocument options) {
512498
}
513499

514500
public void close() {
515-
for (MongoCursor<ChangeStreamDocument<BsonDocument>> cursor : changeStreamCursors.values()) {
516-
cursor.close();
517-
}
518501
for (MongoCursor<BsonDocument> cursor : cursors.values()) {
519502
cursor.close();
520503
}

0 commit comments

Comments
 (0)