コード例 #1
0
 public SharedConnectionPoolFactory(
     IConnectionFactory connectionFactory,
     ConnectionPoolSettings connectionPoolSettings)
 {
     _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
     _connectionPoolSettings = Ensure.IsNotNull(connectionPoolSettings, "connectionPoolSettings");
 }
コード例 #2
0
        // constructors
        public ExclusiveConnectionPool(
            ServerId serverId,
            EndPoint endPoint,
            ConnectionPoolSettings settings,
            IConnectionFactory connectionFactory,
            IEventSubscriber eventSubscriber)
        {
            _serverId = Ensure.IsNotNull(serverId, nameof(serverId));
            _endPoint = Ensure.IsNotNull(endPoint, nameof(endPoint));
            _settings = Ensure.IsNotNull(settings, nameof(settings));
            _connectionFactory = Ensure.IsNotNull(connectionFactory, nameof(connectionFactory));
            Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));

            _connectionHolder = new ListConnectionHolder(eventSubscriber);
            _poolQueue = new WaitQueue(settings.MaxConnections);
            _waitQueue = new SemaphoreSlim(settings.WaitQueueSize);
            _maintenanceCancellationTokenSource = new CancellationTokenSource();
            _state = new InterlockedInt32(State.Initial);

            eventSubscriber.TryGetEventHandler(out _checkingOutConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkedOutConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkingOutConnectionFailedEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkingInConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkedInConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addingConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addedConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _openingEventHandler);
            eventSubscriber.TryGetEventHandler(out _openedEventHandler);
            eventSubscriber.TryGetEventHandler(out _closingEventHandler);
            eventSubscriber.TryGetEventHandler(out _closedEventHandler);
            eventSubscriber.TryGetEventHandler(out _addingConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addedConnectionEventHandler);
        }
コード例 #3
0
        /// <summary>
        /// Configures the connection pool settings.
        /// </summary>
        /// <param name="configurator">The connection pool settings configurator delegate.</param>
        /// <returns>A reconfigured cluster builder.</returns>
        public ClusterBuilder ConfigureConnectionPool(Func <ConnectionPoolSettings, ConnectionPoolSettings> configurator)
        {
            Ensure.IsNotNull(configurator, nameof(configurator));

            _connectionPoolSettings = configurator(_connectionPoolSettings);
            return(this);
        }
コード例 #4
0
 // constructors
 public Builder(ConnectionPoolSettings other)
 {
     _maintenanceInterval = other._maintenanceInterval;
     _maxConnections      = other._maxConnections;
     _minConnections      = other._minConnections;
     _waitQueueSize       = other._waitQueueSize;
     _waitQueueTimeout    = other._waitQueueTimeout;
 }
コード例 #5
0
 // constructors
 public ClusterBuilder()
 {
     _clusterSettings        = new ClusterSettings();
     _serverSettings         = new ServerSettings();
     _connectionPoolSettings = new ConnectionPoolSettings();
     _connectionSettings     = new ConnectionSettings();
     _tcpStreamSettings      = new TcpStreamSettings();
     _streamFactoryWrapper   = inner => inner;
 }
コード例 #6
0
 // constructors
 public ClusterBuilder()
 {
     _clusterSettings = new ClusterSettings();
     _serverSettings = new ServerSettings();
     _connectionPoolSettings = new ConnectionPoolSettings();
     _connectionSettings = new ConnectionSettings();
     _tcpStreamSettings = new TcpStreamSettings();
     _streamFactoryWrapper = inner => inner;
 }
コード例 #7
0
        public void WithInternal_should_return_expected_result()
        {
            var subject = new ConnectionPoolSettings();

            var result = subject.WithInternal(isPausable: false);

            result.IsPausable.Should().Be(false);
            result = subject.WithInternal(isPausable: true);
            result.IsPausable.Should().Be(true);
        }
コード例 #8
0
        public void constructor_should_initialize_instance()
        {
            var subject = new ConnectionPoolSettings();

            subject.MaintenanceInterval.Should().Be(TimeSpan.FromMinutes(1));
            subject.MaxConnections.Should().Be(100);
            subject.MinConnections.Should().Be(0);
            subject.WaitQueueSize.Should().Be(500);
            subject.WaitQueueTimeout.Should().Be(TimeSpan.FromMinutes(2));
        }
コード例 #9
0
        public void constructor_should_initialize_instance()
        {
            var subject = new ConnectionPoolSettings();

            subject.MaintenanceInterval.Should().Be(TimeSpan.FromMinutes(1));
            subject.MaxConnections.Should().Be(100);
            subject.MinConnections.Should().Be(0);
            subject.WaitQueueSize.Should().Be(500);
            subject.WaitQueueTimeout.Should().Be(TimeSpan.FromMinutes(2));
        }
コード例 #10
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="ClusterBuilder"/> class.
 /// </summary>
 public ClusterBuilder()
 {
     _clusterSettings        = new ClusterSettings();
     _sdamLoggingSettings    = new SdamLoggingSettings(null);
     _serverSettings         = new ServerSettings();
     _connectionPoolSettings = new ConnectionPoolSettings();
     _connectionSettings     = new ConnectionSettings();
     _tcpStreamSettings      = new TcpStreamSettings();
     _streamFactoryWrapper   = inner => inner;
     _eventAggregator        = new EventAggregator();
 }
コード例 #11
0
 // constructors
 public SharedConnectionPool(
     ServerId serverId,
     EndPoint endPoint,
     ConnectionPoolSettings settings,
     IConnectionFactory connectionFactory)
 {
     _serverId = Ensure.IsNotNull(serverId, "serverId");
     _endPoint = Ensure.IsNotNull(endPoint, "endPoint");
     _settings = Ensure.IsNotNull(settings, "settings");
     _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
 }
コード例 #12
0
        public void constructor_with_maintenanceInterval_should_initialize_instance()
        {
            var maintenanceInterval = TimeSpan.FromSeconds(123);

            var subject = new ConnectionPoolSettings(maintenanceInterval: maintenanceInterval);

            subject.MaintenanceInterval.Should().Be(maintenanceInterval);
            subject.MaxConnections.Should().Be(__defaults.MaxConnections);
            subject.MinConnections.Should().Be(__defaults.MinConnections);
            subject.WaitQueueSize.Should().Be(__defaults.WaitQueueSize);
            subject.WaitQueueTimeout.Should().Be(__defaults.WaitQueueTimeout);
        }
コード例 #13
0
 public ExclusiveConnectionPoolFactoryTests()
 {
     _connectionFactory = new Mock<IConnectionFactory>().Object;
     _endPoint = new DnsEndPoint("localhost", 27017);
     _serverId = new ServerId(new ClusterId(), _endPoint);
     _eventSubscriber = new Mock<IEventSubscriber>().Object;
     _settings = new ConnectionPoolSettings(
         maintenanceInterval: Timeout.InfiniteTimeSpan,
         maxConnections: 4,
         minConnections: 2,
         waitQueueSize: 1);
 }
コード例 #14
0
        public void constructor_with_maintenanceInterval_should_initialize_instance()
        {
            var maintenanceInterval = TimeSpan.FromSeconds(123);

            var subject = new ConnectionPoolSettings(maintenanceInterval: maintenanceInterval);

            subject.MaintenanceInterval.Should().Be(maintenanceInterval);
            subject.MaxConnections.Should().Be(__defaults.MaxConnections);
            subject.MinConnections.Should().Be(__defaults.MinConnections);
            subject.WaitQueueSize.Should().Be(__defaults.WaitQueueSize);
            subject.WaitQueueTimeout.Should().Be(__defaults.WaitQueueTimeout);
        }
コード例 #15
0
        public void constructor_with_waitQueueSize_should_initialize_instance()
        {
            var waitQueueSize = 123;

            var subject = new ConnectionPoolSettings(waitQueueSize: waitQueueSize);

            subject.MaintenanceInterval.Should().Be(__defaults.MaintenanceInterval);
            subject.MaxConnections.Should().Be(subject.MaxConnections);
            subject.MinConnections.Should().Be(subject.MinConnections);
            subject.WaitQueueSize.Should().Be(waitQueueSize);
            subject.WaitQueueTimeout.Should().Be(__defaults.WaitQueueTimeout);
        }
 public void Setup()
 {
     _connectionFactory = Substitute.For<IConnectionFactory>();
     _endPoint = new DnsEndPoint("localhost", 27017);
     _serverId = new ServerId(new ClusterId(), _endPoint);
     _eventSubscriber = Substitute.For<IEventSubscriber>();
     _settings = new ConnectionPoolSettings(
         maintenanceInterval: Timeout.InfiniteTimeSpan,
         maxConnections: 4,
         minConnections: 2,
         waitQueueSize: 1);
 }
