public void NearCacheListenNoneInvokeTest() { 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); IFilter filter = new GreaterFilter(IdentityExtractor.Instance, 199); IEntryProcessor processor = new ConditionalPut(filter, 204); nearcache.Invoke("Ivan", processor); Assert.AreEqual(4, nearcache["Ivan"]); Assert.AreEqual(4, nearcache.BackCache["Ivan"]); nearcache["Ivan"] = 200; nearcache.Invoke("Ivan", processor); Assert.AreEqual(200, nearcache["Ivan"]); Assert.AreEqual(204, nearcache.BackCache["Ivan"]); 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(); }
public void TestComposite() { 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(); Address addr1 = new Address("XI krajiske divizije", "Belgrade", "Serbia", "11000"); Address addr2 = new Address("Pere Velimirovica", "Belgrade", "Serbia", "11000"); Address addr3 = new Address("Rige od Fere", "Belgrade", "Serbia", "11000"); cache.Insert("addr1", addr1); cache.Insert("addr2", addr2); Assert.IsTrue(cache.Count == 2); LikeFilter likeXI = new LikeFilter(new ReflectionExtractor("Street"), "XI%", '\\', true); ExtractorProcessor extractStreet = new ExtractorProcessor(new ReflectionExtractor("Street")); IEntryProcessor putAddr3 = new ConditionalPut(AlwaysFilter.Instance, addr3); IEntryProcessor removeLikeXI = new ConditionalRemove(likeXI, false); IEntryProcessor[] processors = new IEntryProcessor[] { extractStreet, removeLikeXI, putAddr3 }; CompositeProcessor processor = new CompositeProcessor(processors); Object objResult = cache.Invoke("addr1", processor); Assert.IsTrue(cache.Count == 2); object[] objResultArr = objResult as object[]; Assert.IsNotNull(objResultArr); Assert.AreEqual(addr1.Street, objResultArr[0]); Address res = cache["addr1"] as Address; Assert.IsNotNull(res); Assert.AreEqual(addr3.City, res.City); Assert.AreEqual(addr3.State, res.State); Assert.AreEqual(addr3.Street, res.Street); Assert.AreEqual(addr3.ZIP, res.ZIP); res = cache["addr2"] as Address; Assert.IsNotNull(res); Assert.AreEqual(addr2.City, res.City); Assert.AreEqual(addr2.State, res.State); Assert.AreEqual(addr2.Street, res.Street); Assert.AreEqual(addr2.ZIP, res.ZIP); IDictionary dictResult = cache.InvokeAll(new ArrayList(new object[] { "addr1", "addr2" }), processor); Assert.IsTrue(cache.Count == 2); Address address = cache["addr1"] as Address; Assert.IsNotNull(address); Assert.AreEqual(addr3.Street, address.Street); address = cache["addr2"] as Address; Assert.IsNotNull(address); Assert.AreEqual(addr3.Street, address.Street); object[] objectArr = dictResult["addr1"] as object[]; Assert.IsNotNull(objectArr); Assert.AreEqual(objectArr[0], addr3.Street); objectArr = dictResult["addr2"] as object[]; Assert.IsNotNull(objectArr); Assert.AreEqual(objectArr[0], addr2.Street); CacheFactory.Shutdown(); }
public void ConverterInvocableCacheTests() { IInvocableCache cache = InstantiateCache(); IConverter cDown = new ConvertDown(); IConverter cUp = new ConvertUp(); IEntryProcessor processor = new ConditionalPut(AlwaysFilter.Instance, "value_converted", false); IInvocableCache convCache = ConverterCollections.GetInvocableCache(cache, cUp, cDown, cUp, cDown); Assert.IsNotNull(convCache); Assert.AreEqual(cache.Count, 0); convCache.Invoke("key", processor); Assert.AreEqual(cache.Count, 1); Assert.AreEqual(convCache["key"], cUp.Convert("value_converted")); ArrayList keys = new ArrayList(); keys.Add("key"); keys.Add("anotherkey"); processor = new ConditionalPut(AlwaysFilter.Instance, "newvalue_converted", false); IDictionary result = convCache.InvokeAll(keys, processor); //results should be empty since return is set to false Assert.AreEqual(result.Count, 0); Assert.AreEqual(convCache.Count, 2); foreach (object key in result.Keys) { Assert.IsTrue(convCache.Contains(key)); Assert.AreEqual(convCache[key], cUp.Convert("newvalue_converted")); } processor = new ConditionalPut(AlwaysFilter.Instance, "value_converted", false); result = convCache.InvokeAll(AlwaysFilter.Instance, processor); //results should be empty since return is set to false Assert.AreEqual(result.Count, 0); Assert.AreEqual(convCache.Count, 2); foreach (object key in result.Keys) { Assert.IsTrue(convCache.Contains(key)); Assert.AreEqual(convCache[key], cUp.Convert("value_converted")); } convCache.Clear(); for (int i = 0; i < 5; i++) { convCache.Add(i, i + 1); } IEntryAggregator aggregator = new ComparableMax(IdentityExtractor.Instance); keys.Clear(); keys.Add("2"); keys.Add("3"); object o = convCache.Aggregate(keys, aggregator); Assert.IsNotNull(o); Assert.AreEqual(o, "4"); o = convCache.Aggregate(AlwaysFilter.Instance, aggregator); Assert.IsNotNull(o); Assert.AreEqual(o, "5"); Assert.IsInstanceOf(typeof(ConverterCollections.ConverterInvocableCache), convCache); ConverterCollections.ConverterInvocableCache cc = convCache as ConverterCollections.ConverterInvocableCache; Assert.IsNotNull(cc); Assert.AreEqual(cc.InvocableCache, cache); }