private async void ExecuteAsync() { try { _log.Debug($"Splits Worker, Token: {_cancellationTokenSource.IsCancellationRequested}; Running: {_running}."); while (!_cancellationTokenSource.IsCancellationRequested && _running) { // Wait indefinitely until a segment is queued if (_queue.TryTake(out long changeNumber, -1, _cancellationTokenSource.Token)) { _log.Debug($"ChangeNumber dequeue: {changeNumber}"); await _synchronizer.SynchronizeSplits(changeNumber); } } } catch (Exception ex) { _log.Error($"Execute: {ex.Message}"); } finally { _log.Debug("Split Worker execution finished."); } }
public void SynchronizeSplits_ShouldFetchSplits() { // Act. _synchronizer.SynchronizeSplits(); // Assert. _splitFetcher.Verify(mock => mock.FetchSplits(), Times.Once); }
public void SynchronizeSplits_ShouldFetchSplits() { // Arrange. _splitFetcher .Setup(mock => mock.FetchSplits(It.IsAny <FetchOptions>())) .ReturnsAsync(new FetchResult()); _splitCache .SetupSequence(mock => mock.GetChangeNumber()) .Returns(-1) .Returns(2); // Act. _synchronizer.SynchronizeSplits(1); // Assert. _splitFetcher.Verify(mock => mock.FetchSplits(It.IsAny <FetchOptions>()), Times.Once); _segmentFetcher.Verify(mock => mock.FetchSegmentsIfNotExists(It.IsAny <IList <string> >()), Times.Once); }
private async void ExecuteAsync() { try { while (!_cancellationTokenSource.IsCancellationRequested && _running) { //Wait indefinitely until a segment is queued if (_queue.TryTake(out long changeNumber, -1)) { _log.Debug($"ChangeNumber dequeue: {changeNumber}"); if (changeNumber > _splitCache.GetChangeNumber()) { await _synchronizer.SynchronizeSplits(); } } } } catch (Exception ex) { _log.Error($"Execute: {ex.Message}"); } }