コード例 #17
0
        public void With_waitQueueTimeoutl_should_return_expected_result()
        {
            var oldWaitQueueTimeout = TimeSpan.FromSeconds(1);
            var newWaitQueueTimeout = TimeSpan.FromSeconds(2);
            var subject             = new ConnectionPoolSettings(waitQueueTimeout: oldWaitQueueTimeout);

            var result = subject.With(waitQueueTimeout: newWaitQueueTimeout);

            result.MaintenanceInterval.Should().Be(subject.MaintenanceInterval);
            result.MaxConnections.Should().Be(subject.MaxConnections);
            result.MinConnections.Should().Be(subject.MinConnections);
            result.WaitQueueSize.Should().Be(subject.WaitQueueSize);
            result.WaitQueueTimeout.Should().Be(newWaitQueueTimeout);
        }
コード例 #18
0
        public void With_minConnections_should_return_expected_result()
        {
            var oldMinConnections = 1;
            var newMinConnections = 2;
            var subject           = new ConnectionPoolSettings(minConnections: oldMinConnections);

            var result = subject.With(minConnections: newMinConnections);

            result.MaintenanceInterval.Should().Be(subject.MaintenanceInterval);
            result.MaxConnections.Should().Be(subject.MaxConnections);
            result.MinConnections.Should().Be(newMinConnections);
            result.WaitQueueSize.Should().Be(subject.WaitQueueSize);
            result.WaitQueueTimeout.Should().Be(subject.WaitQueueTimeout);
        }
コード例 #19
0
        public void constructor_with_minConnections_should_initialize_instance()
        {
            var minConnections = 123;

            var subject = new ConnectionPoolSettings(minConnections: minConnections);

            subject.MaintenanceInterval.Should().Be(__defaults.MaintenanceInterval);
            subject.MaxConnections.Should().Be(subject.MaxConnections);
            subject.MinConnections.Should().Be(minConnections);
#pragma warning disable 618
            subject.WaitQueueSize.Should().Be(__defaults.WaitQueueSize);
#pragma warning restore 618
            subject.WaitQueueTimeout.Should().Be(__defaults.WaitQueueTimeout);
        }
コード例 #20
0
        public void constructor_with_waitQueueTimeout_should_initialize_instance()
        {
            var waitQueueTimeout = TimeSpan.FromSeconds(123);

            var subject = new ConnectionPoolSettings(waitQueueTimeout: waitQueueTimeout);

            subject.MaintenanceInterval.Should().Be(__defaults.MaintenanceInterval);
            subject.MaxConnections.Should().Be(subject.MaxConnections);
            subject.MinConnections.Should().Be(subject.MinConnections);
#pragma warning disable 618
            subject.WaitQueueSize.Should().Be(subject.WaitQueueSize);
#pragma warning restore 618
            subject.WaitQueueTimeout.Should().Be(waitQueueTimeout);
        }
コード例 #21
0
        public void With_maintenanceInterval_should_return_expected_result()
        {
            var oldMaintenanceInterval = TimeSpan.FromSeconds(1);
            var newMaintenanceInterval = TimeSpan.FromSeconds(2);
            var subject = new ConnectionPoolSettings(maintenanceInterval: oldMaintenanceInterval);

            var result = subject.With(maintenanceInterval: newMaintenanceInterval);

            result.MaintenanceInterval.Should().Be(newMaintenanceInterval);
            result.MaxConnections.Should().Be(subject.MaxConnections);
            result.MinConnections.Should().Be(subject.MinConnections);
#pragma warning disable 618
            result.WaitQueueSize.Should().Be(subject.WaitQueueSize);
#pragma warning restore 618
            result.WaitQueueTimeout.Should().Be(subject.WaitQueueTimeout);
        }
コード例 #22
0
        public void With_waitQueueSizes_should_return_expected_result()
        {
            var oldWaitQueueSize = 1;
            var newWaitQueueSize = 2;
            var subject          = new ConnectionPoolSettings(waitQueueSize: oldWaitQueueSize);

            var result = subject.With(waitQueueSize: newWaitQueueSize);

            result.MaintenanceInterval.Should().Be(subject.MaintenanceInterval);
            result.MaxConnections.Should().Be(subject.MaxConnections);
            result.MinConnections.Should().Be(subject.MinConnections);
#pragma warning disable 618
            result.WaitQueueSize.Should().Be(newWaitQueueSize);
#pragma warning restore 618
            result.WaitQueueTimeout.Should().Be(subject.WaitQueueTimeout);
        }
