PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Clusters/ServerSelectors/LatencyLimitingServerSelectorTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 66 lines | 43 code | 9 blank | 14 comment | 0 complexity | f585573cf295a208fc86de89e0e826d8 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using System.Linq;
  17. using System.Net;
  18. using FluentAssertions;
  19. using MongoDB.Driver.Core.Helpers;
  20. using MongoDB.Driver.Core.Servers;
  21. using Xunit;
  22. namespace MongoDB.Driver.Core.Clusters.ServerSelectors
  23. {
  24. public class LatencyLimitingServerSelectorTests
  25. {
  26. private ClusterDescription _description;
  27. public LatencyLimitingServerSelectorTests()
  28. {
  29. var clusterId = new ClusterId();
  30. _description = new ClusterDescription(
  31. clusterId,
  32. ClusterConnectionMode.Automatic,
  33. ClusterType.Unknown,
  34. new[]
  35. {
  36. ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), averageRoundTripTime: TimeSpan.FromMilliseconds(10)),
  37. ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), averageRoundTripTime: TimeSpan.FromMilliseconds(30)),
  38. ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), averageRoundTripTime: TimeSpan.FromMilliseconds(20))
  39. });
  40. }
  41. [Fact]
  42. public void Should_select_all_the_servers_within_the_latency()
  43. {
  44. var subject = new LatencyLimitingServerSelector(TimeSpan.FromMilliseconds(15));
  45. var result = subject.SelectServers(_description, _description.Servers).ToList();
  46. result.Count.Should().Be(2);
  47. result.Should().BeEquivalentTo(new[] { _description.Servers[0], _description.Servers[2] });
  48. }
  49. [Fact]
  50. public void Should_select_no_servers_when_none_exist()
  51. {
  52. var subject = new LatencyLimitingServerSelector(TimeSpan.FromMilliseconds(15));
  53. var result = subject.SelectServers(_description, Enumerable.Empty<ServerDescription>()).ToList();
  54. result.Should().BeEmpty();
  55. }
  56. }
  57. }