/// <summary> /// Return an AbstractConnection to the pool /// </summary> /// <param name="cxn">The connection to return to the pool</param> /// <returns></returns> public override object checkIn(AbstractResource cxn) { AbstractConnection theCxn = (AbstractConnection)cxn; // first get a new reference if (!theCxn.IsConnected || !theCxn.isAlive()) // don't add disconnected connections to the pool { this.TotalResources--; return(null); } theCxn.LastUsed = DateTime.Now; if (cxn is VistaPoolConnection) { if (this.PoolSource.Credentials == null) // if not an authenticated connection { ((VistaPoolConnection)theCxn).resetRaw(); // reset the symbol table so we're always receiving fresh from pool ((VistaAccount)((VistaConnection)theCxn).Account).setContext(new MenuOption("XUS SIGNON")); } _pooledCxns.Add(theCxn); } else if (cxn is VistaConnection) { if (this.PoolSource.Credentials == null) // if not an authenticated connection { ((VistaAccount)((VistaConnection)theCxn).Account).setContext(new MenuOption("XUS SIGNON")); } _pooledCxns.Add(theCxn); } else { _pooledCxns.Add(theCxn); } //System.Console.WriteLine("A connection was returned to the pool. {0} available", _pooledCxns.Count); return(null); }
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; }