Пример #1
0
        public void TileRequestThatReturnsNullShouldNotBeRequestedAgain()
        {
            // Arrange
            var tileProvider    = new NullTileProvider();
            var tileSchema      = new GlobalSphericalMercator();
            var tileSource      = new TileSource(tileProvider, tileSchema);
            var cache           = new MemoryCache <Feature>();
            var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, (tileInfo) => TileToFeature(tileSource, tileInfo));
            var tileMachine     = new FetchMachine(fetchDispatcher);
            var level           = "3";
            var tilesInLevel    = 64;

            // Act
            fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
            }
            // do it again
            fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
                Thread.Sleep(1);
            }

            // Assert
            Assert.AreEqual(tilesInLevel, tileProvider.TotalCount);
        }
Пример #2
0
        public void TileFetcherWithFailingFetchesShouldTryAgain()
        {
            // Arrange
            var tileProvider    = new FailingTileProvider();
            var tileSchema      = new GlobalSphericalMercator();
            var tileSource      = new TileSource(tileProvider, tileSchema);
            var cache           = new MemoryCache <Feature>();
            var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, (tileInfo) => TileToFeature(tileSource, tileInfo));
            var tileMachine     = new FetchMachine(fetchDispatcher);
            var level           = "3";
            var tilesInLevel    = 64;

            // Act
            fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
            }
            // do it again
            fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
            }

            // Assert
            Assert.AreEqual(tilesInLevel * 2, tileProvider.TotalCount); // tried all tiles twice
        }
Пример #3
0
        public void TileFetcherWithFailingFetchesShouldTryAgain()
        {
            // Arrange
            var tileProvider = new FailingTileProvider();
            var tileSchema   = new GlobalSphericalMercator();
            var tileSource   = new TileSource(tileProvider, tileSchema);

            using var cache = new MemoryCache <IFeature?>();
            var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, async tileInfo => await TileToFeatureAsync(tileSource, tileInfo));
            var tileMachine     = new FetchMachine(fetchDispatcher);
            var level           = 3;
            var tilesInLevel    = 64;
            var fetchInfo       = new FetchInfo(tileSchema.Extent.ToMRect(), tileSchema.Resolutions[level].UnitsPerPixel);

            // Act
            fetchDispatcher.SetViewport(fetchInfo);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
                Thread.Sleep(1);
            }

            // Act again
            fetchDispatcher.SetViewport(fetchInfo);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
                Thread.Sleep(1);
            }

            // Assert
            Assert.AreEqual(tilesInLevel * 2, tileProvider.TotalCount); // tried all tiles twice
        }
Пример #4
0
        public void TileFetcherShouldRequestAllTilesJustOnes()
        {
            // Arrange
            var tileProvider    = new CountingTileProvider();
            var tileSchema      = new GlobalSphericalMercator();
            var tileSource      = new TileSource(tileProvider, tileSchema);
            var cache           = new MemoryCache <Feature>();
            var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, (tileInfo) => TileToFeature(tileSource, tileInfo));
            var tileMachine     = new FetchMachine(fetchDispatcher);
            var level           = "4";
            var expextedTiles   = 256;

            // Act
            // Get all tiles of level 3
            fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel);
            tileMachine.Start();
            // Assert
            while (fetchDispatcher.Busy)
            {
            }

            Assert.AreEqual(expextedTiles, tileProvider.CountByTile.Keys.Count);
            Assert.AreEqual(expextedTiles, tileProvider.CountByTile.Values.Sum());
            Assert.AreEqual(expextedTiles, tileProvider.TotalCount);
        }
Пример #5
0
        public void RepeatedRestartsShouldNotCauseInfiniteLoop()
        {
            // Arrange
            var tileProvider     = new CountingTileProvider();
            var tileSchema       = new GlobalSphericalMercator();
            var tileSource       = new TileSource(tileProvider, tileSchema);
            var cache            = new MemoryCache <Feature>();
            var fetchDispatcher  = new TileFetchDispatcher(cache, tileSource.Schema, (tileInfo) => TileToFeature(tileSource, tileInfo));
            var tileMachine      = new FetchMachine(fetchDispatcher);
            var numberOfWorkers  = 8;
            var numberOfRestarts = 3;

            // Act
            for (int i = 0; i < numberOfRestarts; i++)
            {
                fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions["3"].UnitsPerPixel);
                tileMachine.Start();
                while (fetchDispatcher.Busy)
                {
                }
            }

            // Assert
            Assert.Greater(numberOfWorkers * numberOfRestarts, FetchWorker.RestartCounter);
        }
Пример #6
0
        public void TileFetcherShouldRequestAllTilesJustOnes()
        {
            // Arrange
            var tileProvider = new CountingTileProvider();
            var tileSchema   = new GlobalSphericalMercator();
            var tileSource   = new TileSource(tileProvider, tileSchema);

            using var cache = new MemoryCache <IFeature?>();
            var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, async tileInfo => await TileToFeatureAsync(tileSource, tileInfo));
            var tileMachine     = new FetchMachine(fetchDispatcher);
            var level           = 3;
            var expectedTiles   = 64;

            var fetchInfo = new FetchInfo(tileSchema.Extent.ToMRect(), tileSchema.Resolutions[level].UnitsPerPixel);

            // Act
            // Get all tiles of level 3
            fetchDispatcher.SetViewport(fetchInfo);
            tileMachine.Start();
            // Assert
            while (fetchDispatcher.Busy)
            {
                Thread.Sleep(1);
            }

            Assert.AreEqual(expectedTiles, tileProvider.CountByTile.Keys.Count);
            Assert.AreEqual(expectedTiles, tileProvider.CountByTile.Values.Sum());
            Assert.AreEqual(expectedTiles, tileProvider.TotalCount);
        }
Пример #7
0
        public void RepeatedRestartsShouldNotCauseInfiniteLoop()
        {
            // Arrange
            var tileProvider = new CountingTileProvider();
            var tileSchema   = new GlobalSphericalMercator();
            var tileSource   = new TileSource(tileProvider, tileSchema);

            using var cache = new MemoryCache <IFeature?>();
            var fetchDispatcher  = new TileFetchDispatcher(cache, tileSource.Schema, async tileInfo => await TileToFeatureAsync(tileSource, tileInfo));
            var tileMachine      = new FetchMachine(fetchDispatcher);
            var numberOfWorkers  = 8;
            var numberOfRestarts = 3;
            var fetchInfo        = new FetchInfo(tileSchema.Extent.ToMRect(), tileSchema.Resolutions[3].UnitsPerPixel);

            // Act
            for (var i = 0; i < numberOfRestarts; i++)
            {
                fetchDispatcher.SetViewport(fetchInfo);
                tileMachine.Start();
                while (fetchDispatcher.Busy)
                {
                    Thread.Sleep(1);
                }
            }

            // Assert
            Assert.Greater(numberOfWorkers * numberOfRestarts, FetchWorker.RestartCounter);
        }
Пример #8
0
        public void TilesFetchedShouldNotBeFetchAgain()
        {
            // Arrange
            var tileProvider = new CountingTileProvider();
            var tileSchema   = new GlobalSphericalMercator();
            var tileSource   = new TileSource(tileProvider, tileSchema);

            using var cache = new MemoryCache <IFeature?>();
            var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, tileInfo => TileToFeature(tileSource, tileInfo));
            var tileMachine     = new FetchMachine(fetchDispatcher);
            var level           = 3;
            var expectedTiles   = 64;
            var fetchInfo       = new FetchInfo(tileSchema.Extent.ToMRect(), tileSchema.Resolutions[level].UnitsPerPixel);

            // Act
            fetchDispatcher.SetViewport(fetchInfo);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
                Thread.Sleep(1);
            }
            var countAfterFirstTry = tileProvider.CountByTile.Keys.Count;

            // do it again
            fetchDispatcher.SetViewport(fetchInfo);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
                Thread.Sleep(1);
            }

            // Assert
            Assert.AreEqual(countAfterFirstTry, tileProvider.CountByTile.Values.Sum());
            Assert.AreEqual(expectedTiles, tileProvider.CountByTile.Keys.Count);
            Assert.AreEqual(expectedTiles, tileProvider.CountByTile.Values.Sum());
            Assert.AreEqual(expectedTiles, tileProvider.TotalCount);
        }
Пример #9
0
        public void TileFetcherWithSometimesFailingFetchesShouldTryAgain()
        {
            // Arrange
            var tileProvider = new SometimesFailingTileProvider();
            var tileSchema   = new GlobalSphericalMercator();
            var tileSource   = new TileSource(tileProvider, tileSchema);

            using var cache = new MemoryCache <IFeature?>();
            var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, tileInfo => TileToFeature(tileSource, tileInfo));
            var tileMachine     = new FetchMachine(fetchDispatcher);
            var level           = 3;
            var tilesInLevel    = 64;
            var fetchInfo       = new FetchInfo(tileSchema.Extent.ToMRect(), tileSchema.Resolutions[level].UnitsPerPixel);

            // Act
            fetchDispatcher.SetViewport(fetchInfo);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
                Thread.Sleep(1);
            }

            var tileCountAfterFirstBatch = tileProvider.TotalCount;

            // Act again
            fetchDispatcher.SetViewport(fetchInfo);
            tileMachine.Start();
            while (fetchDispatcher.Busy)
            {
                Thread.Sleep(1);
            }

            // Assert
            Assert.GreaterOrEqual(tileProvider.TotalCount, tileCountAfterFirstBatch);
            Assert.GreaterOrEqual(tileProvider.CountByTile.Values.Sum(), tilesInLevel);
        }