File tree Expand file tree Collapse file tree 4 files changed +79
-6
lines changed
specifications/sessions/tests
tests/MongoDB.Driver.Tests/Specifications/sessions Expand file tree Collapse file tree 4 files changed +79
-6
lines changed Original file line number Diff line number Diff line change 1061
1061
}
1062
1062
]
1063
1063
},
1064
+ {
1065
+ "name" : " find" ,
1066
+ "object" : " collection0" ,
1067
+ "arguments" : {
1068
+ "session" : " session2" ,
1069
+ "filter" : {}
1070
+ },
1071
+ "expectResult" : [
1072
+ {
1073
+ "_id" : 1 ,
1074
+ "x" : 11
1075
+ },
1076
+ {
1077
+ "_id" : 2 ,
1078
+ "x" : 11
1079
+ }
1080
+ ]
1081
+ },
1064
1082
{
1065
1083
"name" : " find" ,
1066
1084
"object" : " collection0" ,
1115
1133
"databaseName" : " database0"
1116
1134
}
1117
1135
},
1136
+ {
1137
+ "commandStartedEvent" : {
1138
+ "command" : {
1139
+ "find" : " collection0" ,
1140
+ "readConcern" : {
1141
+ "level" : " snapshot" ,
1142
+ "atClusterTime" : {
1143
+ "$$matchesEntity" : " savedSnapshotTime"
1144
+ }
1145
+ }
1146
+ },
1147
+ "databaseName" : " database0"
1148
+ }
1149
+ },
1118
1150
{
1119
1151
"commandStartedEvent" : {
1120
1152
"command" : {
Original file line number Diff line number Diff line change @@ -378,7 +378,7 @@ tests:
378
378
fieldName : x
379
379
filter : {}
380
380
session : session0
381
- expectResult : [ 11 ]
381
+ expectResult : [ 11 ]
382
382
expectEvents :
383
383
- client : client0
384
384
events :
@@ -508,6 +508,16 @@ tests:
508
508
sessionOptions :
509
509
snapshot : true
510
510
snapshotTime : *savedSnapshotTime
511
+ - name : find
512
+ object : collection0
513
+ arguments :
514
+ session : session2
515
+ filter : {}
516
+ expectResult :
517
+ - { _id: 1, x: 11 }
518
+ - { _id: 2, x: 11 }
519
+ # # Calling find again to verify that atClusterTime/snapshotTime has not been modified after the first query
520
+ # # as it would happen if snapshotTime had not been specified
511
521
- name : find
512
522
object : collection0
513
523
arguments :
@@ -540,7 +550,14 @@ tests:
540
550
find : collection0
541
551
readConcern :
542
552
level : snapshot
543
- atClusterTime : { $$matchesEntity: savedSnapshotTime }
553
+ atClusterTime : { $$matchesEntity: *savedSnapshotTime }
554
+ databaseName : database0
555
+ - commandStartedEvent :
556
+ command :
557
+ find : collection0
558
+ readConcern :
559
+ level : snapshot
560
+ atClusterTime : { $$matchesEntity: *savedSnapshotTime }
544
561
databaseName : database0
545
562
- commandStartedEvent :
546
563
command :
Original file line number Diff line number Diff line change @@ -622,12 +622,18 @@ private RenderArgs<BsonDocument> GetRenderArgs()
622
622
623
623
private IClientSessionHandle StartSession ( ClientSessionOptions options )
624
624
{
625
- if ( options != null && options . Snapshot && options . CausalConsistency == true )
625
+ if ( options != null )
626
626
{
627
- throw new NotSupportedException ( "Combining both causal consistency and snapshot options is not supported." ) ;
628
- }
627
+ if ( options . SnapshotTime != null && ! options . Snapshot )
628
+ {
629
+ throw new NotSupportedException ( "Specifying a snapshot time requires snapshot to be true." ) ;
630
+ }
629
631
630
- //TODO Throw an exception if SnapshotTime is set and Snapshot is not true.
632
+ if ( options . Snapshot && options . CausalConsistency == true )
633
+ {
634
+ throw new NotSupportedException ( "Combining both causal consistency and snapshot options is not supported." ) ;
635
+ }
636
+ }
631
637
632
638
options ??= new ClientSessionOptions ( ) ;
633
639
if ( _settings . Timeout . HasValue && options . DefaultTransactionOptions ? . Timeout == null )
Original file line number Diff line number Diff line change @@ -357,6 +357,24 @@ public void Ensure_cluster_times_are_not_gossiped_on_SDAM_commands()
357
357
commandStartedEvents[ 0 ] . Command [ "$clusterTime" ] . Should ( ) . Be ( clusterTime ) ;
358
358
}
359
359
360
+ [ Fact ]
361
+ public void If_SnapshotTime_is_set_Snapshot_must_be_true( )
362
+ {
363
+ RequireServer. Check ( ) ;
364
+
365
+ var sessionOptions = new ClientSessionOptions
366
+ {
367
+ Snapshot = false,
368
+ SnapshotTime = new BsonTimestamp ( 1 , 1 )
369
+ } ;
370
+
371
+ var mongoClient = DriverTestConfiguration. Client;
372
+
373
+ var exception = Record . Exception ( ( ) => mongoClient . StartSession ( sessionOptions ) ) ;
374
+ exception. Should ( ) . BeOfType < NotSupportedException > ( ) ;
375
+ }
376
+
377
+
360
378
private sealed class MongocryptdContext : IDisposable
361
379
{
362
380
public IMongoClient MongoClient { get ; }
You can’t perform that action at this time.
0 commit comments