Skip to content

Commit

Permalink
Move discovery of executedSpaces to RegisterCleanupActions
Browse files Browse the repository at this point in the history
  • Loading branch information
gliljas authored and fredericDelaporte committed Jan 6, 2019
1 parent 92d9b07 commit 646c8c2
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using NHibernate.Cache;
using NHibernate.Cfg;
using NHibernate.Impl;
using NHibernate.Linq;
using NHibernate.Test.SecondLevelCacheTests;
using NSubstitute;
using NUnit.Framework;
Expand Down Expand Up @@ -59,6 +60,7 @@ public async Task InvalidatesEntitiesAsync()

using (var session = OpenSession())
{
//Add Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -70,6 +72,7 @@ public async Task InvalidatesEntitiesAsync()
await (tx.CommitAsync());
}

//Update Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -81,6 +84,7 @@ public async Task InvalidatesEntitiesAsync()
await (tx.CommitAsync());
}

//Delete Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -91,13 +95,44 @@ public async Task InvalidatesEntitiesAsync()

await (tx.CommitAsync());
}

//Update Item using HQL
using (var tx = session.BeginTransaction())
{
await (session.CreateQuery("UPDATE Item SET Name='Test'").ExecuteUpdateAsync());

await (tx.CommitAsync());
}


//Update Item using LINQ
using (var tx = session.BeginTransaction())
{
await (session.Query<Item>()
.UpdateBuilder()
.Set(x => x.Name, "Test")
.UpdateAsync(CancellationToken.None));

await (tx.CommitAsync());
}

//Update Item using SQL
using (var tx = session.BeginTransaction())
{
await (session.CreateSQLQuery("UPDATE Item SET Name='Test'")
.AddSynchronizedQuerySpace("Item")
.ExecuteUpdateAsync());

await (tx.CommitAsync());
}
}

//Should receive one preinvalidation and one invalidation per commit
//Should receive one preinvalidation per non-DML commit
Assert.That(preInvalidations, Has.Count.EqualTo(3));
Assert.That(preInvalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));

Assert.That(invalidations, Has.Count.EqualTo(3));
///...and one invalidation per commit
Assert.That(invalidations, Has.Count.EqualTo(6));
Assert.That(invalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));
}

Expand Down
39 changes: 37 additions & 2 deletions src/NHibernate.Test/SecondLevelCacheTest/InvalidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NHibernate.Cache;
using NHibernate.Cfg;
using NHibernate.Impl;
using NHibernate.Linq;
using NHibernate.Test.SecondLevelCacheTests;
using NSubstitute;
using NUnit.Framework;
Expand Down Expand Up @@ -47,6 +48,7 @@ public void InvalidatesEntities()

using (var session = OpenSession())
{
//Add Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -58,6 +60,7 @@ public void InvalidatesEntities()
tx.Commit();
}

//Update Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -69,6 +72,7 @@ public void InvalidatesEntities()
tx.Commit();
}

//Delete Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -79,13 +83,44 @@ public void InvalidatesEntities()

tx.Commit();
}

//Update Item using HQL
using (var tx = session.BeginTransaction())
{
session.CreateQuery("UPDATE Item SET Name='Test'").ExecuteUpdate();

tx.Commit();
}


//Update Item using LINQ
using (var tx = session.BeginTransaction())
{
session.Query<Item>()
.UpdateBuilder()
.Set(x => x.Name, "Test")
.Update();

tx.Commit();
}

//Update Item using SQL
using (var tx = session.BeginTransaction())
{
session.CreateSQLQuery("UPDATE Item SET Name='Test'")
.AddSynchronizedQuerySpace("Item")
.ExecuteUpdate();

tx.Commit();
}
}

//Should receive one preinvalidation and one invalidation per commit
//Should receive one preinvalidation per non-DML commit
Assert.That(preInvalidations, Has.Count.EqualTo(3));
Assert.That(preInvalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));

Assert.That(invalidations, Has.Count.EqualTo(3));
///...and one invalidation per commit
Assert.That(invalidations, Has.Count.EqualTo(6));
Assert.That(invalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));
}

Expand Down
4 changes: 0 additions & 4 deletions src/NHibernate/Async/Engine/ActionQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ private async Task InnerExecuteAsync(IExecutable executable, CancellationToken c
}
finally
{
if (executable.PropertySpaces != null)
{
executedSpaces.UnionWith(executable.PropertySpaces);
}
RegisterCleanupActions(executable);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate/Engine/ActionQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ private void InnerExecute(IExecutable executable)
}
finally
{
if (executable.PropertySpaces != null)
{
executedSpaces.UnionWith(executable.PropertySpaces);
}
RegisterCleanupActions(executable);
}
}
Expand All @@ -221,6 +217,10 @@ private void RegisterCleanupActions(IExecutable executable)
RegisterProcess(executable.AfterTransactionCompletionProcess);
#pragma warning restore 618,619
}
if (executable.PropertySpaces != null)
{
executedSpaces.UnionWith(executable.PropertySpaces);
}
}

/// <summary>
Expand Down

0 comments on commit 646c8c2

Please sign in to comment.