Пример #1
0
        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.");
            }
        }
Пример #2
0
        public void SynchronizeSplits_ShouldFetchSplits()
        {
            // Act.
            _synchronizer.SynchronizeSplits();

            // Assert.
            _splitFetcher.Verify(mock => mock.FetchSplits(), Times.Once);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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}");
            }
        }