-
Notifications
You must be signed in to change notification settings - Fork 933
Fix stateless batcher #2755
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
Fix stateless batcher #2755
Changes from all commits
3f7dedb
61a2e9d
d0f6cde
305b89a
a1162cf
94e37c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Transactions; | ||
using NHibernate.Cfg; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2750 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class ByCodeFixtureAsync : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<TestEntity>(rc => { rc.Id(x => x.Id, m => m.Generator(Generators.Assigned)); }); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void Configure(Configuration configuration) | ||
{ | ||
configuration.SetProperty(Cfg.Environment.BatchSize, 10.ToString()); | ||
configuration.SetProperty(Cfg.Environment.UseConnectionOnSystemTransactionPrepare, true.ToString()); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ShouldWorkWithOuterSystemTransactionAsync() | ||
{ | ||
if (!Sfi.ConnectionProvider.Driver.SupportsSystemTransactions) | ||
Assert.Ignore("System.Transactions support is required by this test"); | ||
|
||
const int count = 3; | ||
var entities = new List<TestEntity>(count); | ||
for (var i = 0; i < count; i++) | ||
{ | ||
entities.Add(new TestEntity { Id = Guid.NewGuid() }); | ||
} | ||
|
||
using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) | ||
{ | ||
using (var session = Sfi.OpenStatelessSession()) | ||
{ | ||
foreach (var entity in entities) | ||
{ | ||
await (session.InsertAsync(entity)); | ||
} | ||
} | ||
|
||
transaction.Complete(); | ||
} | ||
|
||
using (var session = OpenSession()) | ||
{ | ||
var results = await (session.QueryOver<TestEntity>().ListAsync<TestEntity>()); | ||
|
||
Assert.That(results.Count, Is.EqualTo(count)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ShouldWorkWithInnerSystemTransactionAsync() | ||
{ | ||
if (!Sfi.ConnectionProvider.Driver.SupportsSystemTransactions) | ||
Assert.Ignore("System.Transactions support is required by this test"); | ||
|
||
const int count = 3; | ||
var entities = new List<TestEntity>(count); | ||
for (var i = 0; i < count; i++) | ||
{ | ||
entities.Add(new TestEntity { Id = Guid.NewGuid() }); | ||
} | ||
|
||
using (var session = Sfi.OpenStatelessSession()) | ||
{ | ||
using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) | ||
{ | ||
foreach (var entity in entities) | ||
{ | ||
await (session.InsertAsync(entity)); | ||
} | ||
await (session.FlushBatcherAsync()); | ||
|
||
transaction.Complete(); | ||
} | ||
} | ||
|
||
using (var session = OpenSession()) | ||
{ | ||
var results = await (session.QueryOver<TestEntity>().ListAsync<TestEntity>()); | ||
|
||
Assert.That(results.Count, Is.EqualTo(count)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ShouldWorkWithoutTransactionAsync() | ||
{ | ||
const int count = 3; | ||
var entities = new List<TestEntity>(count); | ||
for (var i = 0; i < count; i++) | ||
{ | ||
entities.Add(new TestEntity { Id = Guid.NewGuid() }); | ||
} | ||
|
||
using (var session = Sfi.OpenStatelessSession()) | ||
{ | ||
foreach (var entity in entities) | ||
{ | ||
await (session.InsertAsync(entity)); | ||
} | ||
} | ||
|
||
using (var session = OpenSession()) | ||
{ | ||
var results = await (session.QueryOver<TestEntity>().ListAsync<TestEntity>()); | ||
|
||
Assert.That(results.Count, Is.EqualTo(count)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ShouldGetEntityAfterInsertAsync() | ||
{ | ||
var entity = new TestEntity { Id = Guid.NewGuid() }; | ||
using (var session = Sfi.OpenStatelessSession()) | ||
{ | ||
await (session.InsertAsync(entity)); | ||
Assert.That(await (session.GetAsync<TestEntity>(entity.Id)), Is.Not.Null); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ShouldQueryEntityAfterInsertAsync() | ||
{ | ||
var entity = new TestEntity { Id = Guid.NewGuid() }; | ||
using (var session = Sfi.OpenStatelessSession()) | ||
{ | ||
await (session.InsertAsync(entity)); | ||
Assert.That(await (session.Query<TestEntity>().FirstOrDefaultAsync(e => e.Id == entity.Id)), Is.Not.Null); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ShouldQueryOverEntityAfterInsertAsync() | ||
{ | ||
var entity = new TestEntity { Id = Guid.NewGuid() }; | ||
using (var session = Sfi.OpenStatelessSession()) | ||
{ | ||
await (session.InsertAsync(entity)); | ||
Assert.That(await (session.QueryOver<TestEntity>().Where(e => e.Id == entity.Id).SingleOrDefaultAsync()), Is.Not.Null); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ShouldHqlQueryEntityAfterInsertAsync() | ||
{ | ||
var entity = new TestEntity { Id = Guid.NewGuid() }; | ||
using (var session = Sfi.OpenStatelessSession()) | ||
{ | ||
await (session.InsertAsync(entity)); | ||
Assert.That(await (session.CreateQuery("from TestEntity where Id = :id").SetGuid("id", entity.Id).UniqueResultAsync()), Is.Not.Null); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2750 | ||
{ | ||
public class TestEntity | ||
{ | ||
public virtual Guid Id { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,179 @@ | ||||||||||||||||||||||||||
using System; | ||||||||||||||||||||||||||
using System.Collections.Generic; | ||||||||||||||||||||||||||
using System.Linq; | ||||||||||||||||||||||||||
using System.Transactions; | ||||||||||||||||||||||||||
using NHibernate.Cfg; | ||||||||||||||||||||||||||
using NHibernate.Cfg.MappingSchema; | ||||||||||||||||||||||||||
using NHibernate.Mapping.ByCode; | ||||||||||||||||||||||||||
using NUnit.Framework; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
namespace NHibernate.Test.NHSpecificTest.GH2750 | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
[TestFixture] | ||||||||||||||||||||||||||
public class ByCodeFixture : TestCaseMappingByCode | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
protected override HbmMapping GetMappings() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var mapper = new ModelMapper(); | ||||||||||||||||||||||||||
mapper.Class<TestEntity>(rc => { rc.Id(x => x.Id, m => m.Generator(Generators.Assigned)); }); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
protected override void Configure(Configuration configuration) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
configuration.SetProperty(Cfg.Environment.BatchSize, 10.ToString()); | ||||||||||||||||||||||||||
configuration.SetProperty(Cfg.Environment.UseConnectionOnSystemTransactionPrepare, true.ToString()); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
protected override void OnTearDown() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
using (var session = OpenSession()) | ||||||||||||||||||||||||||
using (var transaction = session.BeginTransaction()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
transaction.Commit(); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
[Test] | ||||||||||||||||||||||||||
public void ShouldWorkWithOuterSystemTransaction() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
if (!Sfi.ConnectionProvider.Driver.SupportsSystemTransactions) | ||||||||||||||||||||||||||
Assert.Ignore("System.Transactions support is required by this test"); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const int count = 3; | ||||||||||||||||||||||||||
var entities = new List<TestEntity>(count); | ||||||||||||||||||||||||||
for (var i = 0; i < count; i++) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
entities.Add(new TestEntity { Id = Guid.NewGuid() }); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
using (var transaction = new TransactionScope()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
using (var session = Sfi.OpenStatelessSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
foreach (var entity in entities) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
session.Insert(entity); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
transaction.Complete(); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
using (var session = OpenSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var results = session.QueryOver<TestEntity>().List<TestEntity>(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Assert.That(results.Count, Is.EqualTo(count)); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
[Test] | ||||||||||||||||||||||||||
public void ShouldWorkWithInnerSystemTransaction() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
if (!Sfi.ConnectionProvider.Driver.SupportsSystemTransactions) | ||||||||||||||||||||||||||
Assert.Ignore("System.Transactions support is required by this test"); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const int count = 3; | ||||||||||||||||||||||||||
var entities = new List<TestEntity>(count); | ||||||||||||||||||||||||||
for (var i = 0; i < count; i++) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
entities.Add(new TestEntity { Id = Guid.NewGuid() }); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
using (var session = Sfi.OpenStatelessSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
using (var transaction = new TransactionScope()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
foreach (var entity in entities) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
session.Insert(entity); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
session.FlushBatcher(); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I choosed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wanted to clarify that I'm not talking about the general There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of the stateless session, that is the same. But anyway, what does it mean, nhibernate-core/src/NHibernate/Impl/StatelessSessionImpl.cs Lines 385 to 396 in 2bd3c16
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
transaction.Complete(); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
using (var session = OpenSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var results = session.QueryOver<TestEntity>().List<TestEntity>(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Assert.That(results.Count, Is.EqualTo(count)); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
[Test] | ||||||||||||||||||||||||||
public void ShouldWorkWithoutTransaction() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
const int count = 3; | ||||||||||||||||||||||||||
var entities = new List<TestEntity>(count); | ||||||||||||||||||||||||||
for (var i = 0; i < count; i++) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
entities.Add(new TestEntity { Id = Guid.NewGuid() }); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
using (var session = Sfi.OpenStatelessSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
foreach (var entity in entities) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
session.Insert(entity); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
using (var session = OpenSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var results = session.QueryOver<TestEntity>().List<TestEntity>(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Assert.That(results.Count, Is.EqualTo(count)); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
[Test] | ||||||||||||||||||||||||||
public void ShouldGetEntityAfterInsert() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var entity = new TestEntity { Id = Guid.NewGuid() }; | ||||||||||||||||||||||||||
using (var session = Sfi.OpenStatelessSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
session.Insert(entity); | ||||||||||||||||||||||||||
Assert.That(session.Get<TestEntity>(entity.Id), Is.Not.Null); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
[Test] | ||||||||||||||||||||||||||
public void ShouldQueryEntityAfterInsert() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var entity = new TestEntity { Id = Guid.NewGuid() }; | ||||||||||||||||||||||||||
using (var session = Sfi.OpenStatelessSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
session.Insert(entity); | ||||||||||||||||||||||||||
Assert.That(session.Query<TestEntity>().FirstOrDefault(e => e.Id == entity.Id), Is.Not.Null); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
[Test] | ||||||||||||||||||||||||||
public void ShouldQueryOverEntityAfterInsert() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var entity = new TestEntity { Id = Guid.NewGuid() }; | ||||||||||||||||||||||||||
using (var session = Sfi.OpenStatelessSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
session.Insert(entity); | ||||||||||||||||||||||||||
Assert.That(session.QueryOver<TestEntity>().Where(e => e.Id == entity.Id).SingleOrDefault(), Is.Not.Null); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
[Test] | ||||||||||||||||||||||||||
public void ShouldHqlQueryEntityAfterInsert() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var entity = new TestEntity { Id = Guid.NewGuid() }; | ||||||||||||||||||||||||||
using (var session = Sfi.OpenStatelessSession()) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
session.Insert(entity); | ||||||||||||||||||||||||||
Assert.That(session.CreateQuery("from TestEntity where Id = :id").SetGuid("id", entity.Id).UniqueResult(), Is.Not.Null); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.