public void TestClearAndCount() { 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(); Assert.AreEqual(0, cache.Count); cache.Insert("key1", "value1"); Assert.AreEqual(1, cache.Count); cache.Insert("key2", "value2"); Assert.AreEqual(2, cache.Count); cache.Insert("key3", "value3"); cache.Insert("key4", "value4"); Assert.AreEqual(4, cache.Count); cache.Clear(); Assert.AreEqual(0, cache.Count); CacheFactory.Shutdown(); }
public void TestPofExtractorWithValueChangeEventFilter1() { // Testing on remote cache using CustomerKeyClass, which is not // defined on Java side INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); // CustomerKeyClass is not defined on the Java side // Hashtable ht = new Hashtable(); CustomKeyClass key1 = new CustomKeyClass("Customer1"); CustomKeyClass key2 = new CustomKeyClass("Customer2"); ht.Add("key1", key1); ht.Add("key2", key2); cache.InsertAll(ht); SyncListener listener = new SyncListener(); IFilter filter = new ValueChangeEventFilter(new PofExtractor(typeof(String), 0)); cache.AddCacheListener(listener, filter, false); Assert.IsNull(listener.CacheEvent); cache["key1"] = new CustomKeyClass("Customer1"); Assert.IsNull(listener.CacheEvent); cache["key1"] = new CustomKeyClass("Customer12"); Assert.IsNotNull(listener.CacheEvent); CacheFactory.Shutdown(); }
public virtual void TestNamedCacheProperties() { INamedCache cache = CacheFactory.GetCache(CacheName); string key = "testNamedCachePropertiesKey"; string value = "testNamedCachePropertiesValue"; // INamedCache Assert.IsTrue(cache.IsActive); cache.Clear(); Assert.AreEqual(cache.Count, 0); cache.Insert(GetKeyObject(key), value); Assert.AreEqual(cache.Count, 1); Assert.AreEqual(cache[GetKeyObject(key)], value); // SafeNamedCache SafeNamedCache safeCache = (SafeNamedCache)cache; Assert.IsFalse(safeCache.IsReleased); Assert.IsFalse(safeCache.IsFixedSize); Assert.IsFalse(safeCache.IsReadOnly); Assert.IsTrue(safeCache.IsSynchronized); // RemoteNamedCache RemoteNamedCache remoteCache = (RemoteNamedCache)safeCache.NamedCache; Assert.IsTrue(remoteCache.Channel.IsOpen); Assert.IsInstanceOf(typeof(NamedCacheProtocol), remoteCache.Protocol); CacheFactory.ReleaseCache(cache); CacheFactory.Shutdown(); }
public override void TestNamedCacheProperties() { INamedCache cache = CacheFactory.GetCache(CacheName); string key = "testNamedCachePropertiesKey"; string value = "testNamedCachePropertiesValue"; // INamedCache Assert.IsTrue(cache.IsActive); cache.Clear(); Assert.AreEqual(cache.Count, 0); cache.Insert(GetKeyObject(key), value); Assert.AreEqual(cache.Count, 1); Assert.AreEqual(cache[GetKeyObject(key)], value); // BundlingNamedCache BundlingNamedCache bundleCache = (BundlingNamedCache)cache; Assert.IsFalse(bundleCache.IsFixedSize); Assert.IsFalse(bundleCache.IsReadOnly); Assert.IsTrue(bundleCache.IsSynchronized); // RemoteNamedCache SafeNamedCache safeCache = (SafeNamedCache)bundleCache.NamedCache; Assert.IsTrue(safeCache.IsActive); CacheFactory.ReleaseCache(cache); CacheFactory.Shutdown(); }
public void TestPofUpdater() { INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); PortablePerson original = new PortablePerson(); original.Name = "Aleksandar Seovic"; original.Address = new Address("street", "Belgrade", "SRB", "11000"); cache.Insert("p1", original); PofUpdater updName = new PofUpdater(0); PofUpdater updCity = new PofUpdater(new SimplePofPath(new int[] { 1, 1 })); cache.Invoke("p1", new UpdaterProcessor(updName, "Novak Seovic")); cache.Invoke("p1", new UpdaterProcessor(updCity, "Lutz")); PortablePerson modified = (PortablePerson)cache["p1"]; Assert.AreEqual("Novak Seovic", modified.Name); Assert.AreEqual("Lutz", modified.Address.City); CacheFactory.Shutdown(); }
public void TestNamedDefaultPofSerializer() { IXmlElement xmlConfig = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-extend-named-pof-default-serializer-cache-config.xml"); CacheFactory.Configure(xmlConfig, null); INamedCache cache = CacheFactory.GetCache("dist-default"); cache.Clear(); // create a key, and value String sKey = "hello"; String sValue = "grid"; // insert the pair into the cache cache.Add(sKey, sValue); // get the key and value back IDictionary entries = cache.GetAll(cache.Keys); Assert.AreEqual(1, entries.Count); Assert.IsInstanceOf(typeof(IDictionary), entries); Assert.AreEqual(sValue, ((String)((IDictionary)entries)[sKey])); CacheFactory.ReleaseCache(cache); }
public void TestExtractorEventTransformer() { //testing on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Hashtable ht = new Hashtable(); Address address1 = new Address("Street1", "City1", "State1", "Zip1"); Address address2 = new Address("Street2", "City2", "State2", "Zip2"); ht.Add("key1", address1); ht.Add("key2", address2); cache.InsertAll(ht); SyncListener listener = new SyncListener(); IFilter filter = new ValueChangeEventFilter("getStreet"); IValueExtractor extractor = IdentityExtractor.Instance; ICacheEventTransformer transformer = new ExtractorEventTransformer(null, extractor); cache.AddCacheListener(listener, new CacheEventTransformerFilter(filter, transformer), false); Assert.IsNull(listener.CacheEvent); cache["key1"] = new Address("Street1", "City1a", "State1a", "Zip1a"); Assert.IsNull(listener.CacheEvent); cache["key1"] = new Address("Street1a", "City1a", "State1a", "Zip1a"); Assert.IsNotNull(listener.CacheEvent); CacheFactory.Shutdown(); }
public void TestEntryTouch() { 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("key1", 100.0); ht.Add("key2", 80.5); ht.Add("key3", 19.5); ht.Add("key4", 2.0); cache.InsertAll(ht); object result = cache["key2"]; result = cache["key2"]; result = cache["key2"]; result = cache["key1"]; ICacheEntry[] results = cache.GetEntries(new EqualsFilter(new KeyExtractor(IdentityExtractor.Instance), "key2")); // TODO : we don't get back the actual entry!!! // Assert.AreEqual(3, (results[0] as LocalCache.Entry).TouchCount); results = cache.GetEntries(new EqualsFilter(new KeyExtractor(IdentityExtractor.Instance), "key1")); // Assert.AreEqual(1, (results[0] as LocalCache.Entry).TouchCount); CacheFactory.Shutdown(); }
public void TestGetValues() { 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("key1", 100.0); ht.Add("key2", 80.5); ht.Add("key3", 19.5); ht.Add("key4", 2.0); cache.InsertAll(ht); Assert.AreEqual(4, cache.Count); IFilter lessFilter = new LessFilter(IdentityExtractor.Instance, 80.5); object[] result = cache.GetValues(lessFilter); Assert.AreEqual(2, result.Length); foreach (object o in result) { Assert.IsTrue((Convert.ToDouble(o) == 19.5) || (Convert.ToDouble(o) == 2.0)); } CacheFactory.Shutdown(); }
public void TestGetEnumerator() { 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("key1", 100.0); ht.Add("key2", 80.5); ht.Add("key3", 19.5); ht.Add("key4", 2.0); cache.InsertAll(ht); foreach (ICacheEntry entry in cache) { Assert.IsTrue(CollectionUtils.Contains(new ArrayList(ht.Values), entry.Value)); } CacheFactory.Shutdown(); }
/* * common method for tests of this suite */ private void runTest(IXmlDocument config, string cacheName, string serializerName) { IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; IXmlElement originalConfig = ccf.Config; ccf.Config = config; INamedCache cache = ccf.EnsureCache(cacheName); cache.Clear(); // create a key, and value String sKey = "hello"; String sValue = "grid"; // insert the pair into the cache cache.Insert(sKey, sValue); // read back the value, custom serializer should have converted Assert.AreEqual(cache.Count, 1); Assert.AreEqual(cache[sKey], serializerName); ccf.DestroyCache(cache); ccf.Config = originalConfig; }
public void TestListenerEvents() { IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-near-cache-config.xml"); ccf.Config = config; INamedCache cache = CacheFactory.GetCache("dist-extend-direct"); cache.Clear(); ListenerWithWait listen = new ListenerWithWait(); cache.AddCacheListener(listen, "test", true); cache.Insert("test", "c"); CacheEventArgs localEvent = listen.WaitForEvent(2000); Assert.IsNotNull(localEvent); String value = (String)cache["test"]; localEvent = listen.WaitForEvent(4000); Assert.AreEqual("c", value); Assert.IsNull(localEvent); CacheFactory.Shutdown(); }
public void TestReplace() { INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Hashtable ht = new Hashtable(); ht.Add("key4", 0); ht.Add("key3", -10); ht.Add("key2", 45); ht.Add("key1", 398); cache.InsertAll(ht); object result = cache.Replace("key1", 400); Assert.AreEqual(398, result); Assert.AreEqual(400, cache["key1"]); result = cache.Replace("key1", 300, 450); Assert.AreEqual(false, result); result = cache.Replace("key1", 400, 450); Assert.AreEqual(true, result); Assert.AreEqual(450, cache["key1"]); }
public void TestConfiguredTriggerListener() { IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-extend-maptrigger-cache-config.xml"); ccf.Config = config; INamedCache cache = CacheFactory.GetCache(CACHE_NAME); cache.Clear(); SimplePerson pIn = new SimplePerson("123-45-6789", "Eddie", "Van Halen", 1955, "987-65-4321", new String[] { "456-78-9123" }); try { cache.Insert(1, pIn); Object[] keys = cache.GetKeys(AlwaysFilter.Instance); Assert.AreEqual(keys.Length, 1); SimplePerson pOut = (SimplePerson)cache[1]; Assert.AreEqual(pIn.LastName.ToUpper(), pOut.LastName); } finally { CacheFactory.Shutdown(); } }
public virtual void TestNamedCacheLock() { INamedCache cache = CacheFactory.GetCache(CacheName); string key = "testNamedCacheInterfaceMethodsKey"; string value = "testNamedCacheInterfaceMethodsValue"; object[] keys = { GetKeyObject("key1"), GetKeyObject("key2"), GetKeyObject("key3") }; string[] values = { "value1", "value2", "value3" }; cache.Clear(); Assert.IsTrue(cache.Count == 0); cache.Add(GetKeyObject(key), value); Assert.AreEqual(cache.Count, 1); Assert.AreEqual(cache[GetKeyObject(key)], value); Assert.IsTrue(cache.Contains(GetKeyObject(key))); cache.Lock(key); Assert.AreEqual(cache[GetKeyObject(key)], value); cache.Unlock(key); cache.Lock(key); Assert.AreEqual(cache[GetKeyObject(key)], value); cache.Unlock(key); CacheFactory.ReleaseCache(cache); CacheFactory.Shutdown(); }
public void TestPofExtractorWithValueChangeEventFilter2() { // Testing on remote cache using Address, which is defined on // Java side. INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Hashtable ht = new Hashtable(); Address address1 = new Address("Street1", "City1", "State1", "Zip1"); Address address2 = new Address("Street2", "City2", "State2", "Zip2"); ht.Add("key1", address1); ht.Add("key2", address2); cache.InsertAll(ht); SyncListener listener = new SyncListener(); IFilter filter = new ValueChangeEventFilter(new PofExtractor(typeof(String), 0)); cache.AddCacheListener(listener, filter, false); Assert.IsNull(listener.CacheEvent); cache["key1"] = new Address("Street1", "City1a", "State1a", "Zip1a"); Assert.IsNull(listener.CacheEvent); cache["key1"] = new Address("Street1a", "City1", "State1", "Zip1"); Assert.IsNotNull(listener.CacheEvent); CacheFactory.Shutdown(); }
public void TestPreloadRequest() { IEntryProcessor processor = PreloadRequest.Instance; IEntryProcessor processor1 = PreloadRequest.Instance; Assert.AreEqual(processor, processor1); Assert.AreEqual(processor.GetHashCode(), processor1.GetHashCode()); Assert.AreEqual(processor.ToString(), processor1.ToString()); INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Temperature bgd = new Temperature(25, 'c', 12); Temperature nyc = new Temperature(99, 'f', 12); cache.Insert("BGD", bgd); cache.Insert("NYC", nyc); object o = cache.Invoke("BGD", processor); Assert.IsNull(o); CacheFactory.Shutdown(); }
public virtual void TestNamedCacheEntryCollection() { INamedCache cache = CacheFactory.GetCache(CacheName); object[] keys = { GetKeyObject("key1"), GetKeyObject("key2"), GetKeyObject("key3"), GetKeyObject("key4") }; string[] values = { "value1", "value2", "value3", "value4" }; cache.Clear(); IDictionary h = new Hashtable(); h.Add(keys[0], values[0]); h.Add(keys[1], values[1]); h.Add(keys[2], values[2]); h.Add(keys[3], values[3]); cache.InsertAll(h); SafeNamedCache safeCache = (SafeNamedCache)cache; IDictionaryEnumerator de = safeCache.NamedCache.GetEnumerator(); ArrayList al = new ArrayList(h.Values); for (; de.MoveNext();) { Assert.IsTrue(al.Contains(de.Value)); Assert.IsTrue(h.Contains(de.Key)); } CacheFactory.ReleaseCache(cache); CacheFactory.Shutdown(); }
public void TestGetKeys() { INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); IDictionary dict = new Hashtable(); for (int i = 1; i <= 10; i++) { dict.Add(GetKeyObject("key" + i), i); } cache.InsertAll(dict); IFilter filter = new GreaterFilter(IdentityExtractor.Instance, 5); object[] keys = cache.GetKeys(filter); Assert.AreEqual(keys.Length, 5); for (int i = 6; i <= 10; i++) { Assert.Contains(GetKeyObject("key" + i), keys); } CacheFactory.Shutdown(); }
public void TestCompositeAggregator() { IEntryAggregator agg1 = CompositeAggregator.CreateInstance( new IEntryAggregator[] { GroupAggregator.CreateInstance(IdentityExtractor.Instance, new Count()), new LongMax((IdentityExtractor.Instance)) }); ArrayList al = new ArrayList(); al.Add(new TestInvocableCacheEntry("key1", 173)); al.Add(new TestInvocableCacheEntry("key2", 173)); al.Add(new TestInvocableCacheEntry("key3", 185)); al.Add(new TestInvocableCacheEntry("key4", 164)); al.Add(new TestInvocableCacheEntry("key5", 164)); al.Add(new TestInvocableCacheEntry("key6", 164)); object result = agg1.Aggregate(al); if (result is IList) { IDictionary results = (IDictionary)((IList)result)[0]; Assert.AreEqual(results[185], 1); Assert.AreEqual(results[164], 3); Assert.AreEqual(((IList)result)[1], 185); } // aggragation on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); HashDictionary hd = new HashDictionary(); hd.Add("Key1", 435); hd.Add("Key2", 253); hd.Add("Key3", 435); hd.Add("Key4", 435); hd.Add(null, -3); cache.InsertAll(hd); IEntryAggregator aggregator = CompositeAggregator.CreateInstance( new IEntryAggregator[] { GroupAggregator.CreateInstance(IdentityExtractor.Instance, new Count()), new LongMax((IdentityExtractor.Instance)) }); result = cache.Aggregate(cache.Keys, aggregator); if (result is IList) { IDictionary results = (IDictionary)((IList)result)[0]; Assert.AreEqual(results[435], 3); Assert.AreEqual(results[-3], 1); Assert.AreEqual(((IList)result)[1], 435); } CacheFactory.Shutdown(); }
public void TestConditionalPutAll() { Hashtable ht = new Hashtable(); ht.Add("key1", 100); ht.Add("key2", 200); ht.Add("key3", 300); ConditionalPutAll conditionalPutAll = new ConditionalPutAll(AlwaysFilter.Instance, ht); ConditionalPutAll conditionalPutAll1 = new ConditionalPutAll(AlwaysFilter.Instance, ht); Assert.AreEqual(conditionalPutAll.ToString(), conditionalPutAll1.ToString()); LocalCache lCache = new LocalCache(); IInvocableCacheEntry entry = new LocalCache.Entry(lCache, "key2", 400); Object result = conditionalPutAll.Process(entry); Assert.AreEqual(200, entry.Value); // testing on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); 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 ConditionalPutAll processor = new ConditionalPutAll(AlwaysFilter.Instance, htPut); cache.Invoke("conditionalPutAllKey1", processor); Assert.IsNotNull(cache["conditionalPutAllKey1"]); Assert.AreEqual(cache["conditionalPutAllKey1"], htPut["conditionalPutAllKey1"]); // 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 TestEvents() { // start the ProxyService on just one cluster node IInvocationService invocationService = RestartProxy(null); // put data items into inner cache to generate events INamedCache testCache = GetCache("proxy-stop-test"); testCache.Clear(); for (int i = 0; i < SOME_DATA; i++) { testCache.Add("TestKey" + i, i); } // create listener for CQC TestCQCListener listener = new TestCQCListener(SOME_DATA); // instantiate the CQC, will start the test running. theCQC = new ContinuousQueryCache(testCache, AlwaysFilter.Instance, listener); // instantiate a service listener to receive memberLeft event fMemberLeft = false; testCache.CacheService.MemberLeft += new MemberEventHandler(OnMemberLeft); // allow test time to complete. DateTime endTime = DateTime.Now.AddSeconds(30); while (listener.GetActualTotal() < SOME_DATA && (DateTime.Now < endTime)) { Thread.Sleep(250); } // check listener received the correct number of events. Assert.AreEqual(SOME_DATA, listener.GetActualTotal()); listener.ResetActualTotal(); // restart proxy RestartProxy(invocationService); endTime = DateTime.Now.AddSeconds(30); while (!fMemberLeft && (DateTime.Now < endTime)) { Thread.Sleep(250); } // ping the CQC to make it realize the cache needs restart. theCQC.Contains("junkstuff"); // allow test time to complete. endTime = DateTime.Now.AddSeconds(30); while (listener.GetActualTotal() < SOME_DATA && (DateTime.Now < endTime)) { Thread.Sleep(250); } Assert.AreEqual(SOME_DATA, listener.GetActualTotal()); }
public void TestLongMaxAggregator() { LongMax agg1 = new LongMax(IdentityExtractor.Instance); Assert.IsNotNull(agg1); Assert.AreSame(IdentityExtractor.Instance, agg1.Extractor); LongMax agg2 = new LongMax("dummy"); Assert.IsNotNull(agg2); Assert.IsInstanceOf(typeof(ReflectionExtractor), agg2.Extractor); LongMax agg3 = new LongMax("another.dummy"); Assert.IsNotNull(agg3); Assert.IsInstanceOf(typeof(ChainedExtractor), agg3.Extractor); ArrayList al = new ArrayList(); al.Add(new TestInvocableCacheEntry("Ivan", 173)); al.Add(new TestInvocableCacheEntry("Milica", 173)); al.Add(new TestInvocableCacheEntry("Goran", 185.1)); al.Add(new TestInvocableCacheEntry("Ana", 164.08)); Assert.AreEqual(185, agg1.Aggregate(al)); al = new ArrayList(); al.Add(new TestInvocableCacheEntry("Ivan", 173)); al.Add(new TestInvocableCacheEntry("Milica", 173)); al.Add(new TestInvocableCacheEntry("Goran", 185)); al.Add(new TestInvocableCacheEntry("Ana", 164)); Assert.AreEqual(185, agg1.Aggregate(al)); // aggragation on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Hashtable ht = new Hashtable(); ht.Add("key1", 1011.21); ht.Add("key2", 80.5); ht.Add("key3", 19.5); ht.Add("key4", 2); ht.Add("key5", 1010); cache.InsertAll(ht); IEntryAggregator aggregator = new LongMax(IdentityExtractor.Instance); object result = cache.Aggregate(cache.Keys, aggregator); Assert.AreEqual(1011, result); cache.Insert("key5", Int32.MaxValue); result = cache.Aggregate(cache.Keys, aggregator); Assert.AreEqual(Int32.MaxValue, result); CacheFactory.Shutdown(); }
public void TestConditionalRemove() { ConditionalRemove conditionalRemove = new ConditionalRemove(new GreaterFilter(IdentityExtractor.Instance, 100), true); ConditionalRemove conditionalRemove1 = new ConditionalRemove(new GreaterFilter(IdentityExtractor.Instance, 100), true); Assert.AreEqual(conditionalRemove, conditionalRemove1); Assert.AreEqual(conditionalRemove.ToString(), conditionalRemove1.ToString()); Assert.AreEqual(conditionalRemove.GetHashCode(), conditionalRemove1.GetHashCode()); IInvocableCacheEntry entry = new LocalCache.Entry(new LocalCache(), "key1", 1200); Object result = conditionalRemove.Process(entry); Assert.IsNull(entry.Value); entry = new LocalCache.Entry(new LocalCache(), "key1", 50); result = conditionalRemove.Process(entry); Assert.AreEqual(50, entry.Value); // testing on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Hashtable ht = new Hashtable(); ht.Add("conditionalPutAllKey1", 435); ht.Add("conditionalPutAllKey2", 253); ht.Add("conditionalPutAllKey3", 200); ht.Add("conditionalPutAllKey4", 333); cache.InsertAll(ht); IFilter greaterThen300 = new GreaterFilter(IdentityExtractor.Instance, 300); IFilter lessThen300 = new LessFilter(IdentityExtractor.Instance, 300); Assert.IsTrue(cache.Count == 4); // remove key1 with greaterThen300 filter applied ConditionalRemove processor = new ConditionalRemove(greaterThen300, false); cache.Invoke("conditionalPutAllKey1", processor); Assert.IsTrue(cache.Count == 3); // remove all entries that satisfy filter criteria processor = new ConditionalRemove(greaterThen300, false); cache.InvokeAll(ht.Keys, processor); Assert.IsTrue(cache.Count == 2); Assert.IsNotNull(cache["conditionalPutAllKey2"]); Assert.IsNotNull(cache["conditionalPutAllKey3"]); processor = new ConditionalRemove(lessThen300, false); cache.InvokeAll(new GreaterFilter(IdentityExtractor.Instance, 200), processor); Assert.IsTrue(cache.Count == 1); Assert.IsNotNull(cache["conditionalPutAllKey3"]); CacheFactory.Shutdown(); }
/// <summary> /// Test CacheData. /// Put and get a set of data from cache. /// </summary> public void TestCacheData() { var map = new Hashtable(); var keys = new ArrayList(); for (int i = 0; i < 100; i++) { string key = "key" + i; keys.Add(key); map.Add(key, i); } namedCache.Clear(); namedCache.InsertAll(map); ICollection entrySet = namedCache.GetAll(keys); Assert.AreEqual(100, entrySet.Count); namedCache.Release(); }
public void TestGetEntries() { INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); IDictionary dict = new Hashtable(); for (int i = 1; i <= 10; i++) { dict.Add(GetKeyObject("key" + i), i); } cache.InsertAll(dict); IFilter filter = new GreaterFilter(IdentityExtractor.Instance, 5); ICacheEntry[] entries = cache.GetEntries(filter); Assert.AreEqual(entries.Length, 5); object[] keys = new object[5]; object[] values = new object[5]; for (int i = 0; i < 5; i++) { ICacheEntry entry = entries[i]; keys[i] = entry.Key; values[i] = entry.Value; } for (int i = 6; i <= 10; i++) { Assert.Contains(GetKeyObject("key" + i), keys); Assert.Contains(i, values); } entries = cache.GetEntries(filter, SafeComparer.Instance); Assert.AreEqual(entries.Length, 5); keys = new object[5]; values = new object[5]; for (int i = 0; i < 5; i++) { ICacheEntry entry = entries[i]; keys[i] = entry.Key; values[i] = entry.Value; } for (int i = 6; i <= 10; i++) { Assert.Contains(GetKeyObject("key" + i), keys); Assert.Contains(i, values); } Assert.AreEqual(values[0], 6); Assert.AreEqual(values[1], 7); Assert.AreEqual(values[2], 8); Assert.AreEqual(values[3], 9); Assert.AreEqual(values[4], 10); CacheFactory.Shutdown(); }
public void TestComparisonValueExtractor() { // testing on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Score score = new Score(1, 1, 126, 10000L, 1.24f, 1432.55, new decimal(11223344), new RawInt128(new byte[] { 1 }), 1); cache.Insert("score1", score); IValueExtractor exByte = new ReflectionExtractor("getByteValue"); IValueExtractor exShort = new ReflectionExtractor("getShortValue"); IValueExtractor exInt = new ReflectionExtractor("getIntValue"); IValueExtractor exLong = new ReflectionExtractor("getLongValue"); IValueExtractor exFloat = new ReflectionExtractor("getFloatValue"); IValueExtractor exDouble = new ReflectionExtractor("getDoubleValue"); IValueExtractor exDecimal = new ReflectionExtractor("getBigDecimalValue"); IValueExtractor exInt128 = new ReflectionExtractor("getBigIntegerValue"); //different ways to instantiate same extractor ComparisonValueExtractor cve1 = new ComparisonValueExtractor(exByte, exShort); ComparisonValueExtractor cve2 = new ComparisonValueExtractor(exInt, exLong); ComparisonValueExtractor cve3 = new ComparisonValueExtractor(exFloat, exDouble); ComparisonValueExtractor cve4 = new ComparisonValueExtractor(exDecimal, exDecimal); ComparisonValueExtractor cve5 = new ComparisonValueExtractor(exInt128, exInt128); IFilter filter = new EqualsFilter(cve1, score.ByteValue - score.ShortValue); ICollection keys = cache.GetKeys(filter); Assert.IsNotEmpty(keys); Assert.IsTrue(keys.Count == 1); filter = new EqualsFilter(cve2, score.IntValue - score.LongValue); keys = cache.GetKeys(filter); Assert.IsNotEmpty(keys); Assert.IsTrue(keys.Count == 1); filter = new EqualsFilter(cve3, score.FloatValue - score.DoubleValue); keys = cache.GetKeys(filter); Assert.IsNotEmpty(keys); Assert.IsTrue(keys.Count == 1); filter = new EqualsFilter(cve4, (decimal)0); keys = cache.GetKeys(filter); Assert.IsNotEmpty(keys); Assert.IsTrue(keys.Count == 1); filter = new EqualsFilter(cve5, NumberUtils.DecimalToRawInt128(score.RawInt128Value.ToDecimal() - score.RawInt128Value.ToDecimal())); keys = cache.GetKeys(filter); Assert.IsNotEmpty(keys); Assert.IsTrue(keys.Count == 1); CacheFactory.Shutdown(); }
public void TestNumberIncrementor() { Temperature belgrade = new Temperature(25, 'c', 1); int bgdBefore = belgrade.Value; PropertyManipulator valueManipulator = new PropertyManipulator("Value"); IEntryProcessor processor = new NumberIncrementor(valueManipulator, 1, true); IEntryProcessor processor1 = new NumberIncrementor(valueManipulator, 1, true); Assert.AreEqual(processor, processor1); Assert.AreEqual(processor.GetHashCode(), processor1.GetHashCode()); Assert.AreEqual(processor.ToString(), processor1.ToString()); LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "belgrade", belgrade); processor.Process(entry); Assert.AreEqual(bgdBefore + 1, ((Temperature)entry.Value).Value); processor.Process(entry); Assert.AreEqual(bgdBefore + 2, ((Temperature)entry.Value).Value); // testing on Remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Temperature bgd = new Temperature(25, 'c', 12); Temperature nyc = new Temperature(99, 'f', 12); cache.Insert("BGD", bgd); cache.Insert("NYC", nyc); PropertyManipulator manipulator = new PropertyManipulator("Value"); processor = new NumberIncrementor(manipulator, 1, true); object before = cache.Invoke("BGD", processor); Assert.AreEqual(bgd.Value, before); Temperature after = (Temperature)cache["BGD"]; Assert.AreEqual(((int)before) + 1, after.Value); processor = new NumberIncrementor(manipulator, -19, false); object newNYC = cache.Invoke("NYC", processor); Assert.AreEqual(nyc.Value - 19, newNYC); Score score = new Score(1, 1, 1, 1, 1, 1, 1, new RawInt128(new byte[] { 0 }), 1); LocalCache.Entry scoreEntry = new LocalCache.Entry(new LocalCache(), "score", score); valueManipulator = new PropertyManipulator("RawInt128Value"); processor = new NumberIncrementor(valueManipulator, 1, true); processor.Process(scoreEntry); CacheFactory.Shutdown(); }
public void TestDoubleAverageAggregator() { DoubleAverage agg1 = new DoubleAverage(IdentityExtractor.Instance); Assert.IsNotNull(agg1); Assert.AreSame(IdentityExtractor.Instance, agg1.Extractor); DoubleAverage agg2 = new DoubleAverage("dummy"); Assert.IsNotNull(agg2); Assert.IsInstanceOf(typeof(ReflectionExtractor), agg2.Extractor); DoubleAverage agg3 = new DoubleAverage("another.dummy"); Assert.IsNotNull(agg3); Assert.IsInstanceOf(typeof(ChainedExtractor), agg3.Extractor); ArrayList al = new ArrayList(); al.Add(new TestInvocableCacheEntry("Ivan", 173.6)); al.Add(new TestInvocableCacheEntry("Milica", 173.22)); al.Add(new TestInvocableCacheEntry("Goran", 185.1)); al.Add(new TestInvocableCacheEntry("Ana", 164.08)); Assert.AreEqual((173.6 + 173.22 + 185.1 + 164.08) / 4, agg1.Aggregate(al)); // aggragation on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Hashtable ht = new Hashtable(); ht.Add("doubleAvgKey1", 100); ht.Add("doubleAvgKey2", 80.5); ht.Add("doubleAvgKey3", 19.5); ht.Add("doubleAvgKey4", 2); cache.InsertAll(ht); IEntryAggregator aggregator = new DoubleAverage(IdentityExtractor.Instance); object result = cache.Aggregate(cache.Keys, aggregator); Assert.AreEqual(50.5, result); cache.Insert("comparableKey5", null); result = cache.Aggregate(cache.Keys, aggregator); Assert.AreEqual(50.5, result); IFilter filter = new AlwaysFilter(); result = cache.Aggregate(filter, aggregator); Assert.AreEqual(50.5, result); CacheFactory.Shutdown(); }
public virtual void TestNamedCache() { INamedCache cache = CacheFactory.GetCache(CacheName); Assert.IsTrue(cache.IsActive); cache.Clear(); Assert.AreEqual(cache.Count, 0); CacheFactory.ReleaseCache(cache); CacheFactory.Shutdown(); }