|
15 | 15 | using NUnit.Framework; |
16 | 16 | using System.Collections.Generic; |
17 | 17 | using System; |
| 18 | +using NHibernate.Cfg; |
18 | 19 |
|
19 | 20 | namespace NHibernate.Test.NHSpecificTest.NH3050 |
20 | 21 | { |
@@ -70,12 +71,15 @@ protected override void OnTearDown() |
70 | 71 | } |
71 | 72 | } |
72 | 73 |
|
73 | | - [Test] |
74 | | - public async Task NH3050_ReproductionAsync() |
| 74 | + protected override void Configure(Configuration configuration) |
75 | 75 | { |
76 | 76 | //firstly to make things simpler, we set the query plan cache size to 1 |
77 | | - Assert.IsTrue(TrySetQueryPlanCacheSize(Sfi, 1)); |
| 77 | + configuration.Properties[Cfg.Environment.QueryPlanCacheMaxSize] = "1"; |
| 78 | + } |
78 | 79 |
|
| 80 | + [Test] |
| 81 | + public async Task NH3050_ReproductionAsync() |
| 82 | + { |
79 | 83 | using (ISession session = OpenSession()) |
80 | 84 | using (session.BeginTransaction()) |
81 | 85 | { |
@@ -105,35 +109,5 @@ where names.Contains(e.Name) |
105 | 109 | await (query.ToListAsync()); |
106 | 110 | } |
107 | 111 | } |
108 | | - |
109 | | - /// <summary> |
110 | | - /// Uses reflection to create a new SoftLimitMRUCache with a specified size and sets session factory query plan cache to it. |
111 | | - /// This is done like this as NHibernate does not currently provide any way to specify the query plan cache size through configuration. |
112 | | - /// </summary> |
113 | | - /// <param name="factory"></param> |
114 | | - /// <param name="size"></param> |
115 | | - /// <returns></returns> |
116 | | - private static bool TrySetQueryPlanCacheSize(ISessionFactory factory, int size) |
117 | | - { |
118 | | - var factoryImpl = (factory as DebugSessionFactory)?.ActualFactory as Impl.SessionFactoryImpl; |
119 | | - if (factoryImpl != null) |
120 | | - { |
121 | | - var queryPlanCacheFieldInfo = typeof(Impl.SessionFactoryImpl).GetField("queryPlanCache", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); |
122 | | - if (queryPlanCacheFieldInfo != null) |
123 | | - { |
124 | | - var queryPlanCache = (Engine.Query.QueryPlanCache)queryPlanCacheFieldInfo.GetValue(factoryImpl); |
125 | | - |
126 | | - var planCacheFieldInfo = typeof(Engine.Query.QueryPlanCache).GetField("planCache", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); |
127 | | - if (planCacheFieldInfo != null) |
128 | | - { |
129 | | - var softLimitMRUCache = new Util.SoftLimitMRUCache(size); |
130 | | - |
131 | | - planCacheFieldInfo.SetValue(queryPlanCache, softLimitMRUCache); |
132 | | - return true; |
133 | | - } |
134 | | - } |
135 | | - } |
136 | | - return false; |
137 | | - } |
138 | 112 | } |
139 | 113 | } |
0 commit comments