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);
        }
Exemplo n.º 10
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(
                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);
        }
Exemplo n.º 12
0
 // 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;
 }
 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 AcquiredConnection(ExclusiveConnectionPool connectionPool, PooledConnection pooledConnection)
     : base(pooledConnection)
 {
     _connectionPool = connectionPool;
     _pooledConnection = pooledConnection;
     _pooledConnection.IncrementReferenceCount();
 }
 // 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);
        }
 // constructors
 public PooledConnection(ExclusiveConnectionPool connectionPool, IConnection connection)
     : base(connection)
 {
     _connectionPool = connectionPool;
     _generation     = _connectionPool.Generation;
 }
Exemplo n.º 21
0
 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 PooledConnection(ExclusiveConnectionPool connectionPool, IConnection connection)
 {
     _connectionPool = connectionPool;
     _connection = connection;
     _generation = connectionPool._generation;
 }
Exemplo n.º 24
0
 public AcquiredConnection(ExclusiveConnectionPool connectionPool, ReferenceCounted <PooledConnection> reference)
 {
     _connectionPool = connectionPool;
     _reference      = reference;
 }
 // constructors
 public AcquireConnectionHelper(ExclusiveConnectionPool pool)
 {
     _pool = pool;
 }