public void ShouldBeTolerant()
        {
            var tqc = (TolerantQueryCache)sfi.GetQueryCache(regionName);

            Assert.That(tqc.IsTolerated(new[] { "ATable" }));

            tqc = (TolerantQueryCache)sfi.GetQueryCache(regionName1);
            Assert.That(tqc.IsTolerated(new[] { "ATable" }));
            Assert.That(tqc.IsTolerated(new[] { "ATable1" }));
            Assert.That(tqc.IsTolerated(new[] { "ATable", "ATable2" }));
            Assert.That(tqc.IsTolerated(new[] { "ATable", "ATable2", "ATable1" }));
        }
示例#2
0
        /// <summary>
        /// Get the inner Hashtable from the IQueryCache.Cache
        /// </summary>
        /// <returns></returns>
        public static Hashtable GetHashTableUsedAsQueryCache(ISessionFactoryImplementor factory)
        {
            Hashtable hashTable = null;
            var       cache     = (HashtableCache)factory.GetQueryCache(null).Cache;
            var       fieldInfo = typeof(HashtableCache).GetField("hashtable", BindingFlags.Instance | BindingFlags.NonPublic);

            if (fieldInfo != null)
            {
                hashTable = (Hashtable)fieldInfo.GetValue(cache);
            }
            return(hashTable);
        }
示例#3
0
        private Hashtable GetHashTableUsedAsQueryCache()
        {
            ISessionFactoryImplementor factory = (ISessionFactoryImplementor)sessions;
            //need the inner hashtable in the cache
            HashtableCache cache = (HashtableCache)
                                   typeof(StandardQueryCache)
                                   .GetField("queryCache", BindingFlags.Instance | BindingFlags.NonPublic)
                                   .GetValue(factory.GetQueryCache(null));

            return((Hashtable)typeof(HashtableCache)
                   .GetField("hashtable", BindingFlags.Instance | BindingFlags.NonPublic)
                   .GetValue(cache));
        }
		/// <summary>
		/// Get the inner Hashtable from the IQueryCache.Cache
		/// </summary>
		/// <returns></returns>
		public static Hashtable GetHashTableUsedAsQueryCache(ISessionFactoryImplementor factory)
		{
			Hashtable hashTable = null;
			var cache = (HashtableCache)factory.GetQueryCache(null).Cache;
			var fieldInfo = typeof(HashtableCache).GetField("hashtable", BindingFlags.Instance | BindingFlags.NonPublic);
			if (fieldInfo != null)
				hashTable = (Hashtable)fieldInfo.GetValue(cache);
			return hashTable;
		}
        public void CommonRegionHasOneUniqueCacheAndExpectedConcurrency(bool withPrefix)
        {
            const string prefix            = "Prefix";
            const string region            = "Common";
            var          fullRegion        = (withPrefix ? prefix + "." : "") + region;
            ISessionFactoryImplementor sfi = null;

            if (withPrefix)
            {
                cfg.SetProperty(Environment.CacheRegionPrefix, prefix);
            }
            try
            {
                sfi = withPrefix ? BuildSessionFactory() : Sfi;
                var commonRegionCache        = sfi.GetSecondLevelCacheRegion(fullRegion);
                var entityAName              = typeof(EntityA).FullName;
                var entityAConcurrencyCache  = sfi.GetEntityPersister(entityAName).Cache;
                var entityACache             = entityAConcurrencyCache.Cache;
                var entityBName              = typeof(EntityB).FullName;
                var entityBConcurrencyCache  = sfi.GetEntityPersister(entityBName).Cache;
                var entityBCache             = entityBConcurrencyCache.Cache;
                var relatedAConcurrencyCache =
                    sfi.GetCollectionPersister(StringHelper.Qualify(entityAName, nameof(EntityA.Related))).Cache;
                var relatedACache            = relatedAConcurrencyCache.Cache;
                var relatedBConcurrencyCache =
                    sfi.GetCollectionPersister(StringHelper.Qualify(entityBName, nameof(EntityB.Related))).Cache;
                var relatedBCache = relatedBConcurrencyCache.Cache;
                var queryCache    = sfi.GetQueryCache(region).Cache;
                Assert.Multiple(
                    () =>
                {
                    Assert.That(commonRegionCache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for common region");
                    Assert.That(entityACache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for EntityA");
                    Assert.That(entityBCache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for EntityB");
                    Assert.That(relatedACache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for RelatedA");
                    Assert.That(relatedBCache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for RelatedB");
                    Assert.That(queryCache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for query cache");
                });
                Assert.Multiple(
                    () =>
                {
                    Assert.That(entityAConcurrencyCache, Is.InstanceOf <ReadWriteCache>(), "Unexpected concurrency for EntityA");
                    Assert.That(relatedAConcurrencyCache, Is.InstanceOf <NonstrictReadWriteCache>(), "Unexpected concurrency for RelatedA");
                    Assert.That(entityBConcurrencyCache, Is.InstanceOf <ReadOnlyCache>(), "Unexpected concurrency for EntityB");
                    Assert.That(relatedBConcurrencyCache, Is.InstanceOf <ReadWriteCache>(), "Unexpected concurrency for RelatedB");
                    Assert.That(entityACache, Is.SameAs(commonRegionCache), "Unexpected cache for EntityA");
                    Assert.That(entityBCache, Is.SameAs(commonRegionCache), "Unexpected cache for EntityB");
                    Assert.That(relatedACache, Is.SameAs(commonRegionCache), "Unexpected cache for RelatedA");
                    Assert.That(relatedBCache, Is.SameAs(commonRegionCache), "Unexpected cache for RelatedB");
                    Assert.That(queryCache, Is.SameAs(commonRegionCache), "Unexpected cache for query cache");
                });
            }
            finally
            {
                if (withPrefix)
                {
                    cfg.Properties.Remove(Environment.CacheRegionPrefix);
                    sfi?.Dispose();
                }
            }
        }