コード例 #23
0
        public void With_maxConnecting_should_return_expected_result()
        {
            const int oldMaxConnecting = 1;
            const int newMaxConnecting = 2;
            var       subject          = new ConnectionPoolSettings(maxConnecting: oldMaxConnecting);

            var result = subject.With(maxConnecting: newMaxConnecting);

            result.MaintenanceInterval.Should().Be(subject.MaintenanceInterval);
            result.MaxConnecting.Should().Be(newMaxConnecting);
            result.MaxConnections.Should().Be(subject.MaxConnections);
            result.MinConnections.Should().Be(subject.MinConnections);
#pragma warning disable 618
            result.WaitQueueSize.Should().Be(subject.WaitQueueSize);
#pragma warning restore 618
            result.WaitQueueTimeout.Should().Be(subject.WaitQueueTimeout);
        }
コード例 #24
0
        // constructors
        public ExclusiveConnectionPool(
            ServerId serverId,
            EndPoint endPoint,
            ConnectionPoolSettings settings,
            IConnectionFactory connectionFactory,
            IConnectionPoolListener listener)
        {
            _serverId = Ensure.IsNotNull(serverId, "serverId");
            _endPoint = Ensure.IsNotNull(endPoint, "endPoint");
            _settings = Ensure.IsNotNull(settings, "settings");
            _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
            _listener = listener;

            _connectionHolder = new ListConnectionHolder(_listener);
            _poolQueue = new WaitQueue(settings.MaxConnections);
            _waitQueue = new SemaphoreSlim(settings.WaitQueueSize);
            _maintenanceCancellationTokenSource = new CancellationTokenSource();
            _state = new InterlockedInt32(State.Initial);
        }
コード例 #25
0
        public void Setup()
        {
            _connectionFactory = Substitute.For<IConnectionFactory>();
            _endPoint = new DnsEndPoint("localhost", 27017);
            _capturedEvents = new EventCapturer();
            _serverId = new ServerId(new ClusterId(), _endPoint);
            _settings = new ConnectionPoolSettings(
                maintenanceInterval: Timeout.InfiniteTimeSpan,
                maxConnections: 4,
                minConnections: 2,
                waitQueueSize: 1,
                waitQueueTimeout: TimeSpan.FromSeconds(2));

            _subject = new ExclusiveConnectionPool(
                _serverId,
                _endPoint,
                _settings,
                _connectionFactory,
                _capturedEvents);
        }
コード例 #26
0
        public ExclusiveConnectionPoolTests()
        {
            _mockConnectionFactory = new Mock<IConnectionFactory> { DefaultValue = DefaultValue.Mock };
            _endPoint = new DnsEndPoint("localhost", 27017);
            _capturedEvents = new EventCapturer();
            _serverId = new ServerId(new ClusterId(), _endPoint);
            _settings = new ConnectionPoolSettings(
                maintenanceInterval: Timeout.InfiniteTimeSpan,
                maxConnections: 4,
                minConnections: 2,
                waitQueueSize: 1,
                waitQueueTimeout: TimeSpan.FromSeconds(2));

            _subject = new ExclusiveConnectionPool(
                _serverId,
                _endPoint,
                _settings,
                _mockConnectionFactory.Object,
                _capturedEvents);
        }
コード例 #27
0
        public void With_minConnections_should_return_expected_result()
        {
            var oldMinConnections = 1;
            var newMinConnections = 2;
            var subject = new ConnectionPoolSettings(minConnections: oldMinConnections);

            var result = subject.With(minConnections: newMinConnections);

            result.MaintenanceInterval.Should().Be(subject.MaintenanceInterval);
            result.MaxConnections.Should().Be(subject.MaxConnections);
            result.MinConnections.Should().Be(newMinConnections);
            result.WaitQueueSize.Should().Be(subject.WaitQueueSize);
            result.WaitQueueTimeout.Should().Be(subject.WaitQueueTimeout);
        }
コード例 #28
0
 private ConnectionPoolSettings ConfigureConnectionPool(ConnectionPoolSettings settings, ClusterKey clusterKey)
 {
     return settings.With(
         // maintenanceInterval: TODO: should this be configurable?
         maxConnections: clusterKey.MaxConnectionPoolSize,
         minConnections: clusterKey.MinConnectionPoolSize,
         waitQueueSize: clusterKey.WaitQueueSize,
         waitQueueTimeout: clusterKey.WaitQueueTimeout);
 }
