コード例 #1
0
        public void Test_TRexSpatialMemoryCacheStorageTests_FillWithElementsThenOverflowBy(int numElements, int overflowBy)
        {
            var storage    = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(numElements, numElements / 2);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);

            // Fill all available slots
            for (int i = 0; i < numElements; i++)
            {
                storage.Add(new TRexSpatialMemoryCacheContextTests_Element
                {
                    SizeInBytes  = 0,
                    CacheOriginX = (int)(2000 + i * SubGridTreeConsts.SubGridTreeDimension),
                    CacheOriginY = (int)(3000 + i * SubGridTreeConsts.SubGridTreeDimension)
                }, dummyCache);
            }

            Assert.False(storage.HasFreeSpace(), "Storage has free space when filled");

            for (int i = 0; i < overflowBy; i++)
            {
                storage.Add(new TRexSpatialMemoryCacheContextTests_Element
                {
                    SizeInBytes  = 0,
                    CacheOriginX = (int)(2000 + (numElements + i) * SubGridTreeConsts.SubGridTreeDimension),
                    CacheOriginY = (int)(3000 + (numElements + i) * SubGridTreeConsts.SubGridTreeDimension)
                }, dummyCache);
            }

            Assert.True(storage.TokenCount == numElements, $"Element count incorrect (= {storage.TokenCount})");
        }
コード例 #2
0
        public void Test_TRexSpatialMemoryCacheStorageTests_TimeCheckReusingElements(int numElements, int overflowBy)
        {
            var storage    = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(numElements, numElements / 2);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);

            var startTime = DateTime.Now;

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

            // Fill all available slots
            for (int i = 0; i < numElements; i++)
            {
                storage.Add(item, null);
            }

            var midTime = DateTime.Now;

            for (int i = 0; i < overflowBy; i++)
            {
                storage.Add(item, dummyCache);
            }

            Assert.False(true, $"Time for adding {numElements} elements is {midTime - startTime} and adding {overflowBy} overflows is {DateTime.Now - midTime}");
        }
コード例 #3
0
        public void Test_TRexSpatialMemoryCacheStorageTests_TimeCheckCreatingElements(int numElements, int overflowBy)
        {
            var storage    = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(numElements, numElements / 2);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);

            var startTime = DateTime.Now;

            // Fill all available slots
            for (int i = 0; i < numElements; i++)
            {
                storage.Add(new TRexSpatialMemoryCacheContextTests_Element
                {
                    SizeInBytes  = 1000,
                    CacheOriginX = (int)(2000 + i * SubGridTreeConsts.SubGridTreeDimension),
                    CacheOriginY = (int)(3000 + i * SubGridTreeConsts.SubGridTreeDimension)
                }, dummyCache);
            }

            var midTime = DateTime.Now;

            for (int i = 0; i < overflowBy; i++)
            {
                storage.Add(new TRexSpatialMemoryCacheContextTests_Element
                {
                    SizeInBytes  = 1000,
                    CacheOriginX = (int)(1000 + (numElements + i) * SubGridTreeConsts.SubGridTreeDimension),
                    CacheOriginY = (int)(1000 + (numElements + i) * SubGridTreeConsts.SubGridTreeDimension)
                }, dummyCache);
            }

            Assert.False(true, $"Time for adding {numElements} elements is {midTime - startTime} and adding {overflowBy} overflows is {DateTime.Now - midTime}");
        }
コード例 #4
0
        public void Test_TRexCacheItem_Creation_Specific()
        {
            var storage    = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(10, 5);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);

            var theObject = new TRexSpatialMemoryCacheContextTests_Element();
            TRexCacheItem <TRexSpatialMemoryCacheContextTests_Element> item = new TRexCacheItem <TRexSpatialMemoryCacheContextTests_Element>(theObject, dummyCache, 100, 1, 2);

            Assert.True(ReferenceEquals(item.Item, theObject));
            Assert.True(item.Prev == 1);
            Assert.True(item.Next == 2);
            Assert.True(item.MRUEpochToken == 100);
        }
