public AcquiredConnection(ExclusiveConnectionPool connectionPool, PooledConnection pooledConnection) : base(pooledConnection) { _connectionPool = connectionPool; _pooledConnection = pooledConnection; _pooledConnection.IncrementReferenceCount(); }
public MaintenanceHelper(ExclusiveConnectionPool connectionPool, TimeSpan interval) { _connectionPool = Ensure.IsNotNull(connectionPool, nameof(connectionPool)); _globalCancellationTokenSource = new CancellationTokenSource(); _globalCancellationToken = _globalCancellationTokenSource.Token; _interval = interval; }
public ExclusiveConnectionPoolTests() { _mockConnectionFactory = new Mock <IConnectionFactory> { DefaultValue = DefaultValue.Mock }; _endPoint = new DnsEndPoint("localhost", 27017); _capturedEvents = new EventCapturer(); _serverId = new ServerId(new ClusterId(), _endPoint); _mockConnectionFactory .Setup(c => c.CreateConnection(It.IsAny <ServerId>(), It.IsAny <EndPoint>())) .Returns(() => { var connectionMock = new Mock <IConnection>(); connectionMock .Setup(c => c.Settings) .Returns(new ConnectionSettings()); return(connectionMock.Object); }); _settings = new ConnectionPoolSettings( maintenanceInterval: Timeout.InfiniteTimeSpan, maxConnections: 4, minConnections: 2, waitQueueSize: 1, waitQueueTimeout: TimeSpan.FromSeconds(2)); _subject = CreateSubject(); }
public ConnectionCreator(ExclusiveConnectionPool pool, TimeSpan connectingTimeout) { _pool = pool; _connectingTimeout = connectingTimeout; _connectingWaitStatus = SemaphoreSlimSignalable.SemaphoreWaitResult.None; _connection = null; _disposeConnection = true; _stopwatch = null; }
// private methods private IConnection AcquireConnection(ExclusiveConnectionPool subject, bool async) { if (async) { return(subject .AcquireConnectionAsync(CancellationToken.None) .GetAwaiter() .GetResult()); } else { return(subject.AcquireConnection(CancellationToken.None)); } }
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); }
protected override void Dispose(bool disposing) { if (disposing) { if (!Disposed) { _pooledConnection.DecrementReferenceCount(); if (_pooledConnection.ReferenceCount == 0) { _connectionPool.ReleaseConnection(_pooledConnection); } } Disposed = true; _pooledConnection = null; _connectionPool = null; } // don't call base.Dispose here because we don't want the underlying // connection to get disposed... }
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); }
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); }
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( maintenanceInterval: Timeout.InfiniteTimeSpan, maxConnections: 4, minConnections: 2, waitQueueSize: 1, waitQueueTimeout: TimeSpan.FromSeconds(2)); _subject = new ExclusiveConnectionPool( _serverId, _endPoint, _settings, _connectionFactory, _listener); }
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); }
// constructors public AcquireConnectionHelper(ExclusiveConnectionPool pool) { _pool = pool; _timeout = pool._settings.WaitQueueTimeout; }
public static CancellationTokenSource _maintenanceCancellationTokenSource(this ExclusiveConnectionPool obj) { return((CancellationTokenSource)Reflector.GetFieldValue(obj, nameof(_maintenanceCancellationTokenSource))); }
// constructors public AcquireConnectionHelper(ExclusiveConnectionPool pool) { _pool = pool; }
// constructors public PooledConnection(ExclusiveConnectionPool connectionPool, IConnection connection) : base(connection) { _connectionPool = connectionPool; _generation = _connectionPool.Generation; }
public static Task MaintainSizeAsync(this ExclusiveConnectionPool obj) { return((Task)Reflector.Invoke(obj, nameof(MaintainSizeAsync))); }
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); }
public PooledConnection(ExclusiveConnectionPool connectionPool, IConnection connection) { _connectionPool = connectionPool; _connection = connection; _generation = connectionPool._generation; }
public AcquiredConnection(ExclusiveConnectionPool connectionPool, ReferenceCounted<PooledConnection> reference) { _connectionPool = connectionPool; _reference = reference; }
public AcquiredConnection(ExclusiveConnectionPool connectionPool, ReferenceCounted <PooledConnection> reference) { _connectionPool = connectionPool; _reference = reference; }