Skip to content

Commit fca0feb

Browse files
Fix failing tests for SQL Anywhere
And add the Teamcity build
1 parent 49f1359 commit fca0feb

File tree

69 files changed

+781
-169
lines changed

Some content is hidden

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

69 files changed

+781
-169
lines changed

ShowBuildMenu.bat

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ echo F. Add a test configuration for Oracle with managed driver.
5252
echo G. Add a test configuration for SQL Server Compact.
5353
echo H. Add a test configuration for MySql.
5454
echo I. Add a test configuration for SAP HANA.
55+
echo J. Add a test configuration for SAP SQL Anywhere.
5556
echo.
5657
echo X. Exit to main menu.
5758
echo.
5859

59-
%BUILDTOOL% prompt ABCDEFGHIX
60-
if errorlevel 9 goto main-menu
60+
%BUILDTOOL% prompt ABCDEFGHIJX
61+
if errorlevel 10 goto main-menu
62+
if errorlevel 9 goto test-setup-anywhere
6163
if errorlevel 8 goto test-setup-hana
6264
if errorlevel 7 goto test-setup-mysql
6365
if errorlevel 6 goto test-setup-sqlserverce
@@ -131,6 +133,13 @@ set LIB_FILES=
131133
set LIB_FILES2=
132134
goto test-setup-generic
133135

136+
:test-setup-anywhere
137+
set CONFIG_NAME=SapSQLAnywhere
138+
set TEST_PLATFORM=AnyCPU
139+
set LIB_FILES=
140+
set LIB_FILES2=
141+
goto test-setup-generic
142+
134143
:test-setup-generic
135144
set CFGNAME=
136145
set /p CFGNAME=Enter a name for your test configuration or press enter to use default name:
@@ -216,12 +225,14 @@ echo I. NHibernate Trunk - Oracle Managed (64-bit)
216225
echo J. NHibernate Trunk - SQL Server Compact (32-bit)
217226
echo K. NHibernate Trunk - SQL Server Compact (64-bit)
218227
echo L. NHibernate Trunk - SQL Server ODBC (32-bit)
228+
echo M. NHibernate Trunk - SAP SQL Anywhere
219229
echo.
220230
echo X. Exit to main menu.
221231
echo.
222232

223-
%BUILDTOOL% prompt ABCDEFGHIJKLX
224-
if errorlevel 12 goto main-menu
233+
%BUILDTOOL% prompt ABCDEFGHIJKLMX
234+
if errorlevel 13 goto main-menu
235+
if errorlevel 12 goto teamcity-anywhere
225236
if errorlevel 11 goto teamcity-sqlServerOdbc
226237
if errorlevel 10 goto teamcity-sqlServerCe64
227238
if errorlevel 9 goto teamcity-sqlServerCe32
@@ -307,5 +318,11 @@ move "%CURRENT_CONFIGURATION%" "%CURRENT_CONFIGURATION%-backup" 2> nul
307318
move "%CURRENT_CONFIGURATION%-backup" "%CURRENT_CONFIGURATION%" 2> nul
308319
goto main-menu
309320

