コード例 #1
0
        public void TestMaximumPoolSizeIsEnsured()
        {
            var builder = new MongoConnectionStringBuilder { MaximumPoolSize = 2 };
            using(var pool = new PooledConnectionFactory(builder.ToString()))
            {
                var connection1 = pool.Open();
                Assert.IsNotNull(connection1);
                Assert.IsNotNull(pool.Open());

                RawConnection connection3 = null;
                var thread = new Thread(o =>
                {
                    connection3 = pool.Open();
                });
                thread.Start();
                
                Thread.Sleep(300);
                
                Assert.IsNull(connection3);

                pool.Close(connection1);
                
                Thread.Sleep(300);

                Assert.IsNotNull(connection3);

                thread.Abort();
            }
        }
コード例 #2
0
 public void TestDisconnectedConnectionsArentReturndToPool()
 {
     using(var pool = new PooledConnectionFactory(string.Empty))
     {
         var connection = pool.Open();
         connection.Dispose();
         pool.Close(connection);
         Assert.AreEqual(0, pool.PoolSize);
     }
 }
コード例 #3
0
 public void TestClose()
 {
     using(var pool = new PooledConnectionFactory(string.Empty))
     {
         var connection1 = pool.Open();
         pool.Close(connection1);
         var connection2 = pool.Open();
         Assert.AreEqual(connection1,connection2);
         Assert.AreEqual(1, pool.PoolSize);
     }
 }
コード例 #4
0
        public void TestCleanup()
        {
            var builder = new MongoConnectionStringBuilder
            {
                MinimumPoolSize = 0,
                ConnectionLifetime = TimeSpan.FromMilliseconds(100)
            };
            using(var pool = new PooledConnectionFactory(builder.ToString()))
            {
                var connection1 = pool.Open();
                var connection2 = pool.Open();
                var connection3 = pool.Open();
                pool.Close(connection1);
                pool.Close(connection2);
                pool.Close(connection3);

                Thread.Sleep(300); // ensure lifetime reached

                pool.Cleanup();

                Assert.AreEqual(0,pool.PoolSize);
            }
        }
コード例 #5
0
 public void TestIfConnectionLifetimeIsReachedItDoesNotReturndToPool()
 {
     var builder = new MongoConnectionStringBuilder
     {
         ConnectionLifetime = TimeSpan.FromMilliseconds(100)
     };
     using(var pool = new PooledConnectionFactory(builder.ToString()))
     {
         var connection = pool.Open();
         Thread.Sleep(200); // wait for lifetime reached
         pool.Close(connection);
         Assert.AreEqual(0, pool.PoolSize);
     }
 }