16
16
17
17
package com.mongodb.operation
18
18
19
-
20
19
import com.mongodb.MongoException
21
20
import com.mongodb.MongoNamespace
22
21
import com.mongodb.OperationFunctionalSpecification
@@ -155,7 +154,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
155
154
def expected = insertDocuments(helper, [1 , 2 ])
156
155
157
156
then :
158
- def next = nextAndClean(cursor, async)
157
+ def next = nextAndClean(cursor, async, expected . size() )
159
158
next == expected
160
159
161
160
when :
@@ -164,7 +163,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
164
163
165
164
then :
166
165
cursor. getBatchSize() == 5
167
- nextAndClean(cursor, async) == expected
166
+ nextAndClean(cursor, async, expected . size() ) == expected
168
167
169
168
then :
170
169
if (async) {
@@ -193,7 +192,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
193
192
when :
194
193
def cursor = execute(operation, false )
195
194
helper. insertDocuments(BsonDocument . parse(' { _id : 2, x : 2 }' ))
196
- ChangeStreamDocument<BsonDocument > next = next(cursor, false ). get(0 )
195
+ ChangeStreamDocument<BsonDocument > next = next(cursor, false , 1 ). get(0 )
197
196
198
197
then :
199
198
next. getResumeToken() != null
@@ -220,7 +219,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
220
219
when :
221
220
def cursor = execute(operation, false )
222
221
helper. updateOne(BsonDocument . parse(' { _id : 2}' ), BsonDocument . parse(' { $set : {x : 3}, $unset : {y : 1}}' ))
223
- ChangeStreamDocument<BsonDocument > next = next(cursor, false ). get(0 )
222
+ ChangeStreamDocument<BsonDocument > next = next(cursor, false , 1 ). get(0 )
224
223
225
224
then :
226
225
next. getResumeToken() != null
@@ -247,7 +246,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
247
246
when :
248
247
def cursor = execute(operation, false )
249
248
helper. replaceOne(BsonDocument . parse(' { _id : 2}' ), BsonDocument . parse(' { _id : 2, x : 3}' ), false )
250
- ChangeStreamDocument<BsonDocument > next = next(cursor, false ). get(0 )
249
+ ChangeStreamDocument<BsonDocument > next = next(cursor, false , 1 ). get(0 )
251
250
252
251
then :
253
252
next. getResumeToken() != null
@@ -274,7 +273,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
274
273
when :
275
274
def cursor = execute(operation, false )
276
275
helper. deleteOne(BsonDocument . parse(' { _id : 2}' ))
277
- ChangeStreamDocument<BsonDocument > next = next(cursor, false ). get(0 )
276
+ ChangeStreamDocument<BsonDocument > next = next(cursor, false , 1 ). get(0 )
278
277
279
278
then :
280
279
next. getResumeToken() != null
@@ -301,7 +300,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
301
300
when :
302
301
def cursor = execute(operation, false )
303
302
helper. drop()
304
- ChangeStreamDocument<BsonDocument > next = next(cursor, false ). get(0 )
303
+ ChangeStreamDocument<BsonDocument > next = next(cursor, false , 1 ). get(0 )
305
304
306
305
then :
307
306
next. getResumeToken() != null
@@ -329,7 +328,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
329
328
when :
330
329
def cursor = execute(operation, false )
331
330
helper. drop()
332
- ChangeStreamDocument<BsonDocument > next = next(cursor, false ). get(0 )
331
+ ChangeStreamDocument<BsonDocument > next = next(cursor, false , 1 ). get(0 )
333
332
334
333
then :
335
334
next. getResumeToken() != null
@@ -358,7 +357,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
358
357
when :
359
358
def cursor = execute(operation, false )
360
359
helper. dropDatabase(' JavaDriverTest' )
361
- ChangeStreamDocument<BsonDocument > next = next(cursor, false ). get(0 )
360
+ ChangeStreamDocument<BsonDocument > next = next(cursor, false , 1 ). get(0 )
362
361
363
362
then :
364
363
next. getResumeToken() != null
@@ -387,7 +386,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
387
386
when :
388
387
def cursor = execute(operation, false )
389
388
helper. renameCollection(newNamespace)
390
- ChangeStreamDocument<BsonDocument > next = next(cursor, false ). get(0 )
389
+ ChangeStreamDocument<BsonDocument > next = next(cursor, false , 1 ). get(0 )
391
390
392
391
then :
393
392
next. getResumeToken() != null
@@ -442,7 +441,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
442
441
def expected = insertDocuments(helper, [1 , 2 ])
443
442
444
443
then :
445
- nextAndClean(cursor, async) == expected
444
+ nextAndClean(cursor, async, expected . size() ) == expected
446
445
447
446
then :
448
447
tryNextAndClean(cursor, async) == null
@@ -451,7 +450,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
451
450
expected = insertDocuments(helper, [3 , 4 ])
452
451
453
452
then :
454
- nextAndClean(cursor, async) == expected
453
+ nextAndClean(cursor, async, expected . size() ) == expected
455
454
456
455
cleanup :
457
456
cursor?. close()
@@ -473,15 +472,12 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
473
472
def expected = insertDocuments(helper, [1 , 2 ])
474
473
475
474
then :
476
- nextAndClean(cursor, async) == expected
475
+ nextAndClean(cursor, async, expected . size() ) == expected
477
476
478
477
when :
479
478
helper. killCursor(helper. getNamespace(), cursor. getWrapped(). getServerCursor())
480
479
expected = insertDocuments(helper, [3 , 4 ])
481
- def results = nextAndClean(cursor, async)
482
- if (results. size() < expected. size()) {
483
- results. addAll(nextAndClean(cursor, async))
484
- }
480
+ def results = nextAndClean(cursor, async, expected. size())
485
481
486
482
then :
487
483
results == expected
@@ -493,10 +489,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
493
489
expected = insertDocuments(helper, [5 , 6 ])
494
490
helper. killCursor(helper. getNamespace(), cursor. getWrapped(). getServerCursor())
495
491
496
- results = nextAndClean(cursor, async)
497
- if (results. size() < expected. size()) {
498
- results. addAll(nextAndClean(cursor, async))
499
- }
492
+ results = nextAndClean(cursor, async, expected. size())
500
493
501
494
then :
502
495
results == expected
@@ -521,7 +514,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
521
514
522
515
when :
523
516
def expected = insertDocuments(helper, [1 , 2 ])
524
- def result = next(cursor, async)
517
+ def result = next(cursor, async, 2 )
525
518
526
519
then :
527
520
result. size() == 2
@@ -532,7 +525,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
532
525
533
526
operation. startAtOperationTime(result. last(). getTimestamp(' clusterTime' ))
534
527
cursor = execute(operation, async)
535
- result = nextAndClean(cursor, async)
528
+ result = nextAndClean(cursor, async, expected . tail . size() )
536
529
537
530
then :
538
531
result == expected. tail()
@@ -556,7 +549,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
556
549
557
550
when :
558
551
def expected = insertDocuments(helper, [1 , 2 ])
559
- def result = next(cursor, async)
552
+ def result = next(cursor, async, 2 )
560
553
561
554
then :
562
555
result. size() == 2
@@ -567,7 +560,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
567
560
568
561
operation. resumeAfter(result. head(). getDocument(' _id' )). startAtOperationTime(null )
569
562
cursor = execute(operation, async)
570
- result = nextAndClean(cursor, async)
563
+ result = nextAndClean(cursor, async, expected . tail() . size() )
571
564
572
565
then :
573
566
result == expected. tail()
@@ -592,7 +585,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
592
585
593
586
when :
594
587
def expected = insertDocuments(helper, [1 , 2 ])
595
- def result = next(cursor, async)
588
+ def result = next(cursor, async, 2 )
596
589
597
590
then :
598
591
result. size() == 2
@@ -602,7 +595,7 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
602
595
waitForLastRelease(async ? getAsyncCluster() : getCluster())
603
596
604
597
cursor = execute(operation. startAfter(result. head(). getDocument(' _id' )). startAtOperationTime(null ), async)
605
- result = nextAndClean(cursor, async)
598
+ result = nextAndClean(cursor, async, expected . tail() . size() )
606
599
607
600
then :
608
601
result == expected. tail()
@@ -762,6 +755,10 @@ class ChangeStreamOperationSpecification extends OperationFunctionalSpecificatio
762
755
removeExtra(tryNext(cursor, async))
763
756
}
764
757
758
+ def nextAndClean (cursor , boolean async , int minimumCount ) {
759
+ removeExtra(next(cursor, async, minimumCount))
760
+ }
761
+
765
762
def nextAndClean (cursor , boolean async ) {
766
763
removeExtra(next(cursor, async))
767
764
}
0 commit comments