Skip to content

Commit 06da1c9

Browse files
Fix failing tests for SQL Anywhere
And add the Teamcity build
1 parent 4110d2e commit 06da1c9

File tree

69 files changed

+780
-168
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

+780
-168
lines changed

ShowBuildMenu.bat

+21-4
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ echo F. Add a test configuration for Oracle with managed driver.
5757
echo G. Add a test configuration for SQL Server Compact.
5858
echo H. Add a test configuration for MySql.
5959
echo I. Add a test configuration for SAP HANA.
60+
echo J. Add a test configuration for SAP SQL Anywhere.
6061
echo.
6162
echo X. Exit to main menu.
6263
echo.
6364

64-
%BUILDTOOL% prompt ABCDEFGHIX
65-
if errorlevel 9 goto main-menu
65+
%BUILDTOOL% prompt ABCDEFGHIJX
66+
if errorlevel 10 goto main-menu
67+
if errorlevel 9 goto test-setup-anywhere
6668
if errorlevel 8 goto test-setup-hana
6769
if errorlevel 7 goto test-setup-mysql
6870
if errorlevel 6 goto test-setup-sqlserverce
@@ -136,6 +138,13 @@ set LIB_FILES=
136138
set LIB_FILES2=
137139
goto test-setup-generic
138140

141+
:test-setup-anywhere
142+
set CONFIG_NAME=SapSQLAnywhere
143+
set TEST_PLATFORM=AnyCPU
144+
set LIB_FILES=
145+
set LIB_FILES2=
146+
goto test-setup-generic
147+
139148
:test-setup-generic
140149
set CFGNAME=
141150
set /p CFGNAME=Enter a name for your test configuration or press enter to use default name:
@@ -221,12 +230,14 @@ echo I. NHibernate Trunk - Oracle Managed (64-bit)
221230
echo J. NHibernate Trunk - SQL Server Compact (32-bit)
222231
echo K. NHibernate Trunk - SQL Server Compact (64-bit)
223232
echo L. NHibernate Trunk - SQL Server ODBC (32-bit)
233+
echo M. NHibernate Trunk - SAP SQL Anywhere
224234
echo.
225235
echo X. Exit to main menu.
226236
echo.
227237

228-
%BUILDTOOL% prompt ABCDEFGHIJKLX
229-
if errorlevel 12 goto main-menu
238+
%BUILDTOOL% prompt ABCDEFGHIJKLMX
239+
if errorlevel 13 goto main-menu
240+
if errorlevel 12 goto teamcity-anywhere
230241
if errorlevel 11 goto teamcity-sqlServerOdbc
231242
if errorlevel 10 goto teamcity-sqlServerCe64
232243
if errorlevel 9 goto teamcity-sqlServerCe32
@@ -312,5 +323,11 @@ move "%CURRENT_CONFIGURATION%" "%CURRENT_CONFIGURATION%-backup" 2> nul
312323
move "%CURRENT_CONFIGURATION%-backup" "%CURRENT_CONFIGURATION%" 2> nul
313324
goto main-menu
314325

326+
:teamcity-anywhere
327+
move "%CURRENT_CONFIGURATION%" "%CURRENT_CONFIGURATION%-backup" 2> nul
328+
%NANT% /f:teamcity.build -D:skip.manual=true -D:CCNetLabel=-1 -D:config.teamcity=sqlanywhere
329+
move "%CURRENT_CONFIGURATION%-backup" "%CURRENT_CONFIGURATION%" 2> nul
330+
goto main-menu
331+
315332
:end
316333
popd
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+
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

+3-3
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

+2-2
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

+5-1
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

+5-1
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

+4-4
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

+3
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

+9-1
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

+3
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

+9
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

+7-3
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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ public async Task StrAsync()
11951195

11961196
hql = "from Animal a where str(123) = '123'";
11971197
Animal result = (Animal) await (s.CreateQuery(hql).UniqueResultAsync());
1198+
Assert.That(result, Is.Not.Null);
11981199
Assert.AreEqual("abcdef", result.Description);
11991200
}
12001201
}
@@ -1375,7 +1376,8 @@ public async Task BitwiseNotAsync()
13751376
using (var s = OpenSession())
13761377
using (var tx = s.BeginTransaction())
13771378
{
1378-
// ! takes not precedence over & at least with some dialects (maybe all).
1379+
// The bitwise "not" should take precedence over the bitwise "and", but when it is implemented as a
1380+
// function, its argument is the whole following statement, unless parenthesis are used to prevent this.
13791381
var query = s.CreateQuery("from MaterialResource m where ((!m.State) & 3) = 3");
13801382
var result = await (query.ListAsync());
13811383
Assert.That(result, Has.Count.EqualTo(1), "((!m.State) & 3) = 3");
@@ -1415,6 +1417,10 @@ public async Task BitwiseIsThreadsafeAsync()
14151417
new Tuple<string, int> ("select count(*) from MaterialResource m where ((!m.State) & 3) = 2", 1),
14161418
new Tuple<string, int> ("select count(*) from MaterialResource m where ((!m.State) & 3) = 1", 1)
14171419
};
1420+
1421+
if (TestDialect.MaxNumberOfConnections < queries.Count)
1422+
Assert.Ignore("Current database has a too low connection count limit.");
1423+
14181424
// Do not use a ManualResetEventSlim, it does not support async and exhausts the task thread pool in the
14191425
// async counterparts of this test. SemaphoreSlim has the async support and release the thread when waiting.
14201426
var semaphore = new SemaphoreSlim(0);

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

+7-1
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

+7-1
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

+3-1
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

+2
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

+6-3
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)