Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions src/AsyncGenerator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
- conversion: Ignore
name: GetEnumerator
containingTypeName: IFutureEnumerable
# TODO 6.0: Consider if ComputeFlattenedParameters should remain ignored or not
- conversion: Ignore
name: ComputeFlattenedParameters
containingTypeName: SqlQueryImpl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ignoring it would cause an interface change by adding an async counterpart to a method belonging to an interface.

Moreover it generates an async counterpart due to a second level cache check, which would incurs IO only if a distributed cache is enabled.
There is also an IType.GetPropertyValue call which has an async counterpart, but it is called only on component types which currently have a fully synchronous implementation for it.

- conversion: ToAsync
name: ExecuteReader
containingTypeName: IBatcher
Expand Down
246 changes: 246 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/NH3079/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH3079
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
// Disable second level cache
protected override string CacheConcurrencyStrategy => null;

protected override void OnTearDown()
{
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
s.CreateQuery("delete from Employment").ExecuteUpdate();

s.CreateQuery("delete from System.Object").ExecuteUpdate();

t.Commit();
}
}

protected override void OnSetUp()
{
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
var personList = new List<Person>();
var employerList = new List<Employer>();

// Global id to avoid false positive assertion with positional parameter
var gId = 1;

for (var i = 0; i < 3; i++)
{
var personCpId = new PersonCpId { IdA = gId++, IdB = gId++ };
var personObj = new Person
{ CpId = personCpId, Name = "PERSON_" + personCpId.IdA + "_" + personCpId.IdB };
s.Save(personObj);
personList.Add(personObj);
}

for (var i = 0; i < 3; i++)
{
var employerCpId = new EmployerCpId { IdA = gId++, IdB = gId++ };
var employerObj = new Employer
{ CpId = employerCpId, Name = "EMPLOYER_" + employerCpId.IdA + "_" + employerCpId.IdB };
s.Save(employerObj);
employerList.Add(employerObj);
}

var employmentIds = new[]
{
gId++,
gId++,
gId++,
gId++,
};
var employmentNames = new[]
{
//P1 + E1
"EMPLOYMENT_" + employmentIds[0] + "_" +
personList[0].CpId.IdA + "_" + personList[0].CpId.IdA + "_" +
employerList[0].CpId.IdA + "_" + employerList[0].CpId.IdB,
//P1 + E2
"EMPLOYMENT_" + employmentIds[1] + "_" +
personList[0].CpId.IdA + "_" + personList[0].CpId.IdA + "_" +
employerList[1].CpId.IdA + "_" + employerList[1].CpId.IdB,
//P2 + E2
"EMPLOYMENT_" + employmentIds[2] + "_" +
personList[1].CpId.IdA + "_" + personList[1].CpId.IdA + "_" +
employerList[1].CpId.IdA + "_" + employerList[1].CpId.IdB,
//P2 + E3
"EMPLOYMENT_" + employmentIds[2] + "_" +
personList[1].CpId.IdA + "_" + personList[1].CpId.IdA + "_" +
employerList[2].CpId.IdA + "_" + employerList[2].CpId.IdB
};
var employmentPersons = new[]
{
personList[0],
personList[0],
personList[1],
personList[1]
};
var employmentEmployers = new[]
{
employerList[0],
employerList[1],
employerList[1],
employerList[2]
};

for (var k = 0; k < employmentIds.Length; k++)
{
var employmentCpId = new EmploymentCpId
{
Id = employmentIds[k],
PersonObj = employmentPersons[k],
EmployerObj = employmentEmployers[k]
};
var employmentObj = new Employment { CpId = employmentCpId, Name = employmentNames[k] };
s.Save(employmentObj);
}

for (var i = 0; i < 3; i++)
{
var personNoComponentObj = new PersonNoComponent { IdA = gId++, IdB = gId++ };
personNoComponentObj.Name = "PERSON_NO_COMPONENT_" + personNoComponentObj.IdA + "_" +
personNoComponentObj.IdB;
s.Save(personNoComponentObj);
}

t.Commit();
}
}

// Test reproducing the problem.
[Test]
public async Task GetPersonTestAsync()
{
using (var session = OpenSession())
{
var person1_2 = await (session.GetAsync<Person>(new PersonCpId { IdA = 1, IdB = 2 }));
Assert.That(person1_2.Name, Is.EqualTo("PERSON_1_2"));
Assert.That(
person1_2.EmploymentList.Select(e => e.Name),
Is.EquivalentTo(new[] { "EMPLOYMENT_13_1_1_7_8", "EMPLOYMENT_14_1_1_9_10" }));
}
}

// Test reproducing the problem.
[Test]
public async Task GetEmployerTestAsync()
{
using (var session = OpenSession())
{
var employer7_8 = await (session.GetAsync<Employer>(new EmployerCpId { IdA = 7, IdB = 8 }));
Assert.That(employer7_8.Name, Is.EqualTo("EMPLOYER_7_8"));
Assert.That(
employer7_8.EmploymentList.Select(e => e.Name),
Is.EquivalentTo(new[] { "EMPLOYMENT_13_1_1_7_8" }));
}
}

[Test]
public async Task GetEmploymentTestAsync()
{
using (var session = OpenSession())
{
var employment_13_1_2_7_8 =
await (session.GetAsync<Employment>(
new EmploymentCpId
{
Id = 13,
PersonObj =
new Person
{
CpId = new PersonCpId { IdA = 1, IdB = 2 }
},
EmployerObj =
new Employer
{
CpId = new EmployerCpId { IdA = 7, IdB = 8 }
}
}));
Assert.That(employment_13_1_2_7_8.Name, Is.EqualTo("EMPLOYMENT_13_1_1_7_8"));
}
}

[Test]
public async Task HqlPersonPositionalAsync()
{
using (var session = OpenSession())
{
var personList =
await (session
.GetNamedQuery("personPositional")
.SetParameter(0, new PersonCpId { IdA = 1, IdB = 2 })
.SetParameter(1, new PersonCpId { IdA = 3, IdB = 4 })
.ListAsync<Person>());
Assert.That(
personList.Select(e => e.Name),
Is.EquivalentTo(new[] { "PERSON_1_2", "PERSON_3_4" }));
}
}

[Test]
public async Task HqlPersonNamedAsync()
{
using (var session = OpenSession())
{
var personList =
await (session
.GetNamedQuery("personNamed")
.SetParameter("id1", new PersonCpId { IdA = 1, IdB = 2 })
.SetParameter("id2", new PersonCpId { IdA = 3, IdB = 4 })
.ListAsync<Person>());
Assert.That(
personList.Select(e => e.Name),
Is.EquivalentTo(new[] { "PERSON_1_2", "PERSON_3_4" }));
}
}

[Test]
public async Task GetPersonNoComponentAsync()
{
using (var session = OpenSession())
{
var person17_18 =
await (session.GetAsync<PersonNoComponent>(new PersonNoComponent { IdA = 17, IdB = 18 }));
Assert.That(person17_18.Name, Is.EqualTo("PERSON_NO_COMPONENT_17_18"));
}
}

[Test]
public async Task SqlPersonNoComponentAsync()
{
using (var session = OpenSession())
{
var personList =
await (session
.GetNamedQuery("personNoComponentSql")
.SetParameter(0, new PersonNoComponent { IdA = 17, IdB = 18 })
.SetParameter(1, new PersonNoComponent { IdA = 19, IdB = 20 })
.ListAsync<PersonNoComponent>());
Assert.That(
personList.Select(e => e.Name),
Is.EquivalentTo(new[] { "PERSON_NO_COMPONENT_17_18", "PERSON_NO_COMPONENT_19_20" }));
}
}
}
}
13 changes: 13 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3079/Employer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.NH3079
{
public class Employer
{
public virtual EmployerCpId CpId { get; set; }

public virtual string Name { get; set; }

public virtual ICollection<Employment> EmploymentList { get; set; }
}
}
22 changes: 22 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3079/EmployerCpId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace NHibernate.Test.NHSpecificTest.NH3079
{
public class EmployerCpId
{
public virtual int IdA { get; set; }

public virtual int IdB { get; set; }

public override bool Equals(object obj)
{
if (!(obj is EmployerCpId objCpId))
return false;

return IdA == objCpId.IdA && IdB == objCpId.IdB;
}

public override int GetHashCode()
{
return IdA.GetHashCode() ^ IdB.GetHashCode();
}
}
}
9 changes: 9 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3079/Employment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NHibernate.Test.NHSpecificTest.NH3079
{
public class Employment
{
public virtual EmploymentCpId CpId { get; set; }

public virtual string Name { get; set; }
}
}
25 changes: 25 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3079/EmploymentCpId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace NHibernate.Test.NHSpecificTest.NH3079
{
public class EmploymentCpId
{
public virtual int Id { get; set; }

public virtual Person PersonObj { get; set; }

public virtual Employer EmployerObj { get; set; }

public override bool Equals(object obj)
{
if (!(obj is EmploymentCpId objCpId))
return false;

return Id == objCpId.Id && PersonObj.CpId == objCpId.PersonObj.CpId &&
EmployerObj.CpId == objCpId.EmployerObj.CpId;
}

public override int GetHashCode()
{
return Id.GetHashCode() ^ PersonObj.CpId.GetHashCode() ^ EmployerObj.CpId.GetHashCode();
}
}
}
Loading