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); }
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; }