Skip to content

NH-4058 - Fix Oracle (12c) Managed 32 failing tests. #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16,380 changes: 0 additions & 16,380 deletions lib/teamcity/oracle-managed/NHibernate.Test.last-results.xml

This file was deleted.

9 changes: 7 additions & 2 deletions src/NHibernate.Test/DebugSessionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ namespace NHibernate.Test
/// <remarks>Sessions opened from other sessions are not tracked.</remarks>
public class DebugSessionFactory : ISessionFactoryImplementor
{
public DebugConnectionProvider ConnectionProvider { get; }
/// <summary>
/// The debug connection provider if configured for using it, <see langword="null"/> otherwise.
/// Use <c>ActualFactory.ConnectionProvider</c> if needing unconditionally the connection provider, be
/// it debug or not.
/// </summary>
public DebugConnectionProvider DebugConnectionProvider { get; }
public ISessionFactoryImplementor ActualFactory { get; }

public EventListeners EventListeners => ((SessionFactoryImpl)ActualFactory).EventListeners;
Expand All @@ -44,7 +49,7 @@ public class DebugSessionFactory : ISessionFactoryImplementor
public DebugSessionFactory(ISessionFactory actualFactory)
{
ActualFactory = (ISessionFactoryImplementor)actualFactory;
ConnectionProvider = ActualFactory.ConnectionProvider as DebugConnectionProvider;
DebugConnectionProvider = ActualFactory.ConnectionProvider as DebugConnectionProvider;
}

#region Session tracking
Expand Down
104 changes: 58 additions & 46 deletions src/NHibernate.Test/Legacy/SQLFunctionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SQLFunctionsTest : TestCase

protected override IList Mappings
{
get { return new string[] {"Simple.hbm.xml", "Blobber.hbm.xml", "Broken.hbm.xml"}; }
get { return new string[] { "Simple.hbm.xml", "Blobber.hbm.xml", "Broken.hbm.xml" }; }
}

[Test]
Expand All @@ -33,7 +33,7 @@ public void DialectSQLFunctions()
.GetEnumerator();

if (Dialect is MySQLDialect
// Added two dialects below for NH
// Added two dialects below for NH
|| Dialect is MsSql2000Dialect
|| Dialect is PostgreSQLDialect)
{
Expand All @@ -50,20 +50,20 @@ public void DialectSQLFunctions()

// Test to make sure allocating an specified object operates correctly.
Assert.AreEqual(1,
s.CreateQuery("select new S(s.Count, s.Address) from s in class Simple").List()
.Count);
s.CreateQuery("select new S(s.Count, s.Address) from s in class Simple").List()
.Count);

// Quick check the base dialect functions operate correctly
Assert.AreEqual(1,
s.CreateQuery("select max(s.Count) from s in class Simple").List().Count);
s.CreateQuery("select max(s.Count) from s in class Simple").List().Count);
Assert.AreEqual(1,
s.CreateQuery("select count(*) from s in class Simple").List().Count);
s.CreateQuery("select count(*) from s in class Simple").List().Count);

if (Dialect is Oracle8iDialect)
{
// Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
IList rset = s.CreateQuery("select s.Name, sysdate, trunc(s.Pay), round(s.Pay) from s in class Simple").List();
object[] row = (object[]) rset[0];
object[] row = (object[])rset[0];
Assert.IsNotNull(row[0], "Name string should have been returned");
Assert.IsNotNull(row[1], "Todays Date should have been returned");
Assert.AreEqual(45f, row[2], "trunc(45.8) result was incorrect");
Expand All @@ -76,11 +76,6 @@ public void DialectSQLFunctions()
rset = s.CreateQuery("select abs(round(s.Pay)) from s in class Simple").List();
Assert.AreEqual(46f, rset[0], "abs(round(-45.8)) result was incorrect");

rset = s.CreateQuery("select left('abc', 2), right('abc', 2) from s in class Simple").List();
row = (object[]) rset[0];
Assert.AreEqual("ab", row[0], "Left function is broken.");
Assert.AreEqual("bc", row[1], "Right function is broken.");

// Test a larger depth 3 function example - Not a useful combo other than for testing
Assert.AreEqual(1,
s.CreateQuery("select trunc(round(length('A'))) from s in class Simple").List().Count);
Expand Down Expand Up @@ -109,14 +104,31 @@ public void DialectSQLFunctions()
s.Close();
}

[Test]
[Ignore("NH-3893 is not fixed")]
public void LeftAndRight()
{
// As of NH-3893, left and right functions are broken. Seemed confused with join keyword, and not
// supported on Hibernate side.
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
var rset = s.CreateQuery("select left('abc', 2), right('abc', 2) from s in class Simple").List<object[]>();
var row = rset[0];
Assert.AreEqual("ab", row[0], "Left function is broken.");
Assert.AreEqual("bc", row[1], "Right function is broken.");
t.Commit();
}
}

[Test]
public void SetProperties()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
Simple simple = new Simple();
simple.Name = "Simple 1";
s.Save(simple, (long) 10);
s.Save(simple, (long)10);
IQuery q = s.CreateQuery("from s in class Simple where s.Name=:Name and s.Count=:Count");
q.SetProperties(simple);
Assert.AreEqual(simple, q.List()[0]);
Expand Down Expand Up @@ -152,7 +164,7 @@ public void Broken()

s = OpenSession();
t = s.BeginTransaction();
b = (Broken) s.Load(typeof(Broken), b);
b = (Broken)s.Load(typeof(Broken), b);
t.Commit();
s.Close();

Expand All @@ -170,19 +182,19 @@ public void NothingToUpdate()
ITransaction t = s.BeginTransaction();
Simple simple = new Simple();
simple.Name = "Simple 1";
s.Save(simple, (long) 10);
s.Save(simple, (long)10);
t.Commit();
s.Close();

s = OpenSession();
t = s.BeginTransaction();
s.Update(simple, (long) 10);
s.Update(simple, (long)10);
t.Commit();
s.Close();

s = OpenSession();
t = s.BeginTransaction();
s.Update(simple, (long) 10);
s.Update(simple, (long)10);
s.Delete(simple);
t.Commit();
s.Close();
Expand Down Expand Up @@ -215,7 +227,7 @@ public void CachedQuery()
q.SetString("name", "Simple 1");
Assert.AreEqual(1, q.List().Count);

simple = (Simple) q.List()[0];
simple = (Simple)q.List()[0];

q.SetString("name", "Simple 2");
Assert.AreEqual(0, q.List().Count);
Expand Down Expand Up @@ -293,7 +305,7 @@ public void SQLFunctionAsAlias()
t = s.BeginTransaction();
IList result = s.CreateQuery(query).List();
Assert.IsTrue(result[0] is Simple,
"Unexpected result type [" + result[0].GetType().Name + "]");
"Unexpected result type [" + result[0].GetType().Name + "]");
s.Delete(result[0]);
t.Commit();
s.Close();
Expand Down Expand Up @@ -381,7 +393,7 @@ public void CachedQueryRegion()
q.SetCacheable(true);
q.SetString("name", "Simple 1");
Assert.AreEqual(1, q.List().Count);
simple = (Simple) q.List()[0];
simple = (Simple)q.List()[0];

q.SetString("name", "Simple 2");
Assert.AreEqual(0, q.List().Count);
Expand Down Expand Up @@ -419,7 +431,7 @@ public void SQLFunctions()
ITransaction t = s.BeginTransaction();
Simple simple = new Simple();
simple.Name = "Simple 1";
s.Save(simple, (long) 10);
s.Save(simple, (long)10);

if (Dialect is DB2Dialect)
{
Expand All @@ -430,23 +442,23 @@ public void SQLFunctions()

Assert.AreEqual(1, s.CreateQuery("from s in class Simple where upper(s.Name) = 'SIMPLE 1'").List().Count);
Assert.AreEqual(1,
s.CreateQuery(
"from s in class Simple where not( upper(s.Name)='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar')")
.List().Count);
s.CreateQuery(
"from s in class Simple where not( upper(s.Name)='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar')")
.List().Count);

if (!(Dialect is MySQLDialect) && !(Dialect is MsSql2000Dialect))
{
// Dialect.MckoiDialect and Dialect.InterbaseDialect also included
// My Sql has a funny concatenation operator
Assert.AreEqual(1,
s.CreateQuery("from s in class Simple where lower(s.Name || ' foo')='simple 1 foo'").List().Count);
s.CreateQuery("from s in class Simple where lower(s.Name || ' foo')='simple 1 foo'").List().Count);
}

if ((Dialect is MsSql2000Dialect))
{
Assert.AreEqual(1,
s.CreateQuery("from s in class Simple where lower( s.Name + ' foo' ) = 'simple 1 foo'").List().
Count);
s.CreateQuery("from s in class Simple where lower( s.Name + ' foo' ) = 'simple 1 foo'").List().
Count);
}

/*
Expand All @@ -461,46 +473,46 @@ public void SQLFunctions()
other.Name = "Simple 2";
other.Count = 12;
simple.Other = other;
s.Save(other, (long) 20);
s.Save(other, (long)20);
Assert.AreEqual(1, s.CreateQuery("from s in class Simple where upper( s.Other.Name )='SIMPLE 2'").List().Count);
Assert.AreEqual(0, s.CreateQuery("from s in class Simple where not (upper(s.Other.Name)='SIMPLE 2')").List().Count);
Assert.AreEqual(1,
s.CreateQuery(
"select distinct s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2")
.List().Count);
s.CreateQuery(
"select distinct s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2")
.List().Count);
Assert.AreEqual(1,
s.CreateQuery(
"select s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2 order by s.Other.Count")
.List().Count);
s.CreateQuery(
"select s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2 order by s.Other.Count")
.List().Count);

Simple min = new Simple();
min.Count = -1;

s.Save(min, (long) 30);
s.Save(min, (long)30);

if (Dialect.SupportsSubSelects && TestDialect.SupportsOperatorSome)
{
Assert.AreEqual(2,
s.CreateQuery(
"from s in class Simple where s.Count > ( select min(sim.Count) from sim in class NHibernate.DomainModel.Simple )")
.List().Count);
s.CreateQuery(
"from s in class Simple where s.Count > ( select min(sim.Count) from sim in class NHibernate.DomainModel.Simple )")
.List().Count);
t.Commit();
t = s.BeginTransaction();
Assert.AreEqual(2,
s.CreateQuery(
"from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Count>=0) and s.Count >= 0")
.List().Count);
s.CreateQuery(
"from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Count>=0) and s.Count >= 0")
.List().Count);
Assert.AreEqual(1,
s.CreateQuery(
"from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Other.Count=s.Other.Count ) and s.Other.Count > 0")
.List().Count);
s.CreateQuery(
"from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Other.Count=s.Other.Count ) and s.Other.Count > 0")
.List().Count);
}

IEnumerator enumer =
s.CreateQuery("select sum(s.Count) from s in class Simple group by s.Count having sum(s.Count) > 10 ").Enumerable()
.GetEnumerator();
Assert.IsTrue(enumer.MoveNext());
Assert.AreEqual(12, (Int64) enumer.Current); // changed cast from Int32 to Int64 (H3.2)
Assert.AreEqual(12, (Int64)enumer.Current); // changed cast from Int32 to Int64 (H3.2)
Assert.IsFalse(enumer.MoveNext());

if (Dialect.SupportsSubSelects)
Expand Down Expand Up @@ -568,7 +580,7 @@ public void SQLFunctions()
list.Add("Simple 1");
list.Add("foo");
q.SetParameterList("name_list", list);
q.SetParameter("count", (int) -1);
q.SetParameter("count", (int)-1);
Assert.AreEqual(1, q.List().Count);

s.Delete(other);
Expand Down
2 changes: 2 additions & 0 deletions src/NHibernate.Test/Linq/ByMethod/GroupByTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,8 @@ public void GroupByComputedValueInObjectArrayWithJoinInRightSideOfCase()
Assert.Ignore("SQL Server seems unable to match complex group by and select list arguments when running over ODBC.");
if (Dialect is MsSqlCeDialect)
Assert.Ignore("SQL Server CE does not support complex group by expressions.");
if (Dialect is Oracle8iDialect)
Assert.Ignore("ORA-12704: character set mismatch. Due to NHibernate creating Unicode string types as NVarchar2 but querying them as Varchar2.");

var orderGroups = db.OrderLines.GroupBy(o => new[] { o.Order.Customer.CustomerId == null ? "unknown" : o.Order.Customer.CompanyName }).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
Assert.AreEqual(2155, orderGroups.Sum(g => g.Count));
Expand Down
45 changes: 35 additions & 10 deletions src/NHibernate.Test/Linq/MiscellaneousTextFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using NHibernate.Dialect;
using NHibernate.Linq;
using NHibernate.DomainModel.Northwind.Entities;
using NUnit.Framework;
Expand Down Expand Up @@ -86,16 +87,17 @@ public void ReferenceToOuter()
"the second, third and fourth pages of products")]
public void TriplePageSelection()
{
IQueryable<Product> q = (
from p in db.Products
where p.ProductId > 1
orderby p.ProductId
select p
);
var q =
from p in db.Products
where p.ProductId > 1
orderby p.ProductId
select p;

IQueryable<Product> page2 = q.Skip(5).Take(5);
IQueryable<Product> page3 = q.Skip(10).Take(5);
IQueryable<Product> page4 = q.Skip(15).Take(5);
// ToList required otherwise the First call alters the paging and test something else than paging three pages,
// contrary o the test above description.
var page2 = q.Skip(5).Take(5).ToList();
var page3 = q.Skip(10).Take(5).ToList();
var page4 = q.Skip(15).Take(5).ToList();

var firstResultOnPage2 = page2.First();
var firstResultOnPage3 = page3.First();
Expand All @@ -106,7 +108,30 @@ select p
Assert.AreNotEqual(firstResultOnPage2.ProductId, firstResultOnPage4.ProductId);
}

[Test]
[Category("Paging")]
[Test(Description = "NH-4061 - This sample uses a where clause and the Skip and Take operators to select " +
"the second, third and fourth pages of products, but then add a First causing the Take to be pointless.")]
public void TriplePageSelectionWithFirst()
{
if (Dialect is Oracle8iDialect)
Assert.Ignore("Not fixed: NH-4061 - Pointless Take calls screw Oracle dialect paging.");

var q =
from p in db.Products
where p.ProductId > 1
orderby p.ProductId
select p;

var firstResultOnPage2 = q.Skip(5).Take(5).First();
var firstResultOnPage3 = q.Skip(10).Take(5).First();
var firstResultOnPage4 = q.Skip(15).Take(5).First();

Assert.AreNotEqual(firstResultOnPage2.ProductId, firstResultOnPage3.ProductId);
Assert.AreNotEqual(firstResultOnPage3.ProductId, firstResultOnPage4.ProductId);
Assert.AreNotEqual(firstResultOnPage2.ProductId, firstResultOnPage4.ProductId);
}

[Test]
public void SelectFromObject()
{
using (var s = OpenSession())
Expand Down
6 changes: 6 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH1792/Fixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using NHibernate.Criterion;
using NHibernate.Dialect;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH1792
Expand Down Expand Up @@ -79,6 +80,11 @@ public void PageWithDetachedCriteriaSubqueryWithOrderBy()
[Test]
public void PageWithRawSqlSubqueryWithOrderBy()
{
// Theoretically, the ordering of elements in a "where col in (elements)" should not change anything.
// That is not the case for SQL Server, but Oracle just refuses any ordering there.
if (Dialect is Oracle8iDialect)
Assert.Ignore("Oracle does not support pointless order by");

using (ISession session = OpenSession())
{
string top = "";
Expand Down
9 changes: 7 additions & 2 deletions src/NHibernate.Test/NHSpecificTest/NH1985/SampleTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using System;
using System.Data.Common;
using NHibernate.Connection;
using NHibernate.Dialect;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH1985
{
[TestFixture]
public class SampleTest : BugTestCase
{
protected override bool AppliesTo(Dialect.Dialect dialect)
{
// Test written with raw SQL queries, not compatible with all databases.
return dialect is MsSql2000Dialect;
}

protected override void OnSetUp()
{
if (0 == ExecuteStatement("INSERT INTO DomainClass (Id, Label) VALUES (1, 'TEST record');"))
Expand Down
Loading