コード例 #5
0
        public void Test_TRexSpatialMemoryCacheStorageTests_AddOneElement()
        {
            ITRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem> storage = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);

            storage.Add(new TRexSpatialMemoryCacheContextTests_Element
            {
                SizeInBytes  = 0,
                CacheOriginX = 2000,
                CacheOriginY = 3000
            }, dummyCache);

            Assert.True(storage.HasFreeSpace(), "Storage has no free space when filled with only one element");

            Assert.True(storage.TokenCount == 1, $"Element count incorrect (= {storage.TokenCount})");
        }
コード例 #6
0
        public void Test_TRexSpatialMemoryCacheStorageTests_MaxEpochTokenAgeOnGet()
        {
            var storage    = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(1000, 500);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);

            // Fill half slots
            for (int i = 0; i < 500; i++)
            {
                storage.Add(new TRexSpatialMemoryCacheContextTests_Element()
                {
                    CacheOriginX = (int)(1000 + i * SubGridTreeConsts.SubGridTreeDimension),
                    CacheOriginY = 1000,
                    SizeInBytes  = 1000
                }, dummyCache);
            }

            var currentMRUHead = storage.MRUHead;

            // Get each item in the same order and verify they are not touched and moved to the MRUHead
            for (int i = 0; i < 500; i++)
            {
                var item = storage.Get(i);

                Assert.True(storage.MRUHead == currentMRUHead, $"MRUHead changed unexpectedly after getting item {item}: storage.MRUHead = {storage.MRUHead}, currentMRUHead = {currentMRUHead}");
            }

            // Fill remaining slots
            for (int i = 500; i < 1000; i++)
            {
                storage.Add(new TRexSpatialMemoryCacheContextTests_Element()
                {
                    CacheOriginX = (int)(1000 + i * SubGridTreeConsts.SubGridTreeDimension),
                    CacheOriginY = 1000,
                    SizeInBytes  = 1000
                }, dummyCache);
            }

            // Get each item in the same order and verify they are touched and moved to the MRUHead
            for (int i = 0; i < 1000; i++)
            {
                var item = storage.Get(i);

                Assert.True(storage.MRUHead == i, $"Referenced item not promoted to MRU head after getting item {item} at index {i}, MRUHead = {storage.MRUHead}");
            }
        }
コード例 #7
0
        public void Test_TRexSpatialMemoryCacheStorageTests_RemoveOneElement()
        {
            var storage    = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);

            var index = storage.Add(new TRexSpatialMemoryCacheContextTests_Element
            {
                SizeInBytes  = 0,
                CacheOriginX = 2000,
                CacheOriginY = 3000
            }, dummyCache);

            Assert.True(storage.TokenCount == 1, $"Element count incorrect (= {storage.TokenCount})");

            storage.Remove(index);

            Assert.True(storage.TokenCount == 0, $"Element count incorrect (= {storage.TokenCount})");
        }
コード例 #8
0
        public void Test_TRexSpatialMemoryCacheStorageTests_GetElement()
        {
            var storage    = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);

            var item = new TRexSpatialMemoryCacheContextTests_Element
            {
                SizeInBytes  = 0,
                CacheOriginX = 2000,
                CacheOriginY = 3000
            };

            var index = storage.Add(item, dummyCache);

            Assert.True(storage.TokenCount == 1, $"Element count incorrect (= {storage.TokenCount})");

            var getItem = storage.Get(index);

            Assert.True(ReferenceEquals(item, getItem), "Item retrieved from storage not same as item placed in storage");
        }
コード例 #9
0
        public void Test_TRexSpatialMemoryCacheStorageTests_GetAfterRemove()
        {
            var storage    = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50);
            var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage);
            var item       = new TRexSpatialMemoryCacheContextTests_Element
            {
                SizeInBytes  = 0,
                CacheOriginX = 2000,
                CacheOriginY = 3000
            };

            var index = storage.Add(item, dummyCache);

            Assert.True(storage.TokenCount == 1, $"Element count incorrect after add (= {storage.TokenCount})");
            Assert.True(storage.Get(index) != null);

            // Remove the item
            storage.Remove(index);

            Assert.True(storage.Get(index) == null, "Was able to extract item after invalidation");
            Assert.True(storage.TokenCount == 0, $"Element count incorrect after get after invalidation(= {storage.TokenCount})");
        }
コード例 #10
0
        public void Test_TRexSpatialMemoryCacheStorageTests_EvictOneLRUItem_EmptyCache()
        {
            var storage = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50);

            storage.EvictOneLRUItem();
        }