public void RemovalFailureDuringCacheExpirationDoesFireEvents() { ICacheOperations cacheOperations = new FailingOnRemovalCacheOperations(); ExpirationTask expiration = new ExpirationTask(cacheOperations, instrumentationProvider); CacheItem expiredItem1 = new CacheItem(key1, new object(), CacheItemPriority.NotRemovable, new ExceptionThrowingCallback(), new AlwaysExpired()); cacheOperations.CurrentCacheState.Add(key1, expiredItem1); expiredItem1.WillBeExpired = true; expiration.SweepExpiredItemsFromCache(cacheOperations.CurrentCacheState); Assert.AreEqual(1, instrumentationListener.eventArgs.Count); Assert.AreSame(typeof(CacheFailureEventArgs), instrumentationListener.eventArgs[0].GetType()); }
public void RemovalFailureDuringCacheScavengingDoesFireEvents() { ICacheOperations cacheOperations = new FailingOnRemovalCacheOperations(); CacheItem item = new CacheItem(key1, new object(), CacheItemPriority.Low, null); cacheOperations.CurrentCacheState.Add(key1, item); cacheOperations.CurrentCacheState.Add("differentKey", item); ScavengerTask scavenging = new ScavengerTask(1, new CacheCapacityScavengingPolicy(1), cacheOperations, instrumentationProvider); scavenging.DoScavenging(); // two events for each of the items failing to be scavenged, and one for the announcement // that scavenging is finished with 0 items scavenged. Assert.AreEqual(3, instrumentationListener.eventArgs.Count); IList <CacheScavengedEventArgs> scavenges = FilterEventArgs <CacheScavengedEventArgs>(instrumentationListener.eventArgs); IList <CacheFailureEventArgs> failures = FilterEventArgs <CacheFailureEventArgs>(instrumentationListener.eventArgs); Assert.AreEqual(1, scavenges.Count); Assert.AreEqual(2, failures.Count); }
public void CacheScavengeUnsuccessfulDoesFireEvents() { ICacheOperations cacheOperations = new FailingOnRemovalCacheOperations(); CacheItem item1 = new CacheItem(key1, new object(), CacheItemPriority.NotRemovable, null); cacheOperations.CurrentCacheState.Add(key1, item1); CacheItem item2 = new CacheItem(key2, new object(), CacheItemPriority.NotRemovable, null); cacheOperations.CurrentCacheState.Add(key2, item2); CacheItem item3 = new CacheItem(key3, new object(), CacheItemPriority.NotRemovable, null); cacheOperations.CurrentCacheState.Add(key3, item3); ScavengerTask scavenging = new ScavengerTask(2, new CacheCapacityScavengingPolicy(2), cacheOperations, instrumentationProvider); scavenging.DoScavenging(); Assert.AreEqual(1, instrumentationListener.eventArgs.Count); IList <CacheScavengedEventArgs> scavenges = FilterEventArgs <CacheScavengedEventArgs>(instrumentationListener.eventArgs); Assert.AreEqual(1, scavenges.Count); Assert.AreEqual(0L, scavenges[0].ItemsScavenged); }