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