Beispiel #1
0
        public void Test_TRexSpatialMemoryCacheContext_MarkForRemovalViaLastElementRemoved()
        {
            ITRexSpatialMemoryCacheContext context =
                new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(100, 1000000, 0.5),
                                                  new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50));

            Assert.False(context.MarkedForRemoval);

            var currentDate = DateTime.UtcNow;
            var element     = new TRexSpatialMemoryCacheContextTests_Element {
                SizeInBytes = 1000, CacheOriginX = 2000, CacheOriginY = 3000
            };

            Assert.True(context.OwnerMemoryCache.Add(context, element, context.InvalidationVersion) == CacheContextAdditionResult.Added, "Result is false on addition of first element");
            Assert.True(!context.MarkedForRemoval && context.TokenCount == 1);

            context.Remove(element);

            Assert.True(context.MarkedForRemoval, "Removing last element in context for removal did not mark for removal");
            Assert.True(context.MarkedForRemovalAtUtc >= currentDate, "Removal date not expected");
        }
Beispiel #2
0
        public void Test_TRexSpatialMemoryCacheContext_RemoveOneElement()
        {
            ITRexSpatialMemoryCacheContext context =
                new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(100, 1000000, 0.5),
                                                  new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50));

            var element = new TRexSpatialMemoryCacheContextTests_Element {
                SizeInBytes = 1000, CacheOriginX = 2000, CacheOriginY = 3000
            };

            context.OwnerMemoryCache.Add(context, element, context.InvalidationVersion).Should().Be(CacheContextAdditionResult.Added);;

            Assert.True(context.TokenCount == 1, $"Element count incorrect (= {context.TokenCount})");
            Assert.True(context.MRUList.TokenCount == 1, $"MRU list count incorrect (= {context.MRUList.TokenCount})");

            // Check the newly added element in the context is present in the context map with a 1-based index
            Assert.True(context.ContextTokens[element.CacheOriginX >> SubGridTreeConsts.SubGridIndexBitsPerLevel, element.CacheOriginY >> SubGridTreeConsts.SubGridIndexBitsPerLevel] == 1,
                        "Single newly added element does not have index of 1 present in ContextTokens");

            context.Remove(element);

            Assert.True(context.ContextTokens[element.CacheOriginX >> SubGridTreeConsts.SubGridIndexBitsPerLevel, element.CacheOriginY >> SubGridTreeConsts.SubGridIndexBitsPerLevel] == 0, "Removed element did not reset ContextTokens index to 0");
        }