Skip to content

Commit ae3adb1

Browse files
committed
NH-4008 - Enable separate drivers for tests.
1 parent 24ba241 commit ae3adb1

File tree

68 files changed

+1161
-135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1161
-135
lines changed

build-common/nhibernate-properties.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<project xmlns="http://nant.sf.net/release/0.85-rc3/nant.xsd">
33
<property name="nhibernate.dialect" value="NHibernate.Dialect.MsSql2008Dialect" overwrite="false"/>
44
<property name="nhibernate.command_timeout" value="444" overwrite="false"/>
5-
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.Sql2008ClientDriver" overwrite="false"/>
5+
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SqlServer2008Driver, NHibernate.Driver.SqlServer" overwrite="false"/>
66
<property name="nhibernate.connection.connection_string" value="Server=.\SQLExpress;initial catalog=nhibernate;Integrated Security=SSPI" overwrite="false"/>
77
</project>

build-common/teamcity-hibernate.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<property name="format_sql">true</property>
1616

1717
<!-- This is the System.Data.dll provider for MSSQL Server -->
18-
<property name="connection.driver_class">NHibernate.Driver.Sql2008ClientDriver</property>
18+
<property name="connection.driver_class">NHibernate.Driver.SqlServer2008Driver, NHibernate.Driver.SqlServer</property>
1919
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
2020
<property name="connection.connection_string">Server=.\SQLExpress;initial catalog=nhibernate;Integrated Security=SSPI</property>
2121
<property name="show_sql">false</property>

src/NHibernate.Config.Templates/FireBird.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ for your own use before compile tests in VisualStudio.
1616
-->
1717
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
1818
<session-factory name="NHibernate.Test">
19-
<property name="connection.driver_class">NHibernate.Driver.FirebirdClientDriver</property>
19+
<property name="connection.driver_class">NHibernate.Driver.FirebirdDriver, NHibernate.Driver.Firebird</property>
2020
<property name="connection.connection_string">
2121
DataSource=localhost;
2222
Database=nhibernate;

src/NHibernate.Config.Templates/MSSQL.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ for your own use before compile tests in VisualStudio.
77
<!-- This is the System.Data.dll provider for SQL Server -->
88
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
99
<session-factory name="NHibernate.Test">
10-
<property name="connection.driver_class">NHibernate.Driver.Sql2008ClientDriver</property>
10+
<property name="connection.driver_class">NHibernate.Driver.SqlServer2008Driver, NHibernate.Driver.SqlServer</property>
1111
<property name="connection.connection_string">
1212
Server=(local);initial catalog=nhibernate;Integrated Security=SSPI
1313
</property>

src/NHibernate.Config.Templates/MySql.cfg.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ for your own use before compile tests in VisualStudio.
66
-->
77
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
88
<session-factory name="NHibernate.Test">
9-
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
9+
<property name="connection.driver_class">NHibernate.Driver.MySqlDriver, NHibernate.Driver.MySql</property>
1010
<property name="connection.connection_string">
1111
Database=nhibernate;Data Source=localhost;User Id=nhibernate;Password=;
1212
Protocol=memory;Old Guids=True;
1313
</property>
1414
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
1515
</session-factory>
16-
</hibernate-configuration>
16+
</hibernate-configuration>

src/NHibernate.Config.Templates/Oracle-Managed.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ for your own use before compile tests in VisualStudio.
77
<!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->
88
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
99
<session-factory name="NHibernate.Test">
10-
<property name="connection.driver_class">NHibernate.Driver.OracleManagedDataClientDriver</property>
10+
<property name="connection.driver_class">NHibernate.Driver.OracleManagedDriver, NHibernate.Driver.Oracle.Managed</property>
1111
<property name="connection.connection_string">
1212
User ID=nhibernate;Password=nhibernate;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL)))
1313
</property>

src/NHibernate.Config.Templates/PostgreSQL.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ for your own use before compile tests in VisualStudio.
66
-->
77
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
88
<session-factory name="NHibernate.Test">
9-
<property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
9+
<property name="connection.driver_class">NHibernate.Driver.PostgreSqlDriver, NHibernate.Driver.PostgreSql</property>
1010
<property name="connection.connection_string">
1111
Server=localhost;Database=nhibernate;User ID=nhibernate;Password=nhibernate;Enlist=true;
1212
</property>

src/NHibernate.Config.Templates/SQLite.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ for your own use before compile tests in VisualStudio.
66
-->
77
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
88
<session-factory name="NHibernate.Test">
9-
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
9+
<property name="connection.driver_class">NHibernate.Driver.SQLiteDriver, NHibernate.Driver.SQLite</property>
1010
<!-- DateTimeFormatString allows to prevent storing the fact that written date was having kind UTC,
1111
which dodges the undesirable time conversion to local done on reads by System.Data.SQLite.
1212
See https://system.data.sqlite.org/index.html/tktview/44a0955ea344a777ffdbcc077831e1adc8b77a36

