3 // NUnit Test Cases for Mono.Data.Tds.Protocol.TdsConnectionPool
6 // Robert Wilkens <robwilkens@gmail.com>
8 // Copyright (C) 2012 Robert Wilkens (http://www.robssoftwareprojects.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.
30 namespace MonoTests.Mono.Data.Tds
33 using NUnit.Framework;
34 using global::Mono.Data.Tds.Protocol;
37 using System.Net.Sockets;
41 public class TdsConnectionPoolTest
43 const string SERVER="localhost";
45 public void CheckNullException()
48 //set up dummy sql listener, if there is a real sql server on this
49 //machine at that port, in theory this part will fail, but that's ok
50 //becuase something will be listening on the port and that's all we
51 //require at this point: a listener on port 1433...
54 IPAddress hostIP =Dns.GetHostEntry("localhost").AddressList[0];
55 IPEndPoint ep = new IPEndPoint(hostIP, 1433);
56 TcpListener Listener = new TcpListener (ep);
62 //try to connect twice, in earlier failure would get null exception
63 //on 2nd call to pool.GetConnection();
64 //Most of this code ripped from sqlConnection.Open()
66 TdsConnectionPool pool;
68 TdsConnectionPoolManager sqlConnectionPools =
69 new TdsConnectionPoolManager(TdsVersion.tds80);
70 TdsConnectionInfo info=
71 new TdsConnectionInfo(SERVER/*dummyhost*/,1433/*port*/,
72 8192/*pktsize*/,15/*timeout*/,0/*minpoolsize*/,
73 100/*maxpoolsize*/, 0/*lifetime*/);
74 pool=sqlConnectionPools.GetConnectionPool("test",info);
77 //this first one succeeded regardless as long as something answered
78 //the phone on port 1433 of localhost
79 tds=pool.GetConnection();
81 pool.ReleaseConnection(tds);
84 // 2nd time thru: This will fail with nullreferenceexception
85 // at pool.GetConnection() unless the patch by Rob Wilkens which
86 // adds "result=null;" before retry in pool.getConnection() source
88 //First let's pretend we're calling this test fresh, as if we
89 //call sqlConnection.Open() again :
91 info=new TdsConnectionInfo(SERVER/*dummyhost*/,1433/*port*/,
92 8192/*pktsize*/,15/*timeout*/,0/*minpoolsize*/,
93 100/*maxpoolsize*/, 0/*lifetime*/);
95 pool=sqlConnectionPools.GetConnectionPool("test",info);
97 //Then: Test for failure (will raise uncaught exception which
98 //causes failure of test if bug is not fixed
99 tds=pool.GetConnection();
101 pool.ReleaseConnection(tds);