예제 #1
0
        public void Notify_TAGFileDerivedChangeMap_SiteModelsMediatedNotification()
        {
            // Build a site model from a TAG file and verify there is a change map written to the queue that matches the existence map
            // for the newly created model
            var tagFiles = new[]
            {
                Path.Combine(TestHelper.CommonTestDataPath, "TestTAGFile.tag"),
            };

            var siteModel = DITAGFileAndSubGridRequestsFixture.BuildModel(tagFiles, out _);

            // The notifier uses the non-transacted storage proxy:
            var proxy = DIContext.Obtain <Func <IStorageProxyCache <ISiteModelChangeBufferQueueKey, ISiteModelChangeBufferQueueItem> > >()();

            proxy.Should().NotBeNull();

            // Check the new item was placed into the cache
            var testProxy = proxy as IStorageProxyCacheTransacted_TestHarness <ISiteModelChangeBufferQueueKey, ISiteModelChangeBufferQueueItem>;

            testProxy.GetPendingTransactedWrites().Count.Should().Be(1);
            var cachedItem = testProxy.GetPendingTransactedWrites().Values.First();

            cachedItem.Should().NotBeNull();
            cachedItem.ProjectUID.Should().Be(siteModel.ID);
            cachedItem.Operation.Should().Be(SiteModelChangeMapOperation.AddSpatialChanges);
            cachedItem.Origin.Should().Be(SiteModelChangeMapOrigin.Ingest);

            var readMap = new SubGridTreeSubGridExistenceBitMask();

            readMap.FromBytes(cachedItem.Content);

            readMap.CountBits().Should().Be(12);
            readMap.CountBits().Should().Be(siteModel.ExistenceMap.CountBits());
            readMap.ScanAllSetBitsAsSubGridAddresses(x => siteModel.ExistenceMap[x.X >> SubGridTreeConsts.SubGridIndexBitsPerLevel, x.Y >> SubGridTreeConsts.SubGridIndexBitsPerLevel].Should().BeTrue());
        }
예제 #2
0
        public void Test_SubGridTreePersistor_Read_NotEmpty()
        {
            // Create an empty subgrid bit mask tree and persist it into a stream
            SubGridTreeSubGridExistenceBitMask masktree = new SubGridTreeSubGridExistenceBitMask();

            masktree.SetCell(100, 100, true);

            MemoryStream MS = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION);

            Assert.True(SubGridTreePersistor.Write(masktree, "Existence", 1, new BinaryWriter(MS, Encoding.UTF8, true)), "SubGridTreePersistor.Write failed");

            SubGridTreeSubGridExistenceBitMask newtree = new SubGridTreeSubGridExistenceBitMask();

            MS.Position = 0;
            Assert.False(SubGridTreePersistor.Read(newtree, "ExistenceXXX", 1, new BinaryReader(MS, Encoding.UTF8, true)), "Incorrect header did not cause failure");

            MS.Position = 0;
            Assert.False(SubGridTreePersistor.Read(newtree, "Existence", 2, new BinaryReader(MS, Encoding.UTF8, true)), "Incorrect version did not cause failure");

            MS.Position = 0;
            Assert.True(SubGridTreePersistor.Read(newtree, "Existence", 1, new BinaryReader(MS, Encoding.UTF8, true)), "SubGridTreePersistor.Read failed");

            Assert.Equal(1, newtree.CountBits());
            Assert.True(newtree.GetCell(100, 100));
        }
예제 #3
0
        public void Notify_EmptyChangeMap(SiteModelChangeMapOrigin origin, SiteModelChangeMapOperation operation)
        {
            var notifier = new SiteModelChangeMapDeltaNotifier();

            // The notifier uses the non-transacted storage proxy:
            var proxy = DIContext.Obtain <Func <IStorageProxyCache <ISiteModelChangeBufferQueueKey, ISiteModelChangeBufferQueueItem> > >()();

            proxy.Should().NotBeNull();
            proxy.Clear();

            var projectUid = Guid.NewGuid();
            var insertUtc  = DateTime.UtcNow;

            // Ask the notifier to notify a new item
            notifier.Notify(projectUid, insertUtc, new SubGridTreeSubGridExistenceBitMask(), origin, operation);

            // Check the new item was placed into the cache
            var cachedItem = proxy.Get(new SiteModelChangeBufferQueueKey(projectUid, insertUtc));

            cachedItem.Should().NotBeNull();
            cachedItem.Operation.Should().Be(operation);
            cachedItem.Origin.Should().Be(origin);

            var readMap = new SubGridTreeSubGridExistenceBitMask();

            readMap.FromBytes(cachedItem.Content);

            readMap.CountBits().Should().Be(0);
        }
