Beispiel #1
0
        public void TestFindSchemeMapping()
        {
            IConfigurableCacheFactory       ccf  = CacheFactory.ConfigurableCacheFactory;
            DefaultConfigurableCacheFactory dccf = (DefaultConfigurableCacheFactory)ccf;

            DefaultConfigurableCacheFactory.CacheInfo ci = dccf.FindSchemeMapping("nr-2343535");
            Assert.IsNotNull(ci);
            Assert.AreEqual(ci.CacheName, "nr-2343535");
            Assert.AreEqual(ci.SchemeName, "example-near");

            ci = dccf.FindSchemeMapping("loc-test");
            Assert.IsNotNull(ci);
            Assert.AreEqual(ci.CacheName, "loc-test");
            Assert.AreEqual(ci.SchemeName, "example-local");

            dccf.Shutdown();
        }
Beispiel #2
0
        public void TestWhiteSpaceParsing()
        {
            DefaultConfigurableCacheFactory ccf = null;

            DefaultConfigurableCacheFactory.CacheInfo cacheInfo = null;
            try
            {
                ccf       = new DefaultConfigurableCacheFactory("assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config-with-spaces.xml");
                cacheInfo = ccf.FindSchemeMapping("test-GetsPutsCache");
            }
            catch
            {}
            finally
            {
                Assert.IsTrue(cacheInfo != null);
                StringAssert.AreEqualIgnoringCase(cacheInfo.CacheName, "test-GetsPutsCache");
                StringAssert.AreEqualIgnoringCase(cacheInfo.SchemeName, "test-local");
            }
        }
Beispiel #3
0
        public void TestLocalNamedCacheInstancing()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache1 = ccf.EnsureCache("local-default");

            Assert.IsNotNull(cache1);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache1);
            LocalNamedCache lnc = cache1 as LocalNamedCache;

            Assert.IsNotNull(lnc);
            LocalCache lc1 = lnc.LocalCache;

            Assert.AreEqual(lc1.ExpiryDelay, LocalCache.DEFAULT_EXPIRE);
            Assert.AreEqual(lc1.FlushDelay, 0);
            Assert.AreEqual(lc1.HighUnits, LocalCache.DEFAULT_UNITS);
            Assert.AreEqual(lc1.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc1.EvictionType, LocalCache.EvictionPolicyType.Hybrid);

            INamedCache cache2 = ccf.EnsureCache("local-with-init");

            Assert.IsNotNull(cache2);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache1);
            lnc = cache2 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc2 = lnc.LocalCache;

            Assert.AreEqual(lc2.ExpiryDelay, 10);
            Assert.AreEqual(lc2.FlushDelay, 1000);
            Assert.AreEqual(lc2.HighUnits, 32000);
            Assert.AreEqual(lc2.LowUnits, 10);
            Assert.AreEqual(lc2.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc2.EvictionType, LocalCache.EvictionPolicyType.LRU);
            Assert.IsNotNull(lc2.CacheLoader);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), lc2.CacheLoader);

            INamedCache cache3 = ccf.EnsureCache("local-custom-impl");

            Assert.IsNotNull(cache3);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), cache3);

            INamedCache cache4 = ccf.EnsureCache("local-custom-impl-with-init");

            Assert.IsNotNull(cache4);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), cache4);
            TestLocalNamedCache tlnc = cache4 as TestLocalNamedCache;

            Assert.IsNotNull(tlnc);
            LocalCache lc4 = tlnc.LocalCache;

            Assert.AreEqual(lc4.ExpiryDelay, 60000);
            Assert.AreEqual(lc4.FlushDelay, 1000);
            Assert.AreEqual(lc4.HighUnits, 32000);
            Assert.AreEqual(lc4.LowUnits, 10);
            Assert.AreEqual(lc4.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc4.EvictionType, LocalCache.EvictionPolicyType.LFU);

            INamedCache cache5 = ccf.EnsureCache("local-ref");

            Assert.IsNotNull(cache5);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache5);
            lnc = cache5 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc5 = lnc.LocalCache;

            Assert.AreEqual(lc2.ExpiryDelay, lc5.ExpiryDelay);
            Assert.AreEqual(lc2.FlushDelay, lc5.FlushDelay);
            Assert.AreEqual(lc2.HighUnits, lc5.HighUnits);
            Assert.AreEqual(lc2.CalculatorType, lc5.CalculatorType);
            Assert.AreEqual(lc2.EvictionType, lc5.EvictionType);

            Assert.IsInstanceOf(typeof(DefaultConfigurableCacheFactory), ccf);
            DefaultConfigurableCacheFactory dccf = ccf as DefaultConfigurableCacheFactory;

            Assert.IsNotNull(dccf);
            DefaultConfigurableCacheFactory.CacheInfo ci = dccf.FindSchemeMapping("local-override-params");
            Assert.IsNotNull(ci);
            Assert.AreEqual(ci.CacheName, "local-override-params");
            Assert.AreEqual(ci.SchemeName, "example-local-7");
            IDictionary attrs = ci.Attributes;

            Assert.IsNotNull(attrs);
            Assert.AreEqual(attrs.Count, 1);
            Assert.IsTrue(attrs.Contains("LowUnits10"));

            INamedCache cache6 = ccf.EnsureCache("local-override-params");

            Assert.IsNotNull(cache6);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache6);
            lnc = cache6 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc6 = lnc.LocalCache;

            Assert.AreEqual(lc6.ExpiryDelay, LocalCache.DEFAULT_EXPIRE);
            Assert.AreEqual(lc6.FlushDelay, 0);
            Assert.AreEqual(lc6.HighUnits, 100);
            Assert.AreEqual(lc6.LowUnits, 10);
            Assert.AreEqual(lc6.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc6.EvictionType, LocalCache.EvictionPolicyType.LFU);

            Assert.IsNotNull(lc6.CacheLoader);
            ICacheLoader cl         = lc6.CacheLoader;
            TestLoader   testLoader = cl as TestLoader;

            Assert.IsNotNull(testLoader);
            Assert.AreEqual(testLoader.StringProperty, ci.CacheName);
            Assert.AreEqual(testLoader.IntProperty, 10);
            Assert.IsTrue(testLoader.BoolProperty);
            INamedCache c = testLoader.CacheProperty;

            Assert.IsNotNull(c);
            Assert.IsInstanceOf(typeof(LocalNamedCache), c);

            Assert.IsTrue(cache1.IsActive);
            Assert.IsTrue(cache2.IsActive);
            Assert.IsTrue(cache3.IsActive);
            Assert.IsTrue(cache4.IsActive);
            Assert.IsTrue(cache5.IsActive);
            Assert.IsTrue(cache6.IsActive);

            CacheFactory.Shutdown();

            Assert.IsFalse(cache1.IsActive);
            Assert.IsFalse(cache2.IsActive);
            Assert.IsFalse(cache3.IsActive);
            Assert.IsFalse(cache4.IsActive);
            Assert.IsFalse(cache5.IsActive);
            Assert.IsFalse(cache6.IsActive);
        }