Skip to content

Commit

Permalink
Fix failing tests for SQL Anywhere
Browse files Browse the repository at this point in the history
And add the Teamcity build
  • Loading branch information
fredericDelaporte committed Nov 14, 2018
1 parent 4110d2e commit 06da1c9
Show file tree
Hide file tree
Showing 69 changed files with 780 additions and 168 deletions.
25 changes: 21 additions & 4 deletions ShowBuildMenu.bat
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ echo F. Add a test configuration for Oracle with managed driver.
echo G. Add a test configuration for SQL Server Compact.
echo H. Add a test configuration for MySql.
echo I. Add a test configuration for SAP HANA.
echo J. Add a test configuration for SAP SQL Anywhere.
echo.
echo X. Exit to main menu.
echo.

%BUILDTOOL% prompt ABCDEFGHIX
if errorlevel 9 goto main-menu
%BUILDTOOL% prompt ABCDEFGHIJX
if errorlevel 10 goto main-menu
if errorlevel 9 goto test-setup-anywhere
if errorlevel 8 goto test-setup-hana
if errorlevel 7 goto test-setup-mysql
if errorlevel 6 goto test-setup-sqlserverce
Expand Down Expand Up @@ -136,6 +138,13 @@ set LIB_FILES=
set LIB_FILES2=
goto test-setup-generic

:test-setup-anywhere
set CONFIG_NAME=SapSQLAnywhere
set TEST_PLATFORM=AnyCPU
set LIB_FILES=
set LIB_FILES2=
goto test-setup-generic

:test-setup-generic
set CFGNAME=
set /p CFGNAME=Enter a name for your test configuration or press enter to use default name:
Expand Down Expand Up @@ -221,12 +230,14 @@ echo I. NHibernate Trunk - Oracle Managed (64-bit)
echo J. NHibernate Trunk - SQL Server Compact (32-bit)
echo K. NHibernate Trunk - SQL Server Compact (64-bit)
echo L. NHibernate Trunk - SQL Server ODBC (32-bit)
echo M. NHibernate Trunk - SAP SQL Anywhere
echo.
echo X. Exit to main menu.
echo.

%BUILDTOOL% prompt ABCDEFGHIJKLX
if errorlevel 12 goto main-menu
%BUILDTOOL% prompt ABCDEFGHIJKLMX
if errorlevel 13 goto main-menu
if errorlevel 12 goto teamcity-anywhere
if errorlevel 11 goto teamcity-sqlServerOdbc
if errorlevel 10 goto teamcity-sqlServerCe64
if errorlevel 9 goto teamcity-sqlServerCe32
Expand Down Expand Up @@ -312,5 +323,11 @@ move "%CURRENT_CONFIGURATION%" "%CURRENT_CONFIGURATION%-backup" 2> nul
move "%CURRENT_CONFIGURATION%-backup" "%CURRENT_CONFIGURATION%" 2> nul
goto main-menu

:teamcity-anywhere
move "%CURRENT_CONFIGURATION%" "%CURRENT_CONFIGURATION%-backup" 2> nul
%NANT% /f:teamcity.build -D:skip.manual=true -D:CCNetLabel=-1 -D:config.teamcity=sqlanywhere
move "%CURRENT_CONFIGURATION%-backup" "%CURRENT_CONFIGURATION%" 2> nul
goto main-menu

:end
popd
14 changes: 14 additions & 0 deletions lib/teamcity/SapSQLAnywhere/SQLAnywhere_installation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Installation steps for SAP SQL Anywhere 17 for NH TeamCity:
1. Download SAP SQL Anywhere 17 from https://www.sap.com/products/sql-anywhere.html.
Please make sure you comply with it's license.

2. Run the installer
3. Ensure the MSDTC Windows service is enabled. All transaction scope tests, even
those normally not distributed, use it with SAP SQL Anywhere 17

The NHibernate.TestDatabaseSetup should normally do on its own the following operations:
1. Create the test database with default options
2. Run the query
set option ansi_update_constraints = 'Off'
(Otherwise some tests will fail.)

