private void AssertAddedFirst(LRUMap map, Object key, Object value) { map.Add(key, value); Assert.AreEqual(key, ((ArrayList)map.Keys)[0]); Assert.AreEqual(value, ((ArrayList)map.Values)[0]); Assert.IsTrue(map.Count <= map.MaxSize); }
private void AssertSetIsMostRecent(LRUMap map, Object key, Object value) { map[key] = value; Assert.AreEqual(key, ((ArrayList)map.Keys)[0]); Assert.AreEqual(value, ((ArrayList)map.Values)[0]); Assert.IsTrue(map.Count <= map.MaxSize); }
public void RemoveEmpty() { int size = 10; IDictionary cache = new LRUMap(size); cache.Remove("key:" + 1); }
private void AssertGetIsMostRecent(LRUMap map, Object key, Object value) { Object o = map[key]; Assert.AreEqual(value, o); Assert.AreEqual(key, ((ArrayList)map.Keys)[0]); Assert.AreEqual(value, ((ArrayList)map.Values)[0]); }
public void PutAndRemove() { int size = 10; IDictionary cache = new LRUMap(size); cache.Add("key:" + 1, "data:" + 1); cache.Remove("key:" + 1); Assert.IsNull(cache["key:" + 1]); }
public void PutWithSizeLimitOfZero() { IDictionary cache = new LRUMap(0); cache.Add("key", "data"); string data = (string)cache["key"]; Assert.IsNull(data, "Data is wrong."); }
public void IndexerDoesBoundsChecking() { var map = new LRUMap(128); for (int i = 0; i < 200; i++) { map["str" + i] = i; } Assert.That(map.Count, Is.EqualTo(128)); }
public void AddDoesBoundsChecking() { var map = new LRUMap(128); for (int i = 0; i < 200; i++) { map.Add("str" + i, i); } Assert.That(map.Count, Is.EqualTo(128)); }
public void initialize(IRuntimeServices rs) { this.rsvc = rs; int @int = this.rsvc.GetInt("resource.manager.defaultcache.size", 89); if (@int > 0) { LRUMap lRUMap = LRUMap.Synchronized(new LRUMap(@int)); lRUMap.AddAll(this.cache); this.cache = lRUMap; } this.rsvc.Info("ResourceCache : initialized. (" + base.GetType() + ")"); }
/// <seealso cref="org.apache.velocity.runtime.resource.ResourceCache.Initialize(org.apache.velocity.runtime.RuntimeServices)"> /// </seealso> public virtual void Initialize(IRuntimeServices rs) { rsvc = rs; int maxSize = rsvc.GetInt(NVelocity.Runtime.RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE, 89); if (maxSize > 0) { // Create a whole new Map here to avoid hanging on to a // handle to the unsynch'd LRUMap for our lifetime. LRUMap lruCache = LRUMap.Synchronized(new LRUMap(maxSize)); lruCache.AddAll(cache); cache = lruCache; } rsvc.Log.Debug("ResourceCache: initialized (" + this.GetType() + ") with " + cache.GetType() + " cache map."); }
public void PutWithNoSizeLimit() { int size = 10; IDictionary cache = new LRUMap(); for (int i = 0; i < size; i++) { cache.Add("key:" + i, "data:" + i); } for (int i = 0; i < size; i++) { string data = (string)cache["key:" + i]; Assert.AreEqual("data:" + i, data, "Data is wrong."); } }
public void initialize(IRuntimeServices rs) { runtimeServices = rs; int maxSize = runtimeServices.GetInt(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE, 89); if (maxSize > 0) { // Create a whole new Map here to avoid hanging on to a // handle to the unsynch'd LRUMap for our lifetime. LRUMap lruCache = LRUMap.Synchronized(new LRUMap(maxSize)); lruCache.AddAll(cache); cache = lruCache; } runtimeServices.Info(string.Format("ResourceCache : initialized. ({0})", GetType())); }
public void initialize(RuntimeServices rs) { rsvc = rs; int maxSize = rsvc.getInt(RuntimeConstants_Fields.RESOURCE_MANAGER_DEFAULTCACHE_SIZE, 89); if (maxSize > 0) { // Create a whole new Map here to avoid hanging on to a // handle to the unsynch'd LRUMap for our lifetime. LRUMap lruCache = LRUMap.Synchronized(new LRUMap(maxSize)); lruCache.AddAll(cache); cache = lruCache; } rsvc.info("ResourceCache : initialized. (" + this.GetType() + ")"); }
public void GetEntrySet() { int size = 10; IDictionary cache = new LRUMap(size); for (int i = 0; i < size; i++) { cache.Add("key:" + i, "data:" + i); } Assert.AreEqual(size, cache.Keys.Count, "Set contains the wrong number of items."); // check minimal correctness foreach (DictionaryEntry entry in cache) { Assert.AreNotEqual(-1, entry.Value.ToString().IndexOf("data:")); } }
public void Test() { LRUMap map = new LRUMap(5); AssertAddedFirst(map, "One", 1); AssertAddedFirst(map, "Two", 2); AssertAddedFirst(map, "Three", 3); AssertAddedFirst(map, "Four", 4); AssertAddedFirst(map, "Five", 5); AssertAddedFirst(map, "Six", 6); Assert.IsTrue(!map.Contains("One")); AssertAddedFirst(map, "Seven", 7); Assert.IsTrue(!map.Contains("Two")); AssertAddedFirst(map, "Eight", 8); Assert.IsTrue(!map.Contains("Three")); AssertAddedFirst(map, "Nine", 9); Assert.IsTrue(!map.Contains("Four")); AssertAddedFirst(map, "Ten", 10); Assert.IsTrue(!map.Contains("Five")); map.Remove("Eight"); Assert.AreEqual(4, map.Count); map.Add("One", 1); Assert.AreEqual(5, map.Count); Assert.IsTrue(map.Contains("One")); Assert.IsTrue(map.Contains("Six")); Assert.IsTrue(map.Contains("Seven")); Assert.IsTrue(map.Contains("Nine")); Assert.IsTrue(map.Contains("Ten")); Assert.AreEqual("Six", ((ArrayList)map.Keys)[map.Count - 1]); Assert.AreEqual("One", ((ArrayList)map.Keys)[0]); AssertGetIsMostRecent(map, "Six", 6); AssertGetIsMostRecent(map, "Nine", 9); AssertGetIsMostRecent(map, "Seven", 7); AssertGetIsMostRecent(map, "Ten", 10); AssertGetIsMostRecent(map, "One", 1); Assert.AreEqual("Six", ((ArrayList)map.Keys)[map.Count - 1]); AssertSetIsMostRecent(map, "One", "Uno"); AssertSetIsMostRecent(map, "Two", "Dos"); Assert.AreEqual(5, map.Count); }
public LocalCache(int capacity) { this.lru = new LRUMap <TKey, ExpirableValue <TValue> >(capacity); }