18
18
using System . Linq ;
19
19
using System . Net ;
20
20
using System . Reflection ;
21
- using System . Threading ;
22
- using System . Threading . Tasks ;
23
21
using FluentAssertions ;
24
- using MongoDB . Driver . Core . Bindings ;
25
22
using MongoDB . Driver . Core . Clusters ;
26
- using MongoDB . Driver . Core . Clusters . ServerSelectors ;
27
- using MongoDB . Driver . Core . Configuration ;
28
23
using MongoDB . Driver . Core . Misc ;
29
24
using MongoDB . Driver . Core . Servers ;
30
- using MongoDB . Driver . Encryption ;
31
25
using Moq ;
32
26
using Xunit ;
33
27
@@ -205,35 +199,23 @@ public void ReleaseSession_should_have_expected_result(int[] pooledSessionWasRec
205
199
}
206
200
}
207
201
208
- [ Fact ]
209
- public void IsAboutToExpire_should_never_expire_in_load_balancing_mode ( )
210
- {
211
- var subject = CreateSubject ( ) ;
212
- var mockedCluster = new TestCluster ( ClusterType . LoadBalanced ) ;
213
- var mockedServerSessionPool = new CoreServerSessionPool ( mockedCluster ) ;
214
- var mockSession = new Mock < ICoreServerSession > ( ) ;
215
- var lastUsedAt = DateTime . UtcNow . AddSeconds ( 1741 ) ;
216
- mockSession . SetupGet ( m => m . LastUsedAt ) . Returns ( lastUsedAt ) ;
217
-
218
- var result = mockedServerSessionPool . IsAboutToExpire ( mockSession . Object ) ;
219
-
220
- result . Should ( ) . BeFalse ( ) ;
221
- }
222
-
223
202
[ Theory ]
224
- [ InlineData ( null , true ) ]
225
- [ InlineData ( 1741 , true ) ]
226
- [ InlineData ( 1739 , false ) ]
227
- public void IsAboutToExpire_should_return_expected_result ( int ? lastUsedSecondsAgo , bool expectedResult )
203
+ [ InlineData ( ClusterType . Sharded , null , true ) ]
204
+ [ InlineData ( ClusterType . Sharded , 1741 , true ) ]
205
+ [ InlineData ( ClusterType . Sharded , 1739 , false ) ]
206
+ [ InlineData ( ClusterType . LoadBalanced , null , false ) ]
207
+ [ InlineData ( ClusterType . LoadBalanced , 1741 , false ) ]
208
+ [ InlineData ( ClusterType . LoadBalanced , 1739 , false ) ]
209
+ public void IsAboutToExpire_should_return_expected_result ( ClusterType clusterType , int ? lastUsedSecondsAgo , bool isAboutToExpire )
228
210
{
229
- var subject = CreateSubject ( ) ;
211
+ var subject = CreateSubject ( clusterType ) ;
230
212
var mockSession = new Mock < ICoreServerSession > ( ) ;
231
213
var lastUsedAt = lastUsedSecondsAgo == null ? ( DateTime ? ) null : DateTime . UtcNow . AddSeconds ( - lastUsedSecondsAgo . Value ) ;
232
214
mockSession . SetupGet ( m => m . LastUsedAt ) . Returns ( lastUsedAt ) ;
233
215
234
216
var result = subject . IsAboutToExpire ( mockSession . Object ) ;
235
217
236
- result . Should ( ) . Be ( expectedResult ) ;
218
+ result . Should ( ) . Be ( isAboutToExpire ) ;
237
219
}
238
220
239
221
// private methods
@@ -256,7 +238,7 @@ private Mock<ICoreServerSession> CreateMockSession(bool recentlyUsed)
256
238
return recentlyUsed ? CreateMockRecentlyUsedSession ( ) : CreateMockExpiredSession ( ) ;
257
239
}
258
240
259
- private CoreServerSessionPool CreateSubject ( )
241
+ private CoreServerSessionPool CreateSubject ( ClusterType clusterType = ClusterType . Sharded )
260
242
{
261
243
var clusterId = new ClusterId ( ) ;
262
244
var endPoint = new DnsEndPoint ( "localhost" , 27017 ) ;
@@ -270,36 +252,13 @@ private CoreServerSessionPool CreateSubject()
270
252
version : new SemanticVersion ( 3 , 6 , 0 ) ,
271
253
wireVersionRange : new Range < int > ( 6 , 14 ) ) ;
272
254
273
- var clusterDescription = new ClusterDescription ( clusterId , false , null , ClusterType . Sharded , [ serverDescription ] ) ;
255
+ var clusterDescription = new ClusterDescription ( clusterId , false , null , clusterType , [ serverDescription ] ) ;
274
256
275
257
var mockCluster = new Mock < IClusterInternal > ( ) ;
276
258
mockCluster . SetupGet ( m => m . Description ) . Returns ( clusterDescription ) ;
277
259
278
260
return new CoreServerSessionPool ( mockCluster . Object ) ;
279
261
}
280
-
281
- private class TestCluster : IClusterInternal
282
- {
283
- public TestCluster ( ClusterType clusterType )
284
- {
285
- Description = new ClusterDescription ( new ClusterId ( ) , false , null , clusterType , Enumerable . Empty < ServerDescription > ( ) ) ;
286
- }
287
-
288
- public ClusterId ClusterId => throw new NotImplementedException ( ) ;
289
-
290
- public ClusterDescription Description { get ; }
291
-
292
- public ClusterSettings Settings => throw new NotImplementedException ( ) ;
293
-
294
- public event EventHandler < ClusterDescriptionChangedEventArgs > DescriptionChanged ;
295
-
296
- public ICoreServerSession AcquireServerSession ( ) => throw new NotImplementedException ( ) ;
297
- public void Dispose ( ) => throw new NotImplementedException ( ) ;
298
- public void Initialize ( ) => DescriptionChanged ? . Invoke ( this , new ClusterDescriptionChangedEventArgs ( Description , Description ) ) ;
299
- public IServer SelectServer ( IServerSelector selector , CancellationToken cancellationToken ) => throw new NotImplementedException ( ) ;
300
- public Task < IServer > SelectServerAsync ( IServerSelector selector , CancellationToken cancellationToken ) => throw new NotImplementedException ( ) ;
301
- public ICoreSessionHandle StartSession ( CoreSessionOptions options = null ) => throw new NotImplementedException ( ) ;
302
- }
303
262
}
304
263
305
264
internal static class CoreServerSessionPoolReflector
0 commit comments