public void TestNearCacheTruncate() { 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 BetweenFilter(IdentityExtractor.Instance, 2, 10); object[] result = nearcache.GetKeys(filter); Assert.AreEqual(3, result.Length); nearcache.Truncate(); Assert.IsTrue(nearcache.IsActive); Thread.Sleep(2000); result = nearcache.GetKeys(filter); Assert.AreEqual(0, result.Length); nearcache.Release(); Assert.IsFalse(nearcache.IsActive); CacheFactory.Shutdown(); }
public void NearCacheListenNoneAggregateTest() { 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); IEntryAggregator aggregator = new Count(); object count = nearcache.Aggregate(nearcache.Keys, aggregator); Assert.AreEqual(ht.Count, count); IFilter filter = new LessFilter(IdentityExtractor.Instance, 3); count = nearcache.Aggregate(filter, aggregator); Assert.AreEqual(2, count); nearcache.Clear(); nearcache.Release(); Assert.IsFalse(nearcache.IsActive); CacheFactory.Shutdown(); }
public void TestNearCacheDispose() { LocalNamedCache localcache = new LocalNamedCache(); INamedCache safecache = CacheFactory.GetCache(CacheName); NearCache nearcache; string[] keys = { "key1", "key2", "key3", "key4" }; string[] values = { "value1", "value2", "value3", "value4" }; using (nearcache = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone)) { nearcache.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]); nearcache.InsertAll(h); foreach (object key in nearcache.Keys) { Assert.IsTrue(nearcache.Contains(key)); } } //after disposal Assert.IsFalse(nearcache.IsActive); // fresh reference to the cache safecache = CacheFactory.GetCache(CacheName); Assert.IsTrue(safecache.IsActive); CacheFactory.Shutdown(); }
public void NearCacheListenNoneGetEntriesTest() { 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", 4); ht.Add("Goran", 3); ht.Add("Ivan", 2); nearcache.InsertAll(ht); IFilter filter = new BetweenFilter(IdentityExtractor.Instance, 2, 10); object[] result = nearcache.GetEntries(filter); Assert.AreEqual(3, result.Length); result = nearcache.GetEntries(filter, IdentityExtractor.Instance); for (int i = 0; i < result.Length; i++) { Assert.AreEqual(i + 2, ((ICacheEntry)result[i]).Value); } CacheFactory.Shutdown(); }
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 NearCacheListenNoneWithNullsTest() { 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(1, "Aleks"); ht.Add(2, "Ana"); ht.Add(3, "Goran"); ht.Add(4, "Ivan"); nearcache.InsertAll(ht); nearcache.Insert(5, null); Assert.AreEqual(ht.Count + 1, nearcache.Count); Assert.AreEqual(ht.Count, nearcache.FrontCache.Count); nearcache.Clear(); nearcache.Release(); Assert.IsFalse(nearcache.IsActive); CacheFactory.Shutdown(); }
public void NearCacheListenNoneCacheStatisticsTest() { 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(1, "Aleks"); ht.Add(2, "Ana"); ht.Add(3, "Goran"); ht.Add(4, "Ivan"); nearcache.InsertAll(ht); foreach (DictionaryEntry entry in ht) { Assert.IsTrue(nearcache.Contains(entry.Key)); } Assert.AreEqual(ht.Count, nearcache.CacheHits); localcache.LocalCache = new LocalCache(Int32.MaxValue, 1); Thread.Sleep(1); foreach (DictionaryEntry entry in ht) { Assert.IsTrue(nearcache.Contains(entry.Key)); } Assert.AreEqual(ht.Count, nearcache.CacheMisses); nearcache.Clear(); nearcache.Destroy(); Assert.IsFalse(nearcache.IsActive); }
public void TestNearNamedCacheInstancing() { IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-near-cache-config.xml"); ccf.Config = config; INamedCache cache = ccf.EnsureCache("dist-extend-direct"); Assert.IsNotNull(cache); Assert.IsInstanceOf(typeof(NearCache), cache); NearCache nc = cache as NearCache; Assert.IsNotNull(nc); ICache fc = nc.FrontCache; INamedCache bc = nc.BackCache; Assert.IsNotNull(fc); Assert.IsNotNull(bc); Assert.IsInstanceOf(typeof(SafeNamedCache), nc.BackCache); Assert.IsInstanceOf(typeof(LocalNamedCache), nc.FrontCache); SafeNamedCache sc = nc.BackCache as SafeNamedCache; Assert.IsNotNull(sc); Assert.AreEqual(sc.CacheName, "dist-extend-direct"); Assert.IsInstanceOf(typeof(RemoteNamedCache), sc.NamedCache); RemoteNamedCache rc = sc.NamedCache as RemoteNamedCache; Assert.IsNotNull(rc); Assert.AreEqual(rc.CacheName, sc.CacheName); LocalNamedCache lnc = nc.FrontCache as LocalNamedCache; Assert.IsNotNull(lnc); LocalCache lc = lnc.LocalCache; Assert.AreEqual(lc.ExpiryDelay, LocalCache.DEFAULT_EXPIRE); Assert.AreEqual(lc.FlushDelay, 0); Assert.AreEqual(lc.HighUnits, LocalCache.DEFAULT_UNITS); Assert.AreEqual(lc.CalculatorType, LocalCache.UnitCalculatorType.Fixed); Assert.AreEqual(lc.EvictionType, LocalCache.EvictionPolicyType.Hybrid); CacheFactory.Shutdown(); }
public void NearCacheListenNoneUnitsBeforePruningTest() { LocalNamedCache localcache = new LocalNamedCache(3); INamedCache safecache = CacheFactory.GetCache(CacheName); NearCache nearcache = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone); nearcache.Clear(); Hashtable ht = new Hashtable(); ht.Add(1, "Aleks"); ht.Add(2, "Ana"); ht.Add(3, "Goran"); ht.Add(4, "Ivan"); nearcache.InsertAll(ht); int miss = 0; int hit = 0; foreach (ICacheEntry entry in nearcache) { if (nearcache.FrontCache.Contains(entry.Key)) { hit++; } else { miss++; } } for (int i = 0; i < nearcache.Count; i++) { Assert.AreEqual(ht[i], nearcache[i]); } Assert.AreEqual(hit, nearcache.CacheHits); Assert.AreEqual(miss, nearcache.CacheMisses); nearcache.Clear(); nearcache.Release(); Assert.IsFalse(nearcache.IsActive); CacheFactory.Shutdown(); }
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); }
public void Coh8796() { LocalNamedCache localcache = new LocalNamedCache(); INamedCache safecache = CacheFactory.GetCache("dist-extend-direct"); NearCache nearcache = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenLogical); safecache.Clear(); ICache cacheFront = nearcache.FrontCache; ICache cacheBack = nearcache.BackCache; int cPuts = 1000; for (int i = 0; i < cPuts; i++) { cacheBack.Insert(i, i, 10000); if (i % 2 == 0) { Object o = nearcache[i]; Assert.AreEqual(i, o); } } Assert.AreEqual(cPuts / 2, cacheFront.Count); Assert.AreEqual(cPuts, cacheBack.Count); // expire the back map Thread.Sleep(15000); // calling Count expires the entries in the back and sends out synthetic deletes Assert.AreEqual(0, cacheBack.Count); // ensure that synthetic deletes are filtered out; // front map values for evens are still there for (int i = 0; i < cPuts; i++) { if (i % 2 == 0) { Assert.AreEqual(i, cacheFront[i]); } else { Assert.IsNull(cacheFront[i]); } } Assert.AreEqual(cPuts / 2, cacheFront.Count); // 0, 2, 4, ... Assert.AreEqual(0, cacheBack.Count); // ensure that Insert works, and that a value update is properly // raised to both the front and back maps for (int i = 0; i < cPuts; i++) { int nKey = i * 4; nearcache.Insert(nKey, nKey); Assert.AreEqual(nKey, cacheFront[nKey]); Assert.AreEqual(nKey, cacheBack[nKey]); cacheBack.Insert(nKey, nKey + 1); Assert.IsNull(cacheFront[nKey]); Assert.AreEqual(nKey + 1, cacheBack[nKey]); nearcache.Insert(nKey, nKey); Assert.AreEqual(nKey, cacheFront[nKey]); Assert.AreEqual(nKey, cacheBack[nKey]); cacheBack.Remove(nKey); Assert.IsFalse(cacheBack.Contains(nKey)); Assert.IsFalse(cacheFront.Contains(nKey)); Assert.IsNull(cacheBack[nKey]); Assert.IsNull(cacheFront[nKey]); } nearcache.Release(); // fresh reference to the cache safecache = CacheFactory.GetCache(CacheName); safecache.Destroy(); CacheFactory.Shutdown(); }
public void NearCacheListenNoneTest() { LocalNamedCache localcache = new LocalNamedCache(); INamedCache safecache = CacheFactory.GetCache(CacheName); NearCache nearcache = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone); nearcache.Clear(); nearcache.Add(1, "Ivan"); Assert.AreEqual(1, nearcache.Count); Assert.AreEqual(1, nearcache.FrontCache.Count); Assert.AreEqual(1, nearcache.BackCache.Count); nearcache.Insert(2, "Goran"); Assert.AreEqual(2, nearcache.Count); Assert.AreEqual(2, nearcache.FrontCache.Count); Assert.AreEqual(2, nearcache.BackCache.Count); Assert.IsTrue(nearcache.FrontCache.Contains(1)); Assert.IsTrue(nearcache.FrontCache.Contains(2)); Assert.IsTrue(nearcache.BackCache.Contains(1)); Assert.IsTrue(nearcache.BackCache.Contains(2)); object obj = nearcache[1]; Assert.AreEqual("Ivan", obj); obj = nearcache[2]; Assert.AreEqual("Goran", obj); nearcache.Clear(); Assert.AreEqual(0, nearcache.Count); Assert.IsTrue(nearcache.IsActive); localcache.LocalCache = new LocalCache(Int32.MaxValue, 500); nearcache.Insert(1, "Ana"); nearcache.Add(2, "Goran"); Assert.IsTrue(nearcache.FrontCache.Contains(1)); Assert.IsTrue(nearcache.FrontCache.Contains(2)); Assert.IsTrue(nearcache.BackCache.Contains(1)); Assert.IsTrue(nearcache.BackCache.Contains(2)); Thread.Sleep(1000); Assert.IsNull(nearcache.FrontCache[1]); Assert.IsNull(nearcache.FrontCache[2]); nearcache.Insert(3, "Ivan"); IDictionary dict = nearcache.GetAll(new object[] { 1, 2, 3, 4 }); Assert.AreEqual("Ana", dict[1]); Assert.AreEqual("Goran", dict[2]); Assert.AreEqual("Ivan", dict[3]); Assert.AreEqual(null, dict[4]); localcache.LocalCache = new LocalCache(); obj = nearcache[1]; Assert.AreEqual(obj, "Ana"); Assert.IsTrue(nearcache.FrontCache.Contains(1)); Assert.IsNull(nearcache.FrontCache[2]); Hashtable ht = new Hashtable(); ht.Add(2, "Goran"); ht.Add(3, "Ivan"); ht.Add(4, "Aleks"); nearcache.InsertAll(ht); nearcache.Remove(1); Assert.IsNull(nearcache.FrontCache[1]); Assert.IsNull(nearcache[1]); nearcache.Clear(); nearcache.Release(); Assert.IsFalse(nearcache.IsActive); CacheFactory.Shutdown(); }