public async Task Sync_Can_Add_DeltaIndexRange_To_Repository() { _syncTestHeight = 10; var expectedData = GenerateSampleData(0, _syncTestHeight, _syncTestHeight); var sync = new Synchroniser(new SyncState(), _peerSyncManager, _deltaCache, _deltaHeightWatcher, _deltaHashProvider, _deltaDfsReader, _deltaIndexService, _mapperProvider, _userOutput, Substitute.For <ILogger>(), _syncTestHeight); sync.SyncCompleted.Subscribe(x => { _manualResetEventSlim.Set(); }); await sync.StartAsync(CancellationToken.None); _manualResetEventSlim.Wait(); var range = _deltaIndexService.GetRange(0, (ulong)_syncTestHeight).Select(x => DeltaIndexDao.ToProtoBuff <DeltaIndex>(x, _mapperProvider)); range.Should().BeEquivalentTo(expectedData.DeltaIndex); }
/// <param name="deltaHeightRequest"></param> /// <param name="channelHandlerContext"></param> /// <param name="senderPeerId"></param> /// <param name="correlationId"></param> /// <returns></returns> protected override DeltaHistoryResponse HandleRequest(DeltaHistoryRequest deltaHeightRequest, IChannelHandlerContext channelHandlerContext, PeerId senderPeerId, ICorrelationId correlationId) { Guard.Argument(deltaHeightRequest, nameof(deltaHeightRequest)).NotNull(); Guard.Argument(channelHandlerContext, nameof(channelHandlerContext)).NotNull(); Guard.Argument(senderPeerId, nameof(senderPeerId)).NotNull(); Logger.Debug("PeerId: {0} requests: {1} deltas from height: {2}", senderPeerId, deltaHeightRequest.Range, deltaHeightRequest.Height); var rangeDao = _deltaIndexService.GetRange(deltaHeightRequest.Height, deltaHeightRequest.Range) .ToList(); var range = rangeDao.Select(x => DeltaIndexDao.ToProtoBuff <DeltaIndex>(x, _mapperProvider)).ToList(); var response = new DeltaHistoryResponse(); response.DeltaIndex.Add(range); return(response); }