Пример #1
0
        public void NearCacheListenNoneInvokeAllTest()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache  = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone);

            nearcache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("Aleks", 1);
            ht.Add("Ana", 2);
            ht.Add("Goran", 3);
            ht.Add("Ivan", 4);
            nearcache.InsertAll(ht);

            Hashtable htput = new Hashtable();

            htput.Add("Aleks", 195);
            htput.Add("Ana", 205);

            IFilter         filter    = new LessFilter(IdentityExtractor.Instance, 2);
            IEntryProcessor processor = new ConditionalPutAll(AlwaysFilter.Instance, htput);

            nearcache.InvokeAll(filter, processor);
            Assert.AreEqual(195, nearcache.BackCache["Aleks"]);
            Assert.AreEqual(2, nearcache.BackCache["Ana"]);

            nearcache.InvokeAll(htput.Keys, processor);
            Assert.AreEqual(205, nearcache.BackCache["Ana"]);

            nearcache.Clear();
            nearcache.Release();
            Assert.IsFalse(nearcache.IsActive);

            CacheFactory.Shutdown();
        }
        public void TestInvoke()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

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

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("conditionalPutKey1", 435);
            ht.Add("conditionalPutKey2", 253);
            ht.Add("conditionalPutKey3", 3);
            ht.Add("conditionalPutKey4", 200);
            ht.Add("conditionalPutKey5", 333);
            cache.InsertAll(ht);

            IFilter greaterThen600 = new GreaterFilter(IdentityExtractor.Instance, 600);
            IFilter greaterThen200 = new GreaterFilter(IdentityExtractor.Instance, 200);

            // no entries with value>600
            ICollection keys = cache.GetKeys(greaterThen600);

            Assert.IsTrue(keys.Count == 0);

            // invoke processor for one entry with filter that will evaluate to false
            // again, no entries with value>600
            IEntryProcessor processor = new ConditionalPut(greaterThen600, 666);

            cache.Invoke("conditionalPutKey1", processor);
            keys = cache.GetKeys(greaterThen600);
            Assert.IsTrue(keys.Count == 0);

            // invoke processor for one entry with filter that will evaluate to true
            // this will change one entry
            processor = new ConditionalPut(AlwaysFilter.Instance, 666);
            cache.Invoke("conditionalPutKey1", processor);
            keys = cache.GetKeys(greaterThen600);
            Assert.AreEqual(keys.Count, 1);
            Assert.AreEqual(cache["conditionalPutKey1"], 666);

            // 3 entries with value>200
            keys = cache.GetKeys(greaterThen200);
            Assert.AreEqual(keys.Count, 3);

            // invoke processor for these three entries
            processor = new ConditionalPut(greaterThen200, 666);
            cache.InvokeAll(cache.Keys, processor);
            keys = cache.GetKeys(greaterThen600);
            Assert.AreEqual(keys.Count, 3);

            cache.Clear();

            ht = new Hashtable();
            ht.Add("conditionalPutAllKey1", 435);
            ht.Add("conditionalPutAllKey2", 253);
            ht.Add("conditionalPutAllKey3", 200);
            ht.Add("conditionalPutAllKey4", 333);
            cache.InsertAll(ht);

            Hashtable htPut = new Hashtable();

            htPut.Add("conditionalPutAllKey1", 100);
            htPut.Add("conditionalPutAllKey6", 80);
            htPut.Add("conditionalPutAllKey3", 10);

            // put key1 and compare cache value with the put one
            processor = new ConditionalPutAll(AlwaysFilter.Instance, htPut);
            cache.Invoke("conditionalPutAllKey1", processor);
            Assert.IsNotNull(cache["conditionalPutAllKey1"]);
            Assert.AreEqual(cache["conditionalPutAllKey1"], htPut["conditionalPutAllKey1"]);

            // TODO: Decide wheter putall should insert new entries or not
            // put all keys from htPut and compare cache values with put ones
            //cache.InvokeAll(htPut.Keys, processor);
            //Assert.IsTrue(cache.Count == 5);
            //Assert.AreEqual(cache["conditionalPutAllKey1"], htPut["conditionalPutAllKey1"]);
            //Assert.AreEqual(cache["conditionalPutAllKey6"], htPut["conditionalPutAllKey6"]);
            //Assert.AreEqual(cache["conditionalPutAllKey3"], htPut["conditionalPutAllKey3"]);

            //htPut.Clear();
            //htPut.Add("conditionalPutAllKey4", 355);
            //processor = new ConditionalPutAll(AlwaysFilter.Instance, htPut);

            //cache.InvokeAll(new GreaterFilter(IdentityExtractor.Instance, 300), processor);
            //Assert.AreEqual(cache["conditionalPutAllKey4"], htPut["conditionalPutAllKey4"]);

            CacheFactory.Shutdown();
        }