src/NHibernate.Config.Templates/SqlServerCe.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ for your own use before compile tests in VisualStudio.
88
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
99
<session-factory name="NHibernate.Test">
1010
<property name="command_timeout">0</property>
11-
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
11+
<property name="connection.driver_class">NHibernate.Driver.SqlServerCompactDriver, NHibernate.Driver.SqlServer.Compact</property>
1212
<property name="connection.connection_string">
1313
Data Source=NHibernate.sdf
1414
</property>

src/NHibernate.Example.Web/Infrastructure/AppSessionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public AppSessionFactory(Microsoft.Extensions.Logging.ILoggerFactory loggerFacto
2424
{
2525
db.ConnectionString = @"Server=(local)\SQLEXPRESS;initial catalog=nhibernate;Integrated Security=true";
2626
db.Dialect<MsSql2008Dialect>();
27-
db.Driver<Sql2008ClientDriver>();
27+
db.SqlServer2008Driver();
2828
})
2929
.AddMapping(domainMapping);
3030
Configuration.SessionFactory().GenerateStatistics();

src/NHibernate.Example.Web/NHibernate.Example.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32+
<ProjectReference Include="..\NHibernate.Driver.SqlServer\NHibernate.Driver.SqlServer.csproj" />
3233
<ProjectReference Include="..\NHibernate\NHibernate.csproj" />
3334
</ItemGroup>
3435

src/NHibernate.Test/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
3232

33-
<property name="connection.driver_class">NHibernate.Driver.Sql2008ClientDriver</property> <!-- Shouldn't be necessary, but is required by some tests -->
33+
<property name="connection.driver_class">NHibernate.Driver.SqlServer2008Driver, NHibernate.Driver.SqlServer</property> <!-- Shouldn't be necessary, but is required by some tests -->
3434
<property name="connection.connection_string">Server=localhost\sqlexpress;Database=nhibernate;Integrated Security=SSPI</property>
3535
<property name="connection.provider">NHibernate.Test.DebugConnectionProvider, NHibernate.Test</property>
3636
<property name="connection.isolation">ReadCommitted</property> <!-- See System.Data.IsolationLevel for valid values -->

src/NHibernate.Test/Async/CfgTest/ConfigurationFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task ManualConfigurationAsync()
4444

