public void Update_EmptyDirectory_ShouldFetchFileAndUpdateIt() { _fileProvider.GetDirectoryContents(Arg.Any <string>()).Returns(Substitute.For <IDirectoryContents>()); _remoteFileSizeFetcherGateway.GetFileContent(Arg.Any <string>()).Returns(new RemoteFileFetcherGatewayResponse()); _remoteFileSizeFetcherGateway.GetFileContent(Arg.Is <string>(x => x.EndsWith("txt"))).Returns(new RemoteFileFetcherGatewayResponse { Content = Encoding.UTF8.GetBytes("a=b") }); _fetcher.Update().Wait(); _processHelper.Received(3).Start(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }
public async Task <IActionResult> PostUpdateData(UpdateRequest request) { if (!RebuildSemaphore.WaitOne(0)) { return(BadRequest("Can't run two full updates in parallel")); } try { if (!IsRequestLocal()) { return(BadRequest("This operation can't be done from a remote client, please run this from the server")); } if (request == null || request.Routing == false && request.Highways == false && request.PointsOfInterest == false && request.UpdateOsmFile == false && request.DownloadOsmFile == false && request.Images == false && request.SiteMap == false) { request = new UpdateRequest { Routing = true, Highways = true, PointsOfInterest = true, UpdateOsmFile = true, DownloadOsmFile = true, SiteMap = true, Images = true }; _logger.LogInformation("No specific filters were applied, updating all databases."); } _logger.LogInformation("Starting updating site's databases according to request: " + JsonConvert.SerializeObject(request)); await _osmLatestFileFetcherExecutor.Update(request.DownloadOsmFile, request.UpdateOsmFile); _logger.LogInformation("Update OSM file completed."); await _databasesUpdaterService.Rebuild(request); _logger.LogInformation("Finished updating site's databases according to request"); return(Ok()); } finally { RebuildSemaphore.Release(); } }
public void PutUpdateData_WhileRebuildIsRunning_ShouldNotUpdate() { var changes = new OsmChange { Create = new OsmGeo[] { new Node() } }; _osmLatestFileFetcherExecutor.Update().Returns(Task.Delay(100)); _osmLatestFileFetcherExecutor.GetUpdates().Returns(CreateStream(changes)); SetupContext(IPAddress.Parse("1.2.3.4"), IPAddress.Loopback); _controller.PostUpdateData(new UpdateRequest()).ContinueWith((t) => { }); var results = _controller.PutUpdateData().Result as BadRequestObjectResult; _databasesUpdaterService.DidNotReceive().Update(Arg.Is <OsmChange>(x => x.Create.Length == changes.Create.Length)); Assert.IsNotNull(results); }