Esempio n. 1
0
        public ILRUCache <SimpleLRUCacheItem, int> MakeRainbowCache_lockfree(int Capacity)
        {
            var c = new LRUCache_lockfree <SimpleLRUCacheItem, int, string>(Capacity);

            SimpleLRUCacheTests_lockfree.AddRainbowItems(c);
            return(c);
        }
Esempio n. 2
0
        public void CreateLRUCache_lockfree()
        {
            ILRUCache <SimpleLRUCacheItem, int> c = new LRUCache_lockfree <SimpleLRUCacheItem, int, string>();

            Console.WriteLine("Created Empty Cache.");
            Assert.AreEqual(0, c.Count, 0, "Cache size is not zero");
            c.Put(new SimpleLRUCacheItem(1, "Red"));
            Assert.AreEqual(1, c.Count, 0, "Cache size is not one");
            c.Put(new SimpleLRUCacheItem(2, "Blue"));
            Assert.AreEqual(2, c.Count, 0, "Cache size is not two");
            SimpleLRUCacheTests_lockfree.DumpCache(c, "Most Used/ Recently added to Least used/Oldest ");
            Console.WriteLine("lockfree Test Complete.");
        }
Esempio n. 3
0
        public void ExpirationTest1()
        {
            var c = new LRUCache_lockfree <SimpleLRUCacheItem, int, string>(10);

            c.Put(new SimpleLRUCacheItem(1, "Cat", new TimeSpan(0, 0, 5))); // 5 second timespan
            Assert.AreEqual(1, c.Count);
            Thread.Sleep(1 * 1000);                                         // Sleep for 5 seconds.
            Assert.AreEqual(1, c.Count);
            Assert.AreEqual("Cat", c.Get(1).Value);
            Thread.Sleep(4 * 1000); // Sleep for 5 seconds.
            Assert.AreEqual(1, c.Count);
            Thread.Sleep(1 * 1000); // Sleep for 5 seconds.
            try
            {
                var val = c.Get(1);
                Assert.IsTrue(true, "Cat should no longer be present");
            }
            catch
            {
                // Ignore
            }
        }
Esempio n. 4
0
        public void ManyGets10k()
        {
            var c = new LRUCache_lockfree <SimpleLRUCacheItem, int, string>(1000);

            ManyGets(c, 10000);
        }
Esempio n. 5
0
        public void RemoveTest()
        {
            var c = new LRUCache_lockfree <SimpleLRUCacheItem, int, string>(10);

            RemoveOneTest(c);
        }
Esempio n. 6
0
        public void ParallelOperation1()
        {
            var c = new LRUCache_lockfree <SimpleLRUCacheItem, int, string>(1000);

            ParallelOperations(c);
        }