async void RemoveLeastRecentlyUsedCacheItemWhenOverMaxCacheSize_RemoveItemsFromLinkedDictionary_DoesNotRemoveNonExpiredItems(
            [Frozen] Mock <IReliableStateManagerReplica2> stateManager,
            [Frozen] Mock <IReliableDictionary <string, CachedItem> > cacheItemDict,
            [Frozen] Mock <IReliableDictionary <string, CacheStoreMetadata> > metadataDict,
            [Frozen] Mock <ISystemClock> systemClock,
            [Greedy] ServiceFabricDistributedCacheStoreService cacheStore)
        {
            var cacheValue  = new byte[1000000];
            var currentTime = new DateTime(2019, 2, 1, 1, 0, 0);

            systemClock.SetupGet(m => m.UtcNow).Returns(currentTime);

            var cachedItems = SetupInMemoryStores(stateManager, cacheItemDict);
            var metadata    = SetupInMemoryStores(stateManager, metadataDict);

            await cacheStore.SetCachedItemAsync("1", cacheValue, TimeSpan.FromMinutes(10), null);

            for (var i = 2; i <= 10; i++)
            {
                await cacheStore.SetCachedItemAsync(i.ToString(), cacheValue, TimeSpan.FromSeconds(10), null);
            }

            systemClock.SetupGet(m => m.UtcNow).Returns(currentTime.AddSeconds(10));
            await cacheStore.RemoveLeastRecentlyUsedCacheItemWhenOverMaxCacheSize();

            Assert.Single(cachedItems);
            Assert.Equal("1", metadata["CacheStoreMetadata"].FirstCacheKey);
            Assert.Equal("1", metadata["CacheStoreMetadata"].LastCacheKey);
        }
Esempio n. 2
0
        async void RemoveCachedItemAsync_RemoveItemsFromLinkedDictionary_RemovalWorksWithMalformedMetadata(
            [Frozen] Mock <IReliableStateManagerReplica2> stateManager,
            [Frozen] Mock <IReliableDictionary <string, CachedItem> > cacheItemDict,
            [Frozen] Mock <IReliableDictionary <string, CacheStoreMetadata> > metadataDict,
            [Greedy] ServiceFabricDistributedCacheStoreService cacheStore)
        {
            var cacheValue = Encoding.UTF8.GetBytes("someValue");

            var cachedItems = SetupInMemoryStores(stateManager, cacheItemDict);
            var metadata    = SetupInMemoryStores(stateManager, metadataDict);

            await cacheStore.SetCachedItemAsync("1", cacheValue, TimeSpan.FromSeconds(10), null);

            await cacheStore.SetCachedItemAsync("2", cacheValue, TimeSpan.FromSeconds(10), null);

            await cacheStore.SetCachedItemAsync("3", cacheValue, TimeSpan.FromSeconds(10), null);

            metadata["CacheStoreMetadata"] = new CacheStoreMetadata(int.MaxValue, null, "3");
            await cacheStore.RemoveLeastRecentlyUsedCacheItemWhenOverMaxCacheSize();

            metadata["CacheStoreMetadata"] = new CacheStoreMetadata(int.MaxValue, "Garbage", "3");
            await cacheStore.RemoveLeastRecentlyUsedCacheItemWhenOverMaxCacheSize();
        }