public void TestCustomUnitCalculator() { 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-custom-unit-calculator"); Assert.IsTrue(cache is LocalNamedCache); LocalNamedCache localNamedCache = cache as LocalNamedCache; Assert.IsNotNull(localNamedCache); LocalCache localCache = localNamedCache.LocalCache; Assert.IsNotNull(localCache); Assert.IsNotNull(localCache.UnitCalculator); localCache.Insert("key1", "value1"); localCache.Insert("key2", "value2"); LocalCache.Entry entry = localCache.GetEntry("key1"); //evaluates total units in the cache and each entry's units Assert.AreEqual(localCache.CalculatorType, LocalCache.UnitCalculatorType.External); Assert.IsInstanceOf(typeof(TestUnitCalculator), localCache.UnitCalculator); Assert.AreEqual(localCache.Units, 4); Assert.AreEqual(entry.Units, 2); CacheFactory.Shutdown(); }
public void TestInsertWithMillis() { 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"); Assert.IsTrue(cache is LocalNamedCache); LocalNamedCache localNamedCache = cache as LocalNamedCache; Assert.IsNotNull(localNamedCache); localNamedCache.Insert("key1", new LocalCache.Entry(localNamedCache.LocalCache, "key1", "value1"), 300); Assert.IsNotNull(localNamedCache["key1"]); lock (this) { Monitor.Wait(this, 400); } Assert.IsNull(localNamedCache["key1"]); CacheFactory.Shutdown(); }
public void TestCustomEvictionPolicy() { 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-custom-eviction"); Assert.IsTrue(cache is LocalNamedCache); LocalNamedCache localNamedCache = cache as LocalNamedCache; Assert.IsNotNull(localNamedCache); LocalCache localCache = localNamedCache.LocalCache; Assert.IsNotNull(localCache); Assert.AreEqual(localCache.EvictionType, LocalCache.EvictionPolicyType.External); Assert.IsInstanceOf(typeof(TestEvictionPolicy), localCache.EvictionPolicy); CacheFactory.Shutdown(); }
public void TestLocalNamedCacheDispose() { IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml"); ccf.Config = config; INamedCache cache; string[] keys = { "key1", "key2", "key3", "key4" }; string[] values = { "value1", "value2", "value3", "value4" }; using (cache = CacheFactory.GetCache("local-default")) { 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); foreach (object key in cache.Keys) { Assert.IsTrue(cache.Contains(key)); } } //after disposal Assert.IsFalse(cache.IsActive); LocalNamedCache lnc = cache as LocalNamedCache; Assert.IsNotNull(lnc); Assert.IsTrue(lnc.IsReleased); Assert.IsNull(lnc.CacheService); CacheFactory.Shutdown(); }
public void TestIndexes() { 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"); Assert.IsTrue(cache is LocalNamedCache); LocalNamedCache localNamedCache = cache as LocalNamedCache; Assert.IsNotNull(localNamedCache); localNamedCache.AddIndex(IdentityExtractor.Instance, true, null); localNamedCache.RemoveIndex(IdentityExtractor.Instance); localNamedCache.AddIndex(IdentityExtractor.Instance, true, SafeComparer.Instance); localNamedCache.RemoveIndex(IdentityExtractor.Instance); localNamedCache.AddIndex(IdentityExtractor.Instance, false, null); localNamedCache.RemoveIndex(IdentityExtractor.Instance); localNamedCache.AddIndex(IdentityExtractor.Instance, false, SafeComparer.Instance); localNamedCache.RemoveIndex(IdentityExtractor.Instance); CacheFactory.Shutdown(); }
public void TestLocking() { 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"); Assert.IsTrue(cache is LocalNamedCache); LocalNamedCache localNamedCache = cache as LocalNamedCache; Assert.IsNotNull(localNamedCache); Hashtable ht = new Hashtable(); ht.Add("key1", 435); ht.Add("key2", 253); ht.Add("key3", 3); ht.Add("key4", 200); localNamedCache.InsertAll(ht); localNamedCache.Lock("key2"); localNamedCache.Lock("key2", 1000); localNamedCache.Unlock("key2"); GreaterFilter filter = new GreaterFilter(IdentityExtractor.Instance, 280); object[] results = localNamedCache.GetValues(filter, null); Assert.AreEqual(1, results.Length); Assert.AreEqual(435, results[0]); results = localNamedCache.GetEntries(filter, null); Assert.AreEqual(1, results.Length); Assert.AreEqual(435, ((ICacheEntry)results[0]).Value); CacheFactory.Shutdown(); }
public void TestEntries() { 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"); Assert.IsTrue(cache is LocalNamedCache); LocalNamedCache localNamedCache = cache as LocalNamedCache; Assert.IsNotNull(localNamedCache); Hashtable ht = new Hashtable(); ht.Add("key1", 435); ht.Add("key2", 253); ht.Add("key3", 3); ht.Add("key4", 200); localNamedCache.InsertAll(ht); ICollection result = localNamedCache.Entries; Assert.IsNotNull(result); Assert.AreEqual(4, result.Count); result = localNamedCache.Values; Assert.IsNotNull(result); Assert.AreEqual(4, result.Count); int[] results = new int[localNamedCache.Count]; localNamedCache.CopyTo(results, 0); Assert.AreEqual(localNamedCache.Count, result.Count); CacheFactory.Shutdown(); }
public void TestPropertiesAndMethods() { LocalNamedCache lnc = new LocalNamedCache(10, 10, null); Assert.IsNotNull(lnc); lnc = new LocalNamedCache(10, 10, 15.5); Assert.IsNotNull(lnc); 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"); Assert.IsTrue(cache is LocalNamedCache); LocalNamedCache localNamedCache = cache as LocalNamedCache; Assert.IsNotNull(localNamedCache); Assert.AreEqual("local-default", localNamedCache.CacheName); Assert.IsNull(localNamedCache.CacheService); Assert.IsTrue(localNamedCache.IsActive); Assert.IsFalse(localNamedCache.IsReleased); Assert.IsFalse(localNamedCache.IsReadOnly); Assert.IsFalse(localNamedCache.IsFixedSize); Assert.IsNotNull(localNamedCache.SyncRoot); Assert.IsTrue(localNamedCache.IsSynchronized); localNamedCache.Release(); localNamedCache.Destroy(); }
public void TestExpiry() { 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-with-init"); 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); lock (this) { Monitor.Wait(this, 50); } foreach (ICacheEntry entry in cache) { Assert.IsTrue(entry is LocalCache.Entry); Assert.IsTrue(((LocalCache.Entry)entry).IsExpired); } cache = CacheFactory.GetCache("local-custom-impl-with-init"); cache.Clear(); 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); lock (this) { Monitor.Wait(this, 50); } foreach (ICacheEntry entry in cache) { Assert.IsTrue(entry is LocalCache.Entry); Assert.IsFalse(((LocalCache.Entry)entry).IsExpired); } LocalNamedCache localCache = new LocalNamedCache(); localCache.LocalCache.ExpiryDelay = 50; localCache.Clear(); localCache.Insert("key1", 100.0, 2100); localCache.Insert("key2", 801.5, 2100); localCache.Insert("key3", 40.1, 2100); lock (this) { Monitor.Wait(this, 2300); } foreach (ICacheEntry entry in localCache) { Assert.IsTrue(entry is LocalCache.Entry); Assert.IsTrue(((LocalCache.Entry)entry).IsExpired); } CacheFactory.Shutdown(); }