コード例 #1
0
            private ICacheEvent DuplicateEvent(ICacheEvent cacheEvent)
            {
                SettableCacheEvent copyEvent = SettableCacheEvent.Obtain();

                copyEvent.SetCacheKey(cacheEvent.CacheKey);
                copyEvent.SetCacheLimit(cacheEvent.CacheLimit);
                copyEvent.SetCacheSize(cacheEvent.CacheSize);
                copyEvent.SetEvictionReason(cacheEvent.EvictionReason);
                copyEvent.SetException(cacheEvent.Exception);
                copyEvent.SetItemSize(cacheEvent.ItemSize);
                copyEvent.SetResourceId(cacheEvent.ResourceId);
                return(copyEvent);
            }
コード例 #2
0
        private string VerifyListenerOnWriteSuccessAndGetResourceId(
            ICacheKey key,
            long itemSize)
        {
            DuplicatingCacheEventListener listener = (DuplicatingCacheEventListener)_cacheEventListener;

            Assert.IsTrue(listener.GetEvents("OnWriteSuccess").Count != 0);
            SettableCacheEvent cacheEvent = (SettableCacheEvent)listener.GetLastEvent("OnWriteSuccess");

            Assert.IsNotNull(cacheEvent);
            Assert.AreEqual(cacheEvent.CacheKey, key);
            Assert.AreEqual(cacheEvent.ItemSize, itemSize);
            Assert.IsNotNull(cacheEvent.ResourceId);
            return(cacheEvent.ResourceId);
        }
コード例 #3
0
        private void VerifyListenerOnEviction(
            string[] resourceIds,
            long[] itemSizes,
            EvictionReason reason,
            long cacheSizeBeforeEviction)
        {
            int numberItems = resourceIds.Length;
            DuplicatingCacheEventListener listener    = (DuplicatingCacheEventListener)_cacheEventListener;
            IList <ICacheEvent>           cacheEvents = listener.GetEvents("OnEviction");

            Assert.IsTrue(cacheEvents.Count == numberItems);

            bool[] found            = new bool[numberItems];
            long   runningCacheSize = cacheSizeBeforeEviction;

            // The eviction order is unknown so make allowances for them coming in different orders
            foreach (var cacheEvent in cacheEvents)
            {
                Assert.IsNotNull(cacheEvent);
                SettableCacheEvent settableCacheEvent = (SettableCacheEvent)cacheEvent;
                for (int i = 0; i < numberItems; i++)
                {
                    if (!found[i] && resourceIds[i].Equals(settableCacheEvent.ResourceId))
                    {
                        found[i] = true;
                        Assert.IsTrue(settableCacheEvent.ItemSize != 0);
                        Assert.IsNotNull(settableCacheEvent.EvictionReason);
                    }
                }

                runningCacheSize -= settableCacheEvent.ItemSize;
                Assert.IsTrue(settableCacheEvent.CacheSize == runningCacheSize);
            }

            // Ensure all resources were found
            for (int i = 0; i < numberItems; i++)
            {
                Assert.IsTrue(found[i], $"Expected eviction of resource { resourceIds[i] } but wasn't evicted");
            }
        }
コード例 #4
0
        public void TestRecycleClearsAllFields()
        {
            SettableCacheEvent cacheEvent = SettableCacheEvent.Obtain();

            cacheEvent.SetCacheKey(default(ICacheKey));
            cacheEvent.SetCacheLimit(21);
            cacheEvent.SetCacheSize(12332445);
            cacheEvent.SetEvictionReason(EvictionReason.CACHE_MANAGER_TRIMMED);
            cacheEvent.SetException(new IOException());
            cacheEvent.SetItemSize(1435);
            cacheEvent.SetResourceId("sddqrtyjf");

            cacheEvent.Recycle();

            Assert.IsNull(cacheEvent.CacheKey);
            Assert.AreEqual(cacheEvent.CacheLimit, 0);
            Assert.AreEqual(cacheEvent.CacheSize, 0);
            Assert.AreEqual(cacheEvent.EvictionReason, EvictionReason.NONE);
            Assert.IsNull(cacheEvent.Exception);
            Assert.AreEqual(cacheEvent.ItemSize, 0);
            Assert.IsNull(cacheEvent.ResourceId);
        }