321+
:teamcity-anywhere
322+
move "%CURRENT_CONFIGURATION%" "%CURRENT_CONFIGURATION%-backup" 2> nul
323+
%NANT% /f:teamcity.build -D:skip.manual=true -D:CCNetLabel=-1 -D:config.teamcity=sqlanywhere
324+
move "%CURRENT_CONFIGURATION%-backup" "%CURRENT_CONFIGURATION%" 2> nul
325+
goto main-menu
326+
310327
:end
311328
popd
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Installation steps for SAP SQL Anywhere 17 for NH TeamCity:
2+
1. Download SAP SQL Anywhere 17 from https://www.sap.com/products/sql-anywhere.html.
3+
Please make sure you comply with it's license.
4+
5+
2. Run the installer
6+
3. Ensure the MSDTC Windows service is enabled. All transaction scope tests, even
7+
those normally not distributed, use it with SAP SQL Anywhere 17
8+
9+
The NHibernate.TestDatabaseSetup should normally do on its own the following operations:
10+
1. Create the test database with default options
11+
2. Run the query
12+
set option ansi_update_constraints = 'Off'
13+
(Otherwise some tests will fail.)
14+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
This template was written to work with NHibernate.Test.
4+
Copy the template to your NHibernate.Test project folder and rename it hibernate.cfg.xml. Change it
5+
for your own use before compiling tests in Visual Studio.
6+
-->
7+
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
8+
<session-factory name="NHibernate.Test">
9+
<property name="connection.driver_class">NHibernate.Driver.SapSQLAnywhere17Driver</property>
10+
<!-- Sap.Data.SQLAnywhere does not support re-enlisting in the same transaction, wrecking many usages
11+
with NHibernate when both NHibernate and the connection performs auto-enlistment. Setting
12+
"Enlist=false;" in the connection string solves this.
13+
It also requires to have the MSDTC service running, even for transaction scopes using a
14+
single connection. -->
15+
<property name="connection.connection_string">
16+
UID=DBA;PWD=sql;Server=localhost;DBN=nhibernate;DBF=c:\nhibernate.db;ASTOP=No;Enlist=false;
17+
</property>
18+
<property name="dialect">NHibernate.Dialect.SybaseSQLAnywhere12Dialect</property>
19+
<property name="query.substitutions">true=1;false=0</property>
20+
</session-factory>
21+
</hibernate-configuration>

src/NHibernate.DomainModel/ABCProxy.hbm.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</id>
1111
<discriminator column="clazz_discriminata" type="Int32" force="true" not-null="false" />
1212
<property name="Name" />
13-
<many-to-one name="Forward" class="E" cascade="save-update" />
14-
13+
<many-to-one name="Forward" column="`Forward`" class="E" cascade="save-update" />
14+
1515
<subclass name="B" lazy="true" discriminator-value="null">
1616
<property name="Count" column="count_" type="Int32" />
1717
<map name="Map">
@@ -56,4 +56,4 @@
5656
<one-to-one name="Reverse" class="A" property-ref="Forward" cascade="save-update" />
5757
</class>
5858

59-
</hibernate-mapping>
59+
</hibernate-mapping>

src/NHibernate.DomainModel/Northwind/Mappings/Shipper.hbm.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<property name="PhoneNumber" column="Phone" type="string" length="24"
1515
access="field.camelcase-underscore"/>
1616

17-
<property name="Reference" column="Reference" type="guid" access="field.camelcase-underscore"/>
17+
<property name="Reference" column="`Reference`" type="guid" access="field.camelcase-underscore"/>
1818

1919
<bag name="Orders" lazy="true" access="field.camelcase-underscore"
2020
cascade="none">
@@ -24,4 +24,4 @@
2424

2525
</class>
2626

27-
</hibernate-mapping>
27+
</hibernate-mapping>

src/NHibernate.Test/Ado/GenericBatchingBatcherFixture.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
2929
return !(dialect is FirebirdDialect) &&
3030
!(dialect is Oracle8iDialect) &&
3131
!(dialect is MsSqlCeDialect) &&
32-
!(dialect is HanaDialectBase);
32+
!(dialect is HanaDialectBase) &&
33+
// A workaround exists for SQL Anywhere, see https://stackoverflow.com/a/32860293/1178314
34+
// It would imply some tweaking in the generic batcher. The same workaround could
35+
// be used for enabling future support.
36+
!(dialect is SybaseSQLAnywhere10Dialect);
3337
}
3438

3539
[Test]

src/NHibernate.Test/Async/Ado/GenericBatchingBatcherFixture.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
4242
return !(dialect is FirebirdDialect) &&
4343
!(dialect is Oracle8iDialect) &&
4444
!(dialect is MsSqlCeDialect) &&
45-
!(dialect is HanaDialectBase);
45+
!(dialect is HanaDialectBase) &&
46+
// A workaround exists for SQL Anywhere, see https://stackoverflow.com/a/32860293/1178314
47+
// It would imply some tweaking in the generic batcher. The same workaround could
48+
// be used for enabling future support.
49+
!(dialect is SybaseSQLAnywhere10Dialect);
4650
}
4751

4852
[Test]

