Exemplo n.º 1
0
        public void LruBoundedCache_must_work_with_lower_age_threshold()
        {
            foreach (var i in Enumerable.Range(1, 10))
            {
                var seed  = ThreadLocalRandom.Current.Next(1024);
                var cache = new TestCache(4, 2, seed.ToString());

                cache.ExpectComputed("A", "A:0");
                cache.ExpectComputed("B", "B:1");
                cache.ExpectComputed("C", "C:2");
                cache.ExpectComputed("D", "D:3");
                cache.ExpectComputed("E", "E:4");

                cache.ExpectCached("D", "D:3");
                cache.ExpectCached("E", "E:4");

                cache.ExpectComputed("F", "F:5");
                cache.ExpectComputed("G", "G:6");
                cache.ExpectComputed("H", "H:7");
                cache.ExpectComputed("I", "I:8");
                cache.ExpectComputed("J", "J:9");

                cache.ExpectCached("I", "I:8");
                cache.ExpectCached("J", "J:9");
            }
        }
Exemplo n.º 2
0
        public void LruBoundedCache_must_not_cache_noncacheable_values()
        {
            var cache = new TestCache(4, 4);

            cache.ExpectComputedOnly("#A", "#A:0");
            cache.ExpectComputedOnly("#A", "#A:1");
            cache.ExpectComputedOnly("#A", "#A:2");
            cache.ExpectComputedOnly("#A", "#A:3");

            cache.ExpectComputed("A", "A:4");
            cache.ExpectComputed("B", "B:5");
            cache.ExpectComputed("C", "C:6");
            cache.ExpectComputed("D", "D:7");
            cache.ExpectComputed("E", "E:8");

            cache.ExpectComputedOnly("#A", "#A:9");
            cache.ExpectComputedOnly("#A", "#A:10");
            cache.ExpectComputedOnly("#A", "#A:11");
            cache.ExpectComputedOnly("#A", "#A:12");

            // Cacheable values are not affected
            cache.ExpectCached("B", "B:5");
            cache.ExpectCached("C", "C:6");
            cache.ExpectCached("D", "D:7");
            cache.ExpectCached("E", "E:8");
        }
Exemplo n.º 3
0
        public void LruBoundedCache_must_work_in_the_happy_case()
        {
            var cache = new TestCache(4, 4);

            cache.ExpectComputed("A", "A:0");
            cache.ExpectComputed("B", "B:1");
            cache.ExpectComputed("C", "C:2");
            cache.ExpectComputed("D", "D:3");

            cache.ExpectCached("A", "A:0");
            cache.ExpectCached("B", "B:1");
            cache.ExpectCached("C", "C:2");
            cache.ExpectCached("D", "D:3");
        }
Exemplo n.º 4
0
        public void LruBoundedCache_must_evict_oldest_when_full()
        {
            foreach (var i in Enumerable.Range(1, 10))
            {
                var seed  = ThreadLocalRandom.Current.Next(1024);
                var cache = new TestCache(4, 4, seed.ToString());

                cache.ExpectComputed("A", "A:0");
                cache.ExpectComputed("B", "B:1");
                cache.ExpectComputed("C", "C:2");
                cache.ExpectComputed("D", "D:3");
                cache.ExpectComputed("E", "E:4");

                cache.ExpectCached("B", "B:1");
                cache.ExpectCached("C", "C:2");
                cache.ExpectCached("D", "D:3");
                cache.ExpectCached("E", "E:4");

                cache.ExpectComputed("A", "A:5");
                cache.ExpectComputed("B", "B:6");
                cache.ExpectComputed("C", "C:7");
                cache.ExpectComputed("D", "D:8");
                cache.ExpectComputed("E", "E:9");

                cache.ExpectCached("B", "B:6");
                cache.ExpectCached("C", "C:7");
                cache.ExpectCached("D", "D:8");
                cache.ExpectCached("E", "E:9");
            }
        }