From 646c8c22a7342a636c318788651fe2a698cb4566 Mon Sep 17 00:00:00 2001 From: Gunnar Liljas Date: Wed, 2 Jan 2019 20:04:21 +0100 Subject: [PATCH] Move discovery of executedSpaces to RegisterCleanupActions --- .../SecondLevelCacheTest/InvalidationTests.cs | 39 ++++++++++++++++++- .../SecondLevelCacheTest/InvalidationTests.cs | 39 ++++++++++++++++++- src/NHibernate/Async/Engine/ActionQueue.cs | 4 -- src/NHibernate/Engine/ActionQueue.cs | 8 ++-- 4 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/NHibernate.Test/Async/SecondLevelCacheTest/InvalidationTests.cs b/src/NHibernate.Test/Async/SecondLevelCacheTest/InvalidationTests.cs index a998399d52a..e29df97a8b8 100644 --- a/src/NHibernate.Test/Async/SecondLevelCacheTest/InvalidationTests.cs +++ b/src/NHibernate.Test/Async/SecondLevelCacheTest/InvalidationTests.cs @@ -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; @@ -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)) @@ -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)) @@ -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)) @@ -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() + .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")); } diff --git a/src/NHibernate.Test/SecondLevelCacheTest/InvalidationTests.cs b/src/NHibernate.Test/SecondLevelCacheTest/InvalidationTests.cs index 8b05b53fbef..47b6d76d2bd 100644 --- a/src/NHibernate.Test/SecondLevelCacheTest/InvalidationTests.cs +++ b/src/NHibernate.Test/SecondLevelCacheTest/InvalidationTests.cs @@ -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; @@ -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)) @@ -58,6 +60,7 @@ public void InvalidatesEntities() tx.Commit(); } + //Update Item using (var tx = session.BeginTransaction()) { foreach (var i in Enumerable.Range(1, 10)) @@ -69,6 +72,7 @@ public void InvalidatesEntities() tx.Commit(); } + //Delete Item using (var tx = session.BeginTransaction()) { foreach (var i in Enumerable.Range(1, 10)) @@ -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() + .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")); } diff --git a/src/NHibernate/Async/Engine/ActionQueue.cs b/src/NHibernate/Async/Engine/ActionQueue.cs index 204ba7cd8d6..164a833a3ac 100644 --- a/src/NHibernate/Async/Engine/ActionQueue.cs +++ b/src/NHibernate/Async/Engine/ActionQueue.cs @@ -82,10 +82,6 @@ private async Task InnerExecuteAsync(IExecutable executable, CancellationToken c } finally { - if (executable.PropertySpaces != null) - { - executedSpaces.UnionWith(executable.PropertySpaces); - } RegisterCleanupActions(executable); } } diff --git a/src/NHibernate/Engine/ActionQueue.cs b/src/NHibernate/Engine/ActionQueue.cs index 4858122d2f0..5c33537779c 100644 --- a/src/NHibernate/Engine/ActionQueue.cs +++ b/src/NHibernate/Engine/ActionQueue.cs @@ -199,10 +199,6 @@ private void InnerExecute(IExecutable executable) } finally { - if (executable.PropertySpaces != null) - { - executedSpaces.UnionWith(executable.PropertySpaces); - } RegisterCleanupActions(executable); } } @@ -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); + } } ///