public async Task LruRemoveExpired() { const int n = 10; const int maxSize = n * 2; var maxAge = TimeSpan.FromMilliseconds(500); LRU <string, string> .FetchValueDelegate f = null; var flushCounter = 0; var target = new LRU <string, string>(maxSize, maxAge, f); target.RaiseFlushEvent += (object o, LRU <string, string> .FlushEventArgs args) => flushCounter++; for (int i = 0; i < n; i++) { var s = i.ToString(); target.Add(s, $"item {s}"); } target.RemoveExpired(); Assert.Equal(0, flushCounter); Assert.Equal(n, target.Count); await Task.Delay(maxAge.Add(maxAge)); target.Add("expected", "value"); target.RemoveExpired(); Assert.Equal(n, flushCounter); Assert.Equal(1, target.Count); Assert.True(target.TryGetValue("expected", out var value)); Assert.Equal("value", value); }
public void overload_shoul_keep_same_lenght() { LRU sut = new LRU(1); sut.Add(5); sut.Add(6); Assert.That(sut.Elements.Count, Is.EqualTo(1)); }
public void every_element_should_be_first_item() { LRU sut = new LRU(); sut.Add(5); sut.Add(6); Assert.That(sut.Elements.First(), Is.EqualTo(6)); }
public void Add_ExistValut_Should_Move_To_Top() { LRU sut = new LRU(4); sut.Add(5); sut.Add(4); sut.Add(3); sut.Add(5); Assert.That(sut.Elements.Last, Is.Not.EqualTo(5)); }
public void overload_should_no_keep_last_element() { LRU sut = new LRU(1); sut.Add(5); sut.Add(6); List <object> expected = new List <object>() { 6 }; CollectionAssert.AreEqual(sut.Elements, expected); }
public void LruCountTest() { const int maxSize = 10; var maxAge = new TimeSpan(0, 1, 0, 0); var target = new LRU <string, string>(maxSize, maxAge); Assert.Equal(0, target.Count); // "Count wrong after construction" target.Add("1", "one"); Assert.Equal(1, target.Count); // "Count wrong after adding one item" target.Add("2", "two"); Assert.Equal(2, target.Count); // "Count wrong after adding two items" }
public void LruCountTest() { const int maxSize = 10; var maxAge = new TimeSpan(0, 1, 0, 0); LRU<string, string>.FetchValueDelegate f = null; var target = new LRU<string, string>(maxSize, maxAge, f); Assert.Equal(0, target.Count); // "Count wrong after construction" target.Add("1", "one"); Assert.Equal(1, target.Count); // "Count wrong after adding one item" target.Add("2", "two"); Assert.Equal(2, target.Count); // "Count wrong after adding two items" }
public void AddOrUpdate(ActivationAddress value, int version) { var entry = new GrainDirectoryCacheEntry(value, version, initialExpirationTimer); // Notice that LRU should know how to throw the oldest entry if the cache is full cache.Add(value.Grain, entry); }
public void AddOrUpdate(GrainId key, IReadOnlyList <Tuple <SiloAddress, ActivationId> > value, int version) { var entry = new GrainDirectoryCacheEntry(value, version, DateTime.UtcNow, initialExpirationTimer); // Notice that LRU should know how to throw the oldest entry if the cache is full cache.Add(key, entry); }
public void AddOrUpdate(GrainId key, TValue value, int version) { var entry = new GrainDirectoryCacheEntry(value, version, DateTime.UtcNow, initialExpirationTimer); // Notice that LRU should know how to throw the oldest entry if the cache is full cache.Add(key, entry); }
public void add_element_should_contains_in_list() { LRU sut = new LRU(); sut.Add(5); Assert.That(sut.Elements.First(), Is.EqualTo(5)); }
public void LruCountTest() { const int maxSize = 10; var maxAge = new TimeSpan(0, 1, 0, 0); LRU <string, string> .FetchValueDelegate f = null; var target = new LRU <string, string>(maxSize, maxAge, f); Assert.AreEqual(0, target.Count, "Count wrong after construction"); target.Add("1", "one"); Assert.AreEqual(1, target.Count, "Count wrong after adding one item"); target.Add("2", "two"); Assert.AreEqual(2, target.Count, "Count wrong after adding two items"); }
public void LruUsageTest() { const int maxSize = 10; var maxAge = new TimeSpan(0, 1, 0, 0); LRU <string, string> .FetchValueDelegate f = null; var target = new LRU <string, string>(maxSize, maxAge, f); // Fill the LRU with "1" through "10" for (var i = 1; i <= maxSize; i++) { var s = i.ToString(); target.Add(s, "item " + s); Thread.Sleep(10); } // Use "10", then "9", etc. for (var i = maxSize; i >= 1; i--) { var s = i.ToString(); string val; target.TryGetValue(s, out val); } // Add a new item to push the least recently used out -- which should be item "10" var s1 = (maxSize + 1).ToString(); target.Add(s1, "item " + s1); Assert.Equal(maxSize, target.Count); // "Cache has exceeded maximum size" var s0 = maxSize.ToString(); Assert.False(target.ContainsKey(s0), "Least recently used item was not expelled"); for (var i = 1; i < maxSize; i++) { var s = i.ToString(); Assert.True(target.ContainsKey(s), "Recently used item " + s + " was incorrectly expelled"); } }
public void LruUsageTest() { const int maxSize = 10; var maxAge = new TimeSpan(0, 1, 0, 0); LRU<string, string>.FetchValueDelegate f = null; var target = new LRU<string, string>(maxSize, maxAge, f); // Fill the LRU with "1" through "10" for (var i = 1; i <= maxSize; i++) { var s = i.ToString(); target.Add(s, "item " + s); Thread.Sleep(10); } // Use "10", then "9", etc. for (var i = maxSize; i >= 1; i--) { var s = i.ToString(); string val; target.TryGetValue(s, out val); } // Add a new item to push the least recently used out -- which should be item "10" var s1 = (maxSize + 1).ToString(); target.Add(s1, "item " + s1); Assert.Equal(maxSize, target.Count); // "Cache has exceeded maximum size" var s0 = maxSize.ToString(); Assert.False(target.ContainsKey(s0), "Least recently used item was not expelled"); for (var i = 1; i < maxSize; i++) { var s = i.ToString(); Assert.True(target.ContainsKey(s), "Recently used item " + s + " was incorrectly expelled"); } }
public void LruMaximumSizeTest() { const int maxSize = 10; var maxAge = new TimeSpan(0, 1, 0, 0); LRU<string, string>.FetchValueDelegate f = null; var target = new LRU<string, string>(maxSize, maxAge, f); for (var i = 1; i <= maxSize + 5; i++) { var s = i.ToString(); target.Add(s, "item " + s); Thread.Sleep(10); } Assert.Equal(maxSize, target.Count); // "LRU grew larger than maximum size" for (var i = 1; i <= 5; i++) { var s = i.ToString(); Assert.False(target.ContainsKey(s), "'Older' entry is still in cache"); } }
public void LruMaximumSizeTest() { const int maxSize = 10; var maxAge = new TimeSpan(0, 1, 0, 0); var target = new LRU <string, string>(maxSize, maxAge); for (var i = 1; i <= maxSize + 5; i++) { var s = i.ToString(); target.Add(s, "item " + s); Thread.Sleep(10); } Assert.Equal(maxSize, target.Count); // "LRU grew larger than maximum size" for (var i = 1; i <= 5; i++) { var s = i.ToString(); Assert.False(target.ContainsKey(s), "'Older' entry is still in cache"); } }
public void Add_null_Should_Throw_ArgumentNullException() { LRU sut = new LRU(); Assert.Throws <ArgumentNullException>(() => sut.Add(null)); }
public void AddOrUpdate(GrainId key, TValue value, int version) { // ignore the version number cache.Add(key, value); }
public void AddOrUpdate(GrainId key, IReadOnlyList <Tuple <SiloAddress, ActivationId> > value, int version) { // ignore the version number cache.Add(key, value); }