public void TestMainStoreDelete() { var mainStore = new MainStore <int, int>(); mainStore.PutValue(1, 2); mainStore.PutValue(2, 2); Assert.AreEqual(true, mainStore.DeleteValue(1)); Assert.AreEqual(1, mainStore.Count()); Assert.AreEqual(false, mainStore.DeleteValue(3)); }
public void TestMainStoreAdd() { var mainStore = new MainStore <int, int>(); mainStore.PutValue(1, 1); mainStore.PutValue(1, 2); Assert.AreEqual(1, mainStore.Count()); mainStore.PutValue(2, 1); Assert.AreEqual(2, mainStore.Count()); }
public void TestCacheListenerTesting() { var mainStore = new MainStore <int, int>(); uint nWay = 2; uint cacheEntries = 4; var cache = new Cache <int, int>(mainStore, nWay, cacheEntries); List <EventArgs> missEvents = new List <EventArgs>(); cache.CacheMissListener += delegate(object sender, EventArgs e) { missEvents.Add(e); }; List <InvalidationSource> invalidationEvents = new List <InvalidationSource>(); cache.CacheEvictionListener += delegate(object sender, InvalidationEventArgs e) { invalidationEvents.Add(e.Source); }; Assert.AreEqual((uint)2, cache.CacheSets); mainStore.PutValue(1, 1); mainStore.PutValue(2, 2); mainStore.PutValue(3, 3); mainStore.PutValue(4, 4); mainStore.PutValue(5, 5); cache.PutValue(1, 1); cache.PutValue(2, 2); cache.PutValue(3, 3); cache.PutValue(4, 4); // not in the cache int value; value = cache.TryGetValue(5); Assert.AreEqual(5, value); //value 5 isn't in the cache this prompts us to go to the store and reinsert it. Assert.AreEqual(InvalidationSource.Eviction, invalidationEvents[0]); Assert.AreEqual(1, missEvents.Count); cache.PutValue(7, 7); Assert.AreEqual(InvalidationSource.Eviction, invalidationEvents[1]); cache.DeleteValue(2); Assert.AreEqual(InvalidationSource.User, invalidationEvents[2]); cache.PutValue(4, 16); Assert.AreEqual(InvalidationSource.Replacement, invalidationEvents[3]); }
public void TestMainStoreGet() { var mainStore = new MainStore <int, int>(); mainStore.PutValue(1, 2); Assert.AreEqual(2, mainStore.GetValue(1)); mainStore.PutValue(2, 1); Assert.AreNotEqual(2, mainStore.GetValue(2)); var n = mainStore.GetValue(3); }
public void TestCachePutValue() { var mainStore = new MainStore <int, int>(); uint nWay = 4; uint cacheEntries = 8; var cache = new Cache <int, int>(mainStore, nWay, cacheEntries); Assert.AreEqual((uint)2, cache.CacheSets); mainStore.PutValue(1, 1); mainStore.PutValue(2, 2); mainStore.PutValue(3, 3); mainStore.PutValue(4, 4); mainStore.PutValue(5, 5); mainStore.PutValue(6, 6); mainStore.PutValue(7, 7); mainStore.PutValue(8, 8); mainStore.PutValue(9, 9); mainStore.PutValue(10, 10); mainStore.PutValue(11, 11); mainStore.PutValue(12, 12); cache.PutValue(1, 1); cache.PutValue(2, 2); cache.PutValue(3, 3); cache.PutValue(4, 4); cache.PutValue(5, 5); cache.PutValue(6, 6); cache.PutValue(7, 7); cache.PutValue(8, 8); int value; // all good value = cache.TryGetValue(1); Assert.AreEqual(1, value); value = cache.TryGetValue(2); Assert.AreEqual(2, value); value = cache.TryGetValue(3); Assert.AreEqual(3, value); value = cache.TryGetValue(4); Assert.AreEqual(4, value); value = cache.TryGetValue(5); Assert.AreEqual(5, value); value = cache.TryGetValue(6); Assert.AreEqual(6, value); value = cache.TryGetValue(7); Assert.AreEqual(7, value); value = cache.TryGetValue(8); Assert.AreEqual(8, value); // not in the cache value = cache.TryGetValue(9); Assert.AreEqual(9, value); //check that 1 got evicted var invalidateResult = cache.DeleteValue(1); Assert.AreEqual(false, invalidateResult); invalidateResult = cache.DeleteValue(2); Assert.AreEqual(true, invalidateResult); //check exception on search value that is not present var ex = Assert.ThrowsException <KeyNotFoundException>(() => cache.TryGetValue(13)); StringAssert.Contains(ex.Message, "The given key was not present in the dictionary"); }