예제 #1
0
파일: LruTest.cs 프로젝트: zeus82/orleans
        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);
        }
예제 #2
0
파일: LRUTests.cs 프로젝트: BenGab/LRUNunit
        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));
        }
예제 #3
0
파일: LRUTests.cs 프로젝트: BenGab/LRUNunit
        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));
        }
예제 #4
0
파일: LRUTests.cs 프로젝트: BenGab/LRUNunit
        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));
        }
예제 #5
0
파일: LRUTests.cs 프로젝트: BenGab/LRUNunit
        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);
        }
예제 #6
0
        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"
        }
예제 #7
0
파일: LruTest.cs 프로젝트: Rejendo/orleans
        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);
        }
예제 #9
0
        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);
        }
예제 #11
0
파일: LRUTests.cs 프로젝트: BenGab/LRUNunit
        public void add_element_should_contains_in_list()
        {
            LRU sut = new LRU();

            sut.Add(5);

            Assert.That(sut.Elements.First(), Is.EqualTo(5));
        }
예제 #12
0
        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");
        }
예제 #13
0
        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");
            }
        }
예제 #14
0
파일: LruTest.cs 프로젝트: Rejendo/orleans
        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");
            }
        }
예제 #15
0
파일: LruTest.cs 프로젝트: Rejendo/orleans
        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");
            }
        }
예제 #16
0
        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");
            }
        }
예제 #17
0
파일: LRUTests.cs 프로젝트: BenGab/LRUNunit
        public void Add_null_Should_Throw_ArgumentNullException()
        {
            LRU sut = new LRU();

            Assert.Throws <ArgumentNullException>(() => sut.Add(null));
        }
예제 #18
0
 public void AddOrUpdate(GrainId key, TValue value, int version)
 {
     // ignore the version number
     cache.Add(key, value);
 }
예제 #19
0
 public void AddOrUpdate(GrainId key, IReadOnlyList <Tuple <SiloAddress, ActivationId> > value, int version)
 {
     // ignore the version number
     cache.Add(key, value);
 }