예제 #4
0
        private void CompareSiteModels(ISiteModel sm1, ISiteModel sm2,
                                       int expectedExistanceMapSubGridCount, int expectedCallPassCount, int expectedNonNullCelCount)
        {
            var bitCount1 = sm1.ExistenceMap.CountBits();
            var bitCount2 = sm2.ExistenceMap.CountBits();

            // Check both site models have the same number of sub grids in their existence maps
            bitCount1.Should().Be(bitCount2);
            bitCount1.Should().Be(expectedExistanceMapSubGridCount);

            // Check the content of the existence maps is identical
            var testMap = new SubGridTreeSubGridExistenceBitMask();

            testMap.SetOp_OR(sm1.ExistenceMap);
            testMap.SetOp_XOR(sm2.ExistenceMap);
            testMap.CountBits().Should().Be(0);

            // The expected distribution of cell pass counts
            long[] expectedCounts = { 93, 687, 68, 385, 57, 598, 65, 986, 52, 63, 0, 0, 0, 0, 0 };

            // Scan the leaves in each model and count cell passes
            int sm1Count     = 0;
            int sm1LeafCount = 0;

            long[] actualCounts1     = new long[15];
            int    segmentCount1     = 0;
            int    nonNullCellCount1 = 0;

            sm1.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(address =>
            {
                sm1LeafCount++;
                var leaf     = SubGridUtilities.LocateSubGridContaining(sm1.PrimaryStorageProxy, sm1.Grid, address.X, address.Y, sm1.Grid.NumLevels, false, false) as IServerLeafSubGrid;
                var iterator = new SubGridSegmentIterator(leaf, sm1.PrimaryStorageProxy);
                while (iterator.MoveNext())
                {
                    segmentCount1++;
                    TRex.SubGridTrees.Core.Utilities.SubGridUtilities.SubGridDimensionalIterator((x, y) =>
                    {
                        var passCount = iterator.CurrentSubGridSegment.PassesData.PassCount(x, y);
                        sm1Count     += passCount;
                        if (passCount > 0)
                        {
                            nonNullCellCount1++;
                            actualCounts1[passCount - 1]++;
                        }
                    });
                }
            });

            int sm2Count     = 0;
            int sm2LeafCount = 0;

            long[] actualCounts2     = new long[15];
            int    segmentCount2     = 0;
            int    nonNullCellCount2 = 0;

            sm2.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(address =>
            {
                sm2LeafCount++;
                var leaf     = SubGridUtilities.LocateSubGridContaining(sm2.PrimaryStorageProxy, sm2.Grid, address.X, address.Y, sm2.Grid.NumLevels, false, false) as IServerLeafSubGrid;
                var iterator = new SubGridSegmentIterator(leaf, sm2.PrimaryStorageProxy);
                while (iterator.MoveNext())
                {
                    segmentCount2++;
                    TRex.SubGridTrees.Core.Utilities.SubGridUtilities.SubGridDimensionalIterator((x, y) =>
                    {
                        var passCount = iterator.CurrentSubGridSegment.PassesData.PassCount(x, y);
                        sm2Count     += passCount;
                        if (passCount > 0)
                        {
                            nonNullCellCount2++;
                            actualCounts2[passCount - 1]++;
                        }
                    });
                }
            });

            segmentCount1.Should().Be(segmentCount2);
            segmentCount1.Should().Be(sm1LeafCount);

            sm1LeafCount.Should().Be(expectedExistanceMapSubGridCount);
            sm1Count.Should().Be(sm2Count);

            sm2LeafCount.Should().Be(expectedExistanceMapSubGridCount);
            sm1Count.Should().Be(expectedCallPassCount);

            actualCounts1.Should().BeEquivalentTo(actualCounts2);
            actualCounts1.Should().BeEquivalentTo(expectedCounts);

            nonNullCellCount1.Should().Be(nonNullCellCount2);
            nonNullCellCount1.Should().Be(expectedNonNullCelCount);
        }