-
Notifications
You must be signed in to change notification settings - Fork 934
Reduce the number of calls to UpdateTimestampsCache #1467
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
Changes from all commits
391d231
616a1dd
38e569c
bcf4965
5878986
7b04696
b0c5aa2
7e3b9fc
3defece
4f24faa
9607294
63dc8cd
181bba1
298bb22
ed63678
93ae332
fd5c66e
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 |
---|---|---|
|
@@ -4,8 +4,6 @@ | |
applyChanges: true | ||
analyzation: | ||
methodConversion: | ||
- conversion: Ignore | ||
hasAttributeName: ObsoleteAttribute | ||
- conversion: Ignore | ||
name: PostProcessInsert | ||
containingTypeName: HqlSqlWalker | ||
|
@@ -96,6 +94,9 @@ | |
- conversion: Ignore | ||
name: Exists | ||
containingTypeName: AbstractCollectionPersister | ||
- conversion: Ignore | ||
name: QuoteTableAndColumns | ||
containingTypeName: SchemaMetadataUpdater | ||
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. This method was obsoleted in 5.0, and did not have an async counterpart, so ignore it explicitly. |
||
- conversion: ToAsync | ||
name: ExecuteReader | ||
containingTypeName: IBatcher | ||
|
@@ -119,6 +120,8 @@ | |
- name: GetFieldValue | ||
- name: IsDBNull | ||
- name: WriteLine | ||
ignoreAsyncCounterparts: | ||
- rule: Obsolete | ||
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. New from 0.7.0. From now on we want to generate async counterparts for obsolete members, but do not want to call them. Also, we would want to add obsolete members by hands where they ceased to be generated. |
||
callForwarding: true | ||
cancellationTokens: | ||
guards: true | ||
|
@@ -259,6 +262,9 @@ methodRules: | |
- containingType: NHibernate.Tool.hbm2ddl.SchemaValidator | ||
- containingType: NHibernate.Tool.hbm2ddl.SchemaExport | ||
name: PubliclyExposedType | ||
- filters: | ||
- hasAttributeName: ObsoleteAttribute | ||
name: Obsolete | ||
typeRules: | ||
- filters: | ||
- containingAssemblyName: NHibernate | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using NHibernate.Cache; | ||
using NHibernate.Cfg; | ||
using NHibernate.Engine; | ||
using NHibernate.Impl; | ||
using NHibernate.Test.SecondLevelCacheTests; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.SecondLevelCacheTest | ||
{ | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
[TestFixture] | ||
public class InvalidationTestsAsync : TestCase | ||
{ | ||
protected override string MappingsAssembly => "NHibernate.Test"; | ||
|
||
protected override IList Mappings => new[] { "SecondLevelCacheTest.Item.hbm.xml" }; | ||
|
||
protected override void Configure(Configuration configuration) | ||
{ | ||
configuration.SetProperty(Environment.CacheProvider, typeof(HashtableCacheProvider).AssemblyQualifiedName); | ||
configuration.SetProperty(Environment.UseQueryCache, "true"); | ||
} | ||
|
||
[Test] | ||
public async Task InvalidatesEntitiesAsync() | ||
{ | ||
var debugSessionFactory = (DebugSessionFactory) Sfi; | ||
|
||
var cache = Substitute.For<UpdateTimestampsCache>(Sfi.Settings, new Dictionary<string, string>()); | ||
|
||
var updateTimestampsCacheField = typeof(SessionFactoryImpl).GetField( | ||
"updateTimestampsCache", | ||
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); | ||
|
||
updateTimestampsCacheField.SetValue(debugSessionFactory.ActualFactory, cache); | ||
|
||
//"Received" assertions can not be used since the collection is reused and cleared between calls. | ||
//The received args are cloned and stored | ||
var preInvalidations = new List<IReadOnlyCollection<string>>(); | ||
var invalidations = new List<IReadOnlyCollection<string>>(); | ||
|
||
await (cache.PreInvalidateAsync(Arg.Do<IReadOnlyCollection<string>>(x => preInvalidations.Add(x.ToList())), CancellationToken.None)); | ||
await (cache.InvalidateAsync(Arg.Do<IReadOnlyCollection<string>>(x => invalidations.Add(x.ToList())), CancellationToken.None)); | ||
|
||
using (var session = OpenSession()) | ||
{ | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
foreach (var i in Enumerable.Range(1, 10)) | ||
{ | ||
var item = new Item {Id = i}; | ||
await (session.SaveAsync(item)); | ||
} | ||
|
||
await (tx.CommitAsync()); | ||
} | ||
|
||
using (var tx = session.BeginTransaction()) | ||
{ | ||
foreach (var i in Enumerable.Range(1, 10)) | ||
{ | ||
var item = await (session.GetAsync<Item>(i)); | ||
item.Name = item.Id.ToString(); | ||
} | ||
|
||
await (tx.CommitAsync()); | ||
} | ||
|
||
using (var tx = session.BeginTransaction()) | ||
{ | ||
foreach (var i in Enumerable.Range(1, 10)) | ||
{ | ||
var item = await (session.GetAsync<Item>(i)); | ||
await (session.DeleteAsync(item)); | ||
} | ||
|
||
await (tx.CommitAsync()); | ||
} | ||
} | ||
|
||
//Should receive one preinvalidation and one invalidation per 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)); | ||
Assert.That(invalidations, Has.All.Count.EqualTo(1).And.Contains("Item")); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
s.Delete("from Item"); | ||
tx.Commit(); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using NHibernate.Cache; | ||
using NHibernate.Cfg; | ||
using NHibernate.Impl; | ||
using NHibernate.Test.SecondLevelCacheTests; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.SecondLevelCacheTest | ||
{ | ||
[TestFixture] | ||
public class InvalidationTests : TestCase | ||
{ | ||
protected override string MappingsAssembly => "NHibernate.Test"; | ||
|
||
protected override IList Mappings => new[] { "SecondLevelCacheTest.Item.hbm.xml" }; | ||
|
||
protected override void Configure(Configuration configuration) | ||
{ | ||
configuration.SetProperty(Environment.CacheProvider, typeof(HashtableCacheProvider).AssemblyQualifiedName); | ||
configuration.SetProperty(Environment.UseQueryCache, "true"); | ||
} | ||
|
||
[Test] | ||
public void InvalidatesEntities() | ||
{ | ||
var debugSessionFactory = (DebugSessionFactory) Sfi; | ||
|
||
var cache = Substitute.For<UpdateTimestampsCache>(Sfi.Settings, new Dictionary<string, string>()); | ||
|
||
var updateTimestampsCacheField = typeof(SessionFactoryImpl).GetField( | ||
"updateTimestampsCache", | ||
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); | ||
|
||
updateTimestampsCacheField.SetValue(debugSessionFactory.ActualFactory, cache); | ||
|
||
//"Received" assertions can not be used since the collection is reused and cleared between calls. | ||
//The received args are cloned and stored | ||
var preInvalidations = new List<IReadOnlyCollection<string>>(); | ||
var invalidations = new List<IReadOnlyCollection<string>>(); | ||
|
||
cache.PreInvalidate(Arg.Do<IReadOnlyCollection<string>>(x => preInvalidations.Add(x.ToList()))); | ||
cache.Invalidate(Arg.Do<IReadOnlyCollection<string>>(x => invalidations.Add(x.ToList()))); | ||
|
||
using (var session = OpenSession()) | ||
{ | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
foreach (var i in Enumerable.Range(1, 10)) | ||
{ | ||
var item = new Item {Id = i}; | ||
session.Save(item); | ||
} | ||
|
||
tx.Commit(); | ||
} | ||
|
||
using (var tx = session.BeginTransaction()) | ||
{ | ||
foreach (var i in Enumerable.Range(1, 10)) | ||
{ | ||
var item = session.Get<Item>(i); | ||
item.Name = item.Id.ToString(); | ||
} | ||
|
||
tx.Commit(); | ||
} | ||
|
||
using (var tx = session.BeginTransaction()) | ||
{ | ||
foreach (var i in Enumerable.Range(1, 10)) | ||
{ | ||
var item = session.Get<Item>(i); | ||
session.Delete(item); | ||
} | ||
|
||
tx.Commit(); | ||
} | ||
} | ||
|
||
//Should receive one preinvalidation and one invalidation per 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)); | ||
Assert.That(invalidations, Has.All.Count.EqualTo(1).And.Contains("Item")); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
s.Delete("from Item"); | ||
tx.Commit(); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for now we want to generate async counterparts for obsoleted methods (as they were here before the methods were marked obsolete)