5 // James Lewis <james.lewis@7digital.com>
6 // Andres G. Aragoneses <andres@7digital.com>
8 // Copyright (C) 2012 7digital Media Ltd (http://www.7digital.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
34 using Mono.Data.Tds.Protocol;
37 namespace Mono.Data.Tds.Tests
41 public class ConnLifetime
44 public void LifeTimeIsTakenInAccount ()
46 var SMALLEST_LIFETIME_TO_TEST = 1;
47 var WAIT_TO_MAKE_LIFETIME_PASSED = 2;
49 TdsConnectionPoolManager sqlConnectionPools = new FakeConnectionPoolManager ();
50 TdsConnectionInfo info = new TdsConnectionInfo ("dummy", 0, 0, 0,
53 SMALLEST_LIFETIME_TO_TEST/*lifetime*/);
55 TdsConnectionPool pool = sqlConnectionPools.GetConnectionPool ("test",info);
56 Mono.Data.Tds.Protocol.Tds tds, tds2 = null;
58 tds = pool.GetConnection();
60 System.Threading.Thread.Sleep (TimeSpan.FromSeconds (WAIT_TO_MAKE_LIFETIME_PASSED));
61 pool.ReleaseConnection (tds);
63 tds2 = pool.GetConnection ();
66 Assert.IsFalse (object.ReferenceEquals (tds, tds2));
67 pool.ReleaseConnection(tds2);
70 class FakeConnectionPoolManager : TdsConnectionPoolManager {
72 internal FakeConnectionPoolManager () : base (Mono.Data.Tds.Protocol.TdsVersion.tds90)
76 public override Mono.Data.Tds.Protocol.Tds CreateConnection (TdsConnectionInfo info)
78 return new FakeTds (info.LifeTime);
82 class FakeTds : Mono.Data.Tds.Protocol.Tds {
83 internal FakeTds(int lifetime) : base (null, 0, 0, 0, lifetime, Mono.Data.Tds.Protocol.TdsVersion.tds90){
86 public override bool Connect (TdsConnectionParameters connectionParameters)
88 throw new NotImplementedException ();
91 protected override void ProcessColumnInfo ()
93 throw new NotImplementedException ();
96 protected override void InitComm (int port, int timeout)
98 //do nothing, not relevant for the test
101 public override bool IsConnected {
106 public override void Disconnect ()
108 // do nothing, not relevant for the test