@@ -132,14 +132,10 @@ public void Run(
132
132
KillOpenTransactions ( DriverTestConfiguration . Client ) ;
133
133
}
134
134
135
- _entityMap = UnifiedEntityMap . Create ( _eventFormatters , _loggingService . LoggingSettings , async) ;
135
+ BsonDocument lastKnownClusterTime = AddInitialData ( DriverTestConfiguration . Client , initialData ) ;
136
+ _entityMap = UnifiedEntityMap . Create ( _eventFormatters , _loggingService . LoggingSettings , async, lastKnownClusterTime ) ;
136
137
_entityMap . AddRange ( entities ) ;
137
138
138
- if ( initialData != null )
139
- {
140
- AddInitialData ( DriverTestConfiguration . Client , initialData , _entityMap ) ;
141
- }
142
-
143
139
foreach ( var operation in operations )
144
140
{
145
141
var cancellationToken = CancellationToken . None ;
@@ -181,45 +177,36 @@ public void Dispose()
181
177
}
182
178
183
179
// private methods
184
- private void AddInitialData ( IMongoClient client , BsonArray initialData , UnifiedEntityMap entityMap )
180
+ private BsonDocument AddInitialData ( IMongoClient client , BsonArray initialData )
185
181
{
186
- var mongoCollectionSettings = new MongoCollectionSettings ( ) ;
187
-
188
- var writeConcern = WriteConcern . WMajority ;
189
- if ( DriverTestConfiguration . IsReplicaSet ( client ) )
182
+ if ( initialData == null )
190
183
{
191
- // Makes server to wait for ack from all data nodes to make sure the test data availability before running the test itself.
192
- // It's limited to replica set only because there is no simple way to calculate proper w for sharded cluster.
193
- var dataBearingServersCount = DriverTestConfiguration . GetReplicaSetNumberOfDataBearingMembers ( client ) ;
194
- writeConcern = WriteConcern . Acknowledged . With ( w : dataBearingServersCount , journal : true ) ;
184
+ return null ;
195
185
}
196
186
197
- BsonDocument serverTime = null ;
187
+ BsonDocument lastKnownClusterTime = null ;
198
188
foreach ( var dataItem in initialData )
199
189
{
200
190
var collectionName = dataItem [ "collectionName" ] . AsString ;
201
191
var databaseName = dataItem [ "databaseName" ] . AsString ;
202
192
var documents = dataItem [ "documents" ] . AsBsonArray . Cast < BsonDocument > ( ) . ToList ( ) ;
203
193
204
- var database = client . GetDatabase ( databaseName ) . WithWriteConcern ( writeConcern ) ;
205
- var collection = database . GetCollection < BsonDocument > ( collectionName , mongoCollectionSettings ) ;
194
+ var database = client . GetDatabase ( databaseName ) . WithWriteConcern ( WriteConcern . WMajority ) ;
206
195
207
196
_logger . LogDebug ( "Dropping {0}" , collectionName ) ;
208
- var session = client . StartSession ( ) ;
197
+ using var session = client . StartSession ( ) ;
209
198
database . DropCollection ( session , collectionName ) ;
199
+ database . CreateCollection ( session , collectionName ) ;
210
200
if ( documents . Any ( ) )
211
201
{
202
+ var collection = database . GetCollection < BsonDocument > ( collectionName ) ;
212
203
collection . InsertMany ( session , documents ) ;
213
204
}
214
- else
215
- {
216
- database . CreateCollection ( session , collectionName ) ;
217
- }
218
205
219
- serverTime = session . ClusterTime ;
206
+ lastKnownClusterTime = session . ClusterTime ;
220
207
}
221
208
222
- entityMap . AdjustSessionsClusterTime ( serverTime ) ;
209
+ return lastKnownClusterTime ;
223
210
}
224
211
225
212
private void AssertEvents ( BsonArray eventItems , UnifiedEntityMap entityMap )
0 commit comments