71
71
import java .util .stream .Collectors ;
72
72
import java .util .stream .Stream ;
73
73
74
+ import static com .mongodb .ClusterFixture .applyTimeoutMultiplierForServerless ;
74
75
import static com .mongodb .ClusterFixture .getConnectionString ;
75
76
import static com .mongodb .ClusterFixture .isAuthenticated ;
76
77
import static com .mongodb .ClusterFixture .isDiscoverableReplicaSet ;
@@ -153,7 +154,7 @@ public void testBackgroundConnectionPoolingTimeoutMSUsedForHandshakeCommands() {
153
154
builder .minSize (1 );
154
155
builder .addConnectionPoolListener (connectionPoolListener );
155
156
})
156
- .timeout (100 , TimeUnit .MILLISECONDS ))) {
157
+ .timeout (applyTimeoutMultiplierForServerless ( 100 ) , TimeUnit .MILLISECONDS ))) {
157
158
158
159
assertDoesNotThrow (() ->
159
160
connectionPoolListener .waitForEvents (asList (ConnectionCreatedEvent .class , ConnectionClosedEvent .class ),
@@ -188,7 +189,7 @@ public void testBackgroundConnectionPoolingTimeoutMSIsRefreshedForEachHandshakeC
188
189
builder .minSize (1 );
189
190
builder .addConnectionPoolListener (connectionPoolListener );
190
191
})
191
- .timeout (250 , TimeUnit .MILLISECONDS ))) {
192
+ .timeout (applyTimeoutMultiplierForServerless ( 250 ) , TimeUnit .MILLISECONDS ))) {
192
193
193
194
assertDoesNotThrow (() ->
194
195
connectionPoolListener .waitForEvents (asList (ConnectionCreatedEvent .class , ConnectionReadyEvent .class ),
@@ -211,12 +212,12 @@ public void testBlockingIterationMethodsTailableCursor() {
211
212
+ " data: {"
212
213
+ " failCommands: [\" getMore\" ],"
213
214
+ " blockConnection: true,"
214
- + " blockTimeMS: " + 150
215
+ + " blockTimeMS: " + applyTimeoutMultiplierForServerless ( 150 )
215
216
+ " }"
216
217
+ "}" );
217
218
218
219
try (MongoClient client = createMongoClient (getMongoClientSettingsBuilder ()
219
- .timeout (250 , TimeUnit .MILLISECONDS ))) {
220
+ .timeout (applyTimeoutMultiplierForServerless ( 250 ) , TimeUnit .MILLISECONDS ))) {
220
221
MongoCollection <Document > collection = client .getDatabase (namespace .getDatabaseName ())
221
222
.getCollection (namespace .getCollectionName ());
222
223
@@ -243,7 +244,7 @@ public void testBlockingIterationMethodsChangeStream() {
243
244
244
245
BsonTimestamp startTime = new BsonTimestamp ((int ) Instant .now ().getEpochSecond (), 0 );
245
246
collectionHelper .create (namespace .getCollectionName (), new CreateCollectionOptions ());
246
- sleep (2000 );
247
+ sleep (applyTimeoutMultiplierForServerless ( 2000 ) );
247
248
collectionHelper .insertDocuments (singletonList (BsonDocument .parse ("{x: 1}" )), WriteConcern .MAJORITY );
248
249
249
250
collectionHelper .runAdminCommand ("{"
@@ -252,12 +253,12 @@ public void testBlockingIterationMethodsChangeStream() {
252
253
+ " data: {"
253
254
+ " failCommands: [\" getMore\" ],"
254
255
+ " blockConnection: true,"
255
- + " blockTimeMS: " + 150
256
+ + " blockTimeMS: " + applyTimeoutMultiplierForServerless ( 150 )
256
257
+ " }"
257
258
+ "}" );
258
259
259
260
try (MongoClient mongoClient = createMongoClient (getMongoClientSettingsBuilder ()
260
- .timeout (250 , TimeUnit .MILLISECONDS ))) {
261
+ .timeout (applyTimeoutMultiplierForServerless ( 250 ) , TimeUnit .MILLISECONDS ))) {
261
262
262
263
MongoCollection <Document > collection = mongoClient .getDatabase (namespace .getDatabaseName ())
263
264
.getCollection (namespace .getCollectionName ()).withReadPreference (ReadPreference .primary ());
@@ -292,15 +293,15 @@ public void testGridFSUploadViaOpenUploadStreamTimeout() {
292
293
+ " data: {"
293
294
+ " failCommands: [\" insert\" ],"
294
295
+ " blockConnection: true,"
295
- + " blockTimeMS: " + (rtt + 205 )
296
+ + " blockTimeMS: " + (rtt + applyTimeoutMultiplierForServerless ( 205 ) )
296
297
+ " }"
297
298
+ "}" );
298
299
299
300
chunksCollectionHelper .create ();
300
301
filesCollectionHelper .create ();
301
302
302
303
try (MongoClient client = createMongoClient (getMongoClientSettingsBuilder ()
303
- .timeout (rtt + 200 , TimeUnit .MILLISECONDS ))) {
304
+ .timeout (rtt + applyTimeoutMultiplierForServerless ( 200 ) , TimeUnit .MILLISECONDS ))) {
304
305
MongoDatabase database = client .getDatabase (namespace .getDatabaseName ());
305
306
GridFSBucket gridFsBucket = createGridFsBucket (database , GRID_FS_BUCKET_NAME );
306
307
@@ -323,15 +324,15 @@ public void testAbortingGridFsUploadStreamTimeout() throws Throwable {
323
324
+ " data: {"
324
325
+ " failCommands: [\" delete\" ],"
325
326
+ " blockConnection: true,"
326
- + " blockTimeMS: " + (rtt + 305 )
327
+ + " blockTimeMS: " + (rtt + applyTimeoutMultiplierForServerless ( 305 ) )
327
328
+ " }"
328
329
+ "}" );
329
330
330
331
chunksCollectionHelper .create ();
331
332
filesCollectionHelper .create ();
332
333
333
334
try (MongoClient client = createMongoClient (getMongoClientSettingsBuilder ()
334
- .timeout (rtt + 300 , TimeUnit .MILLISECONDS ))) {
335
+ .timeout (rtt + applyTimeoutMultiplierForServerless ( 300 ) , TimeUnit .MILLISECONDS ))) {
335
336
MongoDatabase database = client .getDatabase (namespace .getDatabaseName ());
336
337
GridFSBucket gridFsBucket = createGridFsBucket (database , GRID_FS_BUCKET_NAME ).withChunkSizeBytes (2 );
337
338
@@ -374,12 +375,12 @@ public void testGridFsDownloadStreamTimeout() {
374
375
+ " data: {"
375
376
+ " failCommands: [\" find\" ],"
376
377
+ " blockConnection: true,"
377
- + " blockTimeMS: " + (rtt + 95 )
378
+ + " blockTimeMS: " + (rtt + applyTimeoutMultiplierForServerless ( 95 ) )
378
379
+ " }"
379
380
+ "}" );
380
381
381
382
try (MongoClient client = createMongoClient (getMongoClientSettingsBuilder ()
382
- .timeout (rtt + 100 , TimeUnit .MILLISECONDS ))) {
383
+ .timeout (rtt + applyTimeoutMultiplierForServerless ( 100 ) , TimeUnit .MILLISECONDS ))) {
383
384
MongoDatabase database = client .getDatabase (namespace .getDatabaseName ());
384
385
GridFSBucket gridFsBucket = createGridFsBucket (database , GRID_FS_BUCKET_NAME ).withChunkSizeBytes (2 );
385
386
@@ -472,12 +473,12 @@ public void test9EndSessionClientTimeout() {
472
473
+ " data: {"
473
474
+ " failCommands: [\" abortTransaction\" ],"
474
475
+ " blockConnection: true,"
475
- + " blockTimeMS: " + 150
476
+ + " blockTimeMS: " + applyTimeoutMultiplierForServerless ( 150 )
476
477
+ " }"
477
478
+ "}" );
478
479
479
480
try (MongoClient mongoClient = createMongoClient (getMongoClientSettingsBuilder ().retryWrites (false )
480
- .timeout (100 , TimeUnit .MILLISECONDS ))) {
481
+ .timeout (applyTimeoutMultiplierForServerless ( 100 ) , TimeUnit .MILLISECONDS ))) {
481
482
MongoCollection <Document > collection = mongoClient .getDatabase (namespace .getDatabaseName ())
482
483
.getCollection (namespace .getCollectionName ());
483
484
@@ -488,7 +489,7 @@ public void test9EndSessionClientTimeout() {
488
489
long start = System .nanoTime ();
489
490
session .close ();
490
491
long elapsed = msElapsedSince (start ) - postSessionCloseSleep ();
491
- assertTrue (elapsed <= 150 , "Took too long to time out, elapsedMS: " + elapsed );
492
+ assertTrue (elapsed <= applyTimeoutMultiplierForServerless ( 150 ) , "Took too long to time out, elapsedMS: " + elapsed );
492
493
}
493
494
}
494
495
CommandFailedEvent abortTransactionEvent = assertDoesNotThrow (() ->
@@ -510,7 +511,7 @@ public void test9EndSessionSessionTimeout() {
510
511
+ " data: {"
511
512
+ " failCommands: [\" abortTransaction\" ],"
512
513
+ " blockConnection: true,"
513
- + " blockTimeMS: " + 150
514
+ + " blockTimeMS: " + applyTimeoutMultiplierForServerless ( 150 )
514
515
+ " }"
515
516
+ "}" );
516
517
@@ -519,14 +520,14 @@ public void test9EndSessionSessionTimeout() {
519
520
.getCollection (namespace .getCollectionName ());
520
521
521
522
try (ClientSession session = mongoClient .startSession (ClientSessionOptions .builder ()
522
- .defaultTimeout (100 , TimeUnit .MILLISECONDS ).build ())) {
523
+ .defaultTimeout (applyTimeoutMultiplierForServerless (( 100 )) , TimeUnit .MILLISECONDS ).build ())) {
523
524
session .startTransaction ();
524
525
collection .insertOne (session , new Document ("x" , 1 ));
525
526
526
527
long start = System .nanoTime ();
527
528
session .close ();
528
529
long elapsed = msElapsedSince (start ) - postSessionCloseSleep ();
529
- assertTrue (elapsed <= 150 , "Took too long to time out, elapsedMS: " + elapsed );
530
+ assertTrue (elapsed <= applyTimeoutMultiplierForServerless ( 150 ) , "Took too long to time out, elapsedMS: " + elapsed );
530
531
}
531
532
}
532
533
CommandFailedEvent abortTransactionEvent = assertDoesNotThrow (() ->
@@ -554,10 +555,10 @@ public void test9EndSessionCustomTesEachOperationHasItsOwnTimeoutWithCommit() {
554
555
.getCollection (namespace .getCollectionName ());
555
556
556
557
try (ClientSession session = mongoClient .startSession (ClientSessionOptions .builder ()
557
- .defaultTimeout (200 , TimeUnit .MILLISECONDS ).build ())) {
558
+ .defaultTimeout (applyTimeoutMultiplierForServerless ( 200 ) , TimeUnit .MILLISECONDS ).build ())) {
558
559
session .startTransaction ();
559
560
collection .insertOne (session , new Document ("x" , 1 ));
560
- sleep (200 );
561
+ sleep (applyTimeoutMultiplierForServerless ( 200 ) );
561
562
562
563
assertDoesNotThrow (session ::commitTransaction );
563
564
}
@@ -585,10 +586,10 @@ public void test9EndSessionCustomTesEachOperationHasItsOwnTimeoutWithAbort() {
585
586
.getCollection (namespace .getCollectionName ());
586
587
587
588
try (ClientSession session = mongoClient .startSession (ClientSessionOptions .builder ()
588
- .defaultTimeout (200 , TimeUnit .MILLISECONDS ).build ())) {
589
+ .defaultTimeout (applyTimeoutMultiplierForServerless ( 200 ) , TimeUnit .MILLISECONDS ).build ())) {
589
590
session .startTransaction ();
590
591
collection .insertOne (session , new Document ("x" , 1 ));
591
- sleep (200 );
592
+ sleep (applyTimeoutMultiplierForServerless ( 200 ) );
592
593
593
594
assertDoesNotThrow (session ::close );
594
595
}
@@ -608,11 +609,12 @@ public void test10ConvenientTransactions() {
608
609
+ " data: {"
609
610
+ " failCommands: [\" insert\" , \" abortTransaction\" ],"
610
611
+ " blockConnection: true,"
611
- + " blockTimeMS: " + 150
612
+ + " blockTimeMS: " + applyTimeoutMultiplierForServerless ( 150 )
612
613
+ " }"
613
614
+ "}" );
614
615
615
- try (MongoClient mongoClient = createMongoClient (getMongoClientSettingsBuilder ().timeout (100 , TimeUnit .MILLISECONDS ))) {
616
+ try (MongoClient mongoClient = createMongoClient (getMongoClientSettingsBuilder ()
617
+ .timeout (applyTimeoutMultiplierForServerless (100 ), TimeUnit .MILLISECONDS ))) {
616
618
MongoCollection <Document > collection = mongoClient .getDatabase (namespace .getDatabaseName ())
617
619
.getCollection (namespace .getCollectionName ());
618
620
@@ -642,7 +644,7 @@ public void test10CustomTestWithTransactionUsesASingleTimeout() {
642
644
+ " data: {"
643
645
+ " failCommands: [\" insert\" ],"
644
646
+ " blockConnection: true,"
645
- + " blockTimeMS: " + 25
647
+ + " blockTimeMS: " + applyTimeoutMultiplierForServerless ( 25 )
646
648
+ " }"
647
649
+ "}" );
648
650
@@ -651,11 +653,11 @@ public void test10CustomTestWithTransactionUsesASingleTimeout() {
651
653
.getCollection (namespace .getCollectionName ());
652
654
653
655
try (ClientSession session = mongoClient .startSession (ClientSessionOptions .builder ()
654
- .defaultTimeout (200 , TimeUnit .MILLISECONDS ).build ())) {
656
+ .defaultTimeout (applyTimeoutMultiplierForServerless ( 200 ) , TimeUnit .MILLISECONDS ).build ())) {
655
657
assertThrows (MongoOperationTimeoutException .class ,
656
658
() -> session .withTransaction (() -> {
657
659
collection .insertOne (session , new Document ("x" , 1 ));
658
- sleep (200 );
660
+ sleep (applyTimeoutMultiplierForServerless ( 200 ) );
659
661
return true ;
660
662
})
661
663
);
@@ -675,7 +677,7 @@ public void test10CustomTestWithTransactionUsesASingleTimeoutWithLock() {
675
677
+ " data: {"
676
678
+ " failCommands: [\" insert\" ],"
677
679
+ " blockConnection: true,"
678
- + " blockTimeMS: " + 25
680
+ + " blockTimeMS: " + applyTimeoutMultiplierForServerless ( 25 )
679
681
+ " errorCode: " + 24
680
682
+ " errorLabels: [\" TransientTransactionError\" ]"
681
683
+ " }"
@@ -686,11 +688,11 @@ public void test10CustomTestWithTransactionUsesASingleTimeoutWithLock() {
686
688
.getCollection (namespace .getCollectionName ());
687
689
688
690
try (ClientSession session = mongoClient .startSession (ClientSessionOptions .builder ()
689
- .defaultTimeout (200 , TimeUnit .MILLISECONDS ).build ())) {
691
+ .defaultTimeout (applyTimeoutMultiplierForServerless ( 200 ) , TimeUnit .MILLISECONDS ).build ())) {
690
692
assertThrows (MongoOperationTimeoutException .class ,
691
693
() -> session .withTransaction (() -> {
692
694
collection .insertOne (session , new Document ("x" , 1 ));
693
- sleep (200 );
695
+ sleep (applyTimeoutMultiplierForServerless ( 200 ) );
694
696
return true ;
695
697
})
696
698
);
@@ -712,13 +714,13 @@ public void shouldIgnoreWtimeoutMsOfWriteConcernToInitialAndSubsequentCommitTran
712
714
.getCollection (namespace .getCollectionName ());
713
715
714
716
try (ClientSession session = mongoClient .startSession (ClientSessionOptions .builder ()
715
- .defaultTimeout (200 , TimeUnit .MILLISECONDS )
717
+ .defaultTimeout (applyTimeoutMultiplierForServerless ( 200 ) , TimeUnit .MILLISECONDS )
716
718
.build ())) {
717
719
session .startTransaction (TransactionOptions .builder ()
718
- .writeConcern (WriteConcern .ACKNOWLEDGED .withWTimeout (100 , TimeUnit .MILLISECONDS ))
720
+ .writeConcern (WriteConcern .ACKNOWLEDGED .withWTimeout (applyTimeoutMultiplierForServerless ( 100 ) , TimeUnit .MILLISECONDS ))
719
721
.build ());
720
722
collection .insertOne (session , new Document ("x" , 1 ));
721
- sleep (200 );
723
+ sleep (applyTimeoutMultiplierForServerless ( 200 ) );
722
724
723
725
assertDoesNotThrow (session ::commitTransaction );
724
726
//repeat commit.
@@ -756,13 +758,13 @@ public void testKillCursorsIsNotExecutedAfterGetMoreNetworkErrorWhenTimeoutIsNot
756
758
+ " data: {"
757
759
+ " failCommands: [\" getMore\" ],"
758
760
+ " blockConnection: true,"
759
- + " blockTimeMS: " + (rtt + 600 )
761
+ + " blockTimeMS: " + (rtt + applyTimeoutMultiplierForServerless ( 600 ) )
760
762
+ " }"
761
763
+ "}" );
762
764
763
765
try (MongoClient mongoClient = createMongoClient (getMongoClientSettingsBuilder ()
764
766
.retryReads (true )
765
- .applyToSocketSettings (builder -> builder .readTimeout (500 , TimeUnit .MILLISECONDS )))) {
767
+ .applyToSocketSettings (builder -> builder .readTimeout (applyTimeoutMultiplierForServerless ( 500 ) , TimeUnit .MILLISECONDS )))) {
766
768
767
769
MongoCollection <Document > collection = mongoClient .getDatabase (namespace .getDatabaseName ())
768
770
.getCollection (namespace .getCollectionName ()).withReadPreference (ReadPreference .primary ());
@@ -803,12 +805,12 @@ public void testKillCursorsIsNotExecutedAfterGetMoreNetworkError() {
803
805
+ " data: {"
804
806
+ " failCommands: [\" getMore\" ],"
805
807
+ " blockConnection: true,"
806
- + " blockTimeMS: " + (rtt + 600 )
808
+ + " blockTimeMS: " + (rtt + applyTimeoutMultiplierForServerless ( 600 ) )
807
809
+ " }"
808
810
+ "}" );
809
811
810
812
try (MongoClient mongoClient = createMongoClient (getMongoClientSettingsBuilder ()
811
- .timeout (500 , TimeUnit .MILLISECONDS ))) {
813
+ .timeout (applyTimeoutMultiplierForServerless ( 500 ) , TimeUnit .MILLISECONDS ))) {
812
814
813
815
MongoCollection <Document > collection = mongoClient .getDatabase (namespace .getDatabaseName ())
814
816
.getCollection (namespace .getCollectionName ()).withReadPreference (ReadPreference .primary ());
@@ -845,11 +847,11 @@ public void shouldThrowTimeoutExceptionForSubsequentCommitTransaction() {
845
847
.getCollection (namespace .getCollectionName ());
846
848
847
849
try (ClientSession session = mongoClient .startSession (ClientSessionOptions .builder ()
848
- .defaultTimeout (200 , TimeUnit .MILLISECONDS )
850
+ .defaultTimeout (applyTimeoutMultiplierForServerless ( 200 ) , TimeUnit .MILLISECONDS )
849
851
.build ())) {
850
852
session .startTransaction (TransactionOptions .builder ().build ());
851
853
collection .insertOne (session , new Document ("x" , 1 ));
852
- sleep (200 );
854
+ sleep (applyTimeoutMultiplierForServerless ( 200 ) );
853
855
854
856
assertDoesNotThrow (session ::commitTransaction );
855
857
@@ -859,7 +861,7 @@ public void shouldThrowTimeoutExceptionForSubsequentCommitTransaction() {
859
861
+ " data: {"
860
862
+ " failCommands: [\" commitTransaction\" ],"
861
863
+ " blockConnection: true,"
862
- + " blockTimeMS: " + 500
864
+ + " blockTimeMS: " + applyTimeoutMultiplierForServerless ( 500 )
863
865
+ " }"
864
866
+ "}" );
865
867
0 commit comments