コード例 #29
0
        public void Setup()
        {
            _connectionFactory = Substitute.For<IConnectionFactory>();
            _endPoint = new DnsEndPoint("localhost", 27017);
            _listener = Substitute.For<IConnectionPoolListener>();
            _serverId = new ServerId(new ClusterId(), _endPoint);
            _settings = new ConnectionPoolSettings()
                .WithMaintenanceInterval(Timeout.InfiniteTimeSpan)
                .WithMaxConnections(4)
                .WithMinConnections(2)
                .WithWaitQueueSize(1);

            _subject = new ExclusiveConnectionPool(
                _serverId,
                _endPoint,
                _settings,
                _connectionFactory,
                _listener);
        }
コード例 #30
0
 // constructors
 public Builder(ConnectionPoolSettings other)
 {
     _maintenanceInterval = other._maintenanceInterval;
     _maxConnections = other._maxConnections;
     _minConnections = other._minConnections;
     _waitQueueSize = other._waitQueueSize;
     _waitQueueTimeout = other._waitQueueTimeout;
 }
コード例 #31
0
        public ClusterBuilder ConfigureConnectionPool(Func<ConnectionPoolSettings, ConnectionPoolSettings> configure)
        {
            Ensure.IsNotNull(configure, "configure");

            _connectionPoolSettings = configure(_connectionPoolSettings);
            return this;
        }
コード例 #32
0
 public void ConnectionPoolAfterOpening(ServerId serverId, ConnectionPoolSettings settings)
 {
     _first.ConnectionPoolAfterOpening(serverId, settings);
     _second.ConnectionPoolAfterOpening(serverId, settings);
 }
コード例 #33
0
 public ExclusiveConnectionPoolFactory(ConnectionPoolSettings settings, IConnectionFactory connectionFactory, IEventSubscriber eventSubscriber)
 {
     _settings = Ensure.IsNotNull(settings, nameof(settings));
     _connectionFactory = Ensure.IsNotNull(connectionFactory, nameof(connectionFactory));
     _eventSubscriber = Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));
 }
コード例 #34
0
 public ExclusiveConnectionPoolFactory(ConnectionPoolSettings settings, IConnectionFactory connectionFactory, IConnectionPoolListener listener)
 {
     _settings = Ensure.IsNotNull(settings, "settings");
     _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
     _listener = listener;
 }
 public ExclusiveConnectionPoolFactory(ConnectionPoolSettings settings, IConnectionFactory connectionFactory, IEventSubscriber eventSubscriber)
 {
     _settings = Ensure.IsNotNull(settings, "settings");
     _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
     _eventSubscriber = Ensure.IsNotNull(eventSubscriber, "eventSubscriber");
 }
コード例 #36
0
 // constructors
 public SharedConnectionPoolFactory()
 {
     _connectionFactory = new BinaryConnectionFactory();
     _connectionPoolSettings = new ConnectionPoolSettings();
 }
コード例 #37
0
        public void With_waitQueueTimeoutl_should_return_expected_result()
        {
            var oldWaitQueueTimeout = TimeSpan.FromSeconds(1);
            var newWaitQueueTimeout = TimeSpan.FromSeconds(2);
            var subject = new ConnectionPoolSettings(waitQueueTimeout: oldWaitQueueTimeout);

            var result = subject.With(waitQueueTimeout: newWaitQueueTimeout);

            result.MaintenanceInterval.Should().Be(subject.MaintenanceInterval);
            result.MaxConnections.Should().Be(subject.MaxConnections);
            result.MinConnections.Should().Be(subject.MinConnections);
            result.WaitQueueSize.Should().Be(subject.WaitQueueSize);
            result.WaitQueueTimeout.Should().Be(newWaitQueueTimeout);
        }
コード例 #38
0
        public void constructor_with_maxConnections_should_initialize_instance()
        {
            var maxConnections = 1;
            var waitQueueSize = maxConnections * 5;

            var subject = new ConnectionPoolSettings(maxConnections: maxConnections);

            subject.MaintenanceInterval.Should().Be(__defaults.MaintenanceInterval);
            subject.MaxConnections.Should().Be(maxConnections);
            subject.MinConnections.Should().Be(__defaults.MinConnections);
            subject.WaitQueueSize.Should().Be(waitQueueSize);
            subject.WaitQueueTimeout.Should().Be(__defaults.WaitQueueTimeout);
        }
コード例 #39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConnectionPoolOpenedEvent"/> struct.
 /// </summary>
 /// <param name="serverId">The server identifier.</param>
 /// <param name="connectionPoolSettings">The connection pool settings.</param>
 public ConnectionPoolOpenedEvent(ServerId serverId, ConnectionPoolSettings connectionPoolSettings)
 {
     _serverId = serverId;
     _connectionPoolSettings = connectionPoolSettings;
 }