@@ -938,4 +938,47 @@ describe('Change Stream prose tests', function () {
938
938
}
939
939
} ) ;
940
940
} ) ;
941
+
942
+ describe ( '19. Validate that large ChangeStream events are split when using $changeStreamSplitLargeEvent' , function ( ) {
943
+ let client ;
944
+ let db ;
945
+ let collection ;
946
+
947
+ beforeEach ( async function ( ) {
948
+ const configuration = this . configuration ;
949
+ client = configuration . newClient ( ) ;
950
+ db = client . db ( 'test' ) ;
951
+ // Create a new collection _C_ with changeStreamPreAndPostImages enabled.
952
+ await db . createCollection ( 'changeStreamSplitTests' , {
953
+ changeStreamPreAndPostImages : { enabled : true }
954
+ } ) ;
955
+ collection = db . collection ( 'changeStreamSplitTests' ) ;
956
+ } ) ;
957
+
958
+ afterEach ( async function ( ) {
959
+ await collection . drop ( ) ;
960
+ await client . close ( ) ;
961
+ } ) ;
962
+
963
+ it ( 'splits the event into multiple fragments' , {
964
+ metadata : { requires : { topology : 'replicaset' , mongodb : '>=7.0.0' } } ,
965
+ test : async function ( ) {
966
+ // Insert into _C_ a document at least 10mb in size, e.g. { "value": "q"*10*1024*1024 }
967
+ await collection . insertOne ( { value : 'q' . repeat ( 10 * 1024 * 1024 ) } ) ;
968
+ // Create a change stream _S_ by calling watch on _C_ with pipeline
969
+ // [{ "$changeStreamSplitLargeEvent": {} }] and fullDocumentBeforeChange=required.
970
+ const changeStream = collection . watch ( [ { $changeStreamSplitLargeEvent : { } } ] , {
971
+ fullDocumentBeforeChange : 'required'
972
+ } ) ;
973
+ // Call updateOne on _C_ with an empty query and an update setting the field to a new
974
+ // large value, e.g. { "$set": { "value": "z"*10*1024*1024 } }.
975
+ await collection . updateOne ( { } , { $set : { value : 'z' . repeat ( 10 * 1024 * 1024 ) } } ) ;
976
+ // Collect two events from _S_.
977
+ const eventOne = await changeStream . next ( ) ;
978
+ const eventTwo = await changeStream . next ( ) ;
979
+ expect ( eventOne . splitEvent ) . to . deep . equal ( { fragment : 1 , of : 2 } ) ;
980
+ expect ( eventTwo . splitEvent ) . to . deep . equal ( { fragment : 2 , of : 2 } ) ;
981
+ }
982
+ } ) ;
983
+ } ) ;
941
984
} ) ;
0 commit comments