public void CloseSessionFactory()
 {
     if (sessions != null)
     {
         sessions.Dispose();
     }
     sessions = null;
 }
 public void CloseSessionFactory()
 {
     if (sessions != null)
     {
         sessions.Dispose();
     }
     new SchemaExport(cfg).Drop(false, true);
     sessions = null;
 }
Exemplo n.º 3
0
 public void OneTimeTearDown()
 {
     _sessionFactory?.Dispose();
 }
        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();
                }
            }
        }
 public void ShutdownNh()
 {
     sfi.Dispose();
 }