Ejemplo n.º 1
0
 public void ClosingAConnectionReturnsItToThePool()
 {
     var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=1")));
     var connection1 = provider.Open(null);
     provider.Close(connection1);
     Assert.Same(connection1, provider.Open(null));
 }
 public void WaitsUntilTimeoutForConnectionToFreeUp()
 {
     var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=1&timeout=3")));
     var connection = provider.Open(null);
     new Timer(c => provider.Close(connection), null, 2000, 0);
     Assert.Same(connection, provider.Open(null));
 }
Ejemplo n.º 3
0
        public void ThrowsExceptionIfNoConnectionsAvailable()
        {
            var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=1&timeout=1")));
            provider.Open(null);

            var ex = Assert.Throws<MongoException>(() => provider.Open(null));
            Assert.Equal("Connection timeout trying to get connection from connection pool", ex.Message);
        }
Ejemplo n.º 4
0
        public void ClosingAConnectionReturnsItToThePool()
        {
            var provider    = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=1")));
            var connection1 = provider.Open(null);

            provider.Close(connection1);
            Assert.Same(connection1, provider.Open(null));
        }
Ejemplo n.º 5
0
        public void WaitsUntilTimeoutForConnectionToFreeUp()
        {
            var provider   = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=1&timeout=3")));
            var connection = provider.Open(null);

            new Timer(c => provider.Close(connection), null, 2000, 0);
            Assert.Same(connection, provider.Open(null));
        }
Ejemplo n.º 6
0
 public void PoolsUpToPoolSizeConections()
 {
     var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=4&timeout=1")));
     provider.Open(null);
     provider.Open(null);
     provider.Open(null);
     provider.Open(null);
     Assert.Throws<MongoException>(() => provider.Open(null));
 }
Ejemplo n.º 7
0
        public void PoolsUpToPoolSizeConections()
        {
            var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=4&timeout=1")));

            provider.Open(null);
            provider.Open(null);
            provider.Open(null);
            provider.Open(null);
            Assert.Throws <MongoException>(() => provider.Open(null));
        }
Ejemplo n.º 8
0
        public void ThrowsExceptionIfNoConnectionsAvailable()
        {
            var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=1&timeout=1")));

            provider.Open(null);

            var ex = Assert.Throws <MongoException>(() => provider.Open(null));

            Assert.Equal("Connection timeout trying to get connection from connection pool", ex.Message);
        }
Ejemplo n.º 9
0
        public void WaitsUntilTimeoutForConnectionToFreeUp()
        {
            var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=1&timeout=3")));
            provider.Open(null);

            var start = DateTime.Now; //this doesn't seem like a very good way to do this..we'll see
            Assert.Throws<MongoException>(() => provider.Open(null));
            var elasped = DateTime.Now.Subtract(start).TotalSeconds;
            Assert.True(elasped > 3);
            Assert.True(elasped < 4);
        }
Ejemplo n.º 10
0
        public void WaitsUntilTimeoutForConnectionToFreeUpAndThrowsExceptionIfNot()
        {
            var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=1&timeout=3")));

            provider.Open(null);

            var start = DateTime.Now; //this doesn't seem like a very good way to do this..we'll see

            Assert.Throws <MongoException>(() => provider.Open(null));
            var elasped = DateTime.Now.Subtract(start).TotalSeconds;

            Assert.True(elasped > 3);
            Assert.True(elasped < 4);
        }
 public void AuthenticatesWithProperCredentials()
 {
     var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(AuthenticatedConnectionString("usr", "8e156e298e19afdc3a104ddd172a2bee")));
     var connection = provider.Open(null);
     Assert.Equal(true, connection.Client.Connected);
     provider.Close(connection);
 }
        public void ThrowsExceptionIfConnectingWithInvalidCredentials()
        {
            var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(AuthenticatedConnectionString("bad", "boy")));
            var ex       = Assert.Throws <MongoException>(() => provider.Open(null));

            Assert.Equal("auth fails", ex.Message);
        }
        public void AuthenticatesWithProperCredentials()
        {
            var provider   = new PooledConnectionProvider(ConnectionStringBuilder.Create(AuthenticatedConnectionString("usr", "pss")));
            var connection = provider.Open(null);

            Assert.Equal(true, connection.Client.Connected);
            provider.Close(connection);
        }
Ejemplo n.º 14
0
 public void ReturnsDifferentConnections()
 {
     var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=2")));
     Assert.NotSame(provider.Open(null), provider.Open(null));
 }
 public void ThrowsExceptionIfConnectingWithInvalidCredentials()
 {
     var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(AuthenticatedConnectionString("bad", "boy")));
     var ex = Assert.Throws<MongoException>(() => provider.Open(null));
     Assert.Equal("auth fails", ex.Message);
 }
Ejemplo n.º 16
0
        public void ReturnsDifferentConnections()
        {
            var provider = new PooledConnectionProvider(ConnectionStringBuilder.Create(TestHelper.ConnectionString("pooling=true&poolsize=2")));

            Assert.NotSame(provider.Open(null), provider.Open(null));
        }