Ejemplo n.º 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);
        }
Ejemplo n.º 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
        }
Ejemplo n.º 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
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
0
 /// <inheritdoc />
 public override void RefreshData(BoundingBox extent, double resolution, ChangeType changeType)
 {
     if (Enabled && extent.GetArea() > 0 && _tileFetchDispatcher != null && MaxVisible >= resolution && MinVisible <= resolution)
     {
         _tileFetchDispatcher.SetViewport(extent, resolution);
         _tileFetchDispatcher.StartFetching();
     }
 }
Ejemplo n.º 9
0
 /// <inheritdoc />
 public void RefreshData(FetchInfo fetchInfo)
 {
     if (Enabled &&
         fetchInfo.Extent?.GetArea() > 0 &&
         MaxVisible >= fetchInfo.Resolution &&
         MinVisible <= fetchInfo.Resolution)
     {
         _tileFetchDispatcher.SetViewport(fetchInfo);
         _tileFetchDispatcher.StartFetching();
     }
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }