예제 #1
0
        private static void startConnectionPool()
        {
            MySession          temp       = new MySession();
            AbstractPoolSource defaultSrc = new ConnectionPoolSource()
            {
                CxnSource = new mdo.DataSource()
                {
                    Protocol = "PVISTA"
                },
                Credentials  = new VistaCredentials(),
                LoadStrategy = (LoadingStrategy)Enum.Parse(typeof(LoadingStrategy),
                                                           temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_LOAD_STRATEGY]),
                MaxPoolSize       = Convert.ToInt32(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_MAX_CXNS]),
                MinPoolSize       = Convert.ToInt32(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_MIN_CXNS]),
                PoolExpansionSize = Convert.ToInt32(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_EXPAND_SIZE]),
                WaitTime          = TimeSpan.Parse(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_WAIT_TIME]),
                Timeout           = TimeSpan.Parse(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_CXN_TIMEOUT])
            };

            IList <AbstractPoolSource> sources = new List <AbstractPoolSource>();
            //AbstractPoolSource poolsSource = new ConnectionPoolsSource();
            //((ConnectionPoolsSource)poolsSource).CxnSources = new Dictionary<string, ConnectionPoolSource>();
            AbstractPoolSourceFactory factory = new ConnectionPoolSourceFactory(defaultSrc);         // instantiate the pool source factory
            AbstractPoolSource        result  = (ConnectionPoolsSource)factory.getPoolSources(temp.SiteTable);
            AbstractResourcePool      pools   = AbstractResourcePoolFactory.getResourcePool(result); // this starts the pool
        }
예제 #2
0
        public void testEagerStartupCxnTimeouts()
        {
            _localSource.LoadStrategy = LoadingStrategy.Eager;
            _localSource.Timeout = new TimeSpan(0, 0, 4);
            _pool = AbstractResourcePoolFactory.getResourcePool(_localSource);

            System.Threading.Thread.Sleep(3000); // wait a few seconds for pool to start but not enough for cxns to timeout

            Assert.IsTrue(_pool.TotalResources > 0, "Should have resources before asking for them in eager startup model");
            AbstractConnection cxn = (AbstractConnection)_pool.checkOut("901");
            Assert.IsNotNull(cxn);
            Assert.IsTrue(cxn.isAlive()); // the checkout function of the pool should ensure we're getting an alive connection but assert anyways to prove
            _pool.checkIn(cxn); // cleanup

            System.Threading.Thread.Sleep(5000);
        }
예제 #3
0
        public void testEagerStartupCxnTimeouts()
        {
            _localSource.LoadStrategy = LoadingStrategy.Eager;
            _localSource.Timeout      = new TimeSpan(0, 0, 4);
            _pool = AbstractResourcePoolFactory.getResourcePool(_localSource);

            System.Threading.Thread.Sleep(3000); // wait a few seconds for pool to start but not enough for cxns to timeout

            Assert.IsTrue(_pool.TotalResources > 0, "Should have resources before asking for them in eager startup model");
            AbstractConnection cxn = (AbstractConnection)_pool.checkOut("901");

            Assert.IsNotNull(cxn);
            Assert.IsTrue(cxn.isAlive()); // the checkout function of the pool should ensure we're getting an alive connection but assert anyways to prove
            _pool.checkIn(cxn);           // cleanup

            System.Threading.Thread.Sleep(5000);
        }
예제 #4
0
        public void testRunningPool()
        {
            _localSource.Timeout = new TimeSpan(0, 0, 1); // set this very low so the test can run quickly
            _pool = AbstractResourcePoolFactory.getResourcePool(_localSource);

            System.Threading.Thread.Sleep(5000);

            // let's increase our connection timeout for this test so we can more easily test the state of things
            _localSource.Timeout = new TimeSpan(0, 0, 5); // this should affect all newly created connections

            AbstractConnection cxn    = (AbstractConnection)_pool.checkOutAlive("901");
            Int32 resourceCountBefore = _pool.TotalResources; // we take this immediately after checkOutAlive which should have found all our timed out connections and begun adding new ones

            // the pool shouldn't try to restart connections until they're needed - checkOutAlive should be that signal
            // so, now that checkOutAlive has been called, the pool should have discovered that it doesn't have any alive resources and started adding some back
            Assert.IsTrue(_pool.TotalResources == 1);

            Assert.IsNotNull(cxn);
            Assert.IsTrue(cxn.isAlive());        // the checkout function of the pool should ensure we're getting an alive connection but assert anyways to prove

            System.Threading.Thread.Sleep(1100); // even though our connection is checked out, it should still timeout
            _pool.checkIn(cxn);                  // the pool shouldn't put this item back in its collection (doesn't throw error though)
            Int32 resourcesAfter = _pool.TotalResources;
        }
예제 #5
0
        public void testRunningPool()
        {
            _localSource.Timeout = new TimeSpan(0, 0, 1); // set this very low so the test can run quickly
            _pool = AbstractResourcePoolFactory.getResourcePool(_localSource);

            System.Threading.Thread.Sleep(5000);

            // let's increase our connection timeout for this test so we can more easily test the state of things
            _localSource.Timeout = new TimeSpan(0, 0, 5); // this should affect all newly created connections

            AbstractConnection cxn = (AbstractConnection)_pool.checkOutAlive("901");
            Int32 resourceCountBefore = _pool.TotalResources; // we take this immediately after checkOutAlive which should have found all our timed out connections and begun adding new ones

            // the pool shouldn't try to restart connections until they're needed - checkOutAlive should be that signal
            // so, now that checkOutAlive has been called, the pool should have discovered that it doesn't have any alive resources and started adding some back
            Assert.IsTrue(_pool.TotalResources == 1);

            Assert.IsNotNull(cxn);
            Assert.IsTrue(cxn.isAlive()); // the checkout function of the pool should ensure we're getting an alive connection but assert anyways to prove

            System.Threading.Thread.Sleep(1100); // even though our connection is checked out, it should still timeout
            _pool.checkIn(cxn); // the pool shouldn't put this item back in its collection (doesn't throw error though)
            Int32 resourcesAfter = _pool.TotalResources;
        }