21 changes: 21 additions & 0 deletions src/NHibernate.Config.Templates/SapSQLAnywhere.cfg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This template was written to work with NHibernate.Test.
Copy the template to your NHibernate.Test project folder and rename it hibernate.cfg.xml. Change it
for your own use before compiling tests in Visual Studio.
-->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.SapSQLAnywhere17Driver</property>
<!-- Sap.Data.SQLAnywhere does not support re-enlisting in the same transaction, wrecking many usages
with NHibernate when both NHibernate and the connection performs auto-enlistment. Setting
"Enlist=false;" in the connection string solves this.
It also requires to have the MSDTC service running, even for transaction scopes using a
single connection. -->
<property name="connection.connection_string">
UID=DBA;PWD=sql;Server=localhost;DBN=nhibernate;DBF=c:\nhibernate.db;ASTOP=No;Enlist=false;
</property>
<property name="dialect">NHibernate.Dialect.SybaseSQLAnywhere12Dialect</property>
<property name="query.substitutions">true=1;false=0</property>
</session-factory>
</hibernate-configuration>
6 changes: 3 additions & 3 deletions src/NHibernate.DomainModel/ABCProxy.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</id>
<discriminator column="clazz_discriminata" type="Int32" force="true" not-null="false" />
<property name="Name" />
<many-to-one name="Forward" class="E" cascade="save-update" />
<many-to-one name="Forward" column="`Forward`" class="E" cascade="save-update" />

<subclass name="B" lazy="true" discriminator-value="null">
<property name="Count" column="count_" type="Int32" />
<map name="Map">
Expand Down Expand Up @@ -56,4 +56,4 @@
<one-to-one name="Reverse" class="A" property-ref="Forward" cascade="save-update" />
</class>

</hibernate-mapping>
</hibernate-mapping>
4 changes: 2 additions & 2 deletions src/NHibernate.DomainModel/Northwind/Mappings/Shipper.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<property name="PhoneNumber" column="Phone" type="string" length="24"
access="field.camelcase-underscore"/>

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

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

</class>

</hibernate-mapping>
</hibernate-mapping>
6 changes: 5 additions & 1 deletion src/NHibernate.Test/Ado/GenericBatchingBatcherFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
return !(dialect is FirebirdDialect) &&
!(dialect is Oracle8iDialect) &&
!(dialect is MsSqlCeDialect) &&
!(dialect is HanaDialectBase);
!(dialect is HanaDialectBase) &&
// A workaround exists for SQL Anywhere, see https://stackoverflow.com/a/32860293/1178314
// It would imply some tweaking in the generic batcher. The same workaround could
// be used for enabling future support.
!(dialect is SybaseSQLAnywhere10Dialect);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
return !(dialect is FirebirdDialect) &&
!(dialect is Oracle8iDialect) &&
!(dialect is MsSqlCeDialect) &&
!(dialect is HanaDialectBase);
!(dialect is HanaDialectBase) &&
// A workaround exists for SQL Anywhere, see https://stackoverflow.com/a/32860293/1178314
// It would imply some tweaking in the generic batcher. The same workaround could
// be used for enabling future support.
!(dialect is SybaseSQLAnywhere10Dialect);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ protected override HbmMapping GetMappings()

mapper.Component<Person>(comp =>
{
comp.Property(p => p.Name);
comp.Property(p => p.Dob);
comp.Property(p => p.Name, m => m.NotNullable(true));
comp.Property(p => p.Dob, m => m.NotNullable(true));
comp.Unique(true); // hbm2ddl: Generate a unique constraint in the database
});