src/NHibernate.Test/Async/Component/Basic/ComponentWithUniqueConstraintTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ protected override HbmMapping GetMappings()
3232

3333
mapper.Component<Person>(comp =>
3434
{
35-
comp.Property(p => p.Name);
36-
comp.Property(p => p.Dob);
35+
comp.Property(p => p.Name, m => m.NotNullable(true));
36+
comp.Property(p => p.Dob, m => m.NotNullable(true));
3737
comp.Unique(true); // hbm2ddl: Generate a unique constraint in the database
3838
});
3939

@@ -94,9 +94,9 @@ public void CannotBePersistedWithNonUniqueValuesAsync()
9494
await (session.SaveAsync(e2));
9595
await (session.FlushAsync());
9696
});
97-
Assert.That(exception.InnerException, Is.AssignableTo<DbException>());
97+
Assert.That(exception.InnerException, Is.InstanceOf<DbException>());
9898
Assert.That(exception.InnerException.Message,
99-
Does.Contain("unique").IgnoreCase.And.Contains("constraint").IgnoreCase
99+
Does.Contain("unique").IgnoreCase
100100
.Or.Contains("duplicate entry").IgnoreCase);
101101
}
102102
}

src/NHibernate.Test/Async/Criteria/CriteriaQueryTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,9 @@ public async Task OrderProjectionTestAsync()
27192719
[Test]
27202720
public async Task OrderProjectionAliasedTestAsync()
27212721
{
2722+
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
2723+
Assert.Ignore("Current dialect does not support this test");
2724+
27222725
using (ISession session = OpenSession())
27232726
using (ITransaction t = session.BeginTransaction())
27242727
{

src/NHibernate.Test/Async/Criteria/EntityProjectionsTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//------------------------------------------------------------------------------
99

1010

11+
using NHibernate.Cfg;
1112
using NHibernate.Cfg.MappingSchema;
1213
using NHibernate.Criterion;
1314
using NHibernate.Dialect;
@@ -29,6 +30,11 @@ public class EntityProjectionsTestAsync : TestCaseMappingByCode
2930
private EntityWithCompositeId _entityWithCompositeId;
3031
private EntityCustomEntityName _entityWithCustomEntityName;
3132

33+
protected override void Configure(Configuration configuration)
34+
{
35+
configuration.SetProperty(Environment.FormatSql, "false");
36+
}
37+
3238
protected override HbmMapping GetMappings()
3339
{
3440
var mapper = new ModelMapper();
@@ -252,12 +258,14 @@ public async Task EntityProjectionAsSelectExpressionForArgumentAliasAsync()
252258
[Test]
253259
public async Task EntityProjectionLockModeAsync()
254260
{
261+
// For this test to succeed with SQL Anywhere, ansi_update_constraints must be off.
262+
// In I-SQL: set option ansi_update_constraints = 'Off'
255263
if (Dialect is Oracle8iDialect)
256264
Assert.Ignore("Oracle is not supported due to #1352 bug (NH-3902)");
257265

258266
var upgradeHint = Dialect.ForUpdateString;
259267
if(string.IsNullOrEmpty(upgradeHint))
260-
upgradeHint = this.Dialect.AppendLockHint(LockMode.Upgrade, string.Empty);
268+
upgradeHint = Dialect.AppendLockHint(LockMode.Upgrade, string.Empty);
261269
if (string.IsNullOrEmpty(upgradeHint))
262270
{
263271
Assert.Ignore($"Upgrade hint is not supported by dialect {Dialect.GetType().Name}");

src/NHibernate.Test/Async/Criteria/Lambda/FunctionsIntegrationFixture.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ public async Task FunctionsToLowerToUpperAsync()
146146
[Test]
147147
public async Task ConcatAsync()
148148
{
149+
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
150+
Assert.Ignore("Current dialect does not support this test");
151+
149152
using (var s = OpenSession())
150153
using (s.BeginTransaction())
151154
{

src/NHibernate.Test/Async/Criteria/ProjectionsTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ protected override void OnTearDown()
6969
[Test]
7070
public async Task UsingSqlFunctions_ConcatAsync()
7171
{
72+
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
73+
Assert.Ignore("Current dialect does not support this test");
74+
7275
using (ISession session = Sfi.OpenSession())
7376
{
7477
string result = await (session.CreateCriteria(typeof(Student))
@@ -90,6 +93,9 @@ public async Task UsingSqlFunctions_Concat_WithCastAsync()
9093
{
9194
Assert.Ignore("Not supported by the active dialect:{0}.", Dialect);
9295
}
96+
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
97+
Assert.Ignore("Current dialect does not support this test");
98+
9399
using (ISession session = Sfi.OpenSession())
94100
{
95101
string result = await (session.CreateCriteria(typeof(Student))
@@ -176,6 +182,9 @@ public async Task CanUseParametersWithProjectionsAsync()
176182
[Test]
177183
public async Task UsingConditionalsAsync()
178184
{
185+
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
186+
Assert.Ignore("Current dialect does not support this test");
187+
179188
using (ISession session = Sfi.OpenSession())
180189
{
181190
string result = await (session.CreateCriteria(typeof(Student))

src/NHibernate.Test/Async/Generatedkeys/Seqidentity/SequenceIdentityFixture.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ protected override string MappingsAssembly
2929

3030
protected override bool AppliesTo(Dialect.Dialect dialect)
3131
{
32-
return dialect.SupportsSequences &&
33-
!(dialect is Dialect.MsSql2012Dialect) &&
34-
!(dialect is Dialect.HanaDialectBase); // SAP HANA does not support a syntax allowing to return the inserted id as an output parameter or a return value
32+
return
33+
dialect.SupportsSequences &&
34+
!(dialect is Dialect.MsSql2012Dialect) &&
35+
// SAP HANA does not support a syntax allowing to return the inserted id as an output parameter or a return value
36+
!(dialect is Dialect.HanaDialectBase) &&
37+
// SQL Anywhere does not support a syntax allowing to return the inserted id as an output parameter or a return value
38+
!(dialect is Dialect.SybaseSQLAnywhere10Dialect);
3539
}
3640

3741
[Test]

src/NHibernate.Test/Async/Hql/HQLFunctions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ public async Task StrAsync()
11481148

11491149
hql = "from Animal a where str(123) = '123'";
11501150
Animal result = (Animal) await (s.CreateQuery(hql).UniqueResultAsync());
1151+
Assert.That(result, Is.Not.Null);
11511152
Assert.AreEqual("abcdef", result.Description);
11521153
}
11531154
}
@@ -1328,7 +1329,8 @@ public async Task BitwiseNotAsync()
13281329
using (var s = OpenSession())
13291330
using (var tx = s.BeginTransaction())
13301331
{
1331-
// ! takes not precedence over & at least with some dialects (maybe all).
1332+
// The bitwise "not" should take precedence over the bitwise "and", but when it is implemented as a
1333+
// function, its argument is the whole following statement, unless parenthesis are used to prevent this.
13321334
var query = s.CreateQuery("from MaterialResource m where ((!m.State) & 3) = 3");
13331335
var result = await (query.ListAsync());
13341336
Assert.That(result, Has.Count.EqualTo(1), "((!m.State) & 3) = 3");
@@ -1368,6 +1370,10 @@ public async Task BitwiseIsThreadsafeAsync()
13681370
new Tuple<string, int> ("select count(*) from MaterialResource m where ((!m.State) & 3) = 2", 1),
13691371
new Tuple<string, int> ("select count(*) from MaterialResource m where ((!m.State) & 3) = 1", 1)
13701372
};
1373+
1374+
if (TestDialect.MaxNumberOfConnections < queries.Count)
1375+
Assert.Ignore("Current database has a too low connection count limit.");
1376+
13711377
// Do not use a ManualResetEventSlim, it does not support async and exhausts the task thread pool in the
13721378
// async counterparts of this test. SemaphoreSlim has the async support and release the thread when waiting.
13731379
var semaphore = new SemaphoreSlim(0);

src/NHibernate.Test/Async/MappingByCode/IntegrationTests/NH3269/FixtureNonPublicProperty.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ protected override HbmMapping GetMappings()
5353
mapper.Class<Inherited1>(rc =>
5454
{
5555
rc.Id(x => x.Id, m => m.Generator(Generators.Guid));
56-
rc.Property("Name", m => m.UniqueKey("Inherited1_UX_Name"));
56+
rc.Property(
57+
"Name",
58+
m =>
59+
{
60+
m.UniqueKey("Inherited1_UX_Name");
61+
m.NotNullable(true);
62+
});
5763
});
5864

5965
mapper.Class<Inherited2>(rc =>

src/NHibernate.Test/Async/MappingByCode/IntegrationTests/NH3269/FixturePublicProperty.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ protected override HbmMapping GetMappings()
5353
mapper.Class<Inherited1>(rc =>
5454
{
5555
rc.Id(x => x.Id, m => m.Generator(Generators.Guid));
56-
rc.Property(x => x.Name, m => m.UniqueKey("Inherited1_UX_Name"));
56+
rc.Property(
57+
x => x.Name,
58+
m =>
59+
{
60+
m.UniqueKey("Inherited1_UX_Name");
61+
m.NotNullable(true);
62+
});
5763
});
5864

5965
mapper.Class<Inherited2>(rc =>

src/NHibernate.Test/Async/NHSpecificTest/Dates/DateTimeOffsetFixture.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ protected override bool AppliesTo(Engine.ISessionFactoryImplementor factory)
4545
return DbType.DateTimeOffset;
4646
}
4747

48+
protected virtual long DateAccuracyInTicks => Dialect.TimestampResolutionInTicks;
49+
4850
[Test]
4951
public async Task SavingAndRetrievingTestAsync()
5052
{
51-
DateTimeOffset NowOS = DateTimeOffset.Now;
53+
var NowOS = DateTimeOffsetType.Round(DateTimeOffset.Now, DateAccuracyInTicks);
5254

5355
AllDates dates = new AllDates { Sql_datetimeoffset = NowOS };
5456

src/NHibernate.Test/Async/NHSpecificTest/GH1565/LockEntityWithOuterJoinTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class LockEntityWithOuterJoinTestAsync : BugTestCase
1919
[Test]
2020
public async Task LockWithOuterJoin_ShouldBePossibleAsync()
2121
{
22+
// For this test to succeed with SQL Anywhere, ansi_update_constraints must be off.
23+
// In I-SQL: set option ansi_update_constraints = 'Off'
2224
using (var session = OpenSession())
2325
{
2426
using (var transaction = session.BeginTransaction())

src/NHibernate.Test/Async/NHSpecificTest/Logs/LogsFixture.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,15 @@ public async Task WillGetSessionIdFromSessionLogsConcurrentAsync()
159159
var semaphore = new SemaphoreSlim(0);
160160
var failures = new ConcurrentBag<Exception>();
161161
var sessionIds = new ConcurrentDictionary<int, Guid>();
162+
var threadCount = 10;
163+
if (threadCount > TestDialect.MaxNumberOfConnections)
164+
threadCount = TestDialect.MaxNumberOfConnections.Value;
162165
using (var spy = new TextLogSpy("NHibernate.SQL", "%message | SessionId: %property{sessionId}"))
163166
{
164167
await (Task.WhenAll(
165-
Enumerable.Range(1, 12 - 1).Select(async i =>
168+
Enumerable.Range(1, threadCount + 2 - 1).Select(async i =>
166169
{
167-
if (i > 10)
170+
if (i > threadCount)
168171
{
169172
// Give some time to threads for reaching the wait, having all of them ready to do most of their job concurrently.
170173
await (Task.Delay(100));
@@ -198,7 +201,7 @@ public async Task WillGetSessionIdFromSessionLogsConcurrentAsync()
198201
Assert.That(failures, Is.Empty, $"{failures.Count} task(s) failed.");
199202

200203
var loggingEvent = spy.GetWholeLog();
201-
for (var i = 1; i < 11; i++)
204+
for (var i = 1; i < threadCount + 1; i++)
202205
for (var j = 0; j < 10; j++)
203206
{
204207
var sessionId = sessionIds[i];

0 commit comments

Comments
 (0)