4545
props[Environment.ConnectionProvider] = "NHibernate.Connection.DriverConnectionProvider";
4646
props[Environment.Dialect] = "NHibernate.Dialect.MsSql2000Dialect";
47-
props[Environment.ConnectionDriver] = "NHibernate.Driver.SqlClientDriver";
47+
props[Environment.ConnectionDriver] = "NHibernate.Driver.SqlServer2000Driver, NHibernate.Driver.SqlServer";
4848
props[Environment.ConnectionString] =
4949
"Server=localhost;initial catalog=nhibernate;Integrated Security=SSPI";
5050

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data;
13+
using System.Data.Common;
14+
using NHibernate.Driver;
15+
using NHibernate.SqlCommand;
16+
using NHibernate.SqlTypes;
17+
using NUnit.Framework;
18+
19+
namespace NHibernate.Test.DriverTest
20+
{
21+
using System.Threading.Tasks;
22+
using System.Threading;
23+
[TestFixture]
24+
public class FirebirdDriverFixtureAsync
25+
{
26+
private string _connectionString;
27+
private FirebirdDriver _driver;
28+
29+
[OneTimeSetUp]
30+
public void OneTimeSetup()
31+
{
32+
var cfg = TestConfigurationHelper.GetDefaultConfiguration();
33+
34+
var dlct = cfg.GetProperty("dialect");
35+
if (!dlct.Contains("Firebird"))
36+
Assert.Ignore("Applies only to Firebird");
37+
38+
_driver = new FirebirdDriver();
39+
_driver.Configure(cfg.Properties);
40+
_connectionString = cfg.GetProperty("connection.connection_string");
41+
}
42+
43+
[Test]
44+
public async Task ConnectionPooling_OpenThenCloseThenOpenAnotherOne_OnlyOneConnectionIsPooledAsync()
45+
{
46+
_driver.ClearPool(_connectionString);
47+
48+
var allreadyEstablished = await (GetEstablishedConnectionsAsync());
49+
50+
using (var connection1 = MakeConnection())
51+
using (var connection2 = MakeConnection())
52+
{
53+
//open first connection
54+
await (connection1.OpenAsync());
55+
await (VerifyCountOfEstablishedConnectionsIsAsync(allreadyEstablished + 1, "After first open"));
56+
57+
//return it to the pool
58+
connection1.Close();
59+
await (VerifyCountOfEstablishedConnectionsIsAsync(allreadyEstablished + 1, "After first close"));
60+
61+
//open the second connection
62+
await (connection2.OpenAsync());
63+
await (VerifyCountOfEstablishedConnectionsIsAsync(allreadyEstablished + 1, "After second open"));
64+
65+
//return it to the pool
66+
connection2.Close();
67+
await (VerifyCountOfEstablishedConnectionsIsAsync(allreadyEstablished + 1, "After second close"));
68+
}
69+
}
70+
71+
[Test]
72+
public async Task ConnectionPooling_OpenThenCloseTwoAtTheSameTime_TowConnectionsArePooledAsync()
73+
{
74+
_driver.ClearPool(_connectionString);
75+
76+
var allreadyEstablished = await (GetEstablishedConnectionsAsync());
77+
78+
using (var connection1 = MakeConnection())
79+
using (var connection2 = MakeConnection())
80+
{
81+
//open first connection
82+
await (connection1.OpenAsync());
83+
await (VerifyCountOfEstablishedConnectionsIsAsync(allreadyEstablished + 1, "After first open"));
84+
85+
//open second one
86+
await (connection2.OpenAsync());
87+
await (VerifyCountOfEstablishedConnectionsIsAsync(allreadyEstablished + 2, "After second open"));
88+
89+
//return connection1 to the pool
90+
connection1.Close();
91+
await (VerifyCountOfEstablishedConnectionsIsAsync(allreadyEstablished + 2, "After first close"));
92+
93+
//return connection2 to the pool
94+
connection2.Close();
95+
await (VerifyCountOfEstablishedConnectionsIsAsync(allreadyEstablished + 2, "After second close"));
96+
}
97+
}
98+
99+
private DbConnection MakeConnection()
100+
{
101+
var result = _driver.CreateConnection();
102+
result.ConnectionString = _connectionString;
103+
return result;
104+
}
105+
106+
private async Task VerifyCountOfEstablishedConnectionsIsAsync(int expectedCount, string step, CancellationToken cancellationToken = default(CancellationToken))
107+
{
108+
var physicalConnections = await (GetEstablishedConnectionsAsync(cancellationToken));
109+
Assert.That(physicalConnections, Is.EqualTo(expectedCount), step);
110+
}
111+
112+
private async Task<int> GetEstablishedConnectionsAsync(CancellationToken cancellationToken = default(CancellationToken))
113+
{
114+
using (var conn = _driver.CreateConnection())
115+
{
116+
conn.ConnectionString = _connectionString;
117+
await (conn.OpenAsync(cancellationToken));
118+
using (var cmd = conn.CreateCommand())
119+
{
120+
cmd.CommandText = "select count(*) from mon$attachments where mon$attachment_id <> current_connection";
121+
return Convert.ToInt32(await (cmd.ExecuteScalarAsync(cancellationToken)));
122+
}
123+
}
124+
}
125+
126+
private DbCommand BuildSelectCaseCommand(SqlType paramType)
127+
{
128+
var sqlString = new SqlStringBuilder()
129+
.Add("select (case when col = ")
130+
.AddParameter()
131+
.Add(" then ")
132+
.AddParameter()
133+
.Add(" else ")
134+
.AddParameter()
135+
.Add(" end) from table")
136+
.ToSqlString();
137+
138+
return _driver.GenerateCommand(CommandType.Text, sqlString, new[] { paramType, paramType, paramType });
139+
}
140+
141+
private DbCommand BuildSelectConcatCommand(SqlType paramType)
142+
{
143+
var sqlString = new SqlStringBuilder()
144+
.Add("select col || ")
145+
.AddParameter()
146+
.Add(" || ")
147+
.Add("col ")
148+
.Add("from table")
149+
.ToSqlString();
150+
151+
return _driver.GenerateCommand(CommandType.Text, sqlString, new[] { paramType });
152+
}
153+
154+
private DbCommand BuildSelectAddCommand(SqlType paramType)
155+
{
156+
var sqlString = new SqlStringBuilder()
157+
.Add("select col + ")
158+
.AddParameter()
159+
.Add(" from table")
160+
.ToSqlString();
161+
162+
return _driver.GenerateCommand(CommandType.Text, sqlString, new[] { paramType });
163+
}
164+
165+
private DbCommand BuildInsertWithParamsInSelectCommand(SqlType paramType)
166+
{
167+
var sqlString = new SqlStringBuilder()
168+
.Add("insert into table1 (col1, col2) ")
169+
.Add("select col1, ")
170+
.AddParameter()
171+
.Add(" from table2")
172+
.ToSqlString();
173+
174+
return _driver.GenerateCommand(CommandType.Text, sqlString, new[] { paramType });
175+
}
176+
177+
private DbCommand BuildInsertWithParamsInSelectCommandWithSelectInColumnName(SqlType paramType)
178+
{
179+
var sqlString = new SqlStringBuilder()
180+
.Add("insert into table1 (col1_select_aaa) ")
181+
.Add("values(")
182+
.AddParameter()
183+
.Add(") from table2")
184+
.ToSqlString();
185+
186+
return _driver.GenerateCommand(CommandType.Text, sqlString, new[] { paramType });
187+
}
188+
189+
private DbCommand BuildInsertWithParamsInSelectCommandWithWhereInColumnName(SqlType paramType)
190+
{
191+
var sqlString = new SqlStringBuilder()
192+
.Add("insert into table1 (col1_where_aaa) ")
193+
.Add("values(")
194+
.AddParameter()
195+
.Add(") from table2")
196+
.ToSqlString();
197+
198+
return _driver.GenerateCommand(CommandType.Text, sqlString, new[] { paramType });
199+
}
200+
}
201+
}

0 commit comments

Comments
 (0)