Expand Down Expand Up @@ -94,9 +94,9 @@ public void CannotBePersistedWithNonUniqueValuesAsync()
await (session.SaveAsync(e2));
await (session.FlushAsync());
});
Assert.That(exception.InnerException, Is.AssignableTo<DbException>());
Assert.That(exception.InnerException, Is.InstanceOf<DbException>());
Assert.That(exception.InnerException.Message,
Does.Contain("unique").IgnoreCase.And.Contains("constraint").IgnoreCase
Does.Contain("unique").IgnoreCase
.Or.Contains("duplicate entry").IgnoreCase);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/NHibernate.Test/Async/Criteria/CriteriaQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,9 @@ public async Task OrderProjectionTestAsync()
[Test]
public async Task OrderProjectionAliasedTestAsync()
{
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
Assert.Ignore("Current dialect does not support this test");

using (ISession session = OpenSession())
using (ITransaction t = session.BeginTransaction())
{
Expand Down
10 changes: 9 additions & 1 deletion src/NHibernate.Test/Async/Criteria/EntityProjectionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//------------------------------------------------------------------------------


using NHibernate.Cfg;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Criterion;
using NHibernate.Dialect;
Expand All @@ -29,6 +30,11 @@ public class EntityProjectionsTestAsync : TestCaseMappingByCode
private EntityWithCompositeId _entityWithCompositeId;
private EntityCustomEntityName _entityWithCustomEntityName;

protected override void Configure(Configuration configuration)
{
configuration.SetProperty(Environment.FormatSql, "false");
}

protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
Expand Down Expand Up @@ -252,12 +258,14 @@ public async Task EntityProjectionAsSelectExpressionForArgumentAliasAsync()
[Test]
public async Task EntityProjectionLockModeAsync()
{
// For this test to succeed with SQL Anywhere, ansi_update_constraints must be off.
// In I-SQL: set option ansi_update_constraints = 'Off'
if (Dialect is Oracle8iDialect)
Assert.Ignore("Oracle is not supported due to #1352 bug (NH-3902)");

var upgradeHint = Dialect.ForUpdateString;
if(string.IsNullOrEmpty(upgradeHint))
upgradeHint = this.Dialect.AppendLockHint(LockMode.Upgrade, string.Empty);
upgradeHint = Dialect.AppendLockHint(LockMode.Upgrade, string.Empty);
if (string.IsNullOrEmpty(upgradeHint))
{
Assert.Ignore($"Upgrade hint is not supported by dialect {Dialect.GetType().Name}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public async Task FunctionsToLowerToUpperAsync()
[Test]
public async Task ConcatAsync()
{
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
Assert.Ignore("Current dialect does not support this test");

using (var s = OpenSession())
using (s.BeginTransaction())
{
Expand Down
9 changes: 9 additions & 0 deletions src/NHibernate.Test/Async/Criteria/ProjectionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ protected override void OnTearDown()
[Test]
public async Task UsingSqlFunctions_ConcatAsync()
{
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
Assert.Ignore("Current dialect does not support this test");

using (ISession session = Sfi.OpenSession())
{
string result = await (session.CreateCriteria(typeof(Student))
Expand All @@ -90,6 +93,9 @@ public async Task UsingSqlFunctions_Concat_WithCastAsync()
{
Assert.Ignore("Not supported by the active dialect:{0}.", Dialect);
}
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
Assert.Ignore("Current dialect does not support this test");

using (ISession session = Sfi.OpenSession())
{
string result = await (session.CreateCriteria(typeof(Student))
Expand Down Expand Up @@ -176,6 +182,9 @@ public async Task CanUseParametersWithProjectionsAsync()
[Test]
public async Task UsingConditionalsAsync()
{
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
Assert.Ignore("Current dialect does not support this test");

using (ISession session = Sfi.OpenSession())
{
string result = await (session.CreateCriteria(typeof(Student))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ protected override string MappingsAssembly

protected override bool AppliesTo(Dialect.Dialect dialect)
{
return dialect.SupportsSequences &&
!(dialect is Dialect.MsSql2012Dialect) &&
!(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
return
dialect.SupportsSequences &&
!(dialect is Dialect.MsSql2012Dialect) &&
// SAP HANA does not support a syntax allowing to return the inserted id as an output parameter or a return value
!(dialect is Dialect.HanaDialectBase) &&
// SQL Anywhere does not support a syntax allowing to return the inserted id as an output parameter or a return value
!(dialect is Dialect.SybaseSQLAnywhere10Dialect);
}

[Test]
Expand Down
8 changes: 7 additions & 1 deletion src/NHibernate.Test/Async/Hql/HQLFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ public async Task StrAsync()

hql = "from Animal a where str(123) = '123'";
Animal result = (Animal) await (s.CreateQuery(hql).UniqueResultAsync());
Assert.That(result, Is.Not.Null);
Assert.AreEqual("abcdef", result.Description);
}
}
Expand Down Expand Up @@ -1375,7 +1376,8 @@ public async Task BitwiseNotAsync()
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
// ! takes not precedence over & at least with some dialects (maybe all).
// The bitwise "not" should take precedence over the bitwise "and", but when it is implemented as a
// function, its argument is the whole following statement, unless parenthesis are used to prevent this.
var query = s.CreateQuery("from MaterialResource m where ((!m.State) & 3) = 3");
var result = await (query.ListAsync());
Assert.That(result, Has.Count.EqualTo(1), "((!m.State) & 3) = 3");
Expand Down Expand Up @@ -1415,6 +1417,10 @@ public async Task BitwiseIsThreadsafeAsync()
new Tuple<string, int> ("select count(*) from MaterialResource m where ((!m.State) & 3) = 2", 1),
new Tuple<string, int> ("select count(*) from MaterialResource m where ((!m.State) & 3) = 1", 1)
};

if (TestDialect.MaxNumberOfConnections < queries.Count)
Assert.Ignore("Current database has a too low connection count limit.");

// Do not use a ManualResetEventSlim, it does not support async and exhausts the task thread pool in the
// async counterparts of this test. SemaphoreSlim has the async support and release the thread when waiting.
var semaphore = new SemaphoreSlim(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ protected override HbmMapping GetMappings()
mapper.Class<Inherited1>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.Guid));
rc.Property("Name", m => m.UniqueKey("Inherited1_UX_Name"));
rc.Property(
"Name",
m =>
{
m.UniqueKey("Inherited1_UX_Name");
m.NotNullable(true);
});
});

mapper.Class<Inherited2>(rc =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ protected override HbmMapping GetMappings()
mapper.Class<Inherited1>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.Guid));
rc.Property(x => x.Name, m => m.UniqueKey("Inherited1_UX_Name"));
rc.Property(
x => x.Name,
m =>
{
m.UniqueKey("Inherited1_UX_Name");
m.NotNullable(true);
});
});

mapper.Class<Inherited2>(rc =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ protected override bool AppliesTo(Engine.ISessionFactoryImplementor factory)
return DbType.DateTimeOffset;
}

protected virtual long DateAccuracyInTicks => Dialect.TimestampResolutionInTicks;

[Test]
public async Task SavingAndRetrievingTestAsync()
{
DateTimeOffset NowOS = DateTimeOffset.Now;
var NowOS = DateTimeOffsetType.Round(DateTimeOffset.Now, DateAccuracyInTicks);

AllDates dates = new AllDates { Sql_datetimeoffset = NowOS };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class LockEntityWithOuterJoinTestAsync : BugTestCase
[Test]
public async Task LockWithOuterJoin_ShouldBePossibleAsync()
{
// For this test to succeed with SQL Anywhere, ansi_update_constraints must be off.
// In I-SQL: set option ansi_update_constraints = 'Off'
using (var session = OpenSession())
{
using (var transaction = session.BeginTransaction())
Expand Down
9 changes: 6 additions & 3 deletions src/NHibernate.Test/Async/NHSpecificTest/Logs/LogsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,15 @@ public async Task WillGetSessionIdFromSessionLogsConcurrentAsync()
var semaphore = new SemaphoreSlim(0);
var failures = new ConcurrentBag<Exception>();
var sessionIds = new ConcurrentDictionary<int, Guid>();
var threadCount = 10;
if (threadCount > TestDialect.MaxNumberOfConnections)
threadCount = TestDialect.MaxNumberOfConnections.Value;
using (var spy = new TextLogSpy("NHibernate.SQL", "%message | SessionId: %property{sessionId}"))
{
await (Task.WhenAll(
Enumerable.Range(1, 12 - 1).Select(async i =>
Enumerable.Range(1, threadCount + 2 - 1).Select(async i =>
{
if (i > 10)
if (i > threadCount)
{
// Give some time to threads for reaching the wait, having all of them ready to do most of their job concurrently.
await (Task.Delay(100));
Expand Down Expand Up @@ -198,7 +201,7 @@ public async Task WillGetSessionIdFromSessionLogsConcurrentAsync()
Assert.That(failures, Is.Empty, $"{failures.Count} task(s) failed.");

var loggingEvent = spy.GetWholeLog();
for (var i = 1; i < 11; i++)
for (var i = 1; i < threadCount + 1; i++)
for (var j = 0; j < 10; j++)
{
var sessionId = sessionIds[i];
Expand Down
Loading

0 comments on commit 06da1c9

Please sign in to comment.