|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by AsyncGenerator. |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | + |
| 11 | +using NHibernate.Cfg; |
| 12 | +using NUnit.Framework; |
| 13 | + |
| 14 | +namespace NHibernate.Test.NHSpecificTest.GH1730 |
| 15 | +{ |
| 16 | + using System.Threading.Tasks; |
| 17 | + [TestFixture] |
| 18 | + public class FixtureAsync : BugTestCase |
| 19 | + { |
| 20 | + protected override void Configure(Configuration configuration) |
| 21 | + { |
| 22 | + cfg.SetProperty(Environment.GenerateStatistics, "true"); |
| 23 | + } |
| 24 | + |
| 25 | + protected override void OnTearDown() |
| 26 | + { |
| 27 | + using (var session = OpenSession()) |
| 28 | + using (var transaction = session.BeginTransaction()) |
| 29 | + { |
| 30 | + session.CreateQuery("delete from Entity").ExecuteUpdate(); |
| 31 | + |
| 32 | + transaction.Commit(); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + [Test] |
| 37 | + public async Task HitCacheInSameSessionAsync() |
| 38 | + { |
| 39 | + await (Sfi.EvictQueriesAsync()); |
| 40 | + Sfi.Statistics.Clear(); |
| 41 | + var entities = new System.Collections.Generic.List<Entity>(); |
| 42 | + |
| 43 | + using (var session = OpenSession()) |
| 44 | + { |
| 45 | + using (var transaction = session.BeginTransaction()) |
| 46 | + { |
| 47 | + for (int i = 0; i < 3; i++) |
| 48 | + { |
| 49 | + var e = new Entity { Name = "Name" + i }; |
| 50 | + entities.Add(e); |
| 51 | + await (session.SaveAsync(e)); |
| 52 | + } |
| 53 | + await (transaction.CommitAsync()); |
| 54 | + } |
| 55 | + |
| 56 | + var queryString = "from Entity"; |
| 57 | + |
| 58 | + using (var tx = session.BeginTransaction()) |
| 59 | + { |
| 60 | + // this query will hit the database and create the cache |
| 61 | + await (session.CreateQuery(queryString).SetCacheable(true).ListAsync()); |
| 62 | + await (tx.CommitAsync()); |
| 63 | + } |
| 64 | + |
| 65 | + using (var transaction = session.BeginTransaction()) |
| 66 | + { |
| 67 | + //and this one SHOULD served by the cache |
| 68 | + await (session.CreateQuery(queryString).SetCacheable(true).ListAsync()); |
| 69 | + await (transaction.CommitAsync()); |
| 70 | + } |
| 71 | + |
| 72 | + var qs = Sfi.Statistics.GetQueryStatistics(queryString); |
| 73 | + Assert.AreEqual(1, qs.CacheHitCount); |
| 74 | + Assert.AreEqual(1, qs.